28 #include "vtkAppendPolyData.h" 29 #include "vtkPolyData.h" 30 #include "vtkProperty.h" 31 #include "vtkSmartPointer.h" 33 #include <itkCommand.h> 36 : m_MinSpacing(1.0), m_MaxSpacing(1.0), m_WorkingImage(nullptr), m_ActiveLabel(0)
43 auto it = m_MapOfContourLists.begin();
44 for (; it != m_MapOfContourLists.end(); it++)
46 for (
unsigned int j = 0; j < m_MapOfContourLists[(*it).first].size(); ++j)
48 delete (m_MapOfContourLists[(*it).first].at(j).second);
50 m_MapOfContourLists.erase(it);
57 m_InterpolateSurfaceFilter->SetUseProgressBar(
false);
61 m_InterpolationResult =
nullptr;
68 if (m_Instance ==
nullptr)
79 if (m_ActiveLabel == 0)
82 AffineTransform3D::Pointer transform = AffineTransform3D::New();
88 for (
unsigned int i = 0; i < m_MapOfContourLists[m_ActiveLabel].size(); i++)
90 itk::Matrix<ScalarType> diffM =
91 transform->GetMatrix() - m_MapOfContourLists[m_ActiveLabel].at(i).second->GetTransform()->GetMatrix();
92 bool isSameMatrix(
true);
93 for (
unsigned int j = 0; j < 3; j++)
95 if (fabs(diffM[j][0]) > 0.0001 && fabs(diffM[j][1]) > 0.0001 && fabs(diffM[j][2]) > 0.0001)
101 itk::Vector<float> diffV =
102 m_MapOfContourLists[m_ActiveLabel].at(i).second->GetTransform()->GetOffset() - transform->GetOffset();
103 if (isSameMatrix && m_MapOfContourLists[m_ActiveLabel].at(i).second->GetPos() == op->
GetPos() &&
104 (fabs(diffV[0]) < 0.0001 && fabs(diffV[1]) < 0.0001 && fabs(diffV[2]) < 0.0001))
111 if (pos == -1 && newContour->GetNumberOfVertices() > 0)
115 ContourPositionPair newData = std::make_pair(newContour, newOp);
116 m_MapOfContourLists[m_ActiveLabel].push_back(newData);
120 m_MapOfContourLists[m_ActiveLabel].at(pos).first = newContour;
128 if (m_MapOfContourLists[m_ActiveLabel].size() < 2)
131 m_InterpolationResult =
nullptr;
135 m_InterpolateSurfaceFilter->Reset();
142 vtkSmartPointer<vtkAppendPolyData> polyDataAppender = vtkSmartPointer<vtkAppendPolyData>::New();
144 for (
unsigned int i = 0; i < m_MapOfContourLists[m_ActiveLabel].size(); i++)
147 converter->SetInput(m_MapOfContourLists[m_ActiveLabel].at(i).first);
151 surface->DisconnectPipeline();
154 reduceFilter->SetUseProgressBar(
false);
155 reduceFilter->SetInput(surface);
156 reduceFilter->SetMinSpacing(m_MinSpacing);
157 reduceFilter->SetMaxSpacing(m_MaxSpacing);
158 reduceFilter->Update();
161 normalsFilter->SetUseProgressBar(
false);
162 normalsFilter->SetInput(reduceFilter->GetOutput());
163 normalsFilter->SetMaxSpacing(m_MaxSpacing);
168 m_InterpolateSurfaceFilter->SetInput(i, normalsFilter->GetOutput());
170 polyDataAppender->AddInputData(reduceFilter->GetOutput()->GetVtkPolyData());
173 polyDataAppender->Update();
174 m_Contours->SetVtkPolyData(polyDataAppender->GetOutput());
177 m_InterpolateSurfaceFilter->Update();
178 Image::Pointer distanceImage = m_InterpolateSurfaceFilter->GetOutput();
179 if (distanceImage.IsNull())
182 m_InterpolationResult =
nullptr;
188 imageToSurfaceFilter->SetInput(distanceImage);
189 imageToSurfaceFilter->SetThreshold(0);
190 imageToSurfaceFilter->SetSmooth(
true);
191 imageToSurfaceFilter->SetSmoothIteration(20);
192 imageToSurfaceFilter->Update();
193 m_InterpolationResult = imageToSurfaceFilter->GetOutput();
195 m_InterpolationResult->DisconnectPipeline();
200 return m_InterpolationResult;
210 m_MinSpacing = minSpacing;
215 m_MaxSpacing = maxSpacing;
220 m_DistanceImageVolume = value;
225 m_WorkingImage = workingImage;
230 return m_InterpolateSurfaceFilter->GetOutput();
235 double numberOfPoints = 0.0;
236 for (
unsigned int i = 0; i < m_MapOfContourLists[m_ActiveLabel].size(); i++)
238 numberOfPoints += m_MapOfContourLists[m_ActiveLabel].at(i).first->GetNumberOfVertices() * 3;
241 double sizeOfPoints = pow(numberOfPoints, 2) *
sizeof(double);
243 double percentage = sizeOfPoints / totalMem;
249 if (m_ActiveLabel == activeLabel)
252 if (activeLabel == 0)
255 m_ActiveLabel = activeLabel;
257 auto it = m_MapOfContourLists.find(m_ActiveLabel);
259 if (it == m_MapOfContourLists.end())
261 ContourPositionPairList newList;
262 m_MapOfContourLists.insert(std::pair<unsigned int, ContourPositionPairList>(m_ActiveLabel, newList));
263 m_InterpolationResult =
nullptr;
static vcl_size_t GetTotalSizeOfPhysicalRam()
Class for storing surfaces (vtkPolyData).
static SurfaceBasedInterpolationController * GetInstance()
Surface * GetContoursAsSurface()
Constants for most interaction classes, due to the generic StateMachines.
SurfaceBasedInterpolationController()
void SetMaxSpacing(double maxSpacing)
void AddNewContour(ContourModel::Pointer newContour, RestorePlanePositionOperation *op)
mitk::Surface::Pointer GetInterpolationResult()
void SetActiveLabel(int activeLabel)
void SetDistanceImageVolume(unsigned int value)
Image class for storing images.
void SetWorkingImage(Image *workingImage)
Vector3D GetDirectionVector()
~SurfaceBasedInterpolationController() override
double EstimatePortionOfNeededMemory()
AffineTransform3D::Pointer GetTransform()
void SetMinSpacing(double minSpacing)