19 #include <vtkCellArray.h>
20 #include <vtkImageData.h>
21 #include <vtkPoints.h>
22 #include <vtkPolyData.h>
23 #include <vtkPolygon.h>
24 #include <vtkSmartPointer.h>
35 m_NormalsFilter(NULL),
36 m_DistanceImageCreator(NULL),
37 m_ReferenceImage(NULL),
38 m_SegmentationAsImage(NULL)
49 m_ReferenceImage = referenceImage;
54 if (planarFigure.IsNull())
57 bool newFigure =
true;
58 std::size_t indexOfFigure = 0;
59 for (std::size_t i = 0; i < m_PlanarFigureList.size(); i++)
61 if (m_PlanarFigureList.at(i) == planarFigure)
73 m_PlanarFigureList.push_back(planarFigure);
74 figureAsSurface = this->CreateSurfaceFromPlanarFigure(planarFigure);
75 m_SurfaceList.push_back(figureAsSurface);
76 if (!m_PlanarFigureList.empty())
78 indexOfFigure = m_PlanarFigureList.size() - 1;
83 figureAsSurface = this->CreateSurfaceFromPlanarFigure(planarFigure);
84 m_SurfaceList.at(indexOfFigure) = figureAsSurface;
87 if (m_ReduceFilter.IsNull())
92 m_ReduceFilter->SetInput(indexOfFigure, figureAsSurface);
94 m_NormalsFilter->SetInput(indexOfFigure, m_ReduceFilter->GetOutput(indexOfFigure));
95 m_DistanceImageCreator->SetInput(indexOfFigure, m_NormalsFilter->GetOutput(indexOfFigure));
100 if (planarFigure.IsNull())
103 bool figureFound =
false;
104 std::size_t indexOfFigure = 0;
105 for (std::size_t i = 0; i < m_PlanarFigureList.size(); i++)
107 if (m_PlanarFigureList.at(i) == planarFigure)
118 PlanarFigureListType::iterator whereIter = m_PlanarFigureList.begin();
119 whereIter += indexOfFigure;
120 m_PlanarFigureList.erase(whereIter);
122 SurfaceListType::iterator surfaceIter = m_SurfaceList.begin();
123 surfaceIter += indexOfFigure;
124 m_SurfaceList.erase(surfaceIter);
129 if (
false && indexOfFigure == m_PlanarFigureList.size() - 1)
150 SurfaceListType::iterator surfaceIter = m_SurfaceList.begin();
152 for (surfaceIter = m_SurfaceList.begin(); surfaceIter != m_SurfaceList.end(); surfaceIter++)
154 m_ReduceFilter->SetInput(index, (*surfaceIter));
155 m_NormalsFilter->SetInput(index, m_ReduceFilter->GetOutput(index));
156 m_DistanceImageCreator->SetInput(index, m_NormalsFilter->GetOutput(index));
163 template <
typename TPixel,
unsigned int VImageDimension>
172 m_SegmentationAsImage = NULL;
174 if (m_PlanarFigureList.size() == 0)
177 m_SegmentationAsImage->Initialize(mitk::MakeScalarPixelType<unsigned char>(), *m_ReferenceImage->GetTimeGeometry());
179 return m_SegmentationAsImage;
184 m_DistanceImageCreator->SetReferenceImage(itkImage.GetPointer());
186 m_ReduceFilter->Update();
187 m_NormalsFilter->Update();
188 m_DistanceImageCreator->Update();
193 distanceImage->DisconnectPipeline();
194 m_DistanceImageCreator = NULL;
195 m_NormalsFilter = NULL;
196 m_ReduceFilter = NULL;
201 bool debugOutput(
false);
208 imageToSurfaceFilter->SetInput(distanceImage);
209 imageToSurfaceFilter->SetThreshold(0);
210 imageToSurfaceFilter->Update();
215 segmentationAsSurface->DisconnectPipeline();
216 imageToSurfaceFilter = NULL;
224 surfaceToImageFilter->SetInput(segmentationAsSurface);
225 surfaceToImageFilter->SetImage(m_ReferenceImage);
226 surfaceToImageFilter->SetMakeOutputBinary(
true);
227 surfaceToImageFilter->Update();
229 m_SegmentationAsImage = surfaceToImageFilter->GetOutput();
232 m_SegmentationAsImage->DisconnectPipeline();
234 return m_SegmentationAsImage;
242 MITK_ERROR <<
"Given PlanarFigure is NULL. Please provide valid PlanarFigure.";
257 mitk::PlanarFigure::PolyLineType::iterator iter;
260 int pointCounter = 0;
261 for (iter = planarPolyLine.begin(); iter != planarPolyLine.end(); iter++)
265 figureGeometry->
Map(*iter, pointInWorldCoordiantes);
268 points->InsertNextPoint(pointInWorldCoordiantes[0], pointInWorldCoordiantes[1], pointInWorldCoordiantes[2]);
273 polygon->GetPointIds()->SetNumberOfIds(pointCounter);
274 for (
int i = 0; i < pointCounter; i++)
276 polygon->GetPointIds()->SetId(i, i);
280 cells->InsertNextCell(polygon);
281 polyData->SetPoints(points);
282 polyData->SetPolys(cells);
285 newSurface->SetVtkPolyData(polyData);
293 return m_PlanarFigureList;
300 m_ReduceFilter->SetStepSize(10);
static void Save(const mitk::BaseData *data, const std::string &path)
Save a mitk::BaseData instance.
itk::SmartPointer< Self > Pointer
virtual bool Map(const mitk::Point3D &pt3d_mm, mitk::Point2D &pt2d_mm) const
Project a 3D point given in mm (pt3d_mm) onto the 2D geometry. The result is a 2D point in mm (pt2d_m...
#define AccessFixedDimensionByItk_1(mitkImage, itkImageTypeFunction, dimension, arg1)
Describes a two-dimensional, rectangular plane.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.