Medical Imaging Interaction Toolkit  2018.4.99-4c24e3cb
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 && timePoint < this->GetMaximumTimePoint();
93 }
94 
96 {
97  return timeStep < this->CountTimeSteps();
98 }
99 
101 {
102  TimePointType result = 0.0;
103 
104  if (timeStep < m_MinimumTimePoints.size() )
105  {
106  result = m_MinimumTimePoints[timeStep];
107  }
108 
109  return result;
110 }
111 
113 {
114  mitk::TimeStepType result = 0;
115 
116  if (timePoint >= GetMinimumTimePoint())
117  {
118  for (auto pos = m_MaximumTimePoints.cbegin(); pos != m_MaximumTimePoints.cend(); ++pos)
119  {
120  if (timePoint < *pos)
121  {
122  break;
123  }
124 
125  ++result;
126  }
127  }
128 
129  return result;
130 }
131 
133 {
134  if ( IsValidTimeStep( timeStep ) )
135  {
136  return m_GeometryVector[timeStep];
137  }
138  else
139  {
140  return nullptr;
141  }
142 }
143 
146 {
147  if ( this->IsValidTimePoint( timePoint ) )
148  {
149  const TimeStepType timeStep = this->TimePointToTimeStep( timePoint );
150  return this->GetGeometryForTimeStep( timeStep );
151  }
152  else
153  {
154  return nullptr;
155  }
156 }
157 
160 {
161  if ( timeStep >= m_GeometryVector.size() )
162  return nullptr;
163  return m_GeometryVector[timeStep]->Clone();
164 }
165 
167 {
168  bool isValid = true;
169  isValid &= m_GeometryVector.size() > 0;
170  return isValid;
171 }
172 
174 {
175  m_GeometryVector.clear();
176  m_MinimumTimePoints.clear();
177  m_MaximumTimePoints.clear();
178 }
179 
181 {
182  m_GeometryVector.reserve( numberOfGeometries );
183  m_MinimumTimePoints.reserve( numberOfGeometries );
184  m_MaximumTimePoints.reserve( numberOfGeometries );
185 }
186 
188 {
189  m_GeometryVector.reserve( size );
190 
191  const mitk::TimeStepType lastIndex = this->CountTimeSteps() - 1;
192  const TimePointType minTP = this->GetMinimumTimePoint( lastIndex );
193  TimePointType maxTP = this->GetMaximumTimePoint( lastIndex );
194  const TimePointType duration = maxTP - minTP;
195 
196  while (m_GeometryVector.size() < size)
197  {
198  m_GeometryVector.push_back( Geometry3D::New().GetPointer() );
199  m_MinimumTimePoints.push_back( maxTP );
200  maxTP += duration;
201  m_MaximumTimePoints.push_back( maxTP );
202  }
203 }
204 
206 {
207  for ( auto pos = m_GeometryVector.begin(); pos != m_GeometryVector.end(); ++pos )
208  {
209  *pos = geometry->Clone();
210  }
211 }
212 
214 {
215  assert( timeStep <= m_GeometryVector.size() );
216 
217  if ( timeStep == m_GeometryVector.size() )
218  {
219  m_GeometryVector.push_back( geometry );
220  }
221 
222  m_GeometryVector[timeStep] = geometry;
223 }
224 
225 itk::LightObject::Pointer mitk::ArbitraryTimeGeometry::InternalClone() const
226 {
227  itk::LightObject::Pointer parent = Superclass::InternalClone();
228  ArbitraryTimeGeometry::Pointer newTimeGeometry = dynamic_cast<ArbitraryTimeGeometry *>(parent.GetPointer());
229  newTimeGeometry->m_MinimumTimePoints = this->m_MinimumTimePoints;
230  newTimeGeometry->m_MaximumTimePoints = this->m_MaximumTimePoints;
231  newTimeGeometry->m_GeometryVector.clear();
232  for (TimeStepType i = 0; i < CountTimeSteps(); ++i)
233  {
234  newTimeGeometry->m_GeometryVector.push_back( this->m_GeometryVector[i]->Clone() );
235  }
236  return parent;
237 }
238 
240  TimePointType minimumTimePoint,
241  TimePointType maximumTimePoint)
242 {
243  if ( !geometry )
244  {
245  mitkThrow() << "Cannot append geometry to time geometry. Invalid geometry passed (nullptr pointer).";
246  }
247 
248  if (maximumTimePoint < minimumTimePoint)
249  {
250  mitkThrow() << "Cannot append geometry to time geometry. Time bound conflict. Maxmimum time point ("<<maximumTimePoint<<") is smaller than minimum time point ("<<minimumTimePoint<<").";
251  }
252 
253  if ( !m_GeometryVector.empty() )
254  {
255  if ( m_MaximumTimePoints.back() > minimumTimePoint )
256  {
257  mitkThrow() << "Cannot append geometry to time geometry. Time bound conflict new time point and currently last time point overlapp.";
258  }
259  }
260 
261  m_GeometryVector.push_back( geometry );
262  m_MinimumTimePoints.push_back( minimumTimePoint );
263  m_MaximumTimePoints.push_back( maximumTimePoint );
264 }
265 
267  TimePointType minimumTimePoint,
268  TimePointType maximumTimePoint)
269 {
270  BaseGeometry::Pointer clone = geometry->Clone();
271 
272  this->AppendNewTimeStep(clone, minimumTimePoint, maximumTimePoint);
273 };
274 
275 void mitk::ArbitraryTimeGeometry::PrintSelf(std::ostream &os, itk::Indent indent) const
276 {
277  Superclass::PrintSelf( os, indent );
278 
279  os << indent << " MinimumTimePoint: " << this->GetMinimumTimePoint() << " ms" << std::endl;
280  os << indent << " MaximumTimePoint: " << this->GetMaximumTimePoint() << " ms" << std::endl;
281 
282  os << std::endl;
283  os << indent << " min TimeBounds: " << std::endl;
284  for (TimeStepType i = 0; i < m_MinimumTimePoints.size(); ++i)
285  {
286  os << indent.GetNextIndent() << "Step " << i << ": " << m_MinimumTimePoints[i] << " ms" << std::endl;
287  }
288  os << std::endl;
289  os << indent << " max TimeBounds: " << std::endl;
290  for (TimeStepType i = 0; i < m_MaximumTimePoints.size(); ++i)
291  {
292  os << indent.GetNextIndent() << "Step " << i << ": " << m_MaximumTimePoints[i] << " ms" << std::endl;
293  }
294 }
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.