ITK  4.13.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 "itkAffineGeometryFrame.h"
24 #include "itkCovariantVector.h"
25 #include "itkExceptionObject.h"
26 #include <list>
28 #include "itkProcessObject.h"
29 #include "itkIndex.h"
30 #include "itkImageRegion.h"
32 
33 namespace itk
34 {
55 // Forward reference because of circular dependencies
56 template< unsigned int VDimension >
57 class ITK_FORWARD_EXPORT SpatialObjectTreeNode;
58 
59 template< unsigned int VDimension = 3 >
60 class ITK_TEMPLATE_EXPORT SpatialObject:
61  public DataObject
62 {
63 public:
64 
65  typedef double ScalarType;
66 
67  itkStaticConstMacro(MaximumDepth, unsigned int, 9999999);
68 
71  unsigned int GetMaximumDepth() const { return MaximumDepth; }
72 
75 
78 
80  // Spatial Function Iterator needs the following typedef
83 
87 
88  typedef double *SpacingType;
89 
92 
96 
98 
101 
104 
106  typedef std::list< Pointer > ChildrenListType;
108 
111 
119 
121 
124  virtual bool HasParent() const;
125 
127  virtual const char * GetTypeName(void) const { return m_TypeName.c_str(); }
128 
132  itkStaticConstMacro(ObjectDimension, unsigned int, VDimension);
133 
135  unsigned int GetObjectDimension(void) const { return VDimension; }
136 
138  itkNewMacro(Self);
139 
141  itkTypeMacro(SpatialObject, DataObject);
142 
144  itkSetObjectMacro(AffineGeometryFrame, AffineGeometryFrameType);
145  itkGetModifiableObjectMacro(AffineGeometryFrame, AffineGeometryFrameType);
147 
150  void SetObjectToWorldTransform(TransformType *transform);
151  itkGetModifiableObjectMacro(ObjectToWorldTransform, TransformType);
153 
154  itkGetModifiableObjectMacro(IndexToWorldTransform, TransformType);
155 
159  void ComputeObjectToWorldTransform();
160 
162  void ComputeObjectToParentTransform();
163 
165  ModifiedTimeType GetTransformMTime();
166 
168  ModifiedTimeType GetWorldTransformMTime();
169 
171  virtual bool ValueAt(const PointType & point, double & value,
172  unsigned int depth = 0,
173  char *name = ITK_NULLPTR) const;
174 
181  virtual bool IsEvaluableAt(const PointType & point,
182  unsigned int depth = 0,
183  char *name = ITK_NULLPTR) const;
184 
186  virtual bool IsInside(const PointType & point,
187  unsigned int depth = 0,
188  char *name = ITK_NULLPTR) const;
189 
194  bool Evaluate(const PointType & point) const
195  {
196  return this->IsInside(point);
197  }
198 
200  virtual void DerivativeAt(const PointType & point,
201  short unsigned int order,
202  OutputVectorType & value,
203  unsigned int depth = 0,
204  char *name = ITK_NULLPTR);
205 
208  virtual ModifiedTimeType GetMTime(void) const ITK_OVERRIDE;
209 
212  ModifiedTimeType GetObjectMTime(void) const
213  {
214  return Superclass::GetMTime();
215  }
216 
223  virtual void SetLargestPossibleRegion(const RegionType & region);
224 
231  virtual const RegionType & GetLargestPossibleRegion() const
232  { return m_LargestPossibleRegion; }
233 
237  virtual void SetBufferedRegion(const RegionType & region);
238 
242  virtual const RegionType & GetBufferedRegion() const
243  { return m_BufferedRegion; }
244 
249  virtual void SetRequestedRegion(const RegionType & region);
250 
255  virtual void SetRequestedRegion(const DataObject *data) ITK_OVERRIDE;
256 
261  virtual const RegionType & GetRequestedRegion() const
262  { return m_RequestedRegion; }
263 
273  const OffsetValueType * GetOffsetTable() const { return m_OffsetTable; }
275 
279  {
280  // need to add bounds checking for the region/buffer?
281  OffsetValueType offset = 0;
282  const IndexType & bufferedRegionIndex = m_BufferedRegion.GetIndex();
284 
285  // data is arranged as [][][][slice][row][col]
286  // with Index[0] = col, Index[1] = row, Index[2] = slice
287  for ( int i = VDimension - 1; i > 0; i-- )
288  {
289  offset += ( ind[i] - bufferedRegionIndex[i] ) * m_OffsetTable[i];
290  }
291  offset += ( ind[0] - bufferedRegionIndex[0] );
292 
293  return offset;
294  }
295 
299  {
300  IndexType index;
301  const IndexType & bufferedRegionIndex = m_BufferedRegion.GetIndex();
303 
304  for ( int i = VDimension - 1; i > 0; i-- )
305  {
306  index[i] = static_cast< IndexValueType >( offset / m_OffsetTable[i] );
307  offset -= ( index[i] * m_OffsetTable[i] );
308  index[i] += bufferedRegionIndex[i];
309  }
310  index[0] = bufferedRegionIndex[0] + static_cast< IndexValueType >( offset );
311 
312  return index;
313  }
314 
324  virtual void CopyInformation(const DataObject *data) ITK_OVERRIDE;
325 
333  virtual void UpdateOutputInformation() ITK_OVERRIDE;
334 
338  virtual void SetRequestedRegionToLargestPossibleRegion() ITK_OVERRIDE;
339 
349  virtual bool RequestedRegionIsOutsideOfTheBufferedRegion() ITK_OVERRIDE;
350 
359  virtual bool VerifyRequestedRegion() ITK_OVERRIDE;
360 
362  PropertyType * GetProperty();
363 
364  const PropertyType * GetProperty(void) const { return m_Property; }
365 
367  void SetProperty(PropertyType *property);
368 
370  itkGetConstReferenceMacro(Id, int);
371  itkSetMacro(Id, int);
373 
375  itkSetMacro(ParentId, int);
376  itkGetConstReferenceMacro(ParentId, int);
378 
380  virtual void Update(void) ITK_OVERRIDE;
381 
383  itkSetObjectMacro(TreeNode, TreeNodeType)
384 
386  itkGetModifiableObjectMacro(TreeNode, TreeNodeType);
387 
391  void SetSpacing(const double spacing[itkGetStaticConstMacro(ObjectDimension)])
392  {
393  m_AffineGeometryFrame->GetModifiableIndexToObjectTransform()->SetScale(spacing);
394  this->Modified();
395  }
396 
398  virtual const double * GetSpacing() const
399  {
400  return this->GetIndexToObjectTransform()->GetScale();
401  }
402 
408  const TransformType * GetIndexToObjectTransform() const;
409 
411  {
412  return m_AffineGeometryFrame->GetModifiableIndexToObjectTransform();
413  }
415  {
416  return m_AffineGeometryFrame->GetModifiableIndexToObjectTransform();
417  }
418 
419 
423  void SetObjectToParentTransform(TransformType *transform);
424 
425  TransformType * GetObjectToParentTransform();
426 
427  const TransformType * GetObjectToParentTransform() const;
428 
432  itkLegacyMacro(TransformType * GetObjectToNodeTransform());
433  #if defined(ITK_LEGACY_REMOVE)
434  TransformType * GetModifiableObjectToNodeTransform();
435  #endif
436  const TransformType * GetObjectToNodeTransform() const;
438 
443  void AddSpatialObject(Self *pointer);
444 
449  void RemoveSpatialObject(Self *object);
450 
452  virtual const Self * GetParent() const;
453 
455  virtual Self * GetParent();
456 
462  virtual ChildrenListType * GetChildren(unsigned int depth = 0,
463  char *name = ITK_NULLPTR) const;
464 
466  unsigned int GetNumberOfChildren(unsigned int depth = 0,
467  char *name = ITK_NULLPTR) const;
468 
470  void SetChildren(ChildrenListType & children);
471 
474  virtual void Clear();
475 
498  virtual bool ComputeBoundingBox() const;
499 
500  virtual bool ComputeLocalBoundingBox() const
501  {
502  std::cerr << "SpatialObject::ComputeLocalBoundingBox Not Implemented!"
503  << std::endl;
504  return false;
505  }
506 
509  virtual BoundingBoxType * GetBoundingBox() const;
510 
512  itkSetMacro(BoundingBoxChildrenDepth, unsigned int);
513  itkGetConstReferenceMacro(BoundingBoxChildrenDepth, unsigned int);
515 
518  itkSetMacro(BoundingBoxChildrenName, std::string);
519  itkGetConstReferenceMacro(BoundingBoxChildrenName, std::string);
521 
524  void SetParent(Self *parent);
525 
527  void SetNodeToParentNodeTransform(TransformType *transform);
528 
529  TransformType * GetNodeToParentNodeTransform();
530 
531  const TransformType * GetNodeToParentNodeTransform() const;
532 
535  itkSetMacro(DefaultInsideValue, double);
536  itkGetConstMacro(DefaultInsideValue, double);
538 
541  itkSetMacro(DefaultOutsideValue, double);
542  itkGetConstMacro(DefaultOutsideValue, double);
544 
547  virtual std::string GetSpatialObjectTypeAsString() const;
548 
549 protected:
550 
552  SpatialObject();
553 
555  virtual ~SpatialObject() ITK_OVERRIDE;
556 
557  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
558 
563  void ComputeOffsetTable();
564 
565  itkSetMacro(Dimension, unsigned int);
566  itkGetConstReferenceMacro(Dimension, unsigned int)
567  itkSetMacro(TypeName, std::string);
568  itkGetModifiableObjectMacro(Bounds, BoundingBoxType);
569  itkGetModifiableObjectMacro(InternalInverseTransform, TransformType);
570 
577  bool SetInternalInverseTransformToWorldToIndexTransform() const;
578 
579 private:
580 
581  ITK_DISALLOW_COPY_AND_ASSIGN(SpatialObject);
582 
583  BoundingBoxPointer m_Bounds;
584  mutable ModifiedTimeType m_BoundsMTime;
585 
586  TransformPointer m_ObjectToParentTransform;
587  TransformPointer m_ObjectToWorldTransform;
588  TransformPointer m_IndexToWorldTransform;
589 
591  std::string m_TypeName;
592 
593  unsigned int m_Dimension;
594 
595  OffsetValueType m_OffsetTable[3 + 1];
596 
597  RegionType m_LargestPossibleRegion;
598  RegionType m_RequestedRegion;
599  RegionType m_BufferedRegion;
600 
601  std::string m_BoundingBoxChildrenName;
602  unsigned int m_BoundingBoxChildrenDepth;
603  PropertyPointer m_Property;
604 
606  int m_Id;
607  int m_ParentId;
608 
610  typename TreeNodeType::Pointer m_TreeNode;
611 
613  AffineGeometryFramePointer m_AffineGeometryFrame;
614 
617  ChildrenListType m_InternalChildrenList;
618 
621  TransformPointer m_InternalInverseTransform;
622 
624  double m_DefaultInsideValue;
625 
627  double m_DefaultOutsideValue;
628 };
629 } // end of namespace itk
630 
631 #if !defined( ITK_WRAPPING_PARSER )
632 #ifndef ITK_MANUAL_INSTANTIATION
633 #include "itkSpatialObject.hxx"
634 #endif
635 #endif
636 
637 #endif // itkSpatialObject_h
unsigned int GetMaximumDepth() const
const IndexValueType * GetIndex() const
Definition: itkIndex.h:255
Index< VDimension > IndexType
Point< ScalarType, VDimension > PointType
bool Evaluate(const PointType &point) const
Offset< VDimension > OffsetType
Represents a node in a tree.
Definition: itkTreeNode.h:43
virtual const double * GetSpacing() const
ImageRegion< VDimension > RegionType
BoundingBox< IdentifierType, VDimension, ScalarType, VectorContainerType > BoundingBoxType
SpatialObjectProperty< float > PropertyType
SpatialObject< VDimension > Self
SmartPointer< const Self > ConstPointer
Represent the size (bounds) of a n-dimensional image.
Definition: itkSize.h:52
TransformType * GetModifiableIndexToObjectTransform(void)
signed long OffsetValueType
Definition: itkIntTypes.h:154
AffineGeometryFrameType::Pointer AffineGeometryFramePointer
signed long IndexValueType
Definition: itkIntTypes.h:150
unsigned long ModifiedTimeType
Definition: itkIntTypes.h:164
virtual bool ComputeLocalBoundingBox() const
CovariantVector< double, VDimension > OutputVectorType
virtual const RegionType & GetLargestPossibleRegion() const
SmartPointer< Self > Pointer
VectorContainer< IdentifierType, PointType > VectorContainerType
TransformType * GetIndexToObjectTransform(void)
class ITK_FORWARD_EXPORT SpatialObject
AffineGeometryFrame< double, VDimension > AffineGeometryFrameType
TransformType::Pointer TransformPointer
const TransformType * TransformConstPointer
IndexType ComputeIndex(OffsetValueType offset) const
PropertyType::Pointer PropertyPointer
OutputVectorType * OutputVectorPointer
const OffsetValueType * GetOffsetTable() const
VectorType * VectorPointer
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
Size< VDimension > SizeType
Implementation of the composite pattern.
SpatialObjectTreeNode< VDimension > TreeNodeType
std::list< Pointer > ChildrenListType
Vector< ScalarType, VDimension > VectorType
virtual const RegionType & GetRequestedRegion() const
ChildrenListType * ChildrenListPointer
CovariantVector< ScalarType, VDimension > CovariantVectorType
virtual const RegionType & GetBufferedRegion() const
virtual const char * GetTypeName(void) const
Point< ScalarType, VDimension > InputType
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
ScalableAffineTransform< double, VDimension > TransformType
unsigned int GetObjectDimension(void) const
OffsetValueType ComputeOffset(const IndexType &ind) const
Describes the geometry of a data object.
PointType * PointPointer
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:52
A templated class holding a n-Dimensional covariant vector.
Affine transformation with a specified center of rotation.
Base class for all data objects in ITK.
BoundingBoxType::Pointer BoundingBoxPointer
Represent and compute information about bounding boxes.