Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkContourModelSet.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 #include <algorithm>
17 #include <mitkContourModelSet.h>
18 #include <vtkMath.h>
19 
20 mitk::ContourModelSet::ContourModelSet() : m_Contours(), m_UpdateBoundingBox(true)
21 {
22  this->InitializeEmpty();
23 }
24 
26  : mitk::BaseData(other), m_Contours(other.m_Contours)
27 {
28  this->InitializeTimeGeometry(1);
29 }
30 
32 {
33  this->m_Contours.clear();
34 }
35 
37 {
38  this->InitializeTimeGeometry(1);
39  m_Contours.resize(0);
40 }
41 
43 {
44  this->m_Contours.push_back(&contourModel);
45  m_UpdateBoundingBox = true;
46 }
47 
49 {
50  this->m_Contours.push_back(contourModel);
51  m_UpdateBoundingBox = true;
52 }
53 
55 {
56  if (index >= 0 && static_cast<ContourModelListType::size_type>(index) < this->m_Contours.size())
57  {
58  return this->m_Contours.at(index).GetPointer();
59  }
60  else
61  {
62  return nullptr;
63  }
64 }
65 
67 {
68  return this->m_Contours.empty();
69 }
70 
72 {
73  return &(this->m_Contours);
74 }
75 
77 {
78  auto it = this->m_Contours.begin();
79 
80  auto end = this->m_Contours.end();
81 
82  // search for ContourModel and remove it if exists
83  while (it != end)
84  {
85  if ((*it) == contourModel)
86  {
87  this->m_Contours.erase(it);
88  m_UpdateBoundingBox = true;
89  return true;
90  }
91 
92  it++;
93  }
94 
95  return false;
96 }
97 
99 {
100  if (index >= 0 && static_cast<ContourModelListType::size_type>(index) < this->m_Contours.size())
101  {
102  this->m_Contours.erase(this->m_Contours.begin() + index);
103  m_UpdateBoundingBox = true;
104  return true;
105  }
106  else
107  {
108  return false;
109  }
110 }
111 
113 {
114  this->m_Contours.clear();
115  m_UpdateBoundingBox = true;
116 }
117 
119 {
120  if (this->GetSource())
121  {
122  this->GetSource()->UpdateOutputInformation();
123  }
124 
125  if (this->m_UpdateBoundingBox)
126  {
127  // update the bounds of the geometry according to the stored vertices
128  mitk::ScalarType mitkBounds[6];
129 
130  // calculate the boundingbox at each timestep
131  typedef itk::BoundingBox<unsigned long, 3, ScalarType> BoundingBoxType;
132  typedef BoundingBoxType::PointsContainer PointsContainer;
133 
134  int timesteps = this->GetTimeSteps();
135 
136  // iterate over the timesteps
137  for (int currenTimeStep = 0; currenTimeStep < timesteps; currenTimeStep++)
138  {
139  // only update bounds if the contour was modified
140  if (this->GetMTime() > this->GetGeometry(currenTimeStep)->GetBoundingBox()->GetMTime())
141  {
142  mitkBounds[0] = 0.0;
143  mitkBounds[1] = 0.0;
144  mitkBounds[2] = 0.0;
145  mitkBounds[3] = 0.0;
146  mitkBounds[4] = 0.0;
147  mitkBounds[5] = 0.0;
148 
150 
152 
153  auto contoursIt = this->Begin();
154  auto contoursEnd = this->End();
155 
156  while (contoursIt != contoursEnd)
157  {
158  auto it = contoursIt->GetPointer()->Begin(currenTimeStep);
159  auto end = contoursIt->GetPointer()->End(currenTimeStep);
160 
161  // fill the boundingbox with the points
162  while (it != end)
163  {
164  Point3D currentP = (*it)->Coordinates;
166  p.CastFrom(currentP);
167  points->InsertElement(points->Size(), p);
168 
169  it++;
170  }
171 
172  ++contoursIt;
173  }
174 
175  // construct the new boundingBox
176  boundingBox->SetPoints(points);
177  boundingBox->ComputeBoundingBox();
178  BoundingBoxType::BoundsArrayType tmp = boundingBox->GetBounds();
179  mitkBounds[0] = tmp[0];
180  mitkBounds[1] = tmp[1];
181  mitkBounds[2] = tmp[2];
182  mitkBounds[3] = tmp[3];
183  mitkBounds[4] = tmp[4];
184  mitkBounds[5] = tmp[5];
185 
186  // set boundingBox at current timestep
187  BaseGeometry *geometry3d = this->GetGeometry(currenTimeStep);
188  geometry3d->SetBounds(mitkBounds);
189  }
190  }
191 
192  this->m_UpdateBoundingBox = false;
193  }
194  GetTimeGeometry()->Update();
195 }
mitk::Point3D PointType
ContourModel is a structure of linked vertices defining a contour in 3D space. The vertices are store...
itk::SmartPointer< Self > Pointer
Base of all data objects.
Definition: mitkBaseData.h:39
virtual void UpdateOutputInformation() override
Update the OutputInformation of a ContourModel object.
double ScalarType
virtual bool RemoveContourModel(mitk::ContourModel *contourModel)
Remove the given ContourModel from the container if exists.
std::deque< mitk::ContourModel::Pointer > ContourModelListType
DataCollection - Class to facilitate loading/accessing structured data.
virtual void InitializeEmpty() override
Pure virtual; Must be used in subclasses to get a data object to a valid state. Should at least creat...
virtual void AddContourModel(mitk::ContourModel &contourModel)
Add a ContourModel to the container.
virtual bool RemoveContourModelAt(int index)
Remove a ContourModel at given index within the container if exists.
ContourModelListType * GetContourModelList()
Returns the container of the contours.
itk::BoundingBox< unsigned long, 3, mitk::ScalarType > BoundingBoxType
void SetBounds(const BoundsArrayType &bounds)
Set the bounding box (in index/unit coordinates)
bool IsEmpty() const override
Returns a bool whether the container is empty or not.
itk::SmartPointer< Self > Pointer
Definition: mitkBaseData.h:42
virtual void Clear() override
Clear the storage container.
virtual mitk::ContourModel * GetContourModelAt(int index) const
Returns the ContourModel a given index.
virtual void InitializeTimeGeometry(unsigned int timeSteps=1)
Initialize the TimeGeometry for a number of time steps. The TimeGeometry is initialized empty and eve...
BaseGeometry Describes the geometry of a data object.
BoundingBoxType::BoundsArrayType BoundsArrayType
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.