Medical Imaging Interaction Toolkit  2018.4.99-9a29ffc6
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 #include <limits>
14 
15 #include <algorithm>
16 
17 #include <mitkGeometry3D.h>
18 
20 
22 
24 {
25  this->ClearAllGeometries();
27  geo->Initialize();
28 
29  this->AppendNewTimeStep(geo, 0, 1);
30 
31  Update();
32 }
33 
35 {
36  return static_cast<TimeStepType>(m_GeometryVector.size());
37 }
38 
40 {
41  return m_MinimumTimePoints.empty() ? 0.0 : m_MinimumTimePoints.front();
42 }
43 
45 {
46  TimePointType result = 0;
47  if ( !m_MaximumTimePoints.empty() )
48  {
49  result = m_MaximumTimePoints.back();
50  }
51  return result;
52 }
53 
55 {
57  if (step > 0 && step <= m_MaximumTimePoints.size())
58  {
59  result = m_MaximumTimePoints[step - 1];
60  }
61  return result;
62 };
63 
65 {
66  TimePointType result = 0;
67  if (step < m_MaximumTimePoints.size())
68  {
69  result = m_MaximumTimePoints[step];
70  }
71  return result;
72 };
73 
75 {
76  TimeBounds bounds;
77  bounds[0] = this->GetMinimumTimePoint();
78  bounds[1] = this->GetMaximumTimePoint();
79  return bounds;
80 }
81 
83 {
84  TimeBounds bounds;
85  bounds[0] = this->GetMinimumTimePoint( step );
86  bounds[1] = this->GetMaximumTimePoint( step );
87  return bounds;
88 }
89 
91 {
92  return this->GetMinimumTimePoint() <= timePoint &&
93  (timePoint < this->GetMaximumTimePoint() || (this->HasCollapsedFinalTimeStep() && timePoint <= this->GetMaximumTimePoint()));
94 }
95 
97 {
98  return timeStep < this->CountTimeSteps();
99 }
100 
102 {
103  TimePointType result = 0.0;
104 
105  if (timeStep < m_MinimumTimePoints.size() )
106  {
107  result = m_MinimumTimePoints[timeStep];
108  }
109 
110  return result;
111 }
112 
114 {
115  mitk::TimeStepType result = 0;
116 
117  if (timePoint >= GetMinimumTimePoint())
118  {
119  for (auto pos = m_MaximumTimePoints.cbegin(); pos != m_MaximumTimePoints.cend(); ++pos)
120  {
121  if (timePoint < *pos || (pos==std::prev(m_MaximumTimePoints.cend()) && timePoint <= *pos && this->HasCollapsedFinalTimeStep()))
122  {
123  break;
124  }
125 
126  ++result;
127  }
128  }
129 
130  return result;
131 }
132 
134 {
135  if ( IsValidTimeStep( timeStep ) )
136  {
137  return m_GeometryVector[timeStep];
138  }
139  else
140  {
141  return nullptr;
142  }
143 }
144 
147 {
148  if ( this->IsValidTimePoint( timePoint ) )
149  {
150  const TimeStepType timeStep = this->TimePointToTimeStep( timePoint );
151  return this->GetGeometryForTimeStep( timeStep );
152  }
153  else
154  {
155  return nullptr;
156  }
157 }
158 
161 {
162  if ( timeStep >= m_GeometryVector.size() )
163  return nullptr;
164  return m_GeometryVector[timeStep]->Clone();
165 }
166 
168 {
169  bool isValid = true;
170  isValid &= m_GeometryVector.size() > 0;
171  return isValid;
172 }
173 
175 {
176  m_GeometryVector.clear();
177  m_MinimumTimePoints.clear();
178  m_MaximumTimePoints.clear();
179 }
180 
182 {
183  m_GeometryVector.reserve( numberOfGeometries );
184  m_MinimumTimePoints.reserve( numberOfGeometries );
185  m_MaximumTimePoints.reserve( numberOfGeometries );
186 }
187 
189 {
190  m_GeometryVector.reserve( size );
191 
192  const mitk::TimeStepType lastIndex = this->CountTimeSteps() - 1;
193  const TimePointType minTP = this->GetMinimumTimePoint( lastIndex );
194  TimePointType maxTP = this->GetMaximumTimePoint( lastIndex );
195  const TimePointType duration = maxTP - minTP;
196 
197  while (m_GeometryVector.size() < size)
198  {
199  m_GeometryVector.push_back( Geometry3D::New().GetPointer() );
200  m_MinimumTimePoints.push_back( maxTP );
201  maxTP += duration;
202  m_MaximumTimePoints.push_back( maxTP );
203  }
204 }
205 
207 {
208  for ( auto pos = m_GeometryVector.begin(); pos != m_GeometryVector.end(); ++pos )
209  {
210  *pos = geometry->Clone();
211  }
212 }
213 
215 {
216  assert( timeStep <= m_GeometryVector.size() );
217 
218  if ( timeStep == m_GeometryVector.size() )
219  {
220  m_GeometryVector.push_back( geometry );
221  }
222 
223  m_GeometryVector[timeStep] = geometry;
224 }
225 
226 itk::LightObject::Pointer mitk::ArbitraryTimeGeometry::InternalClone() const
227 {
228  itk::LightObject::Pointer parent = Superclass::InternalClone();
229  ArbitraryTimeGeometry::Pointer newTimeGeometry = dynamic_cast<ArbitraryTimeGeometry *>(parent.GetPointer());
230  newTimeGeometry->m_MinimumTimePoints = this->m_MinimumTimePoints;
231  newTimeGeometry->m_MaximumTimePoints = this->m_MaximumTimePoints;
232  newTimeGeometry->m_GeometryVector.clear();
233  for (TimeStepType i = 0; i < CountTimeSteps(); ++i)
234  {
235  newTimeGeometry->m_GeometryVector.push_back( this->m_GeometryVector[i]->Clone() );
236  }
237  return parent;
238 }
239 
241  TimePointType minimumTimePoint,
242  TimePointType maximumTimePoint)
243 {
244  if ( !geometry )
245  {
246  mitkThrow() << "Cannot append geometry to time geometry. Invalid geometry passed (nullptr pointer).";
247  }
248 
249  if (maximumTimePoint < minimumTimePoint)
250  {
251  mitkThrow() << "Cannot append geometry to time geometry. Time bound conflict. Maxmimum time point ("<<maximumTimePoint<<") is smaller than minimum time point ("<<minimumTimePoint<<").";
252  }
253 
254  if ( !m_GeometryVector.empty() )
255  {
256  if ( m_MaximumTimePoints.back() > minimumTimePoint )
257  {
258  mitkThrow() << "Cannot append geometry to time geometry. Time bound conflict new time point and currently last time point overlapp.";
259  }
260  }
261 
262  m_GeometryVector.push_back( geometry );
263  m_MinimumTimePoints.push_back( minimumTimePoint );
264  m_MaximumTimePoints.push_back( maximumTimePoint );
265 }
266 
268  TimePointType minimumTimePoint,
269  TimePointType maximumTimePoint)
270 {
271  BaseGeometry::Pointer clone = geometry->Clone();
272 
273  this->AppendNewTimeStep(clone, minimumTimePoint, maximumTimePoint);
274 };
275 
276 void mitk::ArbitraryTimeGeometry::PrintSelf(std::ostream &os, itk::Indent indent) const
277 {
278  Superclass::PrintSelf( os, indent );
279 
280  os << indent << " MinimumTimePoint: " << this->GetMinimumTimePoint() << " ms" << std::endl;
281  os << indent << " MaximumTimePoint: " << this->GetMaximumTimePoint() << " ms" << std::endl;
282 
283  os << std::endl;
284  os << indent << " min TimeBounds: " << std::endl;
285  for (TimeStepType i = 0; i < m_MinimumTimePoints.size(); ++i)
286  {
287  os << indent.GetNextIndent() << "Step " << i << ": " << m_MinimumTimePoints[i] << " ms" << std::endl;
288  }
289  os << std::endl;
290  os << indent << " max TimeBounds: " << std::endl;
291  for (TimeStepType i = 0; i < m_MaximumTimePoints.size(); ++i)
292  {
293  os << indent.GetNextIndent() << "Step " << i << ": " << m_MaximumTimePoints[i] << " ms" << std::endl;
294  }
295 }
296 
298 {
299  bool result = false;
300 
301  if (!m_MaximumTimePoints.empty() && !m_MinimumTimePoints.empty())
302  {
303  result = m_MinimumTimePoints.back() == m_MaximumTimePoints.back();
304  }
305 
306  return result;
307 }
void AppendNewTimeStepClone(const BaseGeometry *geometry, TimePointType minimumTimePoint, TimePointType maximumTimePoint)
void ReplaceTimeStepGeometries(const BaseGeometry *geometry) override
Replaces the geometry instances with clones of the passed geometry.
std::vector< TimePointType > m_MinimumTimePoints
itk::FixedArray< ScalarType, 2 > TimeBounds
Standard typedef for time-bounds.
TimeStepType CountTimeSteps() const override
Returns the number of time steps.
Pointer Clone() const
TimePointType GetMaximumTimePoint() const override
Returns the last time point for which the time geometry instance is valid.
static Pointer New()
void PrintSelf(std::ostream &os, itk::Indent indent) const override
void Initialize() override
Initializes a new object with one time steps which contains an empty geometry.
TimePointType TimeStepToTimePoint(TimeStepType timeStep) const override
Converts a time step to a time point.
void ReserveSpaceForGeometries(TimeStepType numberOfGeometries)
void AppendNewTimeStep(BaseGeometry *geometry, TimePointType minimumTimePoint, TimePointType maximumTimePoint)
TimeStepType TimePointToTimeStep(TimePointType timePoint) const override
Converts a time point to the corresponding time step.
TimePointType GetMinimumTimePoint() const override
Returns the first time point for which the time geometry instance is valid.
itk::LightObject::Pointer InternalClone() const override
Makes a deep copy of the current object.
bool IsValidTimeStep(TimeStepType timeStep) const override
Test for the given time step if a geometry is availible.
BaseGeometry::Pointer GetGeometryForTimePoint(TimePointType timePoint) const override
Returns the geometry which corresponds to the given time point.
BaseGeometry::Pointer GetGeometryForTimeStep(TimeStepType timeStep) const override
Returns the geometry which corresponds to the given time step.
static void clone(T *&dst, S *src, int n)
Definition: svm.cpp:59
std::vector< TimePointType > m_MaximumTimePoints
#define mitkThrow()
mitk::ScalarType TimePointType
std::vcl_size_t TimeStepType
void PrintSelf(std::ostream &os, itk::Indent indent) const override
void Expand(TimeStepType size) override
Expands the time geometry to the given number of time steps.
bool IsValidTimePoint(TimePointType timePoint) const override
Tests if a given time point is covered by this time geometry instance.
void SetTimeStepGeometry(BaseGeometry *geometry, TimeStepType timeStep) override
Sets the geometry for the given time step.
BaseGeometry::Pointer GetGeometryCloneForTimeStep(TimeStepType timeStep) const override
Returns the geometry which corresponds to the given time step.
TimeBounds GetTimeBounds() const override
Get the time bounds (in ms) it returns GetMinimumTimePoint() and GetMaximumTimePoint() results as bou...
bool IsValid() const override
Tests if all necessary informations are set and the object is valid.
std::vector< BaseGeometry::Pointer > m_GeometryVector
LightObject::Pointer InternalClone() const override
Makes a deep copy of the current object.
void Update()
Updates the geometry.
BaseGeometry Describes the geometry of a data object.