嗨,大家好,
有谁知道,为什么Java中的这段代码可以编译,但出现错误:
"An unrecoverable stack overflow has occurred.
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_STACK_OVERFLOW (0xc00000fd) at pc=0x5d05b377, pid=4576, tid=4888
#
# JRE version: 6.0_20-b02
# Java VM: Java HotSpot(TM) Client VM (16.3-b01 mixed mode windows-x86 )
# Problematic frame:
# C [vtkVolumeRendering.dll+0x2eb377]
#
# An error report file with more information is saved as:
# D:\Programme\eclipse-workspace\bachelorarbeit_01\hs_err_pid4576.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug."
这是我从 C++ 代码中复制的 java 源代码:http: //permalink.gmane.org/gmane.comp.lib.vtk.user/35844
import vtk.vtkImageData;
import vtk.vtkUnstructuredGrid;
import vtk.vtkPolyDataMapper;
import vtk.vtkActor;
import vtk.vtkRenderWindow;
import vtk.vtkRenderWindowInteractor;
import vtk.vtkRenderer;
import vtk.vtkPoints;
import vtk.vtkVolume;
import vtk.vtkVoxel;
import vtk.vtkDataSetTriangleFilter;
import vtk.vtkUnstructuredGridVolumeRayCastMapper;
import vtk.vtkPiecewiseFunction;
import vtk.vtkVolumeProperty;
import vtk.vtkColorTransferFunction;
import vtk.vtkExtractEdges;
import vtk.vtkDoubleArray;
import vtk.vtkCellData;
public class Visualizer {
public Visualizer()
{
int nbVoxels = 3*3*3;
int voxelSize = 1;
vtkPoints voxelPoints = new vtkPoints();
voxelPoints.SetNumberOfPoints(8*nbVoxels);
voxelPoints.SetDataTypeToDouble();
vtkUnstructuredGrid grid = new vtkUnstructuredGrid();
grid.Allocate(nbVoxels, voxelSize);
vtkVoxel voxel = new vtkVoxel();
int count = 0;
int posX = 0;
int posY = 0;
int posZ = 0;
for ( int v=0; v<nbVoxels ; v++ )
{
voxelPoints.InsertPoint(count*8+0, posX, posY, posZ);
voxelPoints.InsertPoint(count*8+1, posX+voxelSize, posY, posZ);
voxelPoints.InsertPoint(count*8+2, posX, posY+voxelSize, posZ);
voxelPoints.InsertPoint(count*8+3, posX+voxelSize, posY+voxelSize, posZ);
voxelPoints.InsertPoint(count*8+4, posX, posY, posZ+voxelSize);
voxelPoints.InsertPoint(count*8+5, posX+voxelSize, posY, posZ+voxelSize);
voxelPoints.InsertPoint(count*8+6, posX, posY+voxelSize, posZ+voxelSize);
voxelPoints.InsertPoint(count*8+7, posX+voxelSize, posY+voxelSize, posZ+voxelSize);
voxel.GetPointIds().SetId(0, count*8+0);
voxel.GetPointIds().SetId(1, count*8+1);
voxel.GetPointIds().SetId(2, count*8+2);
voxel.GetPointIds().SetId(3, count*8+3);
voxel.GetPointIds().SetId(4, count*8+4);
voxel.GetPointIds().SetId(5, count*8+5);
voxel.GetPointIds().SetId(6, count*8+6);
voxel.GetPointIds().SetId(7, count*8+7);
grid.InsertNextCell(11, voxel.GetPointIds());
count++;
posX += voxelSize;
if ( posX == 3*voxelSize )
{
posX = 0;
posY += voxelSize;
if ( posY == 3*voxelSize )
{
posY = 0;
posZ += voxelSize;
}
}
}
grid.SetPoints(voxelPoints);
//extract edges from unstructured grid
vtkExtractEdges edges = new vtkExtractEdges();
edges.SetInput(grid);
vtkPolyDataMapper gridMapper = new vtkPolyDataMapper();
gridMapper.SetInput(edges.GetOutput());
vtkActor gridActor = new vtkActor();
gridActor.SetMapper(gridMapper);
gridActor.GetProperty().SetColor(0.0,0.0,0.0);
vtkDoubleArray colourPts = new vtkDoubleArray();
for(int i=0; i < nbVoxels; i++)
colourPts.InsertNextValue(i);
vtkCellData cellData = grid.GetCellData();
cellData.SetNumberOfTuples(nbVoxels);
cellData.SetScalars(colourPts);
//create a transfer function mapping scalar value to color
vtkColorTransferFunction fColor = new vtkColorTransferFunction();
for (int idx = 0; idx < nbVoxels; idx++)
{
fColor.AddRGBPoint(colourPts.GetValue(idx),1, 0, 0);
}
vtkPiecewiseFunction fOpacity = new vtkPiecewiseFunction();
fOpacity.AddPoint(0, 1);
fOpacity.AddPoint(nbVoxels, 1);
vtkVolumeProperty volProp = new vtkVolumeProperty();
volProp.SetColor(fColor);
volProp.SetScalarOpacity(fOpacity);
vtkDataSetTriangleFilter filter = new vtkDataSetTriangleFilter();
filter.SetInput(grid);
vtkUnstructuredGridVolumeRayCastMapper vrcm = new vtkUnstructuredGridVolumeRayCastMapper();
vrcm.SetInput(filter.GetOutput());
vtkVolume volume = new vtkVolume();
volume.SetMapper(vrcm);
volume.SetProperty(volProp);
vtkRenderer renderer = new vtkRenderer();
vtkRenderWindow renderWindow = new vtkRenderWindow();
renderWindow.AddRenderer(renderer);
vtkRenderWindowInteractor renderWindowInteractor = new vtkRenderWindowInteractor();
renderWindowInteractor.SetRenderWindow(renderWindow);
renderer.AddActor(volume);
renderer.AddActor(gridActor);
renderer.SetBackground(1,1,1);
//renderer.ResetCamera();
renderWindow.Render();
renderWindowInteractor.Start();
}
}
谢谢你的帮助!
大卫