ITK  4.6.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 template< unsigned int VDimension >
57 
58 template< unsigned int VDimension = 3 >
60  public DataObject
61 {
62 public:
63 
64  typedef double ScalarType;
65 
66  itkStaticConstMacro(MaximumDepth, unsigned int, 9999999);
67 
70  unsigned int GetMaximumDepth() const { return MaximumDepth; }
71 
74 
77 
79  // Spatial Function Iterator needs the following typedef
82 
86 
87  typedef double *SpacingType;
88 
91 
95 
97 
100 
103 
105  typedef std::list< Pointer > ChildrenListType;
107 
110 
118 
120 
123  virtual bool HasParent(void) const;
124 
126  virtual const char * GetTypeName(void) const { return m_TypeName.c_str(); }
127 
131  itkStaticConstMacro(ObjectDimension, unsigned int, VDimension);
132 
134  unsigned int GetObjectDimension(void) const { return VDimension; }
135 
137  itkNewMacro(Self);
138 
140  itkTypeMacro(SpatialObject, DataObject);
141 
143  itkSetObjectMacro(AffineGeometryFrame, AffineGeometryFrameType);
144  itkGetModifiableObjectMacro(AffineGeometryFrame, AffineGeometryFrameType);
146 
149  void SetObjectToWorldTransform(TransformType *transform);
150  itkGetModifiableObjectMacro(ObjectToWorldTransform, TransformType);
152 
153  itkGetModifiableObjectMacro(IndexToWorldTransform, TransformType);
154 
159 
162 
164  unsigned long GetTransformMTime(void);
165 
167  unsigned long GetWorldTransformMTime(void);
168 
170  virtual bool ValueAt(const PointType & point, double & value,
171  unsigned int depth = 0,
172  char *name = ITK_NULLPTR) const;
173 
180  virtual bool IsEvaluableAt(const PointType & point,
181  unsigned int depth = 0,
182  char *name = ITK_NULLPTR) const;
183 
185  virtual bool IsInside(const PointType & point,
186  unsigned int depth = 0,
187  char *name = ITK_NULLPTR) const;
188 
193  bool Evaluate(const PointType & point) const
194  {
195  return this->IsInside(point);
196  }
197 
199  virtual void DerivativeAt(const PointType & point,
200  short unsigned int order,
201  OutputVectorType & value,
202  unsigned int depth = 0,
203  char *name = ITK_NULLPTR);
204 
207  virtual ModifiedTimeType GetMTime(void) const ITK_OVERRIDE;
208 
211  unsigned long GetObjectMTime(void) const
212  {
213  return Superclass::GetMTime();
214  }
215 
222  virtual void SetLargestPossibleRegion(const RegionType & region);
223 
230  virtual const RegionType & GetLargestPossibleRegion() const
231  { return m_LargestPossibleRegion; }
232 
236  virtual void SetBufferedRegion(const RegionType & region);
237 
241  virtual const RegionType & GetBufferedRegion() const
242  { return m_BufferedRegion; }
243 
248  virtual void SetRequestedRegion(const RegionType & region);
249 
254  virtual void SetRequestedRegion(const DataObject *data) ITK_OVERRIDE;
255 
260  virtual const RegionType & GetRequestedRegion() const
261  { return m_RequestedRegion; }
262 
272  const OffsetValueType * GetOffsetTable() const { return m_OffsetTable; }
274 
278  {
279  // need to add bounds checking for the region/buffer?
280  OffsetValueType offset = 0;
281  const IndexType & bufferedRegionIndex = m_BufferedRegion.GetIndex();
283 
284  // data is arranged as [][][][slice][row][col]
285  // with Index[0] = col, Index[1] = row, Index[2] = slice
286  for ( int i = VDimension - 1; i > 0; i-- )
287  {
288  offset += ( ind[i] - bufferedRegionIndex[i] ) * m_OffsetTable[i];
289  }
290  offset += ( ind[0] - bufferedRegionIndex[0] );
291 
292  return offset;
293  }
294 
298  {
299  IndexType index;
300  const IndexType & bufferedRegionIndex = m_BufferedRegion.GetIndex();
302 
303  for ( int i = VDimension - 1; i > 0; i-- )
304  {
305  index[i] = static_cast< IndexValueType >( offset / m_OffsetTable[i] );
306  offset -= ( index[i] * m_OffsetTable[i] );
307  index[i] += bufferedRegionIndex[i];
308  }
309  index[0] = bufferedRegionIndex[0] + static_cast< IndexValueType >( offset );
310 
311  return index;
312  }
313 
323  virtual void CopyInformation(const DataObject *data) ITK_OVERRIDE;
324 
332  virtual void UpdateOutputInformation() ITK_OVERRIDE;
333 
337  virtual void SetRequestedRegionToLargestPossibleRegion() ITK_OVERRIDE;
338 
348  virtual bool RequestedRegionIsOutsideOfTheBufferedRegion() ITK_OVERRIDE;
349 
358  virtual bool VerifyRequestedRegion() ITK_OVERRIDE;
359 
361  PropertyType * GetProperty(void);
362 
363  const PropertyType * GetProperty(void) const { return m_Property; }
364 
366  void SetProperty(PropertyType *property);
367 
369  itkGetConstReferenceMacro(Id, int);
370  itkSetMacro(Id, int);
372 
374  itkSetMacro(ParentId, int);
375  itkGetConstReferenceMacro(ParentId, int);
377 
379  virtual void Update(void) ITK_OVERRIDE;
380 
382  itkSetObjectMacro(TreeNode, TreeNodeType)
383 
385  itkGetModifiableObjectMacro(TreeNode, TreeNodeType);
386 
390  void SetSpacing(const double spacing[itkGetStaticConstMacro(ObjectDimension)])
391  {
392  m_AffineGeometryFrame->GetModifiableIndexToObjectTransform()->SetScale(spacing);
393  this->Modified();
394  }
395 
397  virtual const double * GetSpacing() const
398  {
399  return this->GetIndexToObjectTransform()->GetScale();
400  }
401 
407  const TransformType * GetIndexToObjectTransform(void) const;
408 
410  {
411  return m_AffineGeometryFrame->GetModifiableIndexToObjectTransform();
412  }
414  {
415  return m_AffineGeometryFrame->GetModifiableIndexToObjectTransform();
416  }
417 
418 
422  void SetObjectToParentTransform(TransformType *transform);
423 
425 
426  const TransformType * GetObjectToParentTransform(void) const;
427 
432 
433  const TransformType * GetObjectToNodeTransform(void) const;
434 
439  void AddSpatialObject(Self *pointer);
440 
445  void RemoveSpatialObject(Self *object);
446 
448  virtual const Self * GetParent(void) const;
449 
451  virtual Self * GetParent(void);
452 
458  virtual ChildrenListType * GetChildren(unsigned int depth = 0,
459  char *name = ITK_NULLPTR) const;
460 
462  unsigned int GetNumberOfChildren(unsigned int depth = 0,
463  char *name = ITK_NULLPTR) const;
464 
466  void SetChildren(ChildrenListType & children);
467 
470  virtual void Clear(void);
471 
494  virtual bool ComputeBoundingBox() const;
495 
496  virtual bool ComputeLocalBoundingBox() const
497  {
498  std::cerr << "SpatialObject::ComputeLocalBoundingBox Not Implemented!"
499  << std::endl;
500  return false;
501  }
502 
505  virtual BoundingBoxType * GetBoundingBox() const;
506 
508  itkSetMacro(BoundingBoxChildrenDepth, unsigned int);
509  itkGetConstReferenceMacro(BoundingBoxChildrenDepth, unsigned int);
511 
514  itkSetMacro(BoundingBoxChildrenName, std::string);
515  itkGetConstReferenceMacro(BoundingBoxChildrenName, std::string);
517 
520  void SetParent(Self *parent);
521 
524 
526 
527  const TransformType * GetNodeToParentNodeTransform(void) const;
528 
531  itkSetMacro(DefaultInsideValue, double);
532  itkGetConstMacro(DefaultInsideValue, double);
534 
537  itkSetMacro(DefaultOutsideValue, double);
538  itkGetConstMacro(DefaultOutsideValue, double);
540 
543  virtual std::string GetSpatialObjectTypeAsString() const;
544 
545 protected:
546 
548  SpatialObject();
549 
551  virtual ~SpatialObject();
552 
553  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
554 
559  void ComputeOffsetTable();
560 
561  itkSetMacro(Dimension, unsigned int);
562  itkGetConstReferenceMacro(Dimension, unsigned int)
563  itkSetMacro(TypeName, std::string);
564  itkGetModifiableObjectMacro(Bounds, BoundingBoxType);
565  itkGetModifiableObjectMacro(InternalInverseTransform, TransformType);
566 
574 
575 private:
576 
577  SpatialObject(const Self &); //purposely not implemented
578  void operator=(const Self &); //purposely not implemented
579 
582 
586 
588  std::string m_TypeName;
589 
590  unsigned int m_Dimension;
591 
593 
597 
601 
603  int m_Id;
605 
608 
611 
615 
619 
622 
625 };
626 } // end of namespace itk
627 
628 #if !defined( CABLE_CONFIGURATION )
629 #ifndef ITK_MANUAL_INSTANTIATION
630 #include "itkSpatialObject.hxx"
631 #endif
632 #endif
633 
634 #endif // __itkSpatialObject_h
virtual std::string GetSpatialObjectTypeAsString() const
unsigned int GetMaximumDepth() const
void SetChildren(ChildrenListType &children)
Index< VDimension > IndexType
TransformType * GetObjectToNodeTransform(void)
Point< ScalarType, VDimension > PointType
bool Evaluate(const PointType &point) const
Offset< VDimension > OffsetType
virtual void UpdateOutputInformation() ITK_OVERRIDE
virtual void SetRequestedRegion(const RegionType &region)
Represents a node in a tree.
Definition: itkTreeNode.h:43
const IndexType & GetIndex() const
virtual const double * GetSpacing() const
ImageRegion< VDimension > RegionType
virtual void DerivativeAt(const PointType &point, short unsigned int order, OutputVectorType &value, unsigned int depth=0, char *name=ITK_NULLPTR)
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
const TransformType * GetIndexToObjectTransform(void) const
void SetProperty(PropertyType *property)
AffineGeometryFrameType::Pointer AffineGeometryFramePointer
void operator=(const Self &)
unsigned long GetWorldTransformMTime(void)
void ComputeObjectToParentTransform(void)
signed long IndexValueType
Definition: itkIntTypes.h:150
unsigned long ModifiedTimeType
Definition: itkIntTypes.h:164
virtual void CopyInformation(const DataObject *data) ITK_OVERRIDE
PropertyType * GetProperty(void)
void SetParent(Self *parent)
unsigned int GetNumberOfChildren(unsigned int depth=0, char *name=ITK_NULLPTR) const
virtual bool ComputeLocalBoundingBox() const
TransformPointer m_InternalInverseTransform
CovariantVector< double, VDimension > OutputVectorType
virtual const RegionType & GetLargestPossibleRegion() const
void RemoveSpatialObject(Self *object)
SmartPointer< Self > Pointer
TransformType * GetObjectToParentTransform(void)
virtual void SetRequestedRegionToLargestPossibleRegion() ITK_OVERRIDE
VectorContainer< IdentifierType, PointType > VectorContainerType
TransformType * GetIndexToObjectTransform(void)
TransformType * GetNodeToParentNodeTransform(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
bool SetInternalInverseTransformToWorldToIndexTransform() const
unsigned int m_BoundingBoxChildrenDepth
TransformPointer m_ObjectToParentTransform
OutputVectorType * OutputVectorPointer
virtual void SetBufferedRegion(const RegionType &region)
virtual bool IsEvaluableAt(const PointType &point, unsigned int depth=0, char *name=ITK_NULLPTR) const
const OffsetValueType * GetOffsetTable() const
VectorType * VectorPointer
virtual BoundingBoxType * GetBoundingBox() const
ModifiedTimeType m_BoundsMTime
void SetNodeToParentNodeTransform(TransformType *transform)
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
OffsetValueType m_OffsetTable[3+1]
static const unsigned int ObjectDimension
virtual bool IsInside(const PointType &point, unsigned int depth=0, char *name=ITK_NULLPTR) const
ChildrenListType m_InternalChildrenList
virtual const double * GetScale() const
Size< VDimension > SizeType
std::string m_BoundingBoxChildrenName
virtual void Update(void) ITK_OVERRIDE
virtual void SetLargestPossibleRegion(const RegionType &region)
Implementation of the composite pattern.
SpatialObjectTreeNode< VDimension > TreeNodeType
PropertyPointer m_Property
virtual ModifiedTimeType GetMTime(void) const ITK_OVERRIDE
void AddSpatialObject(Self *pointer)
void ComputeObjectToWorldTransform(void)
std::list< Pointer > ChildrenListType
Vector< ScalarType, VDimension > VectorType
virtual ModifiedTimeType GetMTime() const
virtual bool HasParent(void) const
BoundingBoxPointer m_Bounds
RegionType m_BufferedRegion
virtual void Modified() const
void SetObjectToWorldTransform(TransformType *transform)
void SetSpacing(const double spacing[itkGetStaticConstMacro(ObjectDimension)])
virtual bool ValueAt(const PointType &point, double &value, unsigned int depth=0, char *name=ITK_NULLPTR) const
virtual bool VerifyRequestedRegion() ITK_OVERRIDE
unsigned long GetTransformMTime(void)
virtual const RegionType & GetRequestedRegion() const
virtual ChildrenListType * GetChildren(unsigned int depth=0, char *name=ITK_NULLPTR) const
unsigned long GetObjectMTime(void) const
ChildrenListType * ChildrenListPointer
CovariantVector< ScalarType, VDimension > CovariantVectorType
virtual void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
virtual bool ComputeBoundingBox() const
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
Control indentation during Print() invocation.
Definition: itkIndent.h:49
static const unsigned int MaximumDepth
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.
virtual ~SpatialObject()
PointType * PointPointer
TransformPointer m_ObjectToWorldTransform
virtual const Self * GetParent(void) const
virtual bool RequestedRegionIsOutsideOfTheBufferedRegion() ITK_OVERRIDE
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:51
A templated class holding a n-Dimensional covariant vector.
Affine transformation with a specified center of rotation.
virtual void Clear(void)
Base class for all data objects in ITK.
BoundingBoxType::Pointer BoundingBoxPointer
void SetObjectToParentTransform(TransformType *transform)
Represent and compute information about bounding boxes.
TransformPointer m_IndexToWorldTransform