ITK  5.0.0
Insight Segmentation and Registration 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 "itkExceptionObject.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:
58  public DataObject
59 {
60 public:
61  ITK_DISALLOW_COPY_AND_ASSIGN(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 = 9999999;
70 
73  unsigned int GetMaximumDepth() const
74  { return MaximumDepth; }
75 
78 
81 
82 
83  // Spatial Function Iterator needs the following type alias
85 
91 
94 
96 
100 
102 
103  using BoundingBoxType = BoundingBox< IdentifierType, VDimension,
106 
108  using ChildrenListType = std::list< Pointer >;
110 
111  using ObjectListType = std::list< Pointer >;
112 
114 
116 
117  /* These are needed to participate in a Pipeline */
120 
122  unsigned int GetObjectDimension() const
123  { return VDimension; }
124 
126  itkNewMacro(Self);
127 
129  itkTypeMacro(SpatialObject, DataObject);
130 
132  void SetId(int id);
133  itkGetConstReferenceMacro(Id, int);
135 
139  itkSetMacro(TypeName, std::string);
140 
142  virtual const std::string GetTypeName() const
143  { return m_TypeName; }
144 
146  virtual std::string GetClassNameAndDimension( void ) const;
147 
149  void SetProperty( const PropertyType & property )
150  { this->m_Property = property; this->Modified(); }
151 
153  const PropertyType & GetProperty() const
154  { return this->m_Property; }
155 
157  { return this->m_Property; }
158 
161  ModifiedTimeType GetMTime() const override;
162 
166  { return Superclass::GetMTime(); }
167 
168 
169 /**************/
170  /* Transforms */
171 
172 /**************/
173 
176  void SetObjectToWorldTransform( const TransformType * transform);
177  itkGetModifiableObjectMacro(ObjectToWorldTransform, TransformType);
178  const TransformType * GetObjectToWorldTransformInverse() const;
180 
184  void ComputeObjectToWorldTransform();
185 
188  void SetObjectToParentTransform( const TransformType *transform);
189  itkGetModifiableObjectMacro(ObjectToParentTransform, TransformType);
190  const TransformType * GetObjectToParentTransformInverse() const;
192 
194  void ComputeObjectToParentTransform();
195 
196 /**********************************************************************/
197  /* These are the three member functions that a subclass will typically
198  * overwrite.
199  * * ComputeMyBoundingBox
200  * * IsInsideInObjectSpace
201  * * Update
202  * Optionally, a subclass may also wish to overwrite
203  * * ValueAtInObjectSpace
204  * * IsEvaluableAtInObjectSpace - if the extent is beyond IsInisde.
205  */
206 
207 /**********************************************************************/
208 
210  virtual bool ComputeMyBoundingBox() const;
211 
213  virtual bool IsInsideInObjectSpace(const PointType & point,
214  unsigned int depth = 0,
215  const std::string & name = "") const;
216 
219  void Update() override;
220 
221 
223  virtual bool ValueAtInObjectSpace(const PointType & point, double & value,
224  unsigned int depth = 0,
225  const std::string & name = "") const;
226 
233  virtual bool IsEvaluableAtInObjectSpace(const PointType & point,
234  unsigned int depth = 0,
235  const std::string & name = "") const;
236 
237 /********************************************************/
238  /* Helper functions to recurse queries through children */
239 
240 /********************************************************/
241  virtual bool IsInsideChildrenInObjectSpace(const PointType & point,
242  unsigned int depth = 0, const std::string & name = "") const;
243 
244  virtual bool ValueAtChildrenInObjectSpace(const PointType & point,
245  double & value, unsigned int depth = 0,
246  const std::string & name = "") const;
247 
248  virtual bool IsEvaluableAtChildrenInObjectSpace(const PointType & point,
249  unsigned int depth = 0,
250  const std::string & name = "") const;
251 
252 
253 /**************************/
254  /* Values and derivatives */
255 
256 /**************************/
257 
260  itkSetMacro(DefaultInsideValue, double);
261  itkGetConstMacro(DefaultInsideValue, double);
263 
266  itkSetMacro(DefaultOutsideValue, double);
267  itkGetConstMacro(DefaultOutsideValue, double);
269 
271  virtual bool ValueAtInWorldSpace(const PointType & point, double & value,
272  unsigned int depth = 0,
273  const std::string & name = "") const;
274 
276  virtual bool IsInsideInWorldSpace(const PointType & point,
277  unsigned int depth = 0,
278  const std::string & name = "") const;
279 
281  virtual bool IsEvaluableAtInWorldSpace(const PointType & point,
282  unsigned int depth = 0,
283  const std::string & name = "") const;
284 
285 
287  virtual void DerivativeAtInObjectSpace(const PointType & point,
288  short unsigned int order,
289  CovariantVectorType & value,
290  unsigned int depth = 0,
291  const std::string & name = "",
292  const DerivativeOffsetType & spacing = 1);
293 
295  virtual void DerivativeAtInWorldSpace(const PointType & point,
296  short unsigned int order,
297  CovariantVectorType & value,
298  unsigned int depth = 0,
299  const std::string & name = "",
300  const DerivativeOffsetType & spacing = 1);
301 
302 
303 /*********************/
304  /* Deal with Parents */
305 
306 /*********************/
307 
311  void SetParent(Self *parent);
312 
315  virtual bool HasParent() const;
316 
317 
319  virtual const Self * GetParent() const;
320 
322  virtual Self * GetParent();
323 
325  itkSetMacro(ParentId, int);
326  itkGetConstReferenceMacro(ParentId, int);
328 
329 
330 /**********************/
331  /* Deal with Children */
332 
333 /**********************/
334 
336  void SetChildren(ChildrenListType & children);
337 
339  void AddChild(Self *pointer );
340 
343  bool RemoveChild(Self *object);
344 
346  void RemoveAllChildren( unsigned int depth = MaximumDepth );
347 
353  virtual ChildrenListType * GetChildren(unsigned int depth = 0,
354  const std::string & name = "") const;
355 
356  virtual void AddChildrenToList(ChildrenListType * children,
357  unsigned int depth = 0, const std::string & name = "") const;
358 
360  unsigned int GetNumberOfChildren(unsigned int depth = 0,
361  const std::string & name = "") const;
362 
364  SpatialObject< VDimension > * GetObjectById(int Id);
365 
369  bool FixParentChildHierarchyUsingParentIds();
370 
372  bool CheckIdValidity() const;
373 
375  void FixIdValidity();
376 
378  int GetNextAvailableId() const;
379 
380 
381 /**********************/
382  /* Bounding Box */
383 
384 /**********************/
385 
389  itkGetConstObjectMacro( MyBoundingBoxInObjectSpace, BoundingBoxType );
390 
394  virtual const BoundingBoxType * GetMyBoundingBoxInWorldSpace() const;
395 
398  virtual bool ComputeFamilyBoundingBox( unsigned int depth = 0,
399  const std::string & name = "" ) const;
400 
403  itkGetConstObjectMacro( FamilyBoundingBoxInObjectSpace, BoundingBoxType );
404 
407  virtual const BoundingBoxType * GetFamilyBoundingBoxInWorldSpace() const;
408 
409 
410 /******************************/
411  /* Regions used by DataObject */
412 
413 /******************************/
414 
421  virtual void SetLargestPossibleRegion(const RegionType & region);
422 
429  virtual const RegionType & GetLargestPossibleRegion() const
430  { return m_LargestPossibleRegion; }
431 
435  virtual void SetBufferedRegion(const RegionType & region);
436 
440  virtual const RegionType & GetBufferedRegion() const
441  { return m_BufferedRegion; }
442 
447  virtual void SetRequestedRegion(const RegionType & region);
448 
453  void SetRequestedRegion(const DataObject *data) override;
454 
459  virtual const RegionType & GetRequestedRegion() const
460  { return m_RequestedRegion; }
461 
465  void SetRequestedRegionToLargestPossibleRegion() override;
466 
476  bool RequestedRegionIsOutsideOfTheBufferedRegion() override;
477 
486  bool VerifyRequestedRegion() override;
487 
495  void UpdateOutputInformation() override;
496 
506  void CopyInformation(const DataObject *data) override;
507 
508 /*************************************/
509  /* Evaluate used by SpatialFunctions */
510 
511 /*************************************/
512 
517  bool Evaluate(const PointType & point) const
518  { return this->IsInsideInWorldSpace(point); }
519 
520 
521 protected:
522 
524  SpatialObject();
525 
527  ~SpatialObject() override;
528 
529  void PrintSelf(std::ostream & os, Indent indent) const override;
530 
532  { return m_MyBoundingBoxInObjectSpace.GetPointer(); }
533 
534  typename LightObject::Pointer InternalClone() const override;
535 
536 private:
537 
539  int m_Id;
540 
542  std::string m_TypeName;
543 
545 
548 
552 
557 
560 
563 
565 
568 
571 
572 };
573 
574 } // end of namespace itk
575 
576 #if !defined( ITK_WRAPPING_PARSER )
577 #ifndef ITK_MANUAL_INSTANTIATION
578 #include "itkSpatialObject.hxx"
579 #endif
580 #endif
581 
582 #endif // itkSpatialObject_h
unsigned int GetMaximumDepth() const
PropertyType m_Property
bool Evaluate(const PointType &point) const
ChildrenListType m_ChildrenList
TransformPointer m_ObjectToParentTransformInverse
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:66
virtual const std::string GetTypeName() const
TransformPointer m_ObjectToWorldTransformInverse
virtual const RegionType & GetLargestPossibleRegion() const
BoundingBoxPointer m_FamilyBoundingBoxInObjectSpace
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:41
RegionType m_RequestedRegion
RegionType m_LargestPossibleRegion
TransformPointer m_ObjectToParentTransform
BoundingBoxPointer m_MyBoundingBoxInObjectSpace
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
SizeValueType IdentifierType
Definition: itkIntTypes.h:87
Implementation of the composite pattern.
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:68
void SetProperty(const PropertyType &property)
unsigned int GetObjectDimension() const
const PropertyType & GetProperty() const
unsigned long ModifiedTimeType
Definition: itkIntTypes.h:104
typename BoundingBoxType::Pointer BoundingBoxPointer
RegionType m_BufferedRegion
BoundingBoxPointer m_MyBoundingBoxInWorldSpace
ModifiedTimeType GetMyMTime() const
virtual const RegionType & GetRequestedRegion() const
typename TransformType::Pointer TransformPointer
virtual const RegionType & GetBufferedRegion() const
Define a front-end to the STL &quot;vector&quot; container that conforms to the IndexedContainerInterface.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
PropertyType & GetProperty()
BoundingBoxPointer m_FamilyBoundingBoxInWorldSpace
TransformPointer m_ObjectToWorldTransform
Base class for most ITK classes.
Definition: itkObject.h:60
BoundingBoxType * GetModifiableMyBoundingBoxInObjectSpace() const
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:52
A templated class holding a n-Dimensional covariant vector.
Base class for all data objects in ITK.
Represent and compute information about bounding boxes.