ITK  4.12.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_TEMPLATE_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  TransformType * GetObjectToNodeTransform();
433 
434  const TransformType * GetObjectToNodeTransform() const;
435 
440  void AddSpatialObject(Self *pointer);
441 
446  void RemoveSpatialObject(Self *object);
447 
449  virtual const Self * GetParent() const;
450 
452  virtual Self * GetParent();
453 
459  virtual ChildrenListType * GetChildren(unsigned int depth = 0,
460  char *name = ITK_NULLPTR) const;
461 
463  unsigned int GetNumberOfChildren(unsigned int depth = 0,
464  char *name = ITK_NULLPTR) const;
465 
467  void SetChildren(ChildrenListType & children);
468 
471  virtual void Clear();
472 
495  virtual bool ComputeBoundingBox() const;
496 
497  virtual bool ComputeLocalBoundingBox() const
498  {
499  std::cerr << "SpatialObject::ComputeLocalBoundingBox Not Implemented!"
500  << std::endl;
501  return false;
502  }
503 
506  virtual BoundingBoxType * GetBoundingBox() const;
507 
509  itkSetMacro(BoundingBoxChildrenDepth, unsigned int);
510  itkGetConstReferenceMacro(BoundingBoxChildrenDepth, unsigned int);
512 
515  itkSetMacro(BoundingBoxChildrenName, std::string);
516  itkGetConstReferenceMacro(BoundingBoxChildrenName, std::string);
518 
521  void SetParent(Self *parent);
522 
524  void SetNodeToParentNodeTransform(TransformType *transform);
525 
526  TransformType * GetNodeToParentNodeTransform();
527 
528  const TransformType * GetNodeToParentNodeTransform() const;
529 
532  itkSetMacro(DefaultInsideValue, double);
533  itkGetConstMacro(DefaultInsideValue, double);
535 
538  itkSetMacro(DefaultOutsideValue, double);
539  itkGetConstMacro(DefaultOutsideValue, double);
541 
544  virtual std::string GetSpatialObjectTypeAsString() const;
545 
546 protected:
547 
549  SpatialObject();
550 
552  virtual ~SpatialObject();
553 
554  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
555 
560  void ComputeOffsetTable();
561 
562  itkSetMacro(Dimension, unsigned int);
563  itkGetConstReferenceMacro(Dimension, unsigned int)
564  itkSetMacro(TypeName, std::string);
565  itkGetModifiableObjectMacro(Bounds, BoundingBoxType);
566  itkGetModifiableObjectMacro(InternalInverseTransform, TransformType);
567 
574  bool SetInternalInverseTransformToWorldToIndexTransform() const;
575 
576 private:
577 
578  ITK_DISALLOW_COPY_AND_ASSIGN(SpatialObject);
579 
582 
586 
588  std::string m_TypeName;
589 
590  unsigned int m_Dimension;
591 
592  OffsetValueType m_OffsetTable[3 + 1];
593 
597 
601 
603  int m_Id;
605 
608 
611 
615 
619 
622 
625 };
626 } // end of namespace itk
627 
628 #if !defined( ITK_WRAPPING_PARSER )
629 #ifndef ITK_MANUAL_INSTANTIATION
630 #include "itkSpatialObject.hxx"
631 #endif
632 #endif
633 
634 #endif // itkSpatialObject_h
virtual bool RequestedRegionIsOutsideOfTheBufferedRegion()
unsigned int GetMaximumDepth() const
virtual void CopyInformation(const DataObject *)
const IndexValueType * GetIndex() const
Definition: itkIndex.h:255
Index< VDimension > IndexType
Point< ScalarType, VDimension > PointType
bool Evaluate(const PointType &point) const
virtual void PrintSelf(std::ostream &os, Indent indent) const override
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
virtual void UpdateOutputInformation()
AffineGeometryFrameType::Pointer AffineGeometryFramePointer
signed long IndexValueType
Definition: itkIntTypes.h:150
unsigned long ModifiedTimeType
Definition: itkIntTypes.h:164
virtual bool ComputeLocalBoundingBox() const
TransformPointer m_InternalInverseTransform
CovariantVector< double, VDimension > OutputVectorType
virtual const RegionType & GetLargestPossibleRegion() const
SmartPointer< Self > Pointer
VectorContainer< IdentifierType, PointType > VectorContainerType
TransformType * GetIndexToObjectTransform(void)
AffineGeometryFramePointer m_AffineGeometryFrame
RegionType m_RequestedRegion
AffineGeometryFrame< double, VDimension > AffineGeometryFrameType
TransformType::Pointer TransformPointer
const TransformType * TransformConstPointer
RegionType m_LargestPossibleRegion
IndexType ComputeIndex(OffsetValueType offset) const
PropertyType::Pointer PropertyPointer
unsigned int m_BoundingBoxChildrenDepth
TransformPointer m_ObjectToParentTransform
OutputVectorType * OutputVectorPointer
virtual void SetRequestedRegion(const DataObject *)
const OffsetValueType * GetOffsetTable() const
VectorType * VectorPointer
ModifiedTimeType m_BoundsMTime
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
ChildrenListType m_InternalChildrenList
virtual bool VerifyRequestedRegion()
Size< VDimension > SizeType
std::string m_BoundingBoxChildrenName
virtual void SetRequestedRegionToLargestPossibleRegion()
Implementation of the composite pattern.
SpatialObjectTreeNode< VDimension > TreeNodeType
PropertyPointer m_Property
std::list< Pointer > ChildrenListType
Vector< ScalarType, VDimension > VectorType
BoundingBoxPointer m_Bounds
RegionType m_BufferedRegion
Base class for all data objects in ITK.
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.
unsigned int m_Dimension
virtual void Update()
Control indentation during Print() invocation.
Definition: itkIndent.h:49
ScalableAffineTransform< double, VDimension > TransformType
TreeNodeType::Pointer m_TreeNode
unsigned int GetObjectDimension(void) const
OffsetValueType ComputeOffset(const IndexType &ind) const
Describes the geometry of a data object.
PointType * PointPointer
class ITK_TEMPLATE_EXPORT SpatialObject
TransformPointer m_ObjectToWorldTransform
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.
BoundingBoxType::Pointer BoundingBoxPointer
Represent and compute information about bounding boxes.
TransformPointer m_IndexToWorldTransform