ITK  4.9.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() 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();
165 
167  unsigned long GetWorldTransformMTime();
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 
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 
408 
410  {
411  return m_AffineGeometryFrame->GetModifiableIndexToObjectTransform();
412  }
414  {
415  return m_AffineGeometryFrame->GetModifiableIndexToObjectTransform();
416  }
417 
418 
422  void SetObjectToParentTransform(TransformType *transform);
423 
425 
427 
432 
433  const TransformType * GetObjectToNodeTransform() const;
434 
439  void AddSpatialObject(Self *pointer);
440 
445  void RemoveSpatialObject(Self *object);
446 
448  virtual const Self * GetParent() const;
449 
451  virtual Self * GetParent();
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();
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 
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 &) ITK_DELETE_FUNCTION;
578  void operator=(const Self &) ITK_DELETE_FUNCTION;
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( ITK_WRAPPING_PARSER )
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
Point< ScalarType, VDimension > PointType
bool Evaluate(const PointType &point) const
Offset< VDimension > OffsetType
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
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
void SetProperty(PropertyType *property)
AffineGeometryFrameType::Pointer AffineGeometryFramePointer
TransformType * GetNodeToParentNodeTransform()
virtual void SetRequestedRegionToLargestPossibleRegion() override
signed long IndexValueType
Definition: itkIntTypes.h:150
unsigned long ModifiedTimeType
Definition: itkIntTypes.h:164
unsigned long GetWorldTransformMTime()
void SetParent(Self *parent)
virtual bool ComputeLocalBoundingBox() const
virtual bool HasParent() const
TransformPointer m_InternalInverseTransform
CovariantVector< double, VDimension > OutputVectorType
virtual const RegionType & GetLargestPossibleRegion() const
virtual void PrintSelf(std::ostream &os, Indent indent) const override
void RemoveSpatialObject(Self *object)
SmartPointer< Self > Pointer
unsigned int GetNumberOfChildren(unsigned int depth=0, char *name=nullptr) const
VectorContainer< IdentifierType, PointType > VectorContainerType
TransformType * GetIndexToObjectTransform(void)
AffineGeometryFramePointer m_AffineGeometryFrame
RegionType m_RequestedRegion
AffineGeometryFrame< double, VDimension > AffineGeometryFrameType
TransformType::Pointer TransformPointer
const TransformType * TransformConstPointer
virtual bool ValueAt(const PointType &point, double &value, unsigned int depth=0, char *name=nullptr) const
RegionType m_LargestPossibleRegion
IndexType ComputeIndex(OffsetValueType offset) const
PropertyType::Pointer PropertyPointer
bool SetInternalInverseTransformToWorldToIndexTransform() const
virtual const double * GetScale() const
unsigned int m_BoundingBoxChildrenDepth
virtual void UpdateOutputInformation() override
TransformPointer m_ObjectToParentTransform
OutputVectorType * OutputVectorPointer
virtual void SetBufferedRegion(const RegionType &region)
void ComputeObjectToWorldTransform()
const OffsetValueType * GetOffsetTable() const
TransformType * GetObjectToNodeTransform()
VectorType * VectorPointer
PropertyType * GetProperty()
virtual BoundingBoxType * GetBoundingBox() const
virtual bool IsInside(const PointType &point, unsigned int depth=0, char *name=nullptr) 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
ChildrenListType m_InternalChildrenList
Size< VDimension > SizeType
const TransformType * GetIndexToObjectTransform() const
std::string m_BoundingBoxChildrenName
virtual void Clear()
virtual void Update(void) override
virtual void SetLargestPossibleRegion(const RegionType &region)
Implementation of the composite pattern.
SpatialObjectTreeNode< VDimension > TreeNodeType
PropertyPointer m_Property
void AddSpatialObject(Self *pointer)
virtual ChildrenListType * GetChildren(unsigned int depth=0, char *name=nullptr) const
std::list< Pointer > ChildrenListType
Vector< ScalarType, VDimension > VectorType
virtual ModifiedTimeType GetMTime() const
void ComputeObjectToParentTransform()
BoundingBoxPointer m_Bounds
RegionType m_BufferedRegion
virtual void Modified() const
void SetObjectToWorldTransform(TransformType *transform)
void SetSpacing(const double spacing[itkGetStaticConstMacro(ObjectDimension)])
virtual void DerivativeAt(const PointType &point, short unsigned int order, OutputVectorType &value, unsigned int depth=0, char *name=nullptr)
virtual const RegionType & GetRequestedRegion() const
virtual const Self * GetParent() const
virtual bool IsEvaluableAt(const PointType &point, unsigned int depth=0, char *name=nullptr) const
TransformType * GetObjectToParentTransform()
unsigned long GetObjectMTime(void) const
ChildrenListType * ChildrenListPointer
CovariantVector< ScalarType, VDimension > CovariantVectorType
virtual bool ComputeBoundingBox() const
virtual const RegionType & GetBufferedRegion() const
virtual const char * GetTypeName(void) const
virtual void CopyInformation(const DataObject *data) override
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
virtual ModifiedTimeType GetMTime(void) const override
Describes the geometry of a data object.
virtual ~SpatialObject()
PointType * PointPointer
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.
virtual bool RequestedRegionIsOutsideOfTheBufferedRegion() override
virtual bool VerifyRequestedRegion() override
Affine transformation with a specified center of rotation.
unsigned long GetTransformMTime()
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