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.",
false, root);
79 "Smooth the output contour",
true, root);
85 "Preserve mesh topology during reduction",
true, root);
91 "Values from this threshold and above will be included",
100 "Reduce number of triangles in output surface",
102 retval->setInternal2Display(100);
109 "Color of output model.",
110 QColor(
"green"), root);
116 "Number of iterations in smoothing filter. Higher number = more smoothing",
123 "Band pass width in smoothing filter. Smaller number = more smoothing",
133 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()
202 mPreviewImage = boost::dynamic_pointer_cast<
Image>(
mInputTypes[0]->getData());
205 Eigen::Vector2d threshold = Eigen::Vector2d(mSurfaceThresholdOption->getValue(), mPreviewImage->getMax());
206 mPreviewImage->startThresholdPreview(threshold);
235 mRawResult = this->
execute(input->getBaseVtkImageData(),
236 surfaceThresholdOption->getValue(),
237 reduceResolutionOption->getValue(),
238 smoothingOption->getValue(),
239 preserveTopologyOption->getValue(),
240 decimationOption->getValue(),
241 numberOfIterationsOption->getValue(),
242 passBandOption->getValue());
248 bool reduceResolution,
250 bool preserveTopology,
252 double numberOfIterations,
263 shrinker->SetInputData(input);
264 shrinker->SetShrinkFactors(2,2,2);
271 convert->SetInputConnection(shrinker->GetOutputPort());
273 convert->SetInputData(input);
275 convert->SetValue(0, threshold);
287 smoother->SetInputData(cubesPolyData);
288 smoother->SetNumberOfIterations(numberOfIterations);
289 smoother->SetBoundarySmoothing(
false);
290 smoother->SetFeatureEdgeSmoothing(
false);
291 smoother->SetNormalizeCoordinates(
true);
292 smoother->SetFeatureAngle(120);
293 smoother->SetPassBand(passBand);
295 cubesPolyData = smoother->GetOutput();
304 if (decimation > 0.000001)
306 trifilt->SetInputData(cubesPolyData);
308 deci->SetInputConnection(trifilt->GetOutputPort());
309 deci->SetTargetReduction(decimation);
310 deci->SetPreserveTopology(preserveTopology);
313 cubesPolyData = deci->GetOutput();
316 normals->SetInputData(cubesPolyData);
319 cubesPolyData->DeepCopy(normals->GetOutput());
321 return cubesPolyData;
346 if (!contour || !base)
351 MeshPtr output = patient->createSpecificData<
Mesh>(uid, name);
356 output->get_rMd_History()->setRegistration(base->get_rMd());
357 output->get_rMd_History()->setParentSpace(base->getUid());
359 output->setColor(color);
361 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 getPassBandOption(QDomElement root)
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()
DoublePropertyPtr getNumberOfIterationsOption(QDomElement root)
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
boost::shared_ptr< class SelectDataStringPropertyBase > SelectDataStringPropertyBasePtr
virtual void createInputTypes()
virtual QString getHelp() const
static QString getNameSuffix()
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)
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
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)
Namespace for all CustusX production code.