Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkSpatialObject.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkSpatialObject.h,v $
00005   Language:  C++
00006   Date:      $Date: 2007-01-28 19:24:56 $
00007   Version:   $Revision: 1.64 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017  
00018 #ifndef __itkSpatialObject_h 
00019 #define __itkSpatialObject_h 
00020  
00021 // Disable warning for long symbol names in this file only
00022 #ifdef _MSC_VER
00023 #pragma warning ( disable : 4786 )
00024 #endif
00025 
00026 #include "itkAffineGeometryFrame.h"
00027 #include "itkDataObject.h"
00028 #include "itkBoundingBox.h"
00029 #include "itkPoint.h"
00030 #include "itkScalableAffineTransform.h"
00031 #include "itkSmartPointer.h" 
00032 #include "itkVector.h"
00033 #include "itkCovariantVector.h"
00034 #include "itkExceptionObject.h" 
00035 #include <list> 
00036 #include "itkSpatialObjectProperty.h" 
00037 #include "itkProcessObject.h"
00038 #include "itkIndex.h"
00039 #include "itkSize.h"
00040 #include "itkImageRegion.h"
00041 #include "itkObjectFactory.h"
00042 #include "itkSpatialObjectTreeNode.h"
00043 
00044 namespace itk  
00045 { 
00046 
00066 template <unsigned int TDimension> class SpatialObjectTreeNode;
00067 
00068 
00069 template< unsigned int TDimension = 3> 
00070 class SpatialObject 
00071   :public DataObject
00072 { 
00073 
00074 public: 
00075 
00076   typedef double ScalarType;
00077 
00078   itkStaticConstMacro(MaximumDepth, unsigned int, 9999999);
00079 
00082   unsigned int GetMaximumDepth() { return MaximumDepth; }
00083 
00084   typedef SpatialObject<TDimension> Self;
00085   typedef DataObject                Superclass; 
00086   
00087   typedef SmartPointer< Self >       Pointer;
00088   typedef SmartPointer< const Self > ConstPointer;
00089   
00090   typedef Point < ScalarType, TDimension > PointType; 
00091   // Spatial Function Iterator needs the following typedef 
00092   typedef Point < ScalarType, TDimension > InputType; 
00093   typedef PointType * PointPointer; 
00094   
00095   typedef Vector< ScalarType, TDimension > VectorType; 
00096   typedef CovariantVector<ScalarType, TDimension > CovariantVectorType; 
00097   typedef VectorType * VectorPointer;
00098 
00099   typedef double *                              SpacingType;
00100 
00101   typedef CovariantVector< double, TDimension > OutputVectorType; 
00102   typedef OutputVectorType *                    OutputVectorPointer;
00103 
00104   typedef ScalableAffineTransform< double, TDimension > TransformType;
00105   typedef typename TransformType::Pointer               TransformPointer;
00106   typedef const TransformType*                          TransformConstPointer;
00107   
00108   typedef VectorContainer< unsigned long int, PointType > VectorContainerType;
00109   
00110   typedef BoundingBox< unsigned long int, TDimension, ScalarType,
00111                        VectorContainerType > BoundingBoxType; 
00112   typedef typename BoundingBoxType::Pointer BoundingBoxPointer; 
00113 
00114   typedef AffineGeometryFrame<double,TDimension>    AffineGeometryFrameType;
00115   typedef typename AffineGeometryFrameType::Pointer AffineGeometryFramePointer;
00116 
00118   typedef std::list< Pointer > ChildrenListType; 
00119   typedef ChildrenListType* ChildrenListPointer;
00120 
00121 
00123   typedef Index<TDimension>                   IndexType;
00124   typedef typename IndexType::IndexValueType  IndexValueType;
00125 
00128   typedef Offset<TDimension>                   OffsetType;
00129   typedef typename OffsetType::OffsetValueType OffsetValueType;
00130   typedef ImageRegion<TDimension>              RegionType;
00131   typedef Size<TDimension>                     SizeType; 
00132   typedef SpatialObjectProperty< float >       PropertyType; 
00133   typedef typename PropertyType::Pointer       PropertyPointer; 
00134 
00135   typedef SpatialObjectTreeNode<TDimension> TreeNodeType;
00136 
00139   virtual bool HasParent( void ) const;
00140 
00142   virtual const char* GetTypeName(void) const {return m_TypeName.c_str();}
00143 
00147   itkStaticConstMacro(ObjectDimension, unsigned int, TDimension);
00148 
00150   unsigned int GetObjectDimension(void) const {return TDimension;}
00151 
00153   itkNewMacro( Self );
00154 
00156   itkTypeMacro( SpatialObject, DataObject );
00157 
00159   itkGetConstObjectMacro(AffineGeometryFrame,AffineGeometryFrameType);
00160   itkSetObjectMacro(AffineGeometryFrame,AffineGeometryFrameType);
00162 
00165   void SetObjectToWorldTransform( TransformType * transform );
00166   itkGetObjectMacro(ObjectToWorldTransform,TransformType);
00167   itkGetConstObjectMacro(ObjectToWorldTransform,TransformType);
00168   itkGetObjectMacro(IndexToWorldTransform,TransformType);
00169   itkGetConstObjectMacro(IndexToWorldTransform,TransformType);
00171 
00175   void ComputeObjectToWorldTransform(void);
00176 
00178   void ComputeObjectToParentTransform(void);
00179 
00181   unsigned long GetTransformMTime( void );
00182 
00184   unsigned long GetWorldTransformMTime( void );
00185 
00187   virtual bool ValueAt( const PointType & point, double & value,
00188                         unsigned int depth=0,
00189                         char * name = NULL) const;
00190 
00197   virtual bool IsEvaluableAt( const PointType & point,
00198                               unsigned int depth=0,
00199                               char * name = NULL) const;
00200 
00202   virtual bool IsInside( const PointType & point,
00203                          unsigned int depth=0,
00204                          char * name = NULL) const;
00205 
00210   bool Evaluate( const PointType & point ) const
00211     {
00212     return this->IsInside( point );
00213     };
00215 
00217   virtual void DerivativeAt( const PointType & point,
00218                      short unsigned int order,
00219                      OutputVectorType & value,
00220                      unsigned int depth=0,
00221                      char * name = NULL);
00222 
00223 
00226   unsigned long GetMTime( void ) const;
00227 
00230   unsigned long GetObjectMTime( void ) const
00231     {
00232     return Superclass::GetMTime();
00233     }
00234 
00241   virtual void SetLargestPossibleRegion(const RegionType &region);
00242 
00249   virtual const RegionType& GetLargestPossibleRegion() const
00250   { return m_LargestPossibleRegion;};
00251 
00255   virtual void SetBufferedRegion(const RegionType &region);
00256 
00260   virtual const RegionType& GetBufferedRegion() const
00261   { return m_BufferedRegion;};
00262 
00267   virtual void SetRequestedRegion(const RegionType &region);
00268 
00273   virtual void SetRequestedRegion(DataObject *data);
00274 
00279   virtual const RegionType& GetRequestedRegion() const
00280   { return m_RequestedRegion;};
00281 
00291   const OffsetValueType *GetOffsetTable() const { return m_OffsetTable; };
00293 
00296   OffsetValueType ComputeOffset(const IndexType &ind) const
00297     {
00298     // need to add bounds checking for the region/buffer?
00299     OffsetValueType offset=0;
00300     const IndexType &bufferedRegionIndex = m_BufferedRegion.GetIndex();
00302 
00303     // data is arranged as [][][][slice][row][col]
00304     // with Index[0] = col, Index[1] = row, Index[2] = slice
00305     for (int i=TDimension-1; i > 0; i--)
00306       {
00307       offset += (ind[i] - bufferedRegionIndex[i])*m_OffsetTable[i];
00308       }
00309     offset += (ind[0] - bufferedRegionIndex[0]);
00310 
00311     return offset;
00312     }
00313 
00316   IndexType ComputeIndex(OffsetValueType offset) const
00317     {
00318     IndexType index;
00319     const IndexType &bufferedRegionIndex = m_BufferedRegion.GetIndex();
00321 
00322     for (int i=TDimension-1; i > 0; i--)
00323       {
00324       index[i] = static_cast<IndexValueType>(offset / m_OffsetTable[i]);
00325       offset -= (index[i] * m_OffsetTable[i]);
00326       index[i] += bufferedRegionIndex[i];
00327       }
00328     index[0] = bufferedRegionIndex[0] + static_cast<IndexValueType>(offset);
00329 
00330     return index;
00331     }
00332 
00342   virtual void CopyInformation(const DataObject *data);
00343 
00351   virtual void UpdateOutputInformation();
00352 
00356   virtual void SetRequestedRegionToLargestPossibleRegion();
00357 
00367   virtual bool RequestedRegionIsOutsideOfTheBufferedRegion();
00368 
00377   virtual bool VerifyRequestedRegion();
00378 
00379 
00381   PropertyType * GetProperty( void );
00382   const PropertyType * GetProperty( void ) const {return m_Property;}
00384 
00386   void SetProperty( PropertyType * property ); 
00387 
00389   itkGetConstReferenceMacro(Id,int);
00390   itkSetMacro(Id,int);
00392 
00394   itkSetMacro(ParentId, int);
00395   itkGetConstReferenceMacro(ParentId, int);
00397 
00399   virtual void Update(void);
00400 
00402   itkSetObjectMacro(TreeNode, TreeNodeType)
00403 
00404 
00405   itkGetObjectMacro(TreeNode, TreeNodeType);
00406   itkGetConstObjectMacro(TreeNode, TreeNodeType);
00408 
00412   void SetSpacing( const double 
00413                    spacing[itkGetStaticConstMacro(ObjectDimension)] )
00414     { this->GetIndexToObjectTransform()->SetScale(spacing);}
00415 
00417   virtual const double * GetSpacing() const 
00418     {return this->GetIndexToObjectTransform()->GetScale();}
00419 
00420 
00426   TransformType * GetIndexToObjectTransform( void ); 
00427   const TransformType * GetIndexToObjectTransform( void ) const; 
00429 
00433   void SetObjectToParentTransform( TransformType * transform ); 
00434   TransformType * GetObjectToParentTransform( void );
00435   const TransformType * GetObjectToParentTransform( void ) const;
00437 
00441   TransformType * GetObjectToNodeTransform( void );
00442   const TransformType * GetObjectToNodeTransform( void ) const;
00444 
00449   void AddSpatialObject( Self * pointer ); 
00450 
00455   void RemoveSpatialObject( Self * object ); 
00456 
00458   virtual const Self * GetParent( void ) const; 
00459 
00461   virtual Self * GetParent( void );
00462 
00468   virtual ChildrenListType * GetChildren( unsigned int depth=0, 
00469                                           char * name=NULL ) const;
00470 
00472   unsigned int GetNumberOfChildren( unsigned int depth=0, 
00473                                    char * name=NULL  ) const;
00474 
00476   void SetChildren( ChildrenListType & children ); 
00477 
00480   virtual void Clear( void );
00481 
00504   virtual bool ComputeBoundingBox() const;
00505   virtual bool ComputeLocalBoundingBox() const 
00506     {
00507     std::cerr << "SpatialObject::ComputeLocalBoundingBox Not Implemented!" 
00508               << std::endl;
00509     return false;
00510     }
00512 
00515   virtual BoundingBoxType * GetBoundingBox() const; 
00516 
00517 
00519   itkSetMacro(BoundingBoxChildrenDepth, unsigned int);
00520   itkGetConstReferenceMacro(BoundingBoxChildrenDepth, unsigned int);
00522 
00525   itkSetMacro(BoundingBoxChildrenName, std::string);
00526   itkGetConstReferenceMacro(BoundingBoxChildrenName, std::string);
00528 
00531   void SetParent(Self * parent);
00532 
00533 
00535   void SetNodeToParentNodeTransform( TransformType * transform );
00536   TransformType * GetNodeToParentNodeTransform( void );
00537   const TransformType * GetNodeToParentNodeTransform( void ) const;
00539 
00542   itkSetMacro(DefaultInsideValue,double);
00543   itkGetConstMacro(DefaultInsideValue,double);
00545 
00548   itkSetMacro(DefaultOutsideValue,double);
00549   itkGetConstMacro(DefaultOutsideValue,double);
00551 
00554   virtual std::string GetSpatialObjectTypeAsString() const;
00555 
00556 protected: 
00557  
00559   SpatialObject(); 
00560 
00562   virtual ~SpatialObject(); 
00563 
00564   virtual void PrintSelf( std::ostream& os, Indent indent ) const; 
00565 
00570   void ComputeOffsetTable();
00571 
00572   itkSetMacro(Dimension,unsigned int);
00573   itkGetConstReferenceMacro(Dimension,unsigned int)
00574   itkSetMacro(TypeName,std::string);
00575   itkGetConstObjectMacro(Bounds,BoundingBoxType);
00576   itkGetConstObjectMacro(InternalInverseTransform,TransformType);
00577 
00578 private:
00579 
00580   SpatialObject(const Self&); //purposely not implemented
00581   void operator=(const Self&); //purposely not implemented
00582 
00583   BoundingBoxPointer          m_Bounds; 
00584   mutable unsigned long       m_BoundsMTime;
00585 
00586   TransformPointer    m_ObjectToParentTransform;
00587   TransformPointer    m_ObjectToWorldTransform; 
00588   TransformPointer    m_IndexToWorldTransform; 
00589 
00591   std::string m_TypeName;
00592 
00593   unsigned int m_Dimension;
00594 
00595   OffsetValueType  m_OffsetTable[3+1];
00596 
00597   RegionType          m_LargestPossibleRegion;
00598   RegionType          m_RequestedRegion;
00599   RegionType          m_BufferedRegion;
00600     
00601   std::string     m_BoundingBoxChildrenName;
00602   unsigned int    m_BoundingBoxChildrenDepth;
00603   PropertyPointer m_Property; 
00604 
00606   int m_Id;
00607   int m_ParentId;
00608 
00610   typename TreeNodeType::Pointer m_TreeNode;
00611 
00613   AffineGeometryFramePointer  m_AffineGeometryFrame;
00614 
00617   ChildrenListType m_InternalChildrenList;
00618 
00621   TransformPointer m_InternalInverseTransform;
00622 
00624   double m_DefaultInsideValue;
00625 
00627   double m_DefaultOutsideValue;
00628 }; 
00629 
00630 } // end of namespace itk
00631  
00632 #ifndef ITK_MANUAL_INSTANTIATION 
00633 #include "itkSpatialObject.txx" 
00634 #endif 
00635  
00636 #endif // __itkSpatialObject_h
00637 

Generated at Mon Apr 14 14:29:30 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000