Medical Imaging Interaction Toolkit  2021.02.99-89548602
Medical Imaging Interaction Toolkit
mitkBaseData.h
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 
13 #ifndef BASEDATA_H_HEADER_INCLUDED_C1EBB6FA
14 #define BASEDATA_H_HEADER_INCLUDED_C1EBB6FA
15 
16 #include <itkDataObject.h>
17 
18 #include "mitkBaseProcess.h"
19 #include "mitkIdentifiable.h"
20 #include "mitkIPropertyOwner.h"
21 #include "mitkOperationActor.h"
22 #include "mitkPropertyList.h"
23 #include "mitkTimeGeometry.h"
24 #include <MitkCoreExports.h>
25 
26 namespace mitk
27 {
28  // class BaseProcess;
29 
30  //##Documentation
31  //## @brief Base of all data objects
32  //##
33  //## Base of all data objects, e.g., images, contours, surfaces etc. Inherits
34  //## from itk::DataObject and thus can be included in a pipeline.
35  //## Inherits also from OperationActor and can be used as a destination for Undo
36  //## @remark Some derived classes may support the persistence of the Identifiable UID.
37  //** but it is no guaranteed feature and also depends on the format the data is stored in
38  //** as not all formats support storing of meta information. Please check the documentation
39  //** of the IFileReader and IFileWriter classes to see if the ID-persistance is supported.
40  //** MITK SceneIO supports the UID persistance for all BaseData derived classes.
41  //## @ingroup Data
43  : public itk::DataObject, public OperationActor, public Identifiable, public IPropertyOwner
44  {
45  public:
46  mitkClassMacroItkParent(BaseData, itk::DataObject);
47 
48  // IPropertyProvider
49  BaseProperty::ConstPointer GetConstProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = true) const override;
50  std::vector<std::string> GetPropertyKeys(const std::string &contextName = "", bool includeDefaultContext = false) const override;
51  std::vector<std::string> GetPropertyContextNames() const override;
52 
53  // IPropertyOwner
54  BaseProperty * GetNonConstProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = true) override;
55  void SetProperty(const std::string &propertyKey, BaseProperty *property, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override;
56  void RemoveProperty(const std::string &propertyKey, const std::string &contextName = "", bool fallBackOnDefaultContext = false) override;
57 
67  {
68  return m_TimeGeometry.GetPointer();
69  }
70 
79  mitk::TimeGeometry *GetTimeGeometry() { return m_TimeGeometry.GetPointer(); }
88  const mitk::TimeGeometry *GetUpdatedTimeGeometry();
89 
98  virtual void Expand(unsigned int timeSteps);
99 
111  const mitk::BaseGeometry *GetUpdatedGeometry(int t = 0);
112 
113  //##Documentation
114  //## @brief Return the geometry, which is a TimeGeometry, of the data
115  //## as non-const pointer.
116  //##
117  //## \warning No update will be called. Use GetUpdatedGeometry() if you cannot
118  //## be sure that the geometry is up-to-date.
119  //##
120  //## Normally used in GenerateOutputInformation of subclasses of BaseProcess.
121  mitk::BaseGeometry *GetGeometry(int t = 0) const
122  {
123  if (m_TimeGeometry.IsNull())
124  return nullptr;
125  return m_TimeGeometry->GetGeometryForTimeStep(t);
126  }
127 
128  //##Documentation
129  //## @brief Update the information for this BaseData (the geometry in particular)
130  //## so that it can be used as an output of a BaseProcess.
131  //##
132  //## This method is used in the pipeline mechanism to propagate information and
133  //## initialize the meta data associated with a BaseData. Any implementation
134  //## of this method in a derived class is assumed to call its source's
135  //## BaseProcess::UpdateOutputInformation() which determines modified
136  //## times, LargestPossibleRegions, and any extra meta data like spacing,
137  //## origin, etc. Default implementation simply call's it's source's
138  //## UpdateOutputInformation().
139  //## \note Implementations of this methods in derived classes must take care
140  //## that the geometry is updated by calling
141  //## GetTimeGeometry()->UpdateInformation()
142  //## \em after calling its source's BaseProcess::UpdateOutputInformation().
143  void UpdateOutputInformation() override;
144 
145  //##Documentation
146  //## @brief Set the RequestedRegion to the LargestPossibleRegion.
147  //##
148  //## This forces a filter to produce all of the output in one execution
149  //## (i.e. not streaming) on the next call to Update().
150  void SetRequestedRegionToLargestPossibleRegion() override = 0;
151 
152  //##Documentation
153  //## @brief Determine whether the RequestedRegion is outside of the BufferedRegion.
154  //##
155  //## This method returns true if the RequestedRegion
156  //## is outside the BufferedRegion (true if at least one pixel is
157  //## outside). This is used by the pipeline mechanism to determine
158  //## whether a filter needs to re-execute in order to satisfy the
159  //## current request. If the current RequestedRegion is already
160  //## inside the BufferedRegion from the previous execution (and the
161  //## current filter is up to date), then a given filter does not need
162  //## to re-execute
163  bool RequestedRegionIsOutsideOfTheBufferedRegion() override = 0;
164 
165  //##Documentation
166  //## @brief Verify that the RequestedRegion is within the LargestPossibleRegion.
167  //##
168  //## If the RequestedRegion is not within the LargestPossibleRegion,
169  //## then the filter cannot possibly satisfy the request. This method
170  //## returns true if the request can be satisfied (even if it will be
171  //## necessary to process the entire LargestPossibleRegion) and
172  //## returns false otherwise. This method is used by
173  //## PropagateRequestedRegion(). PropagateRequestedRegion() throws a
174  //## InvalidRequestedRegionError exception if the requested region is
175  //## not within the LargestPossibleRegion.
176  bool VerifyRequestedRegion() override = 0;
177 
178  //##Documentation
179  //## @brief Copy information from the specified data set.
180  //##
181  //## This method is part of the pipeline execution model. By default, a
182  //## BaseProcess will copy meta-data from the first input to all of its
183  //## outputs. See ProcessObject::GenerateOutputInformation(). Each
184  //## subclass of DataObject is responsible for being able to copy
185  //## whatever meta-data it needs from another DataObject.
186  //## The default implementation of this method copies the time sliced geometry
187  //## and the property list of an object. If a subclass overrides this
188  //## method, it should always call its superclass' version.
189  void CopyInformation(const itk::DataObject *data) override;
190 
191  //##Documentation
192  //## @brief Check whether the data has been initialized, i.e.,
193  //## at least the Geometry and other header data has been set
194  //##
195  //## \warning Set to \a true by default for compatibility reasons.
196  //## Set m_Initialized=false in constructors of sub-classes that
197  //## support distinction between initialized and uninitialized state.
198  virtual bool IsInitialized() const;
199 
200  //##Documentation
201  //## @brief Calls ClearData() and InitializeEmpty();
202  //## \warning Only use in subclasses that reimplemented these methods.
203  //## Just calling Clear from BaseData will reset an object to a not initialized,
204  //## invalid state.
205  virtual void Clear();
206 
207  //##Documentation
208  //## @brief Check whether object contains data (at
209  //## a specified time), e.g., a set of points may be empty
210  //##
211  //## \warning Returns IsInitialized()==false by default for
212  //## compatibility reasons. Override in sub-classes that
213  //## support distinction between empty/non-empty state.
214  virtual bool IsEmptyTimeStep(unsigned int t) const;
215 
216  //##Documentation
217  //## @brief Check whether object contains data (at
218  //## least at one point in time), e.g., a set of points
219  //## may be empty
220  //##
221  //## \warning Returns IsInitialized()==false by default for
222  //## compatibility reasons. Override in sub-classes that
223  //## support distinction between empty/non-empty state.
224  virtual bool IsEmpty() const;
225 
226  //##Documentation
227  //## @brief Set the requested region from this data object to match the requested
228  //## region of the data object passed in as a parameter.
229  //##
230  //## This method is implemented in the concrete subclasses of BaseData.
231  void SetRequestedRegion(const itk::DataObject *data) override = 0;
232 
233  //##Documentation
234  //##@brief overwrite if the Data can be called by an Interactor (StateMachine).
235  //##
236  //## Empty by default. Overwrite and implement all the necessary operations here
237  //## and get the necessary information from the parameter operation.
238  void ExecuteOperation(Operation *operation) override;
239 
250  virtual void SetGeometry(BaseGeometry *aGeometry3D);
251 
259  virtual void SetTimeGeometry(TimeGeometry *geometry);
260 
269  virtual void SetClonedGeometry(const BaseGeometry *aGeometry3D);
270 
276  virtual void SetClonedTimeGeometry(const TimeGeometry *geometry);
277 
278  //##Documentation
279  //## @brief Set a clone of the provided geometry as BaseGeometry of a given time step.
280  //##
281  //## \sa SetGeometry
282  virtual void SetClonedGeometry(const BaseGeometry *aGeometry3D, unsigned int time);
283 
284  //##Documentation
285  //## @brief Get the data's property list
286  //## @sa GetProperty
287  //## @sa m_PropertyList
288  mitk::PropertyList::Pointer GetPropertyList() const;
289 
290  //##Documentation
291  //## @brief Set the data's property list
292  //## @sa SetProperty
293  //## @sa m_PropertyList
294  void SetPropertyList(PropertyList *propertyList);
295 
296  //##Documentation
297  //## @brief Get the property (instance of BaseProperty) with key @a propertyKey from the PropertyList,
298  //## and set it to this, respectively;
299  //## @sa GetPropertyList
300  //## @sa m_PropertyList
301  //## @sa m_MapOfPropertyLists
302  mitk::BaseProperty::Pointer GetProperty(const char *propertyKey) const;
303 
304  void SetProperty(const char *propertyKey, BaseProperty *property);
305 
306  //##Documentation
307  //## @brief Convenience method for setting the origin of
308  //## the BaseGeometry instances of all time steps
309  //##
310  //## \warning Geometries contained in the BaseGeometry will
311  //## \em not be changed, e.g. in case the BaseGeometry is a
312  //## SlicedGeometry3D the origin will \em not be propagated
313  //## to the contained slices. The sub-class SlicedData
314  //## does this for the case that the SlicedGeometry3D is
315  //## evenly spaced.
316  virtual void SetOrigin(const Point3D &origin);
317 
331  itk::SmartPointer<mitk::BaseDataSource> GetSource() const;
332 
333  //##Documentation
334  //## @brief Get the number of time steps from the TimeGeometry
335  //## As the base data has not a data vector given by itself, the number
336  //## of time steps is defined over the time sliced geometry. In sub classes,
337  //## a better implementation could be over the length of the data vector.
338  unsigned int GetTimeSteps() const { return m_TimeGeometry->CountTimeSteps(); }
339  //##Documentation
340  //## @brief Get the modified time of the last change of the contents
341  //## this data object or its geometry.
342  unsigned long GetMTime() const override;
343 
347  void Graft(const DataObject *) override;
348 
349  protected:
350  BaseData();
351  BaseData(const BaseData &other);
352  ~BaseData() override;
353 
354  //##Documentation
355  //## \brief Initialize the TimeGeometry for a number of time steps.
356  //## The TimeGeometry is initialized empty and evenly timed.
357  //## In many cases it will be necessary to overwrite this in sub-classes.
358  virtual void InitializeTimeGeometry(unsigned int timeSteps = 1);
359 
360  //##Documentation
361  //## @brief reset to non-initialized state, release memory
362  virtual void ClearData();
363 
364  //##Documentation
365  //## @brief Pure virtual; Must be used in subclasses to get a data object to a
366  //## valid state. Should at least create one empty object and call
367  //## Superclass::InitializeTimeGeometry() to ensure an existing valid geometry
368  virtual void InitializeEmpty() {}
369  void PrintSelf(std::ostream &os, itk::Indent indent) const override;
370 
372 
373  mutable unsigned int m_SourceOutputIndexDuplicate;
374 
376 
377  private:
378  //##Documentation
379  //## @brief PropertyList, f.e. to hold pic-tags, tracking-data,..
380  //##
381  PropertyList::Pointer m_PropertyList;
382 
383  TimeGeometry::Pointer m_TimeGeometry;
384  };
385 
386 } // namespace mitk
387 
388 #endif /* BASEDATA_H_HEADER_INCLUDED_C1EBB6FA */
#define MITKCORE_EXPORT
Base of all data objects.
Definition: mitkBaseData.h:42
Base class of all Operation-classes.
Definition: mitkOperation.h:29
DataCollection - Class to facilitate loading/accessing structured data.
mitk::TimeGeometry * GetTimeGeometry()
Return the TimeGeometry of the data as pointer.
Definition: mitkBaseData.h:79
Key-value list holding instances of BaseProperty.
abstract class, that can be used by Undo to undo an operation.
const mitk::TimeGeometry * GetTimeGeometry() const
Return the TimeGeometry of the data as const pointer.
Definition: mitkBaseData.h:66
Abstract base class for properties.
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:49
bool m_LastRequestedRegionWasOutsideOfTheBufferedRegion
Definition: mitkBaseData.h:371
virtual void InitializeEmpty()
Pure virtual; Must be used in subclasses to get a data object to a valid state. Should at least creat...
Definition: mitkBaseData.h:368
unsigned int GetTimeSteps() const
Get the number of time steps from the TimeGeometry As the base data has not a data vector given by it...
Definition: mitkBaseData.h:338
mitk::BaseGeometry * GetGeometry(int t=0) const
Return the geometry, which is a TimeGeometry, of the data as non-const pointer.
Definition: mitkBaseData.h:121
Base class of identifiable objects.
unsigned int m_SourceOutputIndexDuplicate
Definition: mitkBaseData.h:373
BaseGeometry Describes the geometry of a data object.