ITK  5.3.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 
157  virtual std::string
158  GetClassNameAndDimension() const;
159 
162  virtual void
163  Clear();
164 
166  void
167  SetProperty(const PropertyType & property)
168  {
169  this->m_Property = property;
170  this->Modified();
171  }
175  const PropertyType &
176  GetProperty() const
177  {
178  return this->m_Property;
179  }
180 
181  PropertyType &
183  {
184  return this->m_Property;
185  }
186 
190  GetMTime() const override;
191 
195  GetMyMTime() const
196  {
197  return Superclass::GetMTime();
198  }
199 
200 
201  /**************/
202  /* Transforms */
203 
204  /**************/
205 
208  void
209  SetObjectToWorldTransform(const TransformType * transform);
210  itkGetModifiableObjectMacro(ObjectToWorldTransform, TransformType);
211  const TransformType *
212  GetObjectToWorldTransformInverse() const;
217  void
218  SetObjectToParentTransform(const TransformType * transform);
219  itkGetModifiableObjectMacro(ObjectToParentTransform, TransformType);
220  const TransformType *
221  GetObjectToParentTransformInverse() const;
225  void
226  ComputeObjectToParentTransform();
227 
228  /**********************************************************************/
229  /* These are the three member functions that a subclass will typically
230  * overwrite.
231  * * ComputeMyBoundingBox (protected:)
232  * * IsInsideInObjectSpace
233  * * Update
234  * Optionally, a subclass may also wish to overwrite
235  * * ValueAtInObjectSpace
236  * * IsEvaluableAtInObjectSpace - if the extent is beyond IsInisde.
237  */
238 
239  /**********************************************************************/
240 
242  bool
243  IsInsideInObjectSpace(const PointType & point, unsigned int depth, const std::string & name = "") const;
244 
247  virtual bool
248  IsInsideInObjectSpace(const PointType & point) const;
249 
252  void
253  Update() override;
254 
255 
257  virtual bool
258  ValueAtInObjectSpace(const PointType & point,
259  double & value,
260  unsigned int depth = 0,
261  const std::string & name = "") const;
262 
269  virtual bool
270  IsEvaluableAtInObjectSpace(const PointType & point, unsigned int depth = 0, const std::string & name = "") const;
271 
272  /********************************************************/
273  /* Helper functions to recurse queries through children */
274 
275  /********************************************************/
276  virtual bool
277  IsInsideChildrenInObjectSpace(const PointType & point, unsigned int depth = 0, const std::string & name = "") const;
278 
279  virtual bool
280  ValueAtChildrenInObjectSpace(const PointType & point,
281  double & value,
282  unsigned int depth = 0,
283  const std::string & name = "") const;
284 
285  virtual bool
286  IsEvaluableAtChildrenInObjectSpace(const PointType & point,
287  unsigned int depth = 0,
288  const std::string & name = "") const;
289 
290 
291  /**************************/
292  /* Values and derivatives */
293 
294  /**************************/
295 
298  itkSetMacro(DefaultInsideValue, double);
299  itkGetConstMacro(DefaultInsideValue, double);
304  itkSetMacro(DefaultOutsideValue, double);
305  itkGetConstMacro(DefaultOutsideValue, double);
309  virtual bool
310  ValueAtInWorldSpace(const PointType & point,
311  double & value,
312  unsigned int depth = 0,
313  const std::string & name = "") const;
314 
316  virtual bool
317  IsInsideInWorldSpace(const PointType & point, unsigned int depth = 0, const std::string & name = "") const;
318 
320  virtual bool
321  IsEvaluableAtInWorldSpace(const PointType & point, unsigned int depth = 0, const std::string & name = "") const;
322 
323 
325  virtual void
326  DerivativeAtInObjectSpace(const PointType & point,
327  short unsigned int order,
328  CovariantVectorType & value,
329  unsigned int depth = 0,
330  const std::string & name = "",
331  const DerivativeOffsetType & offset = MakeFilled<DerivativeOffsetType>(1));
332 
334  virtual void
335  DerivativeAtInWorldSpace(const PointType & point,
336  short unsigned int order,
337  CovariantVectorType & value,
338  unsigned int depth = 0,
339  const std::string & name = "",
340  const DerivativeOffsetType & offset = MakeFilled<DerivativeOffsetType>(1));
341 
342 
343  /*********************/
344  /* Deal with Parents */
345 
346  /*********************/
347 
351  void
352  SetParent(Self * parent);
353 
356  virtual bool
357  HasParent() const;
358 
359 
361  virtual const Self *
362  GetParent() const;
363 
365  virtual Self *
366  GetParent();
367 
369  itkSetMacro(ParentId, int);
370  itkGetConstReferenceMacro(ParentId, int);
374  /**********************/
375  /* Deal with Children */
376 
377  /**********************/
378 
380  void
381  SetChildren(ChildrenListType & children);
382 
384  void
385  AddChild(Self * pointer);
386 
389  bool
390  RemoveChild(Self * pointer);
391 
393  void
394  RemoveAllChildren(unsigned int depth = MaximumDepth);
395 
401  virtual ChildrenListType *
402  GetChildren(unsigned int depth = 0, const std::string & name = "") const;
403 
404  virtual ChildrenConstListType *
405  GetConstChildren(unsigned int depth = 0, const std::string & name = "") const;
406 
407  virtual void
408  AddChildrenToList(ChildrenListType * childrenList, unsigned int depth = 0, const std::string & name = "") const;
409 
410  virtual void
411  AddChildrenToConstList(ChildrenConstListType * childrenList,
412  unsigned int depth = 0,
413  const std::string & name = "") const;
414 
416  unsigned int
417  GetNumberOfChildren(unsigned int depth = 0, const std::string & name = "") const;
418 
421  GetObjectById(int id);
422 
426  bool
427  FixParentChildHierarchyUsingParentIds();
428 
430  bool
431  CheckIdValidity() const;
432 
434  void
435  FixIdValidity();
436 
438  int
439  GetNextAvailableId() const;
440 
441 
442  /**********************/
443  /* Bounding Box */
444 
445  /**********************/
446 
450  itkGetConstObjectMacro(MyBoundingBoxInObjectSpace, BoundingBoxType);
451 
455  virtual const BoundingBoxType *
456  GetMyBoundingBoxInWorldSpace() const;
457 
460  virtual bool
461  ComputeFamilyBoundingBox(unsigned int depth = 0, const std::string & name = "") const;
462 
465  itkGetConstObjectMacro(FamilyBoundingBoxInObjectSpace, BoundingBoxType);
466 
469  virtual const BoundingBoxType *
470  GetFamilyBoundingBoxInWorldSpace() const;
471 
472 
473  /******************************/
474  /* Regions used by DataObject */
475 
476  /******************************/
477 
484  virtual void
485  SetLargestPossibleRegion(const RegionType & region);
486 
493  virtual const RegionType &
495  {
496  return m_LargestPossibleRegion;
497  }
498 
502  virtual void
503  SetBufferedRegion(const RegionType & region);
504 
508  virtual const RegionType &
510  {
511  return m_BufferedRegion;
512  }
513 
518  virtual void
519  SetRequestedRegion(const RegionType & region);
520 
525  void
526  SetRequestedRegion(const DataObject * data) override;
527 
532  virtual const RegionType &
534  {
535  return m_RequestedRegion;
536  }
537 
541  void
542  SetRequestedRegionToLargestPossibleRegion() override;
543 
553  bool
554  RequestedRegionIsOutsideOfTheBufferedRegion() override;
555 
564  bool
565  VerifyRequestedRegion() override;
566 
574  void
575  UpdateOutputInformation() override;
576 
586  void
587  CopyInformation(const DataObject * data) override;
588 
589  /*************************************/
590  /* Evaluate used by SpatialFunctions */
591 
592  /*************************************/
593 
598  bool
599  Evaluate(const PointType & point) const
600  {
601  return this->IsInsideInWorldSpace(point);
602  }
603 
604 #if !defined(ITK_LEGACY_REMOVE)
605  itkLegacyMacro(void ComputeObjectToWorldTransform())
606  {
607  this->Update(); /* Update() should be used instead of ProtectedComputeObjectToWorldTransform() */
608  }
609 
610  itkLegacyMacro(void ComputeBoundingBox())
611  {
612  this->Update(); /* Update() should be used instead of outdated ComputeBoundingBox() */
613  }
614 
616  itkLegacyMacro(virtual bool IsInside(const PointType & point, unsigned int depth = 0, const std::string & name = "")
617  const)
618  {
619  return IsInsideInObjectSpace(point, depth, name);
620  };
621 #endif
622 
624 protected:
628  void
629  ProtectedComputeObjectToWorldTransform();
630 
632  virtual void
633  ComputeMyBoundingBox();
634 
639  SpatialObject() = default;
640 
642  ~SpatialObject() override;
643 
644  void
645  PrintSelf(std::ostream & os, Indent indent) const override;
646 
647  BoundingBoxType *
649  {
650  return m_MyBoundingBoxInObjectSpace.GetPointer();
651  }
652 
653  typename LightObject::Pointer
654  InternalClone() const override;
655 
656 private:
658  int m_Id{ -1 };
659 
661  std::string m_TypeName{ "SpatialObject" };
662 
664 
665  int m_ParentId{ -1 };
666  Self * m_Parent{ nullptr };
667 
671 
672  const BoundingBoxPointer m_MyBoundingBoxInObjectSpace{ BoundingBoxType::New() };
673  const BoundingBoxPointer m_MyBoundingBoxInWorldSpace{ BoundingBoxType::New() };
674  const BoundingBoxPointer m_FamilyBoundingBoxInObjectSpace{ BoundingBoxType::New() };
675  const BoundingBoxPointer m_FamilyBoundingBoxInWorldSpace{ BoundingBoxType::New() };
676 
677  const TransformPointer m_ObjectToParentTransform{ TransformType::New() };
678  const TransformPointer m_ObjectToParentTransformInverse{ TransformType::New() };
679 
680  const TransformPointer m_ObjectToWorldTransform{ TransformType::New() };
681  const TransformPointer m_ObjectToWorldTransformInverse{ TransformType::New() };
682 
684 
686  double m_DefaultInsideValue{ 1.0 };
687 
689  double m_DefaultOutsideValue{ 0.0 };
690 };
691 
692 } // end of namespace itk
693 
694 #if !defined(ITK_WRAPPING_PARSER)
695 # ifndef ITK_MANUAL_INSTANTIATION
696 # include "itkSpatialObject.hxx"
697 # endif
698 #endif
699 
700 #endif // itkSpatialObject_h
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:92
itk::SpatialObject::m_LargestPossibleRegion
RegionType m_LargestPossibleRegion
Definition: itkSpatialObject.h:668
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:182
itk::SpatialObject::GetModifiableMyBoundingBoxInObjectSpace
BoundingBoxType * GetModifiableMyBoundingBoxInObjectSpace()
Definition: itkSpatialObject.h:648
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::SpatialObject::m_Property
PropertyType m_Property
Definition: itkSpatialObject.h:663
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:167
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:670
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:176
itk::SpatialObject::GetMyMTime
ModifiedTimeType GetMyMTime() const
Definition: itkSpatialObject.h:195
itk::SpatialObject::m_ChildrenList
ChildrenListType m_ChildrenList
Definition: itkSpatialObject.h:683
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:599
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::m_RequestedRegion
RegionType m_RequestedRegion
Definition: itkSpatialObject.h:669
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:533
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:509
itk::SpatialObject::GetLargestPossibleRegion
virtual const RegionType & GetLargestPossibleRegion() const
Definition: itkSpatialObject.h:494
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