Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkArbitraryTimeGeometry.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 <limits>
18 
19 #include <algorithm>
20 
21 #include <mitkGeometry3D.h>
22 
24 {
25 }
26 
28 {
29 }
30 
32 {
33  this->ClearAllGeometries();
35  this->AppendTimeStep(geo, 1, 0);
36 }
37 
39 {
40  return static_cast<TimeStepType>(m_GeometryVector.size());
41 }
42 
44 {
45  return m_MinimumTimePoint;
46 }
47 
49 {
50  TimePointType result = 0;
51  if (!m_MaximumTimePoints.empty())
52  {
53  result = m_MaximumTimePoints.back();
54  }
55  return result;
56 }
57 
59 {
60  TimePointType result = m_MinimumTimePoint;
61  if (step > 0 && step <= m_MaximumTimePoints.size())
62  {
63  result = m_MaximumTimePoints[step - 1];
64  }
65  return result;
66 };
67 
69 {
70  TimePointType result = 0;
71  if (step < m_MaximumTimePoints.size())
72  {
73  result = m_MaximumTimePoints[step];
74  }
75  return result;
76 };
77 
79 {
80  TimeBounds bounds;
81  bounds[0] = this->GetMinimumTimePoint();
82  bounds[1] = this->GetMaximumTimePoint();
83  return bounds;
84 }
85 
87 {
88  TimeBounds bounds;
89  bounds[0] = this->GetMinimumTimePoint(step);
90  bounds[1] = this->GetMaximumTimePoint(step);
91  return bounds;
92 }
93 
95 {
96  return this->GetMinimumTimePoint() <= timePoint && timePoint < this->GetMaximumTimePoint();
97 }
98 
100 {
101  return timeStep < this->CountTimeSteps();
102 }
103 
105 {
106  TimePointType result = 0.0;
107 
108  if (timeStep == 0)
109  {
110  result = m_MinimumTimePoint;
111  }
112  else if (timeStep > 0 && timeStep < m_MaximumTimePoints.size())
113  {
114  result = m_MaximumTimePoints[timeStep - 1];
115  }
116 
117  return result;
118 }
119 
121 {
122  mitk::TimeStepType result = 0;
123 
124  if (timePoint >= m_MinimumTimePoint)
125  {
126  for (std::vector<TimePointType>::const_iterator pos = m_MaximumTimePoints.begin(); pos != m_MaximumTimePoints.end();
127  ++pos)
128  {
129  if (timePoint < *pos)
130  {
131  result = pos - m_MaximumTimePoints.begin();
132  break;
133  }
134  }
135  }
136 
137  return result;
138 }
139 
141 {
142  if (IsValidTimeStep(timeStep))
143  {
144  return dynamic_cast<BaseGeometry *>(m_GeometryVector[timeStep].GetPointer());
145  }
146  else
147  {
148  return 0;
149  }
150 }
151 
153 {
154  if (this->IsValidTimePoint(timePoint))
155  {
156  TimeStepType timeStep = this->TimePointToTimeStep(timePoint);
157  return this->GetGeometryForTimeStep(timeStep);
158  }
159  else
160  {
161  return 0;
162  }
163 }
164 
166 {
167  if (timeStep >= m_GeometryVector.size())
168  return 0;
169  return m_GeometryVector[timeStep]->Clone();
170 }
171 
173 {
174  bool isValid = true;
175  isValid &= m_GeometryVector.size() > 0;
176  return isValid;
177 }
178 
180 {
181  m_GeometryVector.clear();
182  m_MinimumTimePoint = 0;
183  m_MaximumTimePoints.clear();
184 }
185 
187 {
188  m_GeometryVector.reserve(numberOfGeometries);
189  m_MaximumTimePoints.reserve(numberOfGeometries);
190 }
191 
193 {
194  m_GeometryVector.reserve(size);
195 
196  TimeBounds bounds;
197  TimePointType minTP = this->GetMinimumTimePoint(this->CountTimeSteps() - 1);
198  TimePointType maxTP = this->GetMaximumTimePoint(this->CountTimeSteps() - 1);
199  TimePointType duration = maxTP - minTP;
200 
201  while (m_GeometryVector.size() < size)
202  {
203  m_GeometryVector.push_back(Geometry3D::New().GetPointer());
204  maxTP += duration;
205  m_MaximumTimePoints.push_back(maxTP);
206  }
207 }
208 
210 {
211  for (std::vector<BaseGeometry::Pointer>::iterator pos = m_GeometryVector.begin(); pos != m_GeometryVector.end();
212  ++pos)
213  {
214  *pos = geometry->Clone();
215  }
216 }
217 
219 {
220  assert(timeStep < m_GeometryVector.size());
221 
222  if (timeStep >= m_GeometryVector.size())
223  {
224  return;
225  }
226 
227  m_GeometryVector[timeStep] = geometry;
228 }
229 
231 {
232  itk::LightObject::Pointer parent = Superclass::InternalClone();
233  ArbitraryTimeGeometry::Pointer newTimeGeometry = dynamic_cast<ArbitraryTimeGeometry *>(parent.GetPointer());
234  newTimeGeometry->m_MinimumTimePoint = this->m_MinimumTimePoint;
235  newTimeGeometry->m_MaximumTimePoints = this->m_MaximumTimePoints;
236  newTimeGeometry->m_GeometryVector.clear();
237  for (TimeStepType i = 0; i < CountTimeSteps(); ++i)
238  {
239  newTimeGeometry->m_GeometryVector.push_back(this->m_GeometryVector[i]->Clone());
240  }
241  return parent;
242 }
243 
245  TimePointType maximumTimePoint,
246  TimePointType minimumTimePoint)
247 {
248  if (!geometry)
249  {
250  mitkThrow() << "Cannot append geometry to time geometry. Invalid geometry passed (NULL pointer).";
251  }
252 
253  if (!m_GeometryVector.empty())
254  {
255  if (m_MaximumTimePoints.back() > maximumTimePoint)
256  {
257  mitkThrow() << "Cannot append geometry to time geometry. Time bound conflict.";
258  }
259  }
260  else
261  {
262  m_MinimumTimePoint = minimumTimePoint;
263  }
264 
265  m_GeometryVector.push_back(geometry);
266  m_MaximumTimePoints.push_back(maximumTimePoint);
267 }
268 
270  TimePointType maximumTimePoint,
271  TimePointType minimumTimePoint)
272 {
273  BaseGeometry::Pointer clone = geometry->Clone();
274 
275  this->AppendTimeStep(clone, maximumTimePoint, minimumTimePoint);
276 };
277 
278 void mitk::ArbitraryTimeGeometry::PrintSelf(std::ostream &os, itk::Indent indent) const
279 {
280  Superclass::PrintSelf(os, indent);
281 
282  os << indent << " MinimumTimePoint: " << this->GetMinimumTimePoint() << " ms" << std::endl;
283  os << indent << " MaximumTimePoint: " << this->GetMaximumTimePoint() << " ms" << std::endl;
284 
285  os << std::endl;
286  os << indent << " max TimeBounds: " << std::endl;
287  for (TimeStepType i = 0; i < m_MaximumTimePoints.size(); ++i)
288  {
289  os << indent.GetNextIndent() << "Step " << i << ": " << m_MaximumTimePoints[i] << " ms" << std::endl;
290  }
291 }
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const
virtual TimeStepType TimePointToTimeStep(TimePointType timePoint) const
Converts a time point to the corresponding time step.
itk::SmartPointer< Self > Pointer
Pointer Clone() const
virtual bool IsValidTimePoint(TimePointType timePoint) const
Tests if a given time point is covered by this time geometry instance.
itk::FixedArray< ScalarType, 2 > TimeBounds
Standard typedef for time-bounds.
virtual bool IsValidTimeStep(TimeStepType timeStep) const
Test for the given time step if a geometry is availible.
virtual TimeBounds GetTimeBounds() const
Get the time bounds (in ms) it returns GetMinimumTimePoint() and GetMaximumTimePoint() results as bou...
void AppendTimeStep(BaseGeometry *geometry, TimePointType maximumTimePoint, TimePointType minimumTimePoint=0)
virtual bool IsValid() const
Tests if all necessary informations are set and the object is valid.
virtual TimePointType TimeStepToTimePoint(TimeStepType timeStep) const
Converts a time step to a time point.
virtual void Expand(TimeStepType size)
Expands the time geometry to the given number of time steps.
virtual itk::LightObject::Pointer InternalClone() const
Makes a deep copy of the current object.
virtual void ReplaceTimeStepGeometries(const BaseGeometry *geometry)
Replaces the geometry instances with clones of the passed geometry.
static Pointer New()
void AppendTimeStepClone(const BaseGeometry *geometry, TimePointType maximumTimePoint, TimePointType minimumTimePoint=0)
virtual BaseGeometry::Pointer GetGeometryForTimePoint(TimePointType timePoint) const
Returns the geometry which corresponds to the given time point.
void ReserveSpaceForGeometries(TimeStepType numberOfGeometries)
virtual BaseGeometry::Pointer GetGeometryCloneForTimeStep(TimeStepType timeStep) const
Returns the geometry which corresponds to the given time step.
static void clone(T *&dst, S *src, int n)
Definition: svm.cpp:73
virtual BaseGeometry::Pointer GetGeometryForTimeStep(TimeStepType timeStep) const
Returns the geometry which corresponds to the given time step.
#define mitkThrow()
mitk::ScalarType TimePointType
std::vcl_size_t TimeStepType
virtual TimePointType GetMaximumTimePoint() const
Returns the last time point for which the time geometry instance is valid.
virtual void Initialize()
Initializes a new object with one time steps which contains an empty geometry.
virtual TimePointType GetMinimumTimePoint() const
Returns the first time point for which the time geometry instance is valid.
virtual void SetTimeStepGeometry(BaseGeometry *geometry, TimeStepType timeStep)
Sets the geometry for the given time step.
Pointer Clone() const
BaseGeometry Describes the geometry of a data object.
virtual TimeStepType CountTimeSteps() const
Returns the number of time steps.