vtk java 体素渲染

发布于 2024-09-10 23:49:32 字数 5963 浏览 5 评论 0原文

大家好,

有人知道为什么 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();     

    }

}

感谢您的帮助!

大卫

Hi Guys,

does anyone knows, why this code in Java compiles,
but an Error appears:

"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."

Here is my java source code which I copied from a C++ code here:
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();     

    }

}

Thanks for your help!

David

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

棒棒糖 2024-09-17 23:49:32

消息

崩溃发生在 Java 虚拟机之外的本机代码中。

应该告诉您错误发生在 java 之外,因此查看 java 代码很可能没有什么帮助。

堆栈溢出(无论何种语言)的典型原因是递归调用永远不会到达基本情况,因此永远不会开始回溯。原因是每次调用该方法都会导致返回地址(引用)被放置在堆栈上,调用越多,存储的返回地址就越多,直到堆栈上没有更多空间。

在其他时间对 vtkVolumeRendering.dll 中发生的这种情况进行了快速谷歌搜索,

链接此处,以防上述情况不起作用:)

http://vtk.1045678.n5.nabble.com/vtkFixedPointVolumeRayCastMapper-Problem-in-java-td1244838.html

the message

The crash happened outside the Java Virtual Machine in native code.

should give you an indication that the error is happening outside of java so looking at the java code will most likely be of little help.

The typical cause of stack overflow (regardless of language) is a recursive call that never reaches a base case and hence never starts back tracking. The reason for this is that each call to the method causes the return address (reference) to be placed on the stack, the more calls that are made the more return addresses are stored until there is no more space on the stack.

did a quick google for this happening in vtkVolumeRendering.dll at other times and found this if it's any help.

link here in case above didn't work :)

http://vtk.1045678.n5.nabble.com/vtkFixedPointVolumeRayCastMapper-Problem-in-java-td1244838.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文