18 #include <vtkPolyDataNormals.h> 23 : m_UIDGeneratorSurfaces(
"Surface_"),
24 m_IsLabelSetImage(false)
34 Superclass::Initialize(other);
36 bool syncVisibility(
false);
52 m_SurfaceNodes.clear();
64 catch (std::invalid_argument &)
78 bool applyMedian(
true);
81 bool decimateMesh(
true);
84 unsigned int medianKernelSize(3);
87 double gaussianSD(1.5);
90 double reductionRate(0.8);
93 MITK_INFO <<
"Creating polygon model with smoothing " << smooth <<
" gaussianSD " << gaussianSD <<
" median " 94 << applyMedian <<
" median kernel " << medianKernelSize <<
" mesh reduction " << decimateMesh
95 <<
" reductionRate " << reductionRate;
97 auto labelSetImage =
dynamic_cast<LabelSetImage *
>(image.GetPointer());
99 if (
nullptr != labelSetImage)
103 for (decltype(numberOfLayers) layerIndex = 0; layerIndex < numberOfLayers; ++layerIndex)
105 auto labelSet = labelSetImage->GetLabelSet(layerIndex);
107 for (
auto labelIter = labelSet->IteratorConstBegin(); labelIter != labelSet->IteratorConstEnd(); ++labelIter)
109 if (0 == labelIter->first)
112 auto labelImage = labelSetImage->CreateLabelMask(labelIter->first,
false, layerIndex);
114 if (labelImage.IsNull())
117 auto labelSurface = this->ConvertBinaryImageToSurface(labelImage);
119 if (labelSurface.IsNull())
123 node->SetData(labelSurface);
124 node->SetColor(labelIter->second->GetColor());
125 node->SetName(labelIter->second->GetName());
127 m_SurfaceNodes.push_back(node);
133 auto surface = this->ConvertBinaryImageToSurface(image);
135 if (surface.IsNotNull())
138 node->SetData(surface);
139 m_SurfaceNodes.push_back(node);
143 m_IsLabelSetImage =
nullptr != labelSetImage;
149 for (
const auto &node : m_SurfaceNodes)
151 bool wireframe =
false;
157 if (
nullptr != representation)
165 auto name = node->GetName();
168 if (!m_IsLabelSetImage)
171 name = groupNode->GetName();
181 name.append(
" (smoothed)");
185 if (!m_IsLabelSetImage)
187 auto colorProp = groupNode->GetProperty(
"color");
189 if (
nullptr != colorProp)
191 node->ReplaceProperty(
"color", colorProp->Clone());
199 bool showResult =
true;
202 bool syncVisibility =
false;
205 auto visibleProp = groupNode->GetProperty(
"visible");
207 if (
nullptr != visibleProp && syncVisibility)
209 node->ReplaceProperty(
"visible", visibleProp->Clone());
216 if (!m_IsLabelSetImage)
221 if (image.IsNotNull())
223 auto organTypeProp = image->GetProperty(
"organ type");
225 if (
nullptr != organTypeProp)
226 node->GetData()->SetProperty(
"organ type", organTypeProp);
233 Superclass::ThreadedUpdateSuccessful();
241 bool applyMedian =
true;
244 bool decimateMesh =
true;
247 unsigned int medianKernelSize = 3;
250 double gaussianSD = 1.5;
253 double reductionRate = 0.8;
257 filter->SetInput(binaryImage);
258 filter->SetThreshold(0.5);
259 filter->SetUseGaussianImageSmooth(smooth);
260 filter->SetSmooth(smooth);
261 filter->SetMedianFilter3D(applyMedian);
265 filter->InterpolationOn();
266 filter->SetGaussianStandardDeviation(gaussianSD);
270 filter->SetMedianKernelSize(medianKernelSize, medianKernelSize, medianKernelSize);
273 if (binaryImage->GetDimension() > 3)
274 decimateMesh =
false;
279 filter->SetTargetReduction(reductionRate);
286 filter->UpdateLargestPossibleRegion();
288 auto surface = filter->GetOutput();
289 auto polyData = surface->GetVtkPolyData();
291 if (
nullptr == polyData)
292 throw std::logic_error(
"Could not create polygon model");
294 polyData->SetVerts(
nullptr);
295 polyData->SetLines(
nullptr);
297 if (smooth || applyMedian || decimateMesh)
299 auto normals = vtkSmartPointer<vtkPolyDataNormals>::New();
301 normals->AutoOrientNormalsOn();
302 normals->FlipNormalsOff();
303 normals->SetInputData(polyData);
307 surface->SetVtkPolyData(normals->GetOutput());
311 surface->SetVtkPolyData(polyData);
DataNode * GetGroupNode()
void InsertBelowGroupNode(mitk::DataNode *node)
DataCollection - Class to facilitate loading/accessing structured data.
void SetParameter(const char *parameter, const T &value)
For any kind of normal types.
static std::string NO_NAME_VALUE()
void GetParameter(const char *parameter, T &value) const
unsigned int GetNumberOfLayers() const
~ShowSegmentationAsSurface() override
void Initialize(const NonBlockingAlgorithm *other=nullptr) override
void ThreadedUpdateSuccessful() override
ShowSegmentationAsSurface()
mitk::Image::Pointer image
bool ReadyToRun() override
LabelSetImage class for handling labels and layers in a segmentation session.
void GetPointerParameter(const char *parameter, itk::SmartPointer< T > &value) const
virtual void SetRepresentationToWireframe()
bool ThreadedUpdateFunction() override