35 #include <vtkImageShrink3D.h>
36 #include <vtkMarchingCubes.h>
37 #include <vtkWindowedSincPolyDataFilter.h>
38 #include <vtkTriangleFilter.h>
39 #include <vtkDecimatePro.h>
40 #include <vtkPolyDataNormals.h>
41 #include <vtkImageData.h>
71 return "ContourFilter";
78 "<p><i>Find the surface of a binary volume using marching cubes.</i></p>"
79 "<p>- Optional factor 2 reduction</p>"
80 "<p>- Marching Cubes contouring</p>"
81 "<p>- Optional Windowed Sinc smoothing</p>"
82 "<p>- Decimation of triangles</p>"
89 "Reduce input volumes resolution by a factor of 2 in all directions.",
false, root);
95 "Smooth the output contour",
true, root);
101 "Preserve mesh topology during reduction",
true, root);
107 "Values from this threshold and above will be included",
116 "Reduce number of triangles in output surface",
118 retval->setInternal2Display(100);
125 "Color of output model.",
126 QColor(
"green"), root);
135 connect(mSurfaceThresholdOption.get(), SIGNAL(
changed()),
this, SLOT(thresholdSlot()));
150 temp->setValueName(
"Input");
151 temp->setHelp(
"Select image input for contouring");
152 connect(temp.get(), SIGNAL(dataChanged(QString)),
this, SLOT(imageChangedSlot(QString)));
161 temp->setValueName(
"Output");
162 temp->setHelp(
"Output contour");
171 mServices->visualizationService->removePreview();
174 void ContourFilter::imageChangedSlot(QString uid)
176 ImagePtr image = mServices->getPatientService()->getData<
Image>(uid);
181 mServices->visualizationService->removePreview();
184 image->getBaseVtkImageData()->GetExtent(extent);
185 mReduceResolutionOption->setHelp(
"Current input resolution: " +
qstring_cast(extent[1])
191 void ContourFilter::thresholdSlot()
196 std::vector<double> threshold;
197 threshold.push_back(mSurfaceThresholdOption->getValue());
198 mServices->visualizationService->setPreview(image, threshold);
204 mServices->visualizationService->removePreview();
224 mRawResult = this->
execute(input->getBaseVtkImageData(),
225 surfaceThresholdOption->getValue(),
226 reduceResolutionOption->getValue(),
227 smoothingOption->getValue(),
228 preserveTopologyOption->getValue(),
229 decimationOption->getValue());
235 bool reduceResolution,
237 bool preserveTopology,
248 shrinker->SetInputData(input);
249 shrinker->SetShrinkFactors(2,2,2);
256 convert->SetInputConnection(shrinker->GetOutputPort());
258 convert->SetInputData(input);
260 convert->SetValue(0, threshold);
272 smoother->SetInputData(cubesPolyData);
273 smoother->SetNumberOfIterations(15);
274 smoother->SetBoundarySmoothing(
false);
275 smoother->SetFeatureEdgeSmoothing(
false);
276 smoother->SetNormalizeCoordinates(
true);
277 smoother->SetFeatureAngle(120);
278 smoother->SetPassBand(0.3);
280 cubesPolyData = smoother->GetOutput();
289 if (decimation > 0.000001)
291 trifilt->SetInputData(cubesPolyData);
293 deci->SetInputConnection(trifilt->GetOutputPort());
294 deci->SetTargetReduction(decimation);
295 deci->SetPreserveTopology(preserveTopology);
298 cubesPolyData = deci->GetOutput();
301 normals->SetInputData(cubesPolyData);
304 cubesPolyData->DeepCopy(normals->GetOutput());
306 return cubesPolyData;
320 MeshPtr output = this->
postProcess(mServices->getPatientService(), mRawResult, input, colorOption->getValue());
331 if (!contour || !base)
334 QString uid = base->getUid() +
"_ge%1";
335 QString name = base->getName()+
" ge%1";
336 MeshPtr output = patient->createSpecificData<
Mesh>(uid, name);
341 output->get_rMd_History()->setRegistration(base->get_rMd());
342 output->get_rMd_History()->setParentSpace(base->getUid());
344 output->setColor(color);
346 patient->insertData(output);
QString qstring_cast(const T &val)
vtkSmartPointer< class vtkDecimatePro > vtkDecimateProPtr
static BoolPropertyPtr initialize(const QString &uid, QString name, QString help, bool value, QDomNode root=QDomNode())
std::vector< SelectDataStringPropertyBasePtr > mInputTypes
QDomElement mCopiedOptions
DoublePropertyPtr getSurfaceThresholdOption(QDomElement root)
vtkSmartPointer< class vtkMarchingCubes > vtkMarchingCubesPtr
boost::shared_ptr< class ColorProperty > ColorPropertyPtr
virtual void createOptions()
boost::shared_ptr< class VisServices > VisServicesPtr
virtual void setActive(bool on)
virtual bool preProcess()
Utility class for describing a bounded numeric range.
boost::shared_ptr< class Image > ImagePtr
vtkSmartPointer< class vtkWindowedSincPolyDataFilter > vtkWindowedSincPolyDataFilterPtr
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
ColorPropertyPtr getColorOption(QDomElement root)
BoolPropertyPtr getPreserveTopologyOption(QDomElement root)
std::vector< PropertyPtr > mOptionsAdapters
boost::shared_ptr< class SelectDataStringPropertyBase > SelectDataStringPropertyBasePtr
virtual void createInputTypes()
virtual QString getHelp() const
void setVtkPolyData(const vtkPolyDataPtr &polyData)
virtual QString getType() const
virtual void createOutputTypes()
BoolPropertyPtr getSmoothingOption(QDomElement root)
vtkSmartPointer< class vtkPolyDataNormals > vtkPolyDataNormalsPtr
DoublePropertyPtr getDecimationOption(QDomElement root)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
ContourFilter(VisServicesPtr services)
vtkSmartPointer< class vtkTriangleFilter > vtkTriangleFilterPtr
vtkSmartPointer< class vtkImageShrink3D > vtkImageShrink3DPtr
ImagePtr getCopiedInputImage(int index=0)
virtual void setActive(bool on)
boost::shared_ptr< class DoubleProperty > DoublePropertyPtr
virtual QString getName() const
BoolPropertyPtr getReduceResolutionOption(QDomElement root)
std::vector< SelectDataStringPropertyBasePtr > mOutputTypes
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
virtual bool postProcess()
static StringPropertySelectImagePtr New(PatientModelServicePtr patientModelService)
static ColorPropertyPtr initialize(const QString &uid, QString name, QString help, QColor value, QDomNode root=QDomNode())
boost::shared_ptr< class BoolProperty > BoolPropertyPtr
boost::shared_ptr< class Mesh > MeshPtr
void updateThresholdFromImageChange(QString uid, DoublePropertyPtr threshold)