35 #include "Exception.hpp" 36 #include "ImageToSurface.hpp" 37 #include <vtkThreshold.h> 38 #include <vtkGeometryFilter.h> 39 #include <vtkMarchingCubes.h> 40 #include <vtkTriangleFilter.h> 43 ImageToSurface::ImageToSurface()
44 : mpImage(vtkSmartPointer<vtkImageData>::New()),
45 mSegmentAboveThreshold(true),
48 mUseMarchingCubes(false)
53 boost::shared_ptr<ImageToSurface> ImageToSurface::Create()
59 ImageToSurface::~ImageToSurface()
64 vtkSmartPointer<vtkPolyData> ImageToSurface::GetOutput()
72 EXCEPTION(
"No output set. Did you run 'Update()' ?");
76 void ImageToSurface::SetInput(vtkSmartPointer<vtkImageData> pImage)
81 void ImageToSurface::SetInputRaw(vtkImageData* pImage)
87 void ImageToSurface::SetThreshold(
double threshold,
bool segmentAboveThreshold)
89 mThreshold = threshold;
90 mSegmentAboveThreshold = segmentAboveThreshold;
93 void ImageToSurface::SetUseMarchingCubes(
bool useMarchingCubes)
95 mUseMarchingCubes = useMarchingCubes;
98 void ImageToSurface::Update()
102 EXCEPTION(
"No input set.");
105 if(mUseMarchingCubes)
107 vtkSmartPointer<vtkMarchingCubes> p_marching_cubes = vtkSmartPointer<vtkMarchingCubes>::New();
108 #if VTK_MAJOR_VERSION <= 5 109 p_marching_cubes->SetInput(
mpImage);
111 p_marching_cubes->SetInputData(
mpImage);
114 p_marching_cubes->SetValue(0, mThreshold);
115 p_marching_cubes->Update();
117 mpSurface = p_marching_cubes->GetOutput();
121 vtkSmartPointer<vtkThreshold> p_threshold = vtkSmartPointer<vtkThreshold>::New();
122 #if VTK_MAJOR_VERSION <= 5 123 p_threshold->SetInput(
mpImage);
125 p_threshold->SetInputData(
mpImage);
128 if(mSegmentAboveThreshold)
130 p_threshold->ThresholdByUpper(mThreshold);
134 p_threshold->ThresholdByLower(mThreshold);
137 vtkSmartPointer<vtkGeometryFilter> p_geometry = vtkSmartPointer<vtkGeometryFilter>::New();
138 p_geometry->SetInputConnection(p_threshold->GetOutputPort());
139 p_geometry->Update();
141 vtkSmartPointer<vtkTriangleFilter> p_triangle = vtkSmartPointer<vtkTriangleFilter>::New();
142 p_triangle->SetInputConnection(p_geometry->GetOutputPort());
143 p_triangle->Update();
145 mpSurface = p_triangle->GetOutput();
vtkSmartPointer< vtkImageData > mpImage