Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkBaseData.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 
17 #include "mitkBaseData.h"
18 
19 #include <itkObjectFactoryBase.h>
20 #include <mitkException.h>
21 #include <mitkGeometry3D.h>
23 
24 mitk::BaseData::BaseData() : m_SourceOutputIndexDuplicate(0), m_Initialized(true)
25 {
26  m_TimeGeometry = mitk::ProportionalTimeGeometry::New();
27  m_PropertyList = PropertyList::New();
28 }
29 
31  : itk::DataObject(),
33  m_SourceOutputIndexDuplicate(other.m_SourceOutputIndexDuplicate),
34  m_Initialized(other.m_Initialized)
35 {
36  m_TimeGeometry = dynamic_cast<TimeGeometry *>(other.m_TimeGeometry->Clone().GetPointer());
37  m_PropertyList = other.m_PropertyList->Clone();
38 }
39 
41 {
42 }
43 
44 void mitk::BaseData::InitializeTimeGeometry(unsigned int timeSteps)
45 {
47  mitk::BaseGeometry::Pointer baseGeo = dynamic_cast<BaseGeometry *>(geo3D.GetPointer());
48  baseGeo->Initialize();
49 
50  // The geometry is propagated automatically to the other items,
51  // if EvenlyTimed is true...
52  // Old timeGeometry->InitializeEvenlyTimed( g3d.GetPointer(), timeSteps );
53 
54  TimeGeometry::Pointer timeGeometry = this->GetTimeGeometry();
55  timeGeometry->Initialize();
56  timeGeometry->Expand(timeSteps);
57  for (TimeStepType step = 0; step < timeSteps; ++step)
58  {
59  timeGeometry->SetTimeStepGeometry(baseGeo.GetPointer(), step);
60  }
61 }
62 
64 {
65  if (this->GetSource())
66  {
67  this->GetSource()->UpdateOutputInformation();
68  }
69  if (m_TimeGeometry.IsNotNull())
70  {
71  m_TimeGeometry->UpdateBoundingBox();
72  }
73 }
74 
76 {
77  SetRequestedRegionToLargestPossibleRegion();
78 
79  UpdateOutputInformation();
80 
81  return GetTimeGeometry();
82 }
83 
84 void mitk::BaseData::Expand(unsigned int timeSteps)
85 {
86  if (m_TimeGeometry.IsNotNull())
87  {
88  m_TimeGeometry->Expand(timeSteps);
89  }
90  else
91  {
92  this->InitializeTimeGeometry(timeSteps);
93  }
94 }
95 
97 {
98  SetRequestedRegionToLargestPossibleRegion();
99 
100  UpdateOutputInformation();
101 
102  return GetGeometry(t);
103 }
104 
106 {
108  if (geometry != nullptr)
109  {
110  timeGeometry->Initialize(geometry, 1);
111  }
112  SetTimeGeometry(timeGeometry);
113  return;
114 }
115 
117 {
118  m_TimeGeometry = geometry;
119  this->Modified();
120 }
121 
123 {
124  SetGeometry(static_cast<mitk::BaseGeometry *>(aGeometry3D->Clone().GetPointer()));
125 }
126 
128 {
129  TimeGeometry::Pointer clonedGeometry = geometry->Clone();
130  SetTimeGeometry(clonedGeometry.GetPointer());
131 }
132 
133 void mitk::BaseData::SetClonedGeometry(const BaseGeometry *aGeometry3D, unsigned int time)
134 {
135  if (m_TimeGeometry)
136  {
137  m_TimeGeometry->SetTimeStepGeometry(static_cast<mitk::BaseGeometry *>(aGeometry3D->Clone().GetPointer()), time);
138  }
139 }
140 
141 bool mitk::BaseData::IsEmptyTimeStep(unsigned int) const
142 {
143  return IsInitialized() == false;
144 }
145 
147 {
148  if (IsInitialized() == false)
149  return true;
150  const TimeGeometry *timeGeometry = const_cast<BaseData *>(this)->GetUpdatedTimeGeometry();
151  if (timeGeometry == nullptr)
152  return true;
153  unsigned int timeSteps = timeGeometry->CountTimeSteps();
154  for (unsigned int t = 0; t < timeSteps; ++t)
155  {
156  if (IsEmptyTimeStep(t) == false)
157  return false;
158  }
159  return true;
160 }
161 
163 {
164  return static_cast<mitk::BaseDataSource *>(Superclass::GetSource().GetPointer());
165 }
166 
168 {
169  return m_PropertyList;
170 }
171 
173 {
174  return m_PropertyList->GetProperty(propertyKey);
175 }
176 
177 void mitk::BaseData::SetProperty(const char *propertyKey, BaseProperty *propertyValue)
178 {
179  m_PropertyList->SetProperty(propertyKey, propertyValue);
180 }
181 
183 {
184  m_PropertyList = pList;
185 }
186 
188 {
189  TimeGeometry *timeGeom = GetTimeGeometry();
190 
191  assert(timeGeom != nullptr);
192 
193  TimeStepType steps = timeGeom->CountTimeSteps();
194  for (TimeStepType timestep = 0; timestep < steps; ++timestep)
195  {
196  auto geometry = GetGeometry(timestep);
197  if (geometry != nullptr)
198  {
199  geometry->SetOrigin(origin);
200  }
201  }
202 }
203 
204 unsigned long mitk::BaseData::GetMTime() const
205 {
206  unsigned long time = Superclass::GetMTime();
207  if (m_TimeGeometry.IsNotNull())
208  {
209  if ((time < m_TimeGeometry->GetMTime()))
210  {
211  Modified();
212  return Superclass::GetMTime();
213  }
214  }
215  return time;
216 }
217 
218 void mitk::BaseData::Graft(const itk::DataObject *)
219 {
220  itkExceptionMacro(<< "Graft not implemented for mitk::BaseData subclass " << this->GetNameOfClass())
221 }
222 
223 void mitk::BaseData::CopyInformation(const itk::DataObject *data)
224 {
225  const Self *bd = dynamic_cast<const Self *>(data);
226  if (bd != nullptr)
227  {
228  m_PropertyList = bd->GetPropertyList()->Clone();
229  if (bd->GetTimeGeometry() != nullptr)
230  {
231  m_TimeGeometry = bd->GetTimeGeometry()->Clone();
232  }
233  }
234  else
235  {
236  // pointer could not be cast back down; this can be the case if your filters input
237  // and output objects differ in type; then you have to write your own GenerateOutputInformation method
238  itkExceptionMacro(<< "mitk::BaseData::CopyInformation() cannot cast " << typeid(data).name() << " to "
239  << typeid(Self *).name());
240  }
241 }
242 
244 {
245  return m_Initialized;
246 }
247 
249 {
250  this->ClearData();
251  this->InitializeEmpty();
252 }
253 
255 {
256  if (m_Initialized)
257  {
258  ReleaseData();
259  m_Initialized = false;
260  }
261 }
262 
264 {
265  // empty by default. override if needed!
266 }
267 
268 void mitk::BaseData::PrintSelf(std::ostream &os, itk::Indent indent) const
269 {
270  os << std::endl;
271  os << indent << " TimeGeometry: ";
272  if (GetTimeGeometry() == nullptr)
273  os << "NULL" << std::endl;
274  else
275  GetTimeGeometry()->Print(os, indent);
276  // print out all properties
277  PropertyList::Pointer propertyList = this->GetPropertyList();
278  if (propertyList.IsNotNull() && !propertyList->IsEmpty())
279  {
280  // general headline
281  os << "Properties of BaseData:" << std::endl;
282 
283  const PropertyList::PropertyMap *map = propertyList->GetMap();
284  for (PropertyList::PropertyMap::const_iterator iter = map->begin(); iter != map->end(); ++iter)
285  {
286  os << " " << (*iter).first << " " << (*iter).second->GetValueAsString() << std::endl;
287  }
288  }
289 }
virtual void SetOrigin(const Point3D &origin)
Convenience method for setting the origin of the BaseGeometry instances of all time steps...
virtual void ClearData()
reset to non-initialized state, release memory
virtual void SetClonedTimeGeometry(const TimeGeometry *geometry)
Set a clone of the provided TimeGeometry as TimeGeometry of the data.
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const override
static Pointer New()
Base of all data objects.
Definition: mitkBaseData.h:39
Base class of all Operation-classes.
Definition: mitkOperation.h:33
virtual void SetGeometry(BaseGeometry *aGeometry3D)
Set the BaseGeometry of the data, which will be referenced (not copied!). Assumes the data object has...
virtual void SetTimeGeometry(TimeGeometry *geometry)
Set the TimeGeometry of the data, which will be referenced (not copied!).
Superclass of all classes generating some kind of mitk::BaseData.
DataCollection - Class to facilitate loading/accessing structured data.
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
Definition: mitkBaseData.h:52
Key-value list holding instances of BaseProperty.
static Pointer New()
virtual bool IsEmptyTimeStep(unsigned int t) const
Check whether object contains data (at a specified time), e.g., a set of points may be empty...
void SetPropertyList(PropertyList *propertyList)
Set the data's property list.
abstract class, that can be used by Undo to undo an operation.
void ExecuteOperation(Operation *operation) override
overwrite if the Data can be called by an Interactor (StateMachine).
void SetProperty(const char *propertyKey, BaseProperty *property)
virtual void Graft(const DataObject *) override
Abstract base class for properties.
std::map< std::string, BaseProperty::Pointer > PropertyMap
mitk::PropertyList::Pointer GetPropertyList() const
Get the data's property list.
itk::SmartPointer< mitk::BaseDataSource > GetSource() const
Get the process object that generated this data object.
std::vcl_size_t TimeStepType
virtual unsigned long GetMTime() const override
Get the modified time of the last change of the contents this data object or its geometry.
void UpdateOutputInformation() override
Update the information for this BaseData (the geometry in particular) so that it can be used as an ou...
const mitk::BaseGeometry * GetUpdatedGeometry(int t=0)
Return the BaseGeometry of the data at time t.
virtual void Clear()
Calls ClearData() and InitializeEmpty();.
const mitk::TimeGeometry * GetUpdatedTimeGeometry()
Return the TimeGeometry of the data.
virtual bool IsEmpty() const
Check whether object contains data (at least at one point in time), e.g., a set of points may be empt...
virtual bool IsInitialized() const
Check whether the data has been initialized, i.e., at least the Geometry and other header data has be...
virtual void SetClonedGeometry(const BaseGeometry *aGeometry3D)
Set a clone of the provided TimeGeometry as TimeGeometry of the data. Assumes the data object has onl...
Pointer Clone() const
mitk::BaseProperty::Pointer GetProperty(const char *propertyKey) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList, and set it to this, respectively;.
virtual void Expand(unsigned int timeSteps)
Expands the TimeGeometry to a number of TimeSteps.
Pointer Clone() const
virtual void InitializeTimeGeometry(unsigned int timeSteps=1)
Initialize the TimeGeometry for a number of time steps. The TimeGeometry is initialized empty and eve...
BaseGeometry Describes the geometry of a data object.
void CopyInformation(const itk::DataObject *data) override
Copy information from the specified data set.