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: 2003/02/10 15:59:46 $
00007   Version:   $Revision: 1.26 $
00008 
00009   Copyright (c) 2002 Insight 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 #include "itkDataObject.h"
00022 #include "itkBoundingBox.h"
00023 #include "itkPoint.h"
00024 #include "itkAffineTransform.h"
00025 #include "itkSmartPointer.h" 
00026 #include "itkVector.h"
00027 #include "itkCovariantVector.h"
00028 #include "itkExceptionObject.h" 
00029 #include <list> 
00030 #include "itkSpatialObjectProperty.h" 
00031 #include "itkProcessObject.h"
00032 #include "itkIndex.h"
00033 #include "itkSize.h"
00034 #include "itkImageRegion.h"
00035 #include "itkObjectFactory.h"
00036 
00037 namespace itk  
00038 { 
00039 
00058 template< unsigned int TDimension = 3> 
00059 class SpatialObject 
00060 :public DataObject
00061 { 
00062 
00063 public: 
00064 
00065   typedef double ScalarType;
00066 
00067   itkStaticConstMacro(MaximumDepth, unsigned int, 9999999);
00068 
00069   typedef SpatialObject<TDimension> Self;
00070   typedef DataObject Superclass; 
00071   
00072   typedef SmartPointer< Self > Pointer;
00073   typedef SmartPointer< const Self > ConstPointer;
00074   
00075   typedef Point < ScalarType, TDimension > PointType; 
00076   typedef PointType * PointPointer; 
00077   
00078   typedef Vector< ScalarType, TDimension > VectorType; 
00079   typedef VectorType * VectorPointer;
00080 
00081   typedef CovariantVector< double, TDimension > OutputVectorType; 
00082   typedef OutputVectorType * OutputVectorPointer;
00083 
00084   typedef AffineTransform< double, TDimension>   TransformType;
00085   typedef typename TransformType::Pointer  TransformPointer;
00086   typedef const TransformType*             TransformConstPointer;
00087   
00088   typedef std::list< TransformType * > TransformListType;
00089   
00090   typedef VectorContainer< unsigned long int, PointType > VectorContainerType;
00091   
00092   typedef BoundingBox< unsigned long int, TDimension, ScalarType,
00093                        VectorContainerType > BoundingBoxType; 
00094   typedef typename BoundingBoxType::Pointer BoundingBoxPointer; 
00095 
00096   typedef std::list< Self * > ChildrenListType; 
00097   typedef ChildrenListType* ChildrenListPointer; 
00098    
00100   typedef Index<TDimension>  IndexType;
00101   typedef typename IndexType::IndexValueType  IndexValueType;
00102 
00105   typedef Offset<TDimension>  OffsetType;
00106   typedef typename OffsetType::OffsetValueType OffsetValueType;
00107   typedef ImageRegion<TDimension> RegionType;
00108   typedef Size<TDimension>    SizeType; 
00109   typedef SpatialObjectProperty< float > PropertyType; 
00110   typedef typename PropertyType::Pointer  PropertyPointer; 
00111 
00114   virtual bool HasParent( void ) const;
00115 
00117   virtual const char* GetTypeName(void) const {return m_TypeName;}
00118 
00122   itkStaticConstMacro(ObjectDimension, unsigned int, TDimension);
00123 
00125   itkNewMacro( Self );
00126  
00128   itkTypeMacro( Self, Superclass );
00129 
00131   void SetBoundingBox( BoundingBoxPointer bounds ); 
00132 
00134   virtual BoundingBoxType * GetBoundingBox( void ) const; 
00135 
00141   void SetTransform( TransformType * transform ); 
00142   TransformType * GetTransform( void ); 
00143   const TransformType * GetTransform( void ) const; 
00144 
00147   void SetGlobalTransform( TransformType * transform );
00148   TransformType * GetGlobalTransform( void );
00149   const TransformType * GetGlobalTransform( void ) const;
00150 
00152   itkSetMacro(CenterOfRotation,PointType);
00153   itkGetMacro(CenterOfRotation,PointType);
00154 
00157   virtual bool ValueAt( const PointType & point, double & value,
00158                         unsigned int depth=0,
00159                         char * name = NULL) const;
00160      
00163   virtual bool IsEvaluableAt( const PointType & point,
00164                               unsigned int depth=0,
00165                               char * name = NULL) const;
00166 
00168   virtual bool IsInside( const PointType & point,
00169                          unsigned int depth=0,
00170                          char * name = NULL) const;
00171 
00174   void SetParent(const Self * parent);
00175 
00177   void DerivativeAt( const PointType & point,
00178                      short unsigned int order,
00179                      OutputVectorType & value,
00180                      unsigned int depth=0,
00181                      char * name = NULL);
00182 
00185   void TransformPointToLocalCoordinate( PointType & p ) const;
00186 
00189   void TransformPointToGlobalCoordinate( PointType & p ) const; 
00190 
00192   TransformListType & GetGlobalTransformList( void );
00193 
00214   virtual bool ComputeBoundingBox( unsigned int depth=0,
00215                                    char * name = NULL);
00216 
00218   void SetSpacing( const double spacing[ObjectDimension] );
00219 
00221   void SetScale( const double scale[ObjectDimension] );
00222 
00224   const double* GetSpacing() const {return m_Spacing;}
00225   
00227   const double* GetScale() const {return m_Scale;}
00228 
00230   const double* GetGlobalScale() const {return m_GlobalScale;}
00231 
00234   unsigned long GetMTime( void ) const;
00235 
00239   void ComputeGlobalTransform(void);
00240 
00242   void ComputeTransform(void);
00243 
00245   void AddSpatialObject( Self * pointer ); 
00246      
00251   void RemoveSpatialObject( Self * object ); 
00252 
00254   virtual const Self * GetParent( void ) const; 
00255 
00259   virtual ChildrenListType * GetChildren( unsigned int depth=0,
00260                                           char * name = NULL) const;
00261 
00263   unsigned int GetNumberOfChildren( unsigned int depth=0,
00264                                     char * name = NULL);
00265 
00267   void SetChildren( ChildrenListType & children ); 
00268 
00271   virtual void Clear(void);
00272 
00274   unsigned long GetTransformMTime(void);
00275 
00277   unsigned long GetGlobalTransformMTime(void);
00278 
00285   virtual void SetLargestPossibleRegion(const RegionType &region);
00286 
00293   virtual const RegionType& GetLargestPossibleRegion() const
00294     { return m_LargestPossibleRegion;};
00295 
00299   virtual void SetBufferedRegion(const RegionType &region);
00300 
00304   virtual const RegionType& GetBufferedRegion() const
00305   { return m_BufferedRegion;};
00306   
00311   virtual void SetRequestedRegion(const RegionType &region);
00312 
00317   virtual void SetRequestedRegion(DataObject *data);
00318 
00323   virtual const RegionType& GetRequestedRegion() const
00324   { return m_RequestedRegion;};
00325 
00335   const OffsetValueType *GetOffsetTable() const { return m_OffsetTable; };
00336   
00339   OffsetValueType ComputeOffset(const IndexType &ind) const
00340   {
00341     // need to add bounds checking for the region/buffer?
00342     OffsetValueType offset=0;
00343     const IndexType &bufferedRegionIndex = m_BufferedRegion.GetIndex();
00344   
00345     // data is arranged as [][][][slice][row][col]
00346     // with Index[0] = col, Index[1] = row, Index[2] = slice
00347     for (int i=VImageDimension-1; i > 0; i--)
00348       {
00349       offset += (ind[i] - bufferedRegionIndex[i])*m_OffsetTable[i];
00350       }
00351     offset += (ind[0] - bufferedRegionIndex[0]);
00352 
00353     return offset;
00354   }
00355 
00358   IndexType ComputeIndex(OffsetValueType offset) const
00359   {
00360     IndexType index;
00361     const IndexType &bufferedRegionIndex = m_BufferedRegion.GetIndex();
00362     
00363     for (int i=VImageDimension-1; i > 0; i--)
00364       {
00365       index[i] = static_cast<IndexValueType>(offset / m_OffsetTable[i]);
00366       offset -= (index[i] * m_OffsetTable[i]);
00367       index[i] += bufferedRegionIndex[i];
00368       }
00369     index[0] = bufferedRegionIndex[0] + static_cast<IndexValueType>(offset);
00370 
00371     return index;
00372   }
00373 
00383   virtual void CopyInformation(const DataObject *data);
00384 
00392   virtual void UpdateOutputInformation();
00393 
00397   virtual void SetRequestedRegionToLargestPossibleRegion();
00398 
00408   virtual bool RequestedRegionIsOutsideOfTheBufferedRegion();
00409 
00418   virtual bool VerifyRequestedRegion();
00419 
00420 
00422   PropertyType * GetProperty( void );
00423 
00425   void SetProperty( const PropertyType * property ); 
00426 
00428   void SetParentId(int parentid) {m_ParentId=parentid;}
00429   int  GetParentId(void) {return m_ParentId;}
00430 
00432   itkGetConstMacro(Id,int);
00433   itkSetMacro(Id,int);
00434 
00436   virtual void Update(void);
00437 
00438 
00439 protected: 
00440   
00441   BoundingBoxPointer  m_Bounds; 
00442   unsigned long       m_BoundsMTime;
00443   double              m_Spacing[ObjectDimension];
00444   double              m_Scale[ObjectDimension];
00445   double              m_GlobalScale[ObjectDimension];
00446   PointType           m_CenterOfRotation;
00447   TransformListType   m_GlobalTransformList;
00448 
00449   TransformPointer    m_Transform;
00450   TransformPointer    m_TransformWithCoR;
00451   TransformPointer    m_GlobalTransform; 
00452 
00454   SpatialObject(); 
00455 
00457   virtual ~SpatialObject(); 
00458 
00459   virtual void PrintSelf( std::ostream& os, Indent indent ) const; 
00460 
00463   ChildrenListType m_Children; 
00464 
00469   void ComputeOffsetTable();
00470 
00471   const Self* m_Parent;
00472 
00473   char m_TypeName[255];
00474 
00475   unsigned int m_Dimension;
00476 
00477   double  m_OffsetTable[3+1];
00478 
00479   RegionType          m_LargestPossibleRegion;
00480   RegionType          m_RequestedRegion;
00481   RegionType          m_BufferedRegion;
00482     
00483 
00484   PropertyPointer m_Property; 
00485 
00487   int m_ParentId;
00488 
00490   int m_Id;
00491 
00492 }; 
00493 
00494 } // end of namespace itk
00495  
00496 #ifndef ITK_MANUAL_INSTANTIATION 
00497   #include "itkSpatialObject.txx" 
00498 #endif 
00499  
00500 #endif // __itkSpatialObject_h

Generated at Fri May 21 01:15:21 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000