14 #include <vtkImageShrink3D.h>
15 #include <vtkMarchingCubes.h>
16 #include <vtkWindowedSincPolyDataFilter.h>
17 #include <vtkTriangleFilter.h>
18 #include <vtkDecimatePro.h>
19 #include <vtkPolyDataNormals.h>
20 #include <vtkImageData.h>
50 return "contour_filter";
57 "<p><i>Find the surface of a binary volume using marching cubes.</i></p>"
58 "<p>- Optional factor 2 reduction</p>"
59 "<p>- Marching Cubes contouring</p>"
60 "<p>- Optional Windowed Sinc smoothing</p>"
61 "<p>- Decimation of triangles</p>"
73 "Reduce input volumes resolution by a factor of 2 in all directions.",
80 "Smooth the output contour",
true, root);
86 "Preserve mesh topology during reduction",
true, root);
92 "Values from this threshold and above will be included",
101 "Reduce number of triangles in output surface",
103 retval->setInternal2Display(100);
110 "Color of output model.",
111 QColor(
"green"), root);
117 "Number of iterations in smoothing filter. Higher number = more smoothing",
124 "Band pass width in smoothing filter. Smaller number = more smoothing",
134 connect(mSurfaceThresholdOption.get(), SIGNAL(
changed()),
this, SLOT(thresholdSlot()));
151 temp->setValueName(
"Input");
152 temp->setHelp(
"Select image input for contouring");
153 connect(temp.get(), SIGNAL(dataChanged(QString)),
this, SLOT(imageChangedSlot(QString)));
162 temp->setValueName(
"Output");
163 temp->setHelp(
"Output contour");
175 void ContourFilter::stopPreview()
178 mPreviewImage->stopThresholdPreview();
179 mPreviewImage.reset();
182 void ContourFilter::imageChangedSlot(QString uid)
192 image->getBaseVtkImageData()->GetExtent(extent);
193 mReduceResolutionOption->setHelp(
"Current input resolution: " +
qstring_cast(extent[1])
199 void ContourFilter::thresholdSlot()
203 mPreviewImage = boost::dynamic_pointer_cast<Image>(
mInputTypes[0]->getData());
206 Eigen::Vector2d threshold = Eigen::Vector2d(mSurfaceThresholdOption->getValue(), mPreviewImage->getMax());
207 mPreviewImage->startThresholdPreview(threshold);
236 mRawResult = this->
execute( input->getBaseVtkImageData(),
237 surfaceThresholdOption->getValue(),
238 reduceResolutionOption->getValue(),
239 smoothingOption->getValue(),
240 preserveTopologyOption->getValue(),
241 decimationOption->getValue(),
242 numberOfIterationsOption->getValue(),
243 passBandOption->getValue());
249 bool reduceResolution,
251 bool preserveTopology,
253 double numberOfIterations,
264 shrinker->SetInputData(input);
265 shrinker->SetShrinkFactors(2,2,2);
272 convert->SetInputConnection(shrinker->GetOutputPort());
274 convert->SetInputData(input);
276 convert->SetValue(0, threshold);
288 smoother->SetInputData(cubesPolyData);
289 smoother->SetNumberOfIterations(numberOfIterations);
290 smoother->SetBoundarySmoothing(
false);
291 smoother->SetFeatureEdgeSmoothing(
false);
292 smoother->SetNormalizeCoordinates(
true);
293 smoother->SetFeatureAngle(120);
294 smoother->SetPassBand(passBand);
296 cubesPolyData = smoother->GetOutput();
305 if (decimation > 0.000001)
307 trifilt->SetInputData(cubesPolyData);
309 deci->SetInputConnection(trifilt->GetOutputPort());
310 deci->SetTargetReduction(decimation);
311 deci->SetPreserveTopology(preserveTopology);
314 cubesPolyData = deci->GetOutput();
318 normals->SetInputData(cubesPolyData);
319 normals->SetComputeCellNormals(
true);
320 normals->AutoOrientNormalsOn();
322 cubesPolyData->DeepCopy(normals->GetOutput());
324 return cubesPolyData;
349 if (!contour || !base)
354 MeshPtr output = patient->createSpecificData<
Mesh>(uid, name);
359 output->get_rMd_History()->setRegistration(base->get_rMd());
360 output->get_rMd_History()->setParentSpace(base->getUid());
362 output->setColor(color);
364 patient->insertData(output);