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: 2005/01/21 17:59:18 $
00007   Version:   $Revision: 1.55 $
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 "itkFixedCenterOfRotationAffineTransform.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   typedef Point < ScalarType, TDimension > InputType; // Spatial Function Iterator needs it 
00092   typedef PointType * PointPointer; 
00093   
00094   typedef Vector< ScalarType, TDimension > VectorType; 
00095   typedef CovariantVector<ScalarType, TDimension > CovariantVectorType; 
00096   typedef VectorType * VectorPointer;
00097 
00098   typedef Vector<double, TDimension > SpacingType;
00099 
00100   typedef CovariantVector< double, TDimension > OutputVectorType; 
00101   typedef OutputVectorType * OutputVectorPointer;
00102 
00103   typedef FixedCenterOfRotationAffineTransform< double, TDimension >
00104                                            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   itkNewMacro( Self );
00151  
00153   itkTypeMacro( SpatialObject, DataObject );
00154 
00156   itkGetConstObjectMacro(AffineGeometryFrame,AffineGeometryFrameType);
00157   itkSetObjectMacro(AffineGeometryFrame,AffineGeometryFrameType);
00158 
00161   void SetObjectToWorldTransform( TransformType * transform );
00162   itkGetObjectMacro(ObjectToWorldTransform,TransformType);
00163   itkGetConstObjectMacro(ObjectToWorldTransform,TransformType);
00164   itkGetObjectMacro(IndexToWorldTransform,TransformType);
00165   itkGetConstObjectMacro(IndexToWorldTransform,TransformType);
00166 
00170   void ComputeObjectToWorldTransform(void);
00171 
00173   void ComputeObjectToParentTransform(void);
00174 
00176   unsigned long GetTransformMTime( void );
00177 
00179   unsigned long GetWorldTransformMTime( void );
00180 
00182   virtual bool ValueAt( const PointType & point, double & value,
00183                         unsigned int depth=0,
00184                         char * name = NULL) const;
00185 
00192   virtual bool IsEvaluableAt( const PointType & point,
00193                               unsigned int depth=0,
00194                               char * name = NULL) const;
00195 
00197   virtual bool IsInside( const PointType & point,
00198                          unsigned int depth=0,
00199                          char * name = NULL) const;
00200 
00205   bool Evaluate( const PointType & point ) const
00206   {
00207     return this->IsInside( point );
00208   };
00209 
00211   virtual void DerivativeAt( const PointType & point,
00212                      short unsigned int order,
00213                      OutputVectorType & value,
00214                      unsigned int depth=0,
00215                      char * name = NULL);
00216 
00217 
00220   unsigned long GetMTime( void ) const;
00221 
00224   unsigned long GetObjectMTime( void ) const
00225     {
00226     return Superclass::GetMTime();
00227     }
00228 
00235   virtual void SetLargestPossibleRegion(const RegionType &region);
00236 
00243   virtual const RegionType& GetLargestPossibleRegion() const
00244   { return m_LargestPossibleRegion;};
00245 
00249   virtual void SetBufferedRegion(const RegionType &region);
00250 
00254   virtual const RegionType& GetBufferedRegion() const
00255   { return m_BufferedRegion;};
00256   
00261   virtual void SetRequestedRegion(const RegionType &region);
00262 
00267   virtual void SetRequestedRegion(DataObject *data);
00268 
00273   virtual const RegionType& GetRequestedRegion() const
00274   { return m_RequestedRegion;};
00275 
00285   const OffsetValueType *GetOffsetTable() const { return m_OffsetTable; };
00286   
00289   OffsetValueType ComputeOffset(const IndexType &ind) const
00290   {
00291     // need to add bounds checking for the region/buffer?
00292     OffsetValueType offset=0;
00293     const IndexType &bufferedRegionIndex = m_BufferedRegion.GetIndex();
00294   
00295     // data is arranged as [][][][slice][row][col]
00296     // with Index[0] = col, Index[1] = row, Index[2] = slice
00297     for (int i=TDimension-1; i > 0; i--)
00298       {
00299       offset += (ind[i] - bufferedRegionIndex[i])*m_OffsetTable[i];
00300       }
00301     offset += (ind[0] - bufferedRegionIndex[0]);
00302 
00303     return offset;
00304   }
00305 
00308   IndexType ComputeIndex(OffsetValueType offset) const
00309   {
00310     IndexType index;
00311     const IndexType &bufferedRegionIndex = m_BufferedRegion.GetIndex();
00312     
00313     for (int i=TDimension-1; i > 0; i--)
00314       {
00315       index[i] = static_cast<IndexValueType>(offset / m_OffsetTable[i]);
00316       offset -= (index[i] * m_OffsetTable[i]);
00317       index[i] += bufferedRegionIndex[i];
00318       }
00319     index[0] = bufferedRegionIndex[0] + static_cast<IndexValueType>(offset);
00320 
00321     return index;
00322   }
00323 
00333   virtual void CopyInformation(const DataObject *data);
00334 
00342   virtual void UpdateOutputInformation();
00343 
00347   virtual void SetRequestedRegionToLargestPossibleRegion();
00348 
00358   virtual bool RequestedRegionIsOutsideOfTheBufferedRegion();
00359 
00368   virtual bool VerifyRequestedRegion();
00369 
00370 
00372   PropertyType * GetProperty( void );
00373   const PropertyType * GetProperty( void ) const {return m_Property;}
00374 
00376   void SetProperty( const PropertyType * property ); 
00377 
00379   itkGetConstReferenceMacro(Id,int);
00380   itkSetMacro(Id,int);
00381   
00383   itkSetMacro(ParentId, int);
00384   itkGetMacro(ParentId, int);
00385 
00387   virtual void Update(void);
00388 
00390   void SetTreeNode(TreeNodeType* node) {m_TreeNode = node;}
00391 
00393   typename TreeNodeType::Pointer GetTreeNode() {return m_TreeNode;}
00394   typename TreeNodeType::ConstPointer GetTreeNode() const {return m_TreeNode;}
00395 
00398   void SetSpacing( const double spacing[itkGetStaticConstMacro(ObjectDimension)] )
00399   { this->GetIndexToObjectTransform()->SetScaleComponent(spacing);}
00401   virtual const double* GetSpacing() const 
00402   {return this->GetIndexToObjectTransform()->GetScaleComponent();}
00404   void SetSpacing( const SpacingType & spacing );
00405 
00406 
00412   void SetIndexToObjectTransform( TransformType * transform ); 
00413   TransformType * GetIndexToObjectTransform( void ); 
00414   const TransformType * GetIndexToObjectTransform( void ) const; 
00415 
00419   void SetObjectToParentTransform( TransformType * transform ); 
00420   TransformType * GetObjectToParentTransform( void );
00421   const TransformType * GetObjectToParentTransform( void ) const;
00422 
00426   void SetObjectToNodeTransform( TransformType * transform ); 
00427   TransformType * GetObjectToNodeTransform( void );
00428   const TransformType * GetObjectToNodeTransform( void ) const;
00429 
00430 
00434   void AddSpatialObject( Self * pointer ); 
00435      
00440   void RemoveSpatialObject( Self * object ); 
00441 
00443   virtual const Self * GetParent( void ) const; 
00444 
00446   virtual Self * GetParent( void );
00447 
00453   virtual ChildrenListType * GetChildren( unsigned int depth=0, 
00454                                           char * name=NULL ) const;
00455 
00457   unsigned int GetNumberOfChildren( unsigned int depth=0, 
00458                                    char * name=NULL  ) const;
00459 
00461   void SetChildren( ChildrenListType & children ); 
00462 
00465   virtual void Clear( void );
00466   
00488   virtual bool ComputeBoundingBox() const;
00489   virtual bool ComputeLocalBoundingBox() const 
00490     {std::cout << "SpatialObject::ComputeLocalBoundingBox Not Implemented!" << std::endl;
00491      return false;
00492     }
00493   
00496   virtual BoundingBoxType * GetBoundingBox() const; 
00497 
00498 
00500   itkSetMacro(BoundingBoxChildrenDepth, unsigned int);
00501   itkGetConstReferenceMacro(BoundingBoxChildrenDepth, unsigned int);
00502 
00505   itkSetMacro(BoundingBoxChildrenName, std::string);
00506   itkGetConstReferenceMacro(BoundingBoxChildrenName, std::string);
00507 
00510   void SetParent(Self * parent);
00511 
00512 
00514   void SetNodeToParentNodeTransform( TransformType * transform );
00515   TransformType * GetNodeToParentNodeTransform( void );
00516   const TransformType * GetNodeToParentNodeTransform( void ) const;
00517 
00518 protected: 
00519  
00521   SpatialObject(); 
00522 
00524   virtual ~SpatialObject(); 
00525 
00526   virtual void PrintSelf( std::ostream& os, Indent indent ) const; 
00527 
00532   void ComputeOffsetTable();
00533 
00534   itkSetMacro(Dimension,unsigned int);
00535   itkGetConstReferenceMacro(Dimension,unsigned int)
00536   itkSetMacro(TypeName,std::string);
00537   itkGetConstObjectMacro(Bounds,BoundingBoxType);
00538   itkGetConstObjectMacro(InternalInverseTransform,TransformType);
00539 
00540 private:
00541   BoundingBoxPointer  m_Bounds; 
00542   mutable unsigned long       m_BoundsMTime;
00543 
00544   TransformPointer    m_ObjectToParentTransform;
00545   TransformPointer    m_ObjectToWorldTransform; 
00546   TransformPointer    m_IndexToWorldTransform; 
00547 
00549   std::string m_TypeName;
00550 
00551   unsigned int m_Dimension;
00552 
00553   double  m_OffsetTable[3+1];
00554 
00555   RegionType          m_LargestPossibleRegion;
00556   RegionType          m_RequestedRegion;
00557   RegionType          m_BufferedRegion;
00558     
00559   std::string  m_BoundingBoxChildrenName;
00560   unsigned int m_BoundingBoxChildrenDepth;
00561   PropertyPointer m_Property; 
00562 
00564   int m_Id;
00565   int m_ParentId;
00566 
00568   typename TreeNodeType::Pointer m_TreeNode;
00569 
00571   AffineGeometryFramePointer  m_AffineGeometryFrame;
00572 
00575   ChildrenListType m_InternalChildrenList;
00576 
00579   TransformPointer m_InternalInverseTransform;
00580 }; 
00581 
00582 } // end of namespace itk
00583  
00584 #ifndef ITK_MANUAL_INSTANTIATION 
00585 #include "itkSpatialObject.txx" 
00586 #endif 
00587  
00588 #endif // __itkSpatialObject_h

Generated at Wed Mar 30 00:11:49 2005 for ITK by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2000