Medical Imaging Interaction Toolkit  2018.4.99-36d69b77
Medical Imaging Interaction Toolkit
mitkProportionalTimeGeometry.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 mitk::ProportionalTimeGeometry::ProportionalTimeGeometry() : m_FirstTimePoint(0.0), m_StepDuration(1.0)
16 {
17 }
18 
20 {
21 }
22 
24 {
25  m_FirstTimePoint = 0.0;
26  m_StepDuration = 1.0;
27  m_GeometryVector.resize(1);
28 }
29 
31 {
32  return static_cast<TimeStepType>(m_GeometryVector.size());
33 }
34 
36 {
37  return m_FirstTimePoint;
38 }
39 
41 {
43  if (timePoint > std::numeric_limits<TimePointType>().max())
44  timePoint = std::numeric_limits<TimePointType>().max();
45  return timePoint;
46 }
47 
49 {
50  TimeBounds bounds;
51  bounds[0] = this->GetMinimumTimePoint();
52  bounds[1] = this->GetMaximumTimePoint();
53  return bounds;
54 }
55 
57 {
58  TimePointType timePoint;
59  if (step == 0)
60  {
61  timePoint = m_FirstTimePoint;
62  }
63  else
64  {
65  timePoint = m_FirstTimePoint + m_StepDuration * step;
66  }
67  if (timePoint > std::numeric_limits<TimePointType>().max())
68  timePoint = std::numeric_limits<TimePointType>().max();
69  return timePoint;
70 }
71 
73 {
74  TimePointType timePoint = m_FirstTimePoint + m_StepDuration * (step + 1);
75  if (timePoint > std::numeric_limits<TimePointType>().max())
76  timePoint = std::numeric_limits<TimePointType>().max();
77  return timePoint;
78 }
79 
81 {
82  TimeBounds bounds;
83  bounds[0] = this->GetMinimumTimePoint(step);
84  bounds[1] = this->GetMaximumTimePoint(step);
85  return bounds;
86 }
87 
89 {
90  return this->GetMinimumTimePoint() <= timePoint && timePoint < this->GetMaximumTimePoint();
91 }
92 
94 {
95  return timeStep < this->CountTimeSteps();
96 }
97 
99 {
100  if (m_FirstTimePoint <= itk::NumericTraits<TimePointType>::NonpositiveMin() ||
104  {
105  return static_cast<TimePointType>(timeStep);
106  }
107 
108  return m_FirstTimePoint + timeStep * m_StepDuration;
109 }
110 
112 {
113  if (m_FirstTimePoint <= timePoint)
114  return static_cast<TimeStepType>((timePoint - m_FirstTimePoint) / m_StepDuration);
115  else
116  return 0;
117 }
118 
120 {
121  if (IsValidTimeStep(timeStep))
122  {
123  return m_GeometryVector[timeStep];
124  }
125  else
126  {
127  return nullptr;
128  }
129 }
130 
132 {
133  if (this->IsValidTimePoint(timePoint))
134  {
135  TimeStepType timeStep = this->TimePointToTimeStep(timePoint);
136  return this->GetGeometryForTimeStep(timeStep);
137  }
138  else
139  {
140  return nullptr;
141  }
142 }
143 
145 {
146  if (timeStep >= m_GeometryVector.size())
147  return nullptr;
148  return m_GeometryVector[timeStep]->Clone();
149 }
150 
152 {
153  bool isValid = true;
154  isValid &= m_GeometryVector.size() > 0;
155  isValid &= m_StepDuration > 0;
156  return isValid;
157 }
158 
160 {
161  m_GeometryVector.clear();
162 }
163 
165 {
166  m_GeometryVector.reserve(numberOfGeometries);
167 }
168 
170 {
171  m_GeometryVector.reserve(size);
172  if (m_GeometryVector.size() == 0)
173  {
174  while (m_GeometryVector.size() < size)
175  {
177  m_GeometryVector.push_back(geo3D.GetPointer());
178  }
179  }
180  else
181  {
182  while (m_GeometryVector.size() < size)
183  {
185  m_GeometryVector.push_back(clone);
186  }
187  }
188 }
189 
191 {
192  assert(timeStep <= m_GeometryVector.size());
193 
194  if (timeStep == m_GeometryVector.size())
195  m_GeometryVector.push_back(geometry);
196 
197  m_GeometryVector[timeStep] = geometry;
198 }
199 
200 itk::LightObject::Pointer mitk::ProportionalTimeGeometry::InternalClone() const
201 {
202  itk::LightObject::Pointer parent = Superclass::InternalClone();
203  ProportionalTimeGeometry::Pointer newTimeGeometry = dynamic_cast<ProportionalTimeGeometry *>(parent.GetPointer());
204 
205  newTimeGeometry->m_FirstTimePoint = this->m_FirstTimePoint;
206  newTimeGeometry->m_StepDuration = this->m_StepDuration;
207  newTimeGeometry->m_GeometryVector.clear();
208  newTimeGeometry->Expand(this->CountTimeSteps());
209  for (TimeStepType i = 0; i < CountTimeSteps(); ++i)
210  {
211  BaseGeometry::Pointer tempGeometry = GetGeometryForTimeStep(i)->Clone();
212  newTimeGeometry->SetTimeStepGeometry(tempGeometry, i);
213  }
214  return parent;
215 }
216 
218 {
219  for (TimeStepType currentStep = 0; currentStep < this->CountTimeSteps(); ++currentStep)
220  {
221  BaseGeometry::Pointer clonedGeometry = geometry->Clone();
222  this->SetTimeStepGeometry(clonedGeometry.GetPointer(), currentStep);
223  }
224 }
225 
227 {
228  timeSteps = (timeSteps > 0) ? timeSteps : 1;
229  m_FirstTimePoint = 0.0;
230  m_StepDuration = 1.0;
231  if (timeSteps < 2)
232  {
234  m_StepDuration = std::numeric_limits<mitk::TimePointType>().infinity();
235  }
236 
237  this->ReserveSpaceForGeometries(timeSteps);
238  try
239  {
240  for (TimeStepType currentStep = 0; currentStep < timeSteps; ++currentStep)
241  {
242  BaseGeometry::Pointer clonedGeometry = geometry->Clone();
243  this->SetTimeStepGeometry(clonedGeometry, currentStep);
244  }
245  }
246  catch (...)
247  {
248  MITK_INFO << "Cloning of geometry produced an error!";
249  }
250  Update();
251 }
252 
254 {
256  mitk::BaseGeometry::Pointer geometry = dynamic_cast<BaseGeometry *>(geo3D.GetPointer());
257  geometry->Initialize();
258 
259  this->Initialize(geometry.GetPointer(), timeSteps);
260 }
261 
262 void mitk::ProportionalTimeGeometry::PrintSelf(std::ostream &os, itk::Indent indent) const
263 {
264  os << indent << " TimeSteps: " << this->CountTimeSteps() << std::endl;
265  os << indent << " FirstTimePoint: " << this->GetFirstTimePoint() << std::endl;
266  os << indent << " StepDuration: " << this->GetStepDuration() << " ms" << std::endl;
267  os << indent << " Time Bounds: " << this->GetTimeBounds()[0] << " - " << this->GetTimeBounds()[1] << std::endl;
268 
269  os << std::endl;
270  os << indent << " GetGeometryForTimeStep(0): ";
271  if (GetGeometryForTimeStep(0).IsNull())
272  os << "nullptr" << std::endl;
273  else
274  GetGeometryForTimeStep(0)->Print(os, indent);
275 }
276 
277 bool mitk::Equal(const ProportionalTimeGeometry &leftHandSide,
278  const ProportionalTimeGeometry &rightHandSide,
279  ScalarType eps,
280  bool verbose)
281 {
282  bool result = mitk::Equal(
283  static_cast<const TimeGeometry &>(leftHandSide), static_cast<const TimeGeometry &>(rightHandSide), eps, verbose);
284 
285  if (!result) // early out if base class already is unhappy
286  return false;
287 
288  // base class test already covers all aspects that could differ
289  // no need to test anything more.
290 
291  return result;
292 }
TimeStepType CountTimeSteps() const override
Returns the number of time steps.
itk::FixedArray< ScalarType, 2 > TimeBounds
Standard typedef for time-bounds.
#define MITK_INFO
Definition: mitkLogMacros.h:18
void PrintSelf(std::ostream &os, itk::Indent indent) const override
BaseGeometry::Pointer GetGeometryForTimeStep(TimeStepType timeStep) const override
Returns the geometry which corresponds to the given time step.
TimePointType GetMaximumTimePoint() const override
Returns the last time point for which the object is valid.
double ScalarType
Pointer Clone() const
BaseGeometry::Pointer GetGeometryCloneForTimeStep(TimeStepType timeStep) const override
Returns the geometry which corresponds to the given time step.
static Pointer New()
void ReserveSpaceForGeometries(TimeStepType numberOfGeometries)
itk::LightObject::Pointer InternalClone() const override
Makes a deep copy of the current object.
BaseGeometry::Pointer GetGeometryForTimePoint(TimePointType timePoint) const override
Returns the geometry which corresponds to the given time point.
void ReplaceTimeStepGeometries(const BaseGeometry *geometry) override
Replaces the geometry instances with clones of the passed geometry.
bool IsValidTimeStep(TimeStepType timeStep) const override
Test for the given time step if a geometry is availible.
TimeBounds GetTimeBounds() const override
Get the time bounds (in ms)
static void clone(T *&dst, S *src, int n)
Definition: svm.cpp:59
void Expand(TimeStepType size) override
Expands the time geometry to the given number of time steps.
void SetTimeStepGeometry(BaseGeometry *geometry, TimeStepType timeStep) override
Sets the geometry for the given time step.
virtual TimePointType GetStepDuration() const
bool IsValidTimePoint(TimePointType timePoint) const override
Tests if a given time point is covered by this object.
bool verbose(false)
TimePointType GetMinimumTimePoint() const override
Returns the first time point for which the object is valid.
mitk::ScalarType TimePointType
std::vcl_size_t TimeStepType
bool IsValid() const override
Tests if all necessary informations are set and the object is valid.
static T max(T x, T y)
Definition: svm.cpp:56
TimePointType TimeStepToTimePoint(TimeStepType timeStep) const override
Converts a time step to a time point.
static T min(T x, T y)
Definition: svm.cpp:53
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
virtual TimePointType GetFirstTimePoint() const
MITKCORE_EXPORT const ScalarType eps
TimeStepType TimePointToTimeStep(TimePointType timePoint) const override
Converts a time point to the corresponding time step.
LightObject::Pointer InternalClone() const override
Makes a deep copy of the current object.
void Update()
Updates the geometry.
void Initialize() override
Initilizes a new object with one time steps which contains an empty geometry.
BaseGeometry Describes the geometry of a data object.
std::vector< BaseGeometry::Pointer > m_GeometryVector