ITK  5.4.0
Insight Toolkit
itkSpatialObject.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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_MOVE(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>;
110  using ChildrenConstListType = std::list<ConstPointer>;
113 
114  using ObjectListType = std::list<Pointer>;
115  using ObjectConstListType = std::list<ConstPointer>;
116 
118 
120 
121  /* These are needed to participate in a Pipeline */
124 
126  unsigned int
128  {
129  return VDimension;
130  }
131 
133  itkNewMacro(Self);
134 
136  itkTypeMacro(SpatialObject, DataObject);
137 
139  void
140  SetId(int id);
141  itkGetConstReferenceMacro(Id, int);
147  itkSetMacro(TypeName, std::string);
148 
150  virtual const std::string
151  GetTypeName() const
152  {
153  return m_TypeName;
154  }
155 
162  virtual std::string
163  GetClassNameAndDimension() const;
164 
167  virtual void
168  Clear();
169 
171  void
172  SetProperty(const PropertyType & property)
173  {
174  this->m_Property = property;
175  this->Modified();
176  }
180  const PropertyType &
181  GetProperty() const
182  {
183  return this->m_Property;
184  }
185 
186  PropertyType &
188  {
189  return this->m_Property;
190  }
191 
195  GetMTime() const override;
196 
200  GetMyMTime() const
201  {
202  return Superclass::GetMTime();
203  }
204 
205 
206  /**************/
207  /* Transforms */
208 
209  /**************/
210 
217  void
218  SetObjectToWorldTransform(const TransformType * transform);
219  itkGetModifiableObjectMacro(ObjectToWorldTransform, TransformType);
220  const TransformType *
221  GetObjectToWorldTransformInverse() const;
229  void
230  SetObjectToParentTransform(const TransformType * transform);
231  itkGetModifiableObjectMacro(ObjectToParentTransform, TransformType);
232  const TransformType *
233  GetObjectToParentTransformInverse() const;
243  void
244  ComputeObjectToParentTransform();
245 
246  /**********************************************************************/
247  /* These are the three member functions that a subclass will typically
248  * overwrite.
249  * * ComputeMyBoundingBox (protected:)
250  * * IsInsideInObjectSpace
251  * * Update
252  * Optionally, a subclass may also wish to overwrite
253  * * ValueAtInObjectSpace
254  * * IsEvaluableAtInObjectSpace - if the extent is beyond IsInside.
255  */
256 
257  /**********************************************************************/
258 
260  bool
261  IsInsideInObjectSpace(const PointType & point, unsigned int depth, const std::string & name = "") const;
262 
265  virtual bool
266  IsInsideInObjectSpace(const PointType & point) const;
267 
270  void
271  Update() override;
272 
273 
275  virtual bool
276  ValueAtInObjectSpace(const PointType & point,
277  double & value,
278  unsigned int depth = 0,
279  const std::string & name = "") const;
280 
287  virtual bool
288  IsEvaluableAtInObjectSpace(const PointType & point, unsigned int depth = 0, const std::string & name = "") const;
289 
290  /********************************************************/
291  /* Helper functions to recurse queries through children */
292 
293  /********************************************************/
294 
296  virtual bool
297  IsInsideChildrenInObjectSpace(const PointType & point, unsigned int depth = 0, const std::string & name = "") const;
298 
300  virtual bool
301  ValueAtChildrenInObjectSpace(const PointType & point,
302  double & value,
303  unsigned int depth = 0,
304  const std::string & name = "") const;
305 
307  virtual bool
308  IsEvaluableAtChildrenInObjectSpace(const PointType & point,
309  unsigned int depth = 0,
310  const std::string & name = "") const;
311 
312 
313  /**************************/
314  /* Values and derivatives */
315 
316  /**************************/
317 
320  itkSetMacro(DefaultInsideValue, double);
321  itkGetConstMacro(DefaultInsideValue, double);
326  itkSetMacro(DefaultOutsideValue, double);
327  itkGetConstMacro(DefaultOutsideValue, double);
331  virtual bool
332  ValueAtInWorldSpace(const PointType & point,
333  double & value,
334  unsigned int depth = 0,
335  const std::string & name = "") const;
336 
338  virtual bool
339  IsInsideInWorldSpace(const PointType & point, unsigned int depth = 0, const std::string & name = "") const;
340 
342  virtual bool
343  IsEvaluableAtInWorldSpace(const PointType & point, unsigned int depth = 0, const std::string & name = "") const;
344 
345 
347  virtual void
348  DerivativeAtInObjectSpace(const PointType & point,
349  short unsigned int order,
350  CovariantVectorType & value,
351  unsigned int depth = 0,
352  const std::string & name = "",
353  const DerivativeOffsetType & offset = MakeFilled<DerivativeOffsetType>(1));
354 
356  virtual void
357  DerivativeAtInWorldSpace(const PointType & point,
358  short unsigned int order,
359  CovariantVectorType & value,
360  unsigned int depth = 0,
361  const std::string & name = "",
362  const DerivativeOffsetType & offset = MakeFilled<DerivativeOffsetType>(1));
363 
364 
365  /*********************/
366  /* Deal with Parents */
367 
368  /*********************/
369 
373  void
374  SetParent(Self * parent);
375 
378  virtual bool
379  HasParent() const;
380 
385  virtual const Self *
386  GetParent() const;
387 
392  virtual Self *
393  GetParent();
394 
396  itkSetMacro(ParentId, int);
397  itkGetConstReferenceMacro(ParentId, int);
401  /**********************/
402  /* Deal with Children */
403 
404  /**********************/
405 
407  void
408  SetChildren(ChildrenListType & children);
409 
411  void
412  AddChild(Self * pointer);
413 
416  bool
417  RemoveChild(Self * pointer);
418 
420  void
421  RemoveAllChildren(unsigned int depth = MaximumDepth);
422 
428  virtual ChildrenListType *
429  GetChildren(unsigned int depth = 0, const std::string & name = "") const;
430 
436  virtual ChildrenConstListType *
437  GetConstChildren(unsigned int depth = 0, const std::string & name = "") const;
438 
439  virtual void
440  AddChildrenToList(ChildrenListType * childrenList, unsigned int depth = 0, const std::string & name = "") const;
441 
442  virtual void
443  AddChildrenToConstList(ChildrenConstListType * childrenList,
444  unsigned int depth = 0,
445  const std::string & name = "") const;
446 
448  unsigned int
449  GetNumberOfChildren(unsigned int depth = 0, const std::string & name = "") const;
450 
453  GetObjectById(int id);
454 
458  bool
459  FixParentChildHierarchyUsingParentIds();
460 
465  bool
466  CheckIdValidity() const;
467 
469  void
470  FixIdValidity();
471 
476  int
477  GetNextAvailableId() const;
478 
479 
480  /**********************/
481  /* Bounding Box */
482 
483  /**********************/
484 
488  itkGetConstObjectMacro(MyBoundingBoxInObjectSpace, BoundingBoxType);
489 
493  virtual const BoundingBoxType *
494  GetMyBoundingBoxInWorldSpace() const;
495 
501  virtual bool
502  ComputeFamilyBoundingBox(unsigned int depth = 0, const std::string & name = "") const;
503 
506  itkGetConstObjectMacro(FamilyBoundingBoxInObjectSpace, BoundingBoxType);
507 
510  virtual const BoundingBoxType *
511  GetFamilyBoundingBoxInWorldSpace() const;
512 
513 
514  /******************************/
515  /* Regions used by DataObject */
516 
517  /******************************/
518 
527  virtual void
528  SetLargestPossibleRegion(const RegionType & region);
529 
536  virtual const RegionType &
538  {
539  return m_LargestPossibleRegion;
540  }
541 
545  virtual void
546  SetBufferedRegion(const RegionType & region);
547 
551  virtual const RegionType &
553  {
554  return m_BufferedRegion;
555  }
556 
561  virtual void
562  SetRequestedRegion(const RegionType & region);
563 
568  void
569  SetRequestedRegion(const DataObject * data) override;
570 
575  virtual const RegionType &
577  {
578  return m_RequestedRegion;
579  }
580 
584  void
585  SetRequestedRegionToLargestPossibleRegion() override;
586 
596  bool
597  RequestedRegionIsOutsideOfTheBufferedRegion() override;
598 
607  bool
608  VerifyRequestedRegion() override;
609 
617  void
618  UpdateOutputInformation() override;
619 
629  void
630  CopyInformation(const DataObject * data) override;
631 
632  /*************************************/
633  /* Evaluate used by SpatialFunctions */
634 
635  /*************************************/
636 
641  bool
642  Evaluate(const PointType & point) const
643  {
644  return this->IsInsideInWorldSpace(point);
645  }
646 
647 #if !defined(ITK_LEGACY_REMOVE)
648  itkLegacyMacro(void ComputeObjectToWorldTransform())
649  {
650  this->Update(); /* Update() should be used instead of ProtectedComputeObjectToWorldTransform() */
651  }
652 
653  itkLegacyMacro(void ComputeBoundingBox())
654  {
655  this->Update(); /* Update() should be used instead of outdated ComputeBoundingBox() */
656  }
657 
659  itkLegacyMacro(virtual bool IsInside(const PointType & point, unsigned int depth = 0, const std::string & name = "")
660  const)
661  {
662  return IsInsideInObjectSpace(point, depth, name);
663  };
664 #endif
665 
667 protected:
671  void
672  ProtectedComputeObjectToWorldTransform();
673 
675  virtual void
676  ComputeMyBoundingBox();
677 
682  SpatialObject() = default;
683 
685  ~SpatialObject() override;
686 
687  void
688  PrintSelf(std::ostream & os, Indent indent) const override;
689 
690  BoundingBoxType *
692  {
693  return m_MyBoundingBoxInObjectSpace.GetPointer();
694  }
695 
696  typename LightObject::Pointer
697  InternalClone() const override;
698 
699 private:
701  int m_Id{ -1 };
702 
704  std::string m_TypeName{ "SpatialObject" };
705 
706  PropertyType m_Property{};
707 
708  int m_ParentId{ -1 };
709  Self * m_Parent{ nullptr };
710 
711  RegionType m_LargestPossibleRegion{};
712  RegionType m_RequestedRegion{};
713  RegionType m_BufferedRegion{};
714 
715  const BoundingBoxPointer m_MyBoundingBoxInObjectSpace{ BoundingBoxType::New() };
716  const BoundingBoxPointer m_MyBoundingBoxInWorldSpace{ BoundingBoxType::New() };
717  const BoundingBoxPointer m_FamilyBoundingBoxInObjectSpace{ BoundingBoxType::New() };
718  const BoundingBoxPointer m_FamilyBoundingBoxInWorldSpace{ BoundingBoxType::New() };
719 
720  const TransformPointer m_ObjectToParentTransform{ TransformType::New() };
721  const TransformPointer m_ObjectToParentTransformInverse{ TransformType::New() };
722 
723  const TransformPointer m_ObjectToWorldTransform{ TransformType::New() };
724  const TransformPointer m_ObjectToWorldTransformInverse{ TransformType::New() };
725 
726  ChildrenListType m_ChildrenList{};
727 
729  double m_DefaultInsideValue{ 1.0 };
730 
732  double m_DefaultOutsideValue{ 0.0 };
733 };
734 
735 } // end of namespace itk
736 
737 #if !defined(ITK_WRAPPING_PARSER)
738 # ifndef ITK_MANUAL_INSTANTIATION
739 # include "itkSpatialObject.hxx"
740 # endif
741 #endif
742 
743 #endif // itkSpatialObject_h
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:92
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:70
itkCovariantVector.h
itk::SpatialObject::GetProperty
PropertyType & GetProperty()
Definition: itkSpatialObject.h:187
itk::SpatialObject::GetModifiableMyBoundingBoxInObjectSpace
BoundingBoxType * GetModifiableMyBoundingBoxInObjectSpace()
Definition: itkSpatialObject.h:691
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:151
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:71
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:172
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< TMesh::PointDimension >::ObjectListType
std::list< Pointer > ObjectListType
Definition: itkSpatialObject.h:114
itk::SmartPointer< Self >
itkAffineTransform.h
itk::AffineTransform
Definition: itkAffineTransform.h:101
itk::SpatialObject::GetMaximumDepth
unsigned int GetMaximumDepth() const
Definition: itkSpatialObject.h:73
itkSpatialObjectProperty.h
itk::SpatialObject< TMesh::PointDimension >::ObjectConstListType
std::list< ConstPointer > ObjectConstListType
Definition: itkSpatialObject.h:115
itkImageRegion.h
itk::SpatialObject::GetProperty
const PropertyType & GetProperty() const
Definition: itkSpatialObject.h:181
itk::SpatialObject::GetMyMTime
ModifiedTimeType GetMyMTime() const
Definition: itkSpatialObject.h:200
itkMacro.h
itkProcessObject.h
itk::point
*par Constraints *The filter requires an image with at least two dimensions and a vector *length of at least The theory supports extension to scalar but *the implementation of the itk vector classes do not **The template parameter TRealType must be floating point(float or double) or *a user-defined "real" numerical type with arithmetic operations defined *sufficient to compute derivatives. **\par Performance *This filter will automatically multithread if run with *SetUsePrincipleComponents
itk::SpatialObjectProperty
Definition: itkSpatialObjectProperty.h:38
itk::SpatialObject::GetObjectDimension
unsigned int GetObjectDimension() const
Definition: itkSpatialObject.h:127
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::SpatialObject::Evaluate
bool Evaluate(const PointType &point) const
Definition: itkSpatialObject.h:642
itk::SpatialObject
Implementation of the composite pattern.
Definition: itkSpatialObject.h:57
itk::SpatialObject< TMesh::PointDimension >::ChildrenConstListPointer
ChildrenConstListType * ChildrenConstListPointer
Definition: itkSpatialObject.h:112
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:70
itk::SpatialObject< TMesh::PointDimension >::ScalarType
double ScalarType
Definition: itkSpatialObject.h:62
itkVectorContainer.h
itk::SpatialObject< TMesh::PointDimension >::ChildrenConstListType
std::list< ConstPointer > ChildrenConstListType
Definition: itkSpatialObject.h:110
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::SpatialObject::GetRequestedRegion
virtual const RegionType & GetRequestedRegion() const
Definition: itkSpatialObject.h:576
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::Point
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:53
New
static Pointer New()
itk::BoundingBox
Represent and compute information about bounding boxes.
Definition: itkBoundingBox.h:70
AddImageFilter
Definition: itkAddImageFilter.h:80
itk::SpatialObject::GetBufferedRegion
virtual const RegionType & GetBufferedRegion() const
Definition: itkSpatialObject.h:552
itk::SpatialObject::GetLargestPossibleRegion
virtual const RegionType & GetLargestPossibleRegion() const
Definition: itkSpatialObject.h:537
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:293
itk::SpatialObject< TMesh::PointDimension >::ChildrenListPointer
ChildrenListType * ChildrenListPointer
Definition: itkSpatialObject.h:111