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