[vtkusers] ImageToPolyDataFilter
Thibault Varacca
thibault.varacca at gmail.com
Mon May 6 08:59:59 EDT 2013
Hello everybody,
I have .raw (binary) files which are segmented data. I load it with a .mhd
file and want to convert it to polydata to finally apply the marching cubes
filter.
but i have the following error :
# JRE version: 7.0_21-b11
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.21-b01 mixed mode
windows-amd64 compressed oops)
# Problematic frame:
# C [vtkHybrid.dll+0x5db28] vtkImageToPolyDataFilter::ProcessImage+0x18
#
# Failed to write core dump. Minidumps are not enabled by default on client
versions of Windows
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/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 code:
import java.lang.reflect.InvocationTargetException;
import javax.swing.SwingUtilities;
import vtk.vtkActor;
import vtk.vtkImageData;
import vtk.vtkImageToPolyDataFilter;
import vtk.vtkMarchingCubes;
import vtk.vtkMetaImageReader;
import vtk.vtkPolyDataMapper;
import vtk.vtkRenderWindow;
import vtk.vtkRenderWindowInteractor;
import vtk.vtkRenderer;
import vtk.vtkSTLWriter;
import vtk.vtkVoxelModeller;
public class MeshVtk implements Runnable {
@Override
public void run() {
String filename = "ressources\\output_piston.xy.mhd";
vtkVoxelModeller voxelModeller = new vtkVoxelModeller();
vtkMarchingCubes marchingcubes = new vtkMarchingCubes();
vtkRenderer renderer = new vtkRenderer();
vtkRenderWindow renderWindow = new vtkRenderWindow();
vtkRenderWindowInteractor interactor = new
vtkRenderWindowInteractor();
vtkPolyDataMapper mapper = new vtkPolyDataMapper();
vtkActor actor = new vtkActor();
double bounds[] = new double[] {};
/* reader */
vtkMetaImageReader reader = new vtkMetaImageReader();
reader.SetFileName(filename);
reader.Update();
vtkImageData img = new vtkImageData();
img = reader.GetOutput();
vtkImageToPolyDataFilter img2poly = new vtkImageToPolyDataFilter();
img2poly.SetInput(img);
img2poly.DecimationOn();
img2poly.SetError(0);
img2poly.DecimationOn();
img2poly.SetDecimationError(0.0);
img2poly.Update();
bounds = reader.GetOutput().GetBounds(); /* bounds */
for (int i = 0; i < 6; i += 2) {
double range = bounds[i + 1] - bounds[i];
bounds[i] = bounds[i] - .1 * range;
bounds[i + 1] = bounds[i + 1] + .1 * range;
}
voxelModeller.SetSampleDimensions(75, 75, 75);
voxelModeller.SetModelBounds(bounds);
voxelModeller.SetScalarTypeToFloat();
voxelModeller.SetMaximumDistance(.1);
voxelModeller.SetInput(reader.GetOutput());
/* marching cubes */
marchingcubes.SetInput(voxelModeller.GetOutput());
marchingcubes.ComputeNormalsOn();
marchingcubes.SetValue(0, 1);
renderer.SetBackground(.1, .2, .3);
renderWindow.AddRenderer(renderer);
interactor.SetRenderWindow(renderWindow);
mapper.SetInput(marchingcubes.GetOutput());
actor.SetMapper(mapper);
renderer.AddActor(actor);
renderWindow.Render();
interactor.Start();
vtkSTLWriter writer = new vtkSTLWriter();
writer.SetFileTypeToBinary();
writer.AddInputConnection(marchingcubes.GetOutputPort());
writer.SetFileName("ressources\\output_piston.xy.stl");
writer.Write();
}
public static void main(String[] args) {
try {
Class.forName("vtk.vtkPanel");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
SwingUtilities.invokeAndWait(new MeshVtk());
} catch (InvocationTargetException | InterruptedException e) {
e.printStackTrace();
}
}
}
I hope somebody could help me to fix this.
Regards,
--
Thibault Varacca
EFREI Promo 2014
06 60 53 11 35
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130506/8ea16ce0/attachment.htm>
More information about the vtkusers
mailing list