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");
174 void ContourFilter::stopPreview()
177 mPreviewImage->stopThresholdPreview();
178 mPreviewImage.reset();
181 void ContourFilter::imageChangedSlot(QString uid)
191 image->getBaseVtkImageData()->GetExtent(extent);
192 mReduceResolutionOption->setHelp(
"Current input resolution: " +
qstring_cast(extent[1])
198 void ContourFilter::thresholdSlot()
203 mPreviewImage = boost::dynamic_pointer_cast<Image>(
mInputTypes[0]->getData());
204 Eigen::Vector2d threshold = Eigen::Vector2d(mSurfaceThresholdOption->getValue(), mPreviewImage->getMax());
205 mPreviewImage->startThresholdPreview(threshold);
231 mRawResult = this->
execute(input->getBaseVtkImageData(),
232 surfaceThresholdOption->getValue(),
233 reduceResolutionOption->getValue(),
234 smoothingOption->getValue(),
235 preserveTopologyOption->getValue(),
236 decimationOption->getValue());
242 bool reduceResolution,
244 bool preserveTopology,
255 shrinker->SetInputData(input);
256 shrinker->SetShrinkFactors(2,2,2);
263 convert->SetInputConnection(shrinker->GetOutputPort());
265 convert->SetInputData(input);
267 convert->SetValue(0, threshold);
279 smoother->SetInputData(cubesPolyData);
280 smoother->SetNumberOfIterations(15);
281 smoother->SetBoundarySmoothing(
false);
282 smoother->SetFeatureEdgeSmoothing(
false);
283 smoother->SetNormalizeCoordinates(
true);
284 smoother->SetFeatureAngle(120);
285 smoother->SetPassBand(0.3);
287 cubesPolyData = smoother->GetOutput();
296 if (decimation > 0.000001)
298 trifilt->SetInputData(cubesPolyData);
300 deci->SetInputConnection(trifilt->GetOutputPort());
301 deci->SetTargetReduction(decimation);
302 deci->SetPreserveTopology(preserveTopology);
305 cubesPolyData = deci->GetOutput();
308 normals->SetInputData(cubesPolyData);
311 cubesPolyData->DeepCopy(normals->GetOutput());
313 return cubesPolyData;
338 if (!contour || !base)
341 QString uid = base->getUid() +
"_ge%1";
342 QString name = base->getName()+
" ge%1";
343 MeshPtr output = patient->createSpecificData<
Mesh>(uid, name);
348 output->get_rMd_History()->setRegistration(base->get_rMd());
349 output->get_rMd_History()->setParentSpace(base->getUid());
351 output->setColor(color);
353 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
ColorPropertyPtr getColorOption(QDomElement root)
BoolPropertyPtr getPreserveTopologyOption(QDomElement root)
std::vector< PropertyPtr > mOptionsAdapters
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
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)