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
35namespace itk
36{
57template <unsigned int VDimension = 3>
58class ITK_TEMPLATE_EXPORT SpatialObject : public DataObject
59{
60public:
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
153 {
154 return m_TypeName;
155 }
156
163 virtual std::string
165
168 virtual void
170
172 void
173 SetProperty(const PropertyType & property)
174 {
175 this->m_Property = property;
176 this->Modified();
177 }
181 const PropertyType &
183 {
184 return this->m_Property;
185 }
186
187 PropertyType &
189 {
190 return this->m_Property;
191 }
192
196 GetMTime() const override;
197
202 {
203 return Superclass::GetMTime();
204 }
205
206
207 /**************/
208 /* Transforms */
209
210 /**************/
211
218 void
220 itkGetModifiableObjectMacro(ObjectToWorldTransform, TransformType);
221 const TransformType *
230 void
232 itkGetModifiableObjectMacro(ObjectToParentTransform, TransformType);
233 const TransformType *
244 void
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
268
271 void
272 Update() override;
273
274
276 virtual bool
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
303 double & value,
304 unsigned int depth = 0,
305 const std::string & name = "") const;
306
308 virtual bool
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
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
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
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
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 *
432
434 itkSetMacro(ParentId, int);
435 itkGetConstReferenceMacro(ParentId, int);
439 /**********************/
440 /* Deal with Children */
441
442 /**********************/
443
445 void
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
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
492
496 bool
498
503 bool
505
507 void
509
514 int
516
517
518 /**********************/
519 /* Bounding Box */
520
521 /**********************/
522
526 itkGetConstObjectMacro(MyBoundingBoxInObjectSpace, BoundingBoxType);
527
531 virtual const BoundingBoxType *
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 *
550
551
552 /******************************/
553 /* Regions used by DataObject */
554
555 /******************************/
556
565 virtual void
567
574 virtual const RegionType &
576 {
577 return m_LargestPossibleRegion;
578 }
579
583 virtual void
585
589 virtual const RegionType &
591 {
592 return m_BufferedRegion;
593 }
594
599 virtual void
601
606 void
607 SetRequestedRegion(const DataObject * data) override;
608
613 virtual const RegionType &
615 {
616 return m_RequestedRegion;
617 }
618
622 void
624
634 bool
636
645 bool
647
655 void
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
704protected:
708 void
710
712 virtual void
714
719 SpatialObject() = default;
720
722 ~SpatialObject() override;
723
724 void
725 PrintSelf(std::ostream & os, Indent indent) const override;
726
729 {
730 return m_MyBoundingBoxInObjectSpace.GetPointer();
731 }
732
733 typename LightObject::Pointer
734 InternalClone() const override;
735
736private:
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
Represent and compute information about bounding boxes.
A templated class holding a n-Dimensional covariant vector.
Base class for all data objects in ITK.
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Base class for most ITK classes.
Definition: itkObject.h:62
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:54
Implementation of the composite pattern.
typename TransformType::Pointer TransformPointer
void SetObjectToParentTransform(const TransformType *transform)
virtual const BoundingBoxType * GetFamilyBoundingBoxInWorldSpace() const
virtual void Clear()
virtual void ComputeMyBoundingBox()
std::list< ConstPointer > ChildrenConstListType
virtual Self * GetParent()
void SetProperty(const PropertyType &property)
virtual ChildrenListType * GetChildren(unsigned int depth=0, const std::string &name="") const
virtual ChildrenConstListType * GetConstChildren(unsigned int depth=0, const std::string &name="") const
virtual bool IsInsideChildrenInObjectSpace(const PointType &point, unsigned int depth=0, const std::string &name="") const
void SetId(int id)
virtual void AddChildrenToList(ChildrenListType *childrenList, unsigned int depth=0, const std::string &name="") const
void UpdateOutputInformation() override
virtual std::string GetTypeName() const
ChildrenListType * ChildrenListPointer
bool VerifyRequestedRegion() override
virtual const BoundingBoxType * GetMyBoundingBoxInWorldSpace() const
virtual void DerivativeAtInObjectSpace(const PointType &point, short unsigned int order, CovariantVectorType &value, unsigned int depth=0, const std::string &name="", const DerivativeOffsetType &offset=MakeFilled< DerivativeOffsetType >(1))
virtual std::string GetClassNameAndDimension() const
SpatialObject()=default
virtual bool IsInsideInObjectSpace(const PointType &point) const
const PropertyType & GetProperty() const
virtual void SetLargestPossibleRegion(const RegionType &region)
virtual bool IsEvaluableAtChildrenInObjectSpace(const PointType &point, unsigned int depth=0, const std::string &name="") const
virtual void AddChildrenToConstList(ChildrenConstListType *childrenList, unsigned int depth=0, const std::string &name="") const
virtual const Self * GetParent() const
int GetNextAvailableId() const
void SetRequestedRegionToLargestPossibleRegion() override
void SetRequestedRegion(const DataObject *data) override
void SetParent(Self *parent)
bool ValueAtInWorldSpace(const PointType &point, double &value, unsigned int depth=0, const std::string &name="") const
virtual const RegionType & GetRequestedRegion() const
void Update() override
virtual void SetRequestedRegion(const RegionType &region)
bool RequestedRegionIsOutsideOfTheBufferedRegion() override
void PrintSelf(std::ostream &os, Indent indent) const override
bool RemoveChild(Self *pointer)
bool IsInsideInWorldSpace(const PointType &point, unsigned int depth, const std::string &name="") const
void DerivativeAtInWorldSpace(const PointType &point, short unsigned int order, CovariantVectorType &value, unsigned int depth=0, const std::string &name="", const DerivativeOffsetType &offset=MakeFilled< DerivativeOffsetType >(1))
unsigned int GetMaximumDepth() const
virtual bool ComputeFamilyBoundingBox(unsigned int depth=0, const std::string &name="") const
ModifiedTimeType GetMTime() const override
void ProtectedComputeObjectToWorldTransform()
virtual const RegionType & GetLargestPossibleRegion() const
virtual bool ValueAtInObjectSpace(const PointType &point, double &value, unsigned int depth=0, const std::string &name="") const
unsigned int ObjectDimensionType
bool IsInsideInObjectSpace(const PointType &point, unsigned int depth, const std::string &name="") const
LightObject::Pointer InternalClone() const override
std::list< Pointer > ObjectListType
bool IsEvaluableAtInWorldSpace(const PointType &point, unsigned int depth=0, const std::string &name="") const
unsigned int GetObjectDimension() const
void SetChildren(ChildrenListType &children)
SpatialObject< VDimension > * GetObjectById(int id)
ChildrenConstListType * ChildrenConstListPointer
bool FixParentChildHierarchyUsingParentIds()
unsigned int GetNumberOfChildren(unsigned int depth=0, const std::string &name="") const
void AddChild(Self *pointer)
const TransformType * GetObjectToWorldTransformInverse() const
virtual bool ValueAtChildrenInObjectSpace(const PointType &point, double &value, unsigned int depth=0, const std::string &name="") const
void RemoveAllChildren(unsigned int depth=MaximumDepth)
~SpatialObject() override
ModifiedTimeType GetMyMTime() const
const TransformType * GetObjectToParentTransformInverse() const
virtual bool HasParent() const
virtual void SetBufferedRegion(const RegionType &region)
bool Evaluate(const PointType &point) const
void SetObjectToWorldTransform(const TransformType *transform)
void ComputeObjectToParentTransform()
typename BoundingBoxType::Pointer BoundingBoxPointer
virtual bool IsEvaluableAtInObjectSpace(const PointType &point, unsigned int depth=0, const std::string &name="") const
PropertyType & GetProperty()
BoundingBoxType * GetModifiableMyBoundingBoxInObjectSpace()
std::list< ConstPointer > ObjectConstListType
std::list< Pointer > ChildrenListType
bool CheckIdValidity() const
bool IsInsideInWorldSpace(const PointType &point) const
virtual const RegionType & GetBufferedRegion() const
void CopyInformation(const DataObject *data) override
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:63
Define a front-end to the STL "vector" container that conforms to the IndexedContainerInterface.
static Pointer New()
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:42
*par Constraints *The filter 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
SizeValueType ModifiedTimeType
Definition: itkIntTypes.h:105