ITK  5.1.0
Insight Toolkit
itkSpatialObject.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkSpatialObject_h
19 #define itkSpatialObject_h
20 
21 // Disable warning for lengthy symbol names in this file only
22 
23 #include "itkCovariantVector.h"
24 #include "itkMacro.h"
25 #include <list>
27 #include "itkProcessObject.h"
28 #include "itkIndex.h"
29 #include "itkImageRegion.h"
30 #include "itkAffineTransform.h"
31 #include "itkVectorContainer.h"
32 #include "itkBoundingBox.h"
33 
34 namespace itk
35 {
56 template <unsigned int VDimension = 3>
57 class ITK_TEMPLATE_EXPORT SpatialObject : public DataObject
58 {
59 public:
60  ITK_DISALLOW_COPY_AND_ASSIGN(SpatialObject);
61 
62  using ScalarType = double;
63 
64  using ObjectDimensionType = unsigned int;
65 
66  static constexpr ObjectDimensionType ObjectDimension = VDimension;
67 
68  static constexpr unsigned int MaximumDepth = 9999999;
69 
72  unsigned int
74  {
75  return MaximumDepth;
76  }
77 
80 
83 
84 
85  // Spatial Function Iterator needs the following type alias
87 
93 
96 
98 
102 
104 
107 
109  using ChildrenListType = std::list<Pointer>;
111 
112  using ObjectListType = std::list<Pointer>;
113 
115 
117 
118  /* These are needed to participate in a Pipeline */
121 
123  unsigned int
125  {
126  return VDimension;
127  }
128 
130  itkNewMacro(Self);
131 
133  itkTypeMacro(SpatialObject, DataObject);
134 
136  void
137  SetId(int id);
138  itkGetConstReferenceMacro(Id, int);
140 
144  itkSetMacro(TypeName, std::string);
145 
147  virtual const std::string
148  GetTypeName() const
149  {
150  return m_TypeName;
151  }
152 
154  virtual std::string
155  GetClassNameAndDimension(void) const;
156 
159  virtual void
160  Clear(void);
161 
163  void
164  SetProperty(const PropertyType & property)
165  {
166  this->m_Property = property;
167  this->Modified();
168  }
170 
172  const PropertyType &
173  GetProperty() const
174  {
175  return this->m_Property;
176  }
177 
178  PropertyType &
180  {
181  return this->m_Property;
182  }
183 
187  GetMTime() const override;
188 
192  GetMyMTime() const
193  {
194  return Superclass::GetMTime();
195  }
196 
197 
198 /**************/
199  /* Transforms */
200 
201 /**************/
202 
205  void
206  SetObjectToWorldTransform(const TransformType * transform);
207  itkGetModifiableObjectMacro(ObjectToWorldTransform, TransformType);
208  const TransformType *
209  GetObjectToWorldTransformInverse() const;
211 
214  void
215  SetObjectToParentTransform(const TransformType * transform);
216  itkGetModifiableObjectMacro(ObjectToParentTransform, TransformType);
217  const TransformType *
218  GetObjectToParentTransformInverse() const;
220 
222  void
223  ComputeObjectToParentTransform();
224 
225 /**********************************************************************/
226  /* These are the three member functions that a subclass will typically
227  * overwrite.
228  * * ComputeMyBoundingBox (protected:)
229  * * IsInsideInObjectSpace
230  * * Update
231  * Optionally, a subclass may also wish to overwrite
232  * * ValueAtInObjectSpace
233  * * IsEvaluableAtInObjectSpace - if the extent is beyond IsInisde.
234  */
235 
236 /**********************************************************************/
237 
239  bool
240  IsInsideInObjectSpace(const PointType & point, unsigned int depth, const std::string & name = "") const;
241 
244  virtual bool
245  IsInsideInObjectSpace(const PointType & point) const;
246 
249  void
250  Update() override;
251 
252 
254  virtual bool
255  ValueAtInObjectSpace(const PointType & point,
256  double & value,
257  unsigned int depth = 0,
258  const std::string & name = "") const;
259 
266  virtual bool
267  IsEvaluableAtInObjectSpace(const PointType & point, unsigned int depth = 0, const std::string & name = "") const;
268 
269 /********************************************************/
270  /* Helper functions to recurse queries through children */
271 
272 /********************************************************/
273  virtual bool
274  IsInsideChildrenInObjectSpace(const PointType & point, unsigned int depth = 0, const std::string & name = "") const;
275 
276  virtual bool
277  ValueAtChildrenInObjectSpace(const PointType & point,
278  double & value,
279  unsigned int depth = 0,
280  const std::string & name = "") const;
281 
282  virtual bool
283  IsEvaluableAtChildrenInObjectSpace(const PointType & point,
284  unsigned int depth = 0,
285  const std::string & name = "") const;
286 
287 
288 /**************************/
289  /* Values and derivatives */
290 
291 /**************************/
292 
295  itkSetMacro(DefaultInsideValue, double);
296  itkGetConstMacro(DefaultInsideValue, double);
298 
301  itkSetMacro(DefaultOutsideValue, double);
302  itkGetConstMacro(DefaultOutsideValue, double);
304 
306  virtual bool
307  ValueAtInWorldSpace(const PointType & point,
308  double & value,
309  unsigned int depth = 0,
310  const std::string & name = "") const;
311 
313  virtual bool
314  IsInsideInWorldSpace(const PointType & point, unsigned int depth = 0, const std::string & name = "") const;
315 
317  virtual bool
318  IsEvaluableAtInWorldSpace(const PointType & point, unsigned int depth = 0, const std::string & name = "") const;
319 
320 
322  virtual void
323  DerivativeAtInObjectSpace(const PointType & point,
324  short unsigned int order,
325  CovariantVectorType & value,
326  unsigned int depth = 0,
327  const std::string & name = "",
328  const DerivativeOffsetType & spacing = 1);
329 
331  virtual void
332  DerivativeAtInWorldSpace(const PointType & point,
333  short unsigned int order,
334  CovariantVectorType & value,
335  unsigned int depth = 0,
336  const std::string & name = "",
337  const DerivativeOffsetType & spacing = 1);
338 
339 
340 /*********************/
341  /* Deal with Parents */
342 
343 /*********************/
344 
348  void
349  SetParent(Self * parent);
350 
353  virtual bool
354  HasParent() const;
355 
356 
358  virtual const Self *
359  GetParent() const;
360 
362  virtual Self *
363  GetParent();
364 
366  itkSetMacro(ParentId, int);
367  itkGetConstReferenceMacro(ParentId, int);
369 
370 
371 /**********************/
372  /* Deal with Children */
373 
374 /**********************/
375 
377  void
378  SetChildren(ChildrenListType & children);
379 
381  void
382  AddChild(Self * pointer);
383 
386  bool
387  RemoveChild(Self * object);
388 
390  void
391  RemoveAllChildren(unsigned int depth = MaximumDepth);
392 
398  virtual ChildrenListType *
399  GetChildren(unsigned int depth = 0, const std::string & name = "") const;
400 
401  virtual void
402  AddChildrenToList(ChildrenListType * children, unsigned int depth = 0, const std::string & name = "") const;
403 
405  unsigned int
406  GetNumberOfChildren(unsigned int depth = 0, const std::string & name = "") const;
407 
410  GetObjectById(int Id);
411 
415  bool
416  FixParentChildHierarchyUsingParentIds();
417 
419  bool
420  CheckIdValidity() const;
421 
423  void
424  FixIdValidity();
425 
427  int
428  GetNextAvailableId() const;
429 
430 
431 /**********************/
432  /* Bounding Box */
433 
434 /**********************/
435 
439  itkGetConstObjectMacro(MyBoundingBoxInObjectSpace, BoundingBoxType);
440 
444  virtual const BoundingBoxType *
445  GetMyBoundingBoxInWorldSpace() const;
446 
449  virtual bool
450  ComputeFamilyBoundingBox(unsigned int depth = 0, const std::string & name = "") const;
451 
454  itkGetConstObjectMacro(FamilyBoundingBoxInObjectSpace, BoundingBoxType);
455 
458  virtual const BoundingBoxType *
459  GetFamilyBoundingBoxInWorldSpace() const;
460 
461 
462 /******************************/
463  /* Regions used by DataObject */
464 
465 /******************************/
466 
473  virtual void
474  SetLargestPossibleRegion(const RegionType & region);
475 
482  virtual const RegionType &
484  {
485  return m_LargestPossibleRegion;
486  }
487 
491  virtual void
492  SetBufferedRegion(const RegionType & region);
493 
497  virtual const RegionType &
499  {
500  return m_BufferedRegion;
501  }
502 
507  virtual void
508  SetRequestedRegion(const RegionType & region);
509 
514  void
515  SetRequestedRegion(const DataObject * data) override;
516 
521  virtual const RegionType &
523  {
524  return m_RequestedRegion;
525  }
526 
530  void
531  SetRequestedRegionToLargestPossibleRegion() override;
532 
542  bool
543  RequestedRegionIsOutsideOfTheBufferedRegion() override;
544 
553  bool
554  VerifyRequestedRegion() override;
555 
563  void
564  UpdateOutputInformation() override;
565 
575  void
576  CopyInformation(const DataObject * data) override;
577 
578 /*************************************/
579  /* Evaluate used by SpatialFunctions */
580 
581 /*************************************/
582 
587  bool
588  Evaluate(const PointType & point) const
589  {
590  return this->IsInsideInWorldSpace(point);
591  }
592 
593 #if !defined(ITK_LEGACY_REMOVE)
594  itkLegacyMacro(void ComputeObjectToWorldTransform())
595  {
596  this->Update(); /* Update() should be used instead of ProtectedComputeObjectToWorldTransform() */
597  }
598 
599  itkLegacyMacro(void ComputeBoundingBox())
600  {
601  this->Update(); /* Update() should be used instead of outdated ComputeBoundingBox() */
602  }
603 
605  itkLegacyMacro(virtual bool IsInside(const PointType & point, unsigned int depth = 0, const std::string & name = "")
606  const)
607  {
608  return IsInsideInObjectSpace(point, depth, name);
609  };
610 #endif
611 
612 
613 protected:
617  void
618  ProtectedComputeObjectToWorldTransform();
619 
621  virtual void
622  ComputeMyBoundingBox();
623 
628  SpatialObject() = default;
629 
631  ~SpatialObject() override;
632 
633  void
634  PrintSelf(std::ostream & os, Indent indent) const override;
635 
636  BoundingBoxType *
638  {
639  return m_MyBoundingBoxInObjectSpace.GetPointer();
640  }
641 
642  typename LightObject::Pointer
643  InternalClone() const override;
644 
645 private:
647  int m_Id{ -1 };
648 
650  std::string m_TypeName{ "SpatialObject" };
651 
653 
654  int m_ParentId{ -1 };
655  Self * m_Parent{ nullptr };
656 
660 
661  const BoundingBoxPointer m_MyBoundingBoxInObjectSpace{ BoundingBoxType::New() };
662  const BoundingBoxPointer m_MyBoundingBoxInWorldSpace{ BoundingBoxType::New() };
663  const BoundingBoxPointer m_FamilyBoundingBoxInObjectSpace{ BoundingBoxType::New() };
664  const BoundingBoxPointer m_FamilyBoundingBoxInWorldSpace{ BoundingBoxType::New() };
665 
666  const TransformPointer m_ObjectToParentTransform{ TransformType::New() };
667  const TransformPointer m_ObjectToParentTransformInverse{ TransformType::New() };
668 
669  const TransformPointer m_ObjectToWorldTransform{ TransformType::New() };
670  const TransformPointer m_ObjectToWorldTransformInverse{ TransformType::New() };
671 
673 
675  double m_DefaultInsideValue{ 1.0 };
676 
678  double m_DefaultOutsideValue{ 0.0 };
679 };
680 
681 } // end of namespace itk
682 
683 #if !defined(ITK_WRAPPING_PARSER)
684 # ifndef ITK_MANUAL_INSTANTIATION
685 # include "itkSpatialObject.hxx"
686 # endif
687 #endif
688 
689 #endif // itkSpatialObject_h
itk::SpatialObject::m_LargestPossibleRegion
RegionType m_LargestPossibleRegion
Definition: itkSpatialObject.h:657
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:66
itkCovariantVector.h
itk::SpatialObject::GetProperty
PropertyType & GetProperty()
Definition: itkSpatialObject.h:179
itk::SpatialObject::GetModifiableMyBoundingBoxInObjectSpace
BoundingBoxType * GetModifiableMyBoundingBoxInObjectSpace()
Definition: itkSpatialObject.h:637
itk::SpatialObject< TMesh::PointDimension >::TransformPointer
typename TransformType::Pointer TransformPointer
Definition: itkSpatialObject.h:100
itk::ModifiedTimeType
SizeValueType ModifiedTimeType
Definition: itkIntTypes.h:102
itk::SpatialObject::GetTypeName
virtual const std::string GetTypeName() const
Definition: itkSpatialObject.h:148
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:69
itk::SpatialObject::m_Property
PropertyType m_Property
Definition: itkSpatialObject.h:652
itk::ImageRegion< VDimension >
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::SpatialObject::SetProperty
void SetProperty(const PropertyType &property)
Definition: itkSpatialObject.h:164
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::SpatialObject< TMesh::PointDimension >::ChildrenListType
std::list< Pointer > ChildrenListType
Definition: itkSpatialObject.h:109
itk::SpatialObject< TMesh::PointDimension >::BoundingBoxPointer
typename BoundingBoxType::Pointer BoundingBoxPointer
Definition: itkSpatialObject.h:106
itk::SpatialObject::m_BufferedRegion
RegionType m_BufferedRegion
Definition: itkSpatialObject.h:659
itk::SpatialObject< TMesh::PointDimension >::ObjectListType
std::list< Pointer > ObjectListType
Definition: itkSpatialObject.h:112
itk::SmartPointer< Self >
itkAffineTransform.h
itk::AffineTransform
Definition: itkAffineTransform.h:101
itk::SpatialObject::GetMaximumDepth
unsigned int GetMaximumDepth() const
Definition: itkSpatialObject.h:73
itkSpatialObjectProperty.h
itkImageRegion.h
itk::SpatialObject::GetProperty
const PropertyType & GetProperty() const
Definition: itkSpatialObject.h:173
itk::SpatialObject::GetMyMTime
ModifiedTimeType GetMyMTime() const
Definition: itkSpatialObject.h:192
itk::SpatialObject::m_ChildrenList
ChildrenListType m_ChildrenList
Definition: itkSpatialObject.h:672
itkMacro.h
itkProcessObject.h
itk::SpatialObjectProperty
Definition: itkSpatialObjectProperty.h:38
itk::SpatialObject::GetObjectDimension
unsigned int GetObjectDimension() const
Definition: itkSpatialObject.h:124
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::SpatialObject::Evaluate
bool Evaluate(const PointType &point) const
Definition: itkSpatialObject.h:588
itk::SpatialObject
Implementation of the composite pattern.
Definition: itkSpatialObject.h:57
itk::DataObject
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:42
itkIndex.h
itk::SpatialObject< TMesh::PointDimension >::ObjectDimensionType
unsigned int ObjectDimensionType
Definition: itkSpatialObject.h:64
itk::CovariantVector
A templated class holding a n-Dimensional covariant vector.
Definition: itkCovariantVector.h:68
itk::SpatialObject< TMesh::PointDimension >::ScalarType
double ScalarType
Definition: itkSpatialObject.h:62
itkVectorContainer.h
itk::SpatialObject::m_RequestedRegion
RegionType m_RequestedRegion
Definition: itkSpatialObject.h:658
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkArray.h:26
itk::SpatialObject::GetRequestedRegion
virtual const RegionType & GetRequestedRegion() const
Definition: itkSpatialObject.h:522
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:60
itk::Point
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:52
itk::BoundingBox
Represent and compute information about bounding boxes.
Definition: itkBoundingBox.h:69
itk::SpatialObject::GetBufferedRegion
virtual const RegionType & GetBufferedRegion() const
Definition: itkSpatialObject.h:498
itk::SpatialObject::GetLargestPossibleRegion
virtual const RegionType & GetLargestPossibleRegion() const
Definition: itkSpatialObject.h:483
itk::VectorContainer
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.
Definition: itkVectorContainer.h:48
itkBoundingBox.h
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:288
itk::SpatialObject< TMesh::PointDimension >::ChildrenListPointer
ChildrenListType * ChildrenListPointer
Definition: itkSpatialObject.h:110