ITK  6.0.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 #include <limits>
34 
35 namespace itk
36 {
57 template <unsigned int VDimension = 3>
58 class ITK_TEMPLATE_EXPORT SpatialObject : public DataObject
59 {
60 public:
61  ITK_DISALLOW_COPY_AND_MOVE(SpatialObject);
62 
63  using ScalarType = double;
64 
65  using ObjectDimensionType = unsigned int;
66 
67  static constexpr ObjectDimensionType ObjectDimension = VDimension;
68 
69  static constexpr unsigned int MaximumDepth = std::numeric_limits<unsigned int>::max();
70 
73  unsigned int
75  {
76  return MaximumDepth;
77  }
78 
81 
84 
85 
86  // Spatial Function Iterator needs the following type alias
88 
94 
97 
99 
103 
105 
108 
110  using ChildrenListType = std::list<Pointer>;
111  using ChildrenConstListType = std::list<ConstPointer>;
114 
115  using ObjectListType = std::list<Pointer>;
116  using ObjectConstListType = std::list<ConstPointer>;
117 
119 
121 
122  /* These are needed to participate in a Pipeline */
125 
127  unsigned int
129  {
130  return VDimension;
131  }
132 
134  itkNewMacro(Self);
135 
137  itkOverrideGetNameOfClassMacro(SpatialObject);
138 
140  void
141  SetId(int id);
142  itkGetConstReferenceMacro(Id, int);
148  itkSetMacro(TypeName, std::string);
149 
151  virtual std::string
152  GetTypeName() const
153  {
154  return m_TypeName;
155  }
156 
163  virtual std::string
164  GetClassNameAndDimension() const;
165 
168  virtual void
169  Clear();
170 
172  void
173  SetProperty(const PropertyType & property)
174  {
175  this->m_Property = property;
176  this->Modified();
177  }
181  const PropertyType &
182  GetProperty() const
183  {
184  return this->m_Property;
185  }
186 
187  PropertyType &
189  {
190  return this->m_Property;
191  }
192 
196  GetMTime() const override;
197 
201  GetMyMTime() const
202  {
203  return Superclass::GetMTime();
204  }
205 
206 
207  /**************/
208  /* Transforms */
209 
210  /**************/
211 
218  void
219  SetObjectToWorldTransform(const TransformType * transform);
220  itkGetModifiableObjectMacro(ObjectToWorldTransform, TransformType);
221  const TransformType *
222  GetObjectToWorldTransformInverse() const;
230  void
231  SetObjectToParentTransform(const TransformType * transform);
232  itkGetModifiableObjectMacro(ObjectToParentTransform, TransformType);
233  const TransformType *
234  GetObjectToParentTransformInverse() const;
244  void
245  ComputeObjectToParentTransform();
246 
247  /**********************************************************************/
248  /* These are the three member functions that a subclass will typically
249  * override.
250  * * ComputeMyBoundingBox (protected:)
251  * * IsInsideInObjectSpace
252  * * Update
253  * Optionally, a subclass may also wish to override
254  * * ValueAtInObjectSpace
255  * * IsEvaluableAtInObjectSpace - if the extent is beyond IsInside.
256  */
257 
258  /**********************************************************************/
259 
261  bool
262  IsInsideInObjectSpace(const PointType & point, unsigned int depth, const std::string & name = "") const;
263 
266  virtual bool
267  IsInsideInObjectSpace(const PointType & point) const;
268 
271  void
272  Update() override;
273 
274 
276  virtual bool
277  ValueAtInObjectSpace(const PointType & point,
278  double & value,
279  unsigned int depth = 0,
280  const std::string & name = "") const;
281 
288  virtual bool
289  IsEvaluableAtInObjectSpace(const PointType & point, unsigned int depth = 0, const std::string & name = "") const;
290 
291  /********************************************************/
292  /* Helper functions to recurse queries through children */
293 
294  /********************************************************/
295 
297  virtual bool
298  IsInsideChildrenInObjectSpace(const PointType & point, unsigned int depth = 0, const std::string & name = "") const;
299 
301  virtual bool
302  ValueAtChildrenInObjectSpace(const PointType & point,
303  double & value,
304  unsigned int depth = 0,
305  const std::string & name = "") const;
306 
308  virtual bool
309  IsEvaluableAtChildrenInObjectSpace(const PointType & point,
310  unsigned int depth = 0,
311  const std::string & name = "") const;
312 
313 
314  /**************************/
315  /* Values and derivatives */
316 
317  /**************************/
318 
321  itkSetMacro(DefaultInsideValue, double);
322  itkGetConstMacro(DefaultInsideValue, double);
327  itkSetMacro(DefaultOutsideValue, double);
328  itkGetConstMacro(DefaultOutsideValue, double);
337 #ifndef ITK_FUTURE_LEGACY_REMOVE
338  virtual
339 #endif
340  bool
341  ValueAtInWorldSpace(const PointType & point,
342  double & value,
343  unsigned int depth = 0,
344  const std::string & name = "") const;
345 
352 #ifndef ITK_FUTURE_LEGACY_REMOVE
353  virtual
354 #endif
355  bool
356  IsInsideInWorldSpace(const PointType & point, unsigned int depth, const std::string & name = "") const;
357 
360  bool
361  IsInsideInWorldSpace(const PointType & point) const;
362 
369 #ifndef ITK_FUTURE_LEGACY_REMOVE
370  virtual
371 #endif
372  bool
373  IsEvaluableAtInWorldSpace(const PointType & point, unsigned int depth = 0, const std::string & name = "") const;
374 
375 
377  virtual void
378  DerivativeAtInObjectSpace(const PointType & point,
379  short unsigned int order,
380  CovariantVectorType & value,
381  unsigned int depth = 0,
382  const std::string & name = "",
383  const DerivativeOffsetType & offset = MakeFilled<DerivativeOffsetType>(1));
384 
391 #ifndef ITK_FUTURE_LEGACY_REMOVE
392  virtual
393 #endif
394  void
395  DerivativeAtInWorldSpace(const PointType & point,
396  short unsigned int order,
397  CovariantVectorType & value,
398  unsigned int depth = 0,
399  const std::string & name = "",
400  const DerivativeOffsetType & offset = MakeFilled<DerivativeOffsetType>(1));
401 
402 
403  /*********************/
404  /* Deal with Parents */
405 
406  /*********************/
407 
411  void
412  SetParent(Self * parent);
413 
416  virtual bool
417  HasParent() const;
418 
423  virtual const Self *
424  GetParent() const;
425 
430  virtual Self *
431  GetParent();
432 
434  itkSetMacro(ParentId, int);
435  itkGetConstReferenceMacro(ParentId, int);
439  /**********************/
440  /* Deal with Children */
441 
442  /**********************/
443 
445  void
446  SetChildren(ChildrenListType & children);
447 
449  void
450  AddChild(Self * pointer);
451 
454  bool
455  RemoveChild(Self * pointer);
456 
458  void
459  RemoveAllChildren(unsigned int depth = MaximumDepth);
460 
466  virtual ChildrenListType *
467  GetChildren(unsigned int depth = 0, const std::string & name = "") const;
468 
474  virtual ChildrenConstListType *
475  GetConstChildren(unsigned int depth = 0, const std::string & name = "") const;
476 
477  virtual void
478  AddChildrenToList(ChildrenListType * childrenList, unsigned int depth = 0, const std::string & name = "") const;
479 
480  virtual void
481  AddChildrenToConstList(ChildrenConstListType * childrenList,
482  unsigned int depth = 0,
483  const std::string & name = "") const;
484 
486  unsigned int
487  GetNumberOfChildren(unsigned int depth = 0, const std::string & name = "") const;
488 
491  GetObjectById(int id);
492 
496  bool
497  FixParentChildHierarchyUsingParentIds();
498 
503  bool
504  CheckIdValidity() const;
505 
507  void
508  FixIdValidity();
509 
514  int
515  GetNextAvailableId() const;
516 
517 
518  /**********************/
519  /* Bounding Box */
520 
521  /**********************/
522 
526  itkGetConstObjectMacro(MyBoundingBoxInObjectSpace, BoundingBoxType);
527 
531  virtual const BoundingBoxType *
532  GetMyBoundingBoxInWorldSpace() const;
533 
539  virtual bool
540  ComputeFamilyBoundingBox(unsigned int depth = 0, const std::string & name = "") const;
541 
544  itkGetConstObjectMacro(FamilyBoundingBoxInObjectSpace, BoundingBoxType);
545 
548  virtual const BoundingBoxType *
549  GetFamilyBoundingBoxInWorldSpace() const;
550 
551 
552  /******************************/
553  /* Regions used by DataObject */
554 
555  /******************************/
556 
565  virtual void
566  SetLargestPossibleRegion(const RegionType & region);
567 
574  virtual const RegionType &
576  {
577  return m_LargestPossibleRegion;
578  }
579 
583  virtual void
584  SetBufferedRegion(const RegionType & region);
585 
589  virtual const RegionType &
591  {
592  return m_BufferedRegion;
593  }
594 
599  virtual void
600  SetRequestedRegion(const RegionType & region);
601 
606  void
607  SetRequestedRegion(const DataObject * data) override;
608 
613  virtual const RegionType &
615  {
616  return m_RequestedRegion;
617  }
618 
622  void
623  SetRequestedRegionToLargestPossibleRegion() override;
624 
634  bool
635  RequestedRegionIsOutsideOfTheBufferedRegion() override;
636 
645  bool
646  VerifyRequestedRegion() override;
647 
655  void
656  UpdateOutputInformation() override;
657 
667  void
668  CopyInformation(const DataObject * data) override;
669 
670  /*************************************/
671  /* Evaluate used by SpatialFunctions */
672 
673  /*************************************/
674 
679  bool
680  Evaluate(const PointType & point) const
681  {
682  return this->IsInsideInWorldSpace(point);
683  }
684 
685 #if !defined(ITK_LEGACY_REMOVE)
686  itkLegacyMacro(void ComputeObjectToWorldTransform())
687  {
688  this->Update(); /* Update() should be used instead of ProtectedComputeObjectToWorldTransform() */
689  }
690 
691  itkLegacyMacro(void ComputeBoundingBox())
692  {
693  this->Update(); /* Update() should be used instead of outdated ComputeBoundingBox() */
694  }
695 
697  itkLegacyMacro(virtual bool IsInside(const PointType & point, unsigned int depth = 0, const std::string & name = "")
698  const)
699  {
700  return IsInsideInObjectSpace(point, depth, name);
701  }
702 #endif
703 
704 protected:
708  void
709  ProtectedComputeObjectToWorldTransform();
710 
712  virtual void
713  ComputeMyBoundingBox();
714 
719  SpatialObject() = default;
720 
722  ~SpatialObject() override;
723 
724  void
725  PrintSelf(std::ostream & os, Indent indent) const override;
726 
727  BoundingBoxType *
729  {
730  return m_MyBoundingBoxInObjectSpace.GetPointer();
731  }
732 
733  typename LightObject::Pointer
734  InternalClone() const override;
735 
736 private:
738  int m_Id{ -1 };
739 
741  std::string m_TypeName{ "SpatialObject" };
742 
743  PropertyType m_Property{};
744 
745  int m_ParentId{ -1 };
746  Self * m_Parent{ nullptr };
747 
748  RegionType m_LargestPossibleRegion{};
749  RegionType m_RequestedRegion{};
750  RegionType m_BufferedRegion{};
751 
752  const BoundingBoxPointer m_MyBoundingBoxInObjectSpace{ BoundingBoxType::New() };
753  const BoundingBoxPointer m_MyBoundingBoxInWorldSpace{ BoundingBoxType::New() };
754  const BoundingBoxPointer m_FamilyBoundingBoxInObjectSpace{ BoundingBoxType::New() };
755  const BoundingBoxPointer m_FamilyBoundingBoxInWorldSpace{ BoundingBoxType::New() };
756 
757  const TransformPointer m_ObjectToParentTransform{ TransformType::New() };
758  const TransformPointer m_ObjectToParentTransformInverse{ TransformType::New() };
759 
760  const TransformPointer m_ObjectToWorldTransform{ TransformType::New() };
761  const TransformPointer m_ObjectToWorldTransformInverse{ TransformType::New() };
762 
763  ChildrenListType m_ChildrenList{};
764 
766  double m_DefaultInsideValue{ 1.0 };
767 
769  double m_DefaultOutsideValue{ 0.0 };
770 };
771 
772 } // end of namespace itk
773 
774 #if !defined(ITK_WRAPPING_PARSER)
775 # ifndef ITK_MANUAL_INSTANTIATION
776 # include "itkSpatialObject.hxx"
777 # endif
778 #endif
779 
780 #endif // itkSpatialObject_h
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:68
itkCovariantVector.h
itk::SpatialObject::GetProperty
PropertyType & GetProperty()
Definition: itkSpatialObject.h:188
itk::detail::VectorContainer
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.
Definition: itkVectorContainer.h:51
itk::SpatialObject::GetModifiableMyBoundingBoxInObjectSpace
BoundingBoxType * GetModifiableMyBoundingBoxInObjectSpace()
Definition: itkSpatialObject.h:728
itk::SpatialObject< TMesh::PointDimension >::TransformPointer
typename TransformType::Pointer TransformPointer
Definition: itkSpatialObject.h:101
itk::ModifiedTimeType
SizeValueType ModifiedTimeType
Definition: itkIntTypes.h:105
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:69
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:173
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:110
itk::SpatialObject< TMesh::PointDimension >::BoundingBoxPointer
typename BoundingBoxType::Pointer BoundingBoxPointer
Definition: itkSpatialObject.h:107
itk::SpatialObject< TMesh::PointDimension >::ObjectListType
std::list< Pointer > ObjectListType
Definition: itkSpatialObject.h:115
itk::SmartPointer< Self >
itkAffineTransform.h
itk::AffineTransform
Definition: itkAffineTransform.h:101
itk::SpatialObject::GetMaximumDepth
unsigned int GetMaximumDepth() const
Definition: itkSpatialObject.h:74
itkSpatialObjectProperty.h
itk::SpatialObject< TMesh::PointDimension >::ObjectConstListType
std::list< ConstPointer > ObjectConstListType
Definition: itkSpatialObject.h:116
itkImageRegion.h
itk::SpatialObject::GetProperty
const PropertyType & GetProperty() const
Definition: itkSpatialObject.h:182
itk::SpatialObject::GetMyMTime
ModifiedTimeType GetMyMTime() const
Definition: itkSpatialObject.h:201
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:128
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::SpatialObject::Evaluate
bool Evaluate(const PointType &point) const
Definition: itkSpatialObject.h:680
itk::SpatialObject
Implementation of the composite pattern.
Definition: itkSpatialObject.h:58
itk::SpatialObject< TMesh::PointDimension >::ChildrenConstListPointer
ChildrenConstListType * ChildrenConstListPointer
Definition: itkSpatialObject.h:113
itk::DataObject
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:42
itkIndex.h
itk::SpatialObject< TMesh::PointDimension >::ObjectDimensionType
unsigned int ObjectDimensionType
Definition: itkSpatialObject.h:65
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:63
itk::SpatialObject::GetTypeName
virtual std::string GetTypeName() const
Definition: itkSpatialObject.h:152
itkVectorContainer.h
itk::SpatialObject< TMesh::PointDimension >::ChildrenConstListType
std::list< ConstPointer > ChildrenConstListType
Definition: itkSpatialObject.h:111
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::SpatialObject::GetRequestedRegion
virtual const RegionType & GetRequestedRegion() const
Definition: itkSpatialObject.h:614
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:81
itk::SpatialObject::GetBufferedRegion
virtual const RegionType & GetBufferedRegion() const
Definition: itkSpatialObject.h:590
itk::SpatialObject::GetLargestPossibleRegion
virtual const RegionType & GetLargestPossibleRegion() const
Definition: itkSpatialObject.h:575
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:112