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/10/09 21:01:34 $
00007   Version:   $Revision: 1.61 $
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);
00161 
00164   void SetObjectToWorldTransform( TransformType * transform );
00165   itkGetObjectMacro(ObjectToWorldTransform,TransformType);
00166   itkGetConstObjectMacro(ObjectToWorldTransform,TransformType);
00167   itkGetObjectMacro(IndexToWorldTransform,TransformType);
00168   itkGetConstObjectMacro(IndexToWorldTransform,TransformType);
00169 
00173   void ComputeObjectToWorldTransform(void);
00174 
00176   void ComputeObjectToParentTransform(void);
00177 
00179   unsigned long GetTransformMTime( void );
00180 
00182   unsigned long GetWorldTransformMTime( void );
00183 
00185   virtual bool ValueAt( const PointType & point, double & value,
00186                         unsigned int depth=0,
00187                         char * name = NULL) const;
00188 
00195   virtual bool IsEvaluableAt( const PointType & point,
00196                               unsigned int depth=0,
00197                               char * name = NULL) const;
00198 
00200   virtual bool IsInside( const PointType & point,
00201                          unsigned int depth=0,
00202                          char * name = NULL) const;
00203 
00208   bool Evaluate( const PointType & point ) const
00209   {
00210     return this->IsInside( point );
00211   };
00212 
00214   virtual void DerivativeAt( const PointType & point,
00215                      short unsigned int order,
00216                      OutputVectorType & value,
00217                      unsigned int depth=0,
00218                      char * name = NULL);
00219 
00220 
00223   unsigned long GetMTime( void ) const;
00224 
00227   unsigned long GetObjectMTime( void ) const
00228     {
00229     return Superclass::GetMTime();
00230     }
00231 
00238   virtual void SetLargestPossibleRegion(const RegionType &region);
00239 
00246   virtual const RegionType& GetLargestPossibleRegion() const
00247   { return m_LargestPossibleRegion;};
00248 
00252   virtual void SetBufferedRegion(const RegionType &region);
00253 
00257   virtual const RegionType& GetBufferedRegion() const
00258   { return m_BufferedRegion;};
00259   
00264   virtual void SetRequestedRegion(const RegionType &region);
00265 
00270   virtual void SetRequestedRegion(DataObject *data);
00271 
00276   virtual const RegionType& GetRequestedRegion() const
00277   { return m_RequestedRegion;};
00278 
00288   const OffsetValueType *GetOffsetTable() const { return m_OffsetTable; };
00289   
00292   OffsetValueType ComputeOffset(const IndexType &ind) const
00293   {
00294     // need to add bounds checking for the region/buffer?
00295     OffsetValueType offset=0;
00296     const IndexType &bufferedRegionIndex = m_BufferedRegion.GetIndex();
00297   
00298     // data is arranged as [][][][slice][row][col]
00299     // with Index[0] = col, Index[1] = row, Index[2] = slice
00300     for (int i=TDimension-1; i > 0; i--)
00301       {
00302       offset += (ind[i] - bufferedRegionIndex[i])*m_OffsetTable[i];
00303       }
00304     offset += (ind[0] - bufferedRegionIndex[0]);
00305 
00306     return offset;
00307   }
00308 
00311   IndexType ComputeIndex(OffsetValueType offset) const
00312   {
00313     IndexType index;
00314     const IndexType &bufferedRegionIndex = m_BufferedRegion.GetIndex();
00315     
00316     for (int i=TDimension-1; i > 0; i--)
00317       {
00318       index[i] = static_cast<IndexValueType>(offset / m_OffsetTable[i]);
00319       offset -= (index[i] * m_OffsetTable[i]);
00320       index[i] += bufferedRegionIndex[i];
00321       }
00322     index[0] = bufferedRegionIndex[0] + static_cast<IndexValueType>(offset);
00323 
00324     return index;
00325   }
00326 
00336   virtual void CopyInformation(const DataObject *data);
00337 
00345   virtual void UpdateOutputInformation();
00346 
00350   virtual void SetRequestedRegionToLargestPossibleRegion();
00351 
00361   virtual bool RequestedRegionIsOutsideOfTheBufferedRegion();
00362 
00371   virtual bool VerifyRequestedRegion();
00372 
00373 
00375   PropertyType * GetProperty( void );
00376   const PropertyType * GetProperty( void ) const {return m_Property;}
00377 
00379   void SetProperty( PropertyType * property ); 
00380 
00382   itkGetConstReferenceMacro(Id,int);
00383   itkSetMacro(Id,int);
00384   
00386   itkSetMacro(ParentId, int);
00387   itkGetConstReferenceMacro(ParentId, int);
00388 
00390   virtual void Update(void);
00391 
00393   void SetTreeNode(TreeNodeType* node) {m_TreeNode = node;}
00394 
00396   typename TreeNodeType::Pointer GetTreeNode() {return m_TreeNode;}
00397   typename TreeNodeType::ConstPointer GetTreeNode() const {return m_TreeNode;}
00398 
00401   void SetSpacing( const double 
00402                    spacing[itkGetStaticConstMacro(ObjectDimension)] )
00403     { this->GetIndexToObjectTransform()->SetScale(spacing);}
00405   virtual const double * GetSpacing() const 
00406     {return this->GetIndexToObjectTransform()->GetScale();}
00407 
00408 
00414   TransformType * GetIndexToObjectTransform( void ); 
00415   const TransformType * GetIndexToObjectTransform( void ) const; 
00416 
00420   void SetObjectToParentTransform( TransformType * transform ); 
00421   TransformType * GetObjectToParentTransform( void );
00422   const TransformType * GetObjectToParentTransform( void ) const;
00423 
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     {
00491     std::cerr << "SpatialObject::ComputeLocalBoundingBox Not Implemented!" 
00492               << std::endl;
00493      return false;
00494     }
00495   
00498   virtual BoundingBoxType * GetBoundingBox() const; 
00499 
00500 
00502   itkSetMacro(BoundingBoxChildrenDepth, unsigned int);
00503   itkGetConstReferenceMacro(BoundingBoxChildrenDepth, unsigned int);
00504 
00507   itkSetMacro(BoundingBoxChildrenName, std::string);
00508   itkGetConstReferenceMacro(BoundingBoxChildrenName, std::string);
00509 
00512   void SetParent(Self * parent);
00513 
00514 
00516   void SetNodeToParentNodeTransform( TransformType * transform );
00517   TransformType * GetNodeToParentNodeTransform( void );
00518   const TransformType * GetNodeToParentNodeTransform( void ) const;
00519 
00521   itkSetMacro(DefaultInsideValue,double);
00522   itkGetConstMacro(DefaultInsideValue,double);
00523 
00525   itkSetMacro(DefaultOutsideValue,double);
00526   itkGetConstMacro(DefaultOutsideValue,double);
00527 
00530   virtual std::string GetSpatialObjectTypeAsString() const;
00531 
00532 protected: 
00533  
00535   SpatialObject(); 
00536 
00538   virtual ~SpatialObject(); 
00539 
00540   virtual void PrintSelf( std::ostream& os, Indent indent ) const; 
00541 
00546   void ComputeOffsetTable();
00547 
00548   itkSetMacro(Dimension,unsigned int);
00549   itkGetConstReferenceMacro(Dimension,unsigned int)
00550   itkSetMacro(TypeName,std::string);
00551   itkGetConstObjectMacro(Bounds,BoundingBoxType);
00552   itkGetConstObjectMacro(InternalInverseTransform,TransformType);
00553 
00554 private:
00555   BoundingBoxPointer  m_Bounds; 
00556   mutable unsigned long       m_BoundsMTime;
00557 
00558   TransformPointer    m_ObjectToParentTransform;
00559   TransformPointer    m_ObjectToWorldTransform; 
00560   TransformPointer    m_IndexToWorldTransform; 
00561 
00563   std::string m_TypeName;
00564 
00565   unsigned int m_Dimension;
00566 
00567   OffsetValueType  m_OffsetTable[3+1];
00568 
00569   RegionType          m_LargestPossibleRegion;
00570   RegionType          m_RequestedRegion;
00571   RegionType          m_BufferedRegion;
00572     
00573   std::string  m_BoundingBoxChildrenName;
00574   unsigned int m_BoundingBoxChildrenDepth;
00575   PropertyPointer m_Property; 
00576 
00578   int m_Id;
00579   int m_ParentId;
00580 
00582   typename TreeNodeType::Pointer m_TreeNode;
00583 
00585   AffineGeometryFramePointer  m_AffineGeometryFrame;
00586 
00589   ChildrenListType m_InternalChildrenList;
00590 
00593   TransformPointer m_InternalInverseTransform;
00594 
00596   double m_DefaultInsideValue;
00597 
00599   double m_DefaultOutsideValue;
00600 }; 
00601 
00602 } // end of namespace itk
00603  
00604 #ifndef ITK_MANUAL_INSTANTIATION 
00605 #include "itkSpatialObject.txx" 
00606 #endif 
00607  
00608 #endif // __itkSpatialObject_h

Generated at Thu May 25 00:05:55 2006 for ITK by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2000