00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 "itkFixedCenterOfRotationAffineTransform.h"
00026 #include "itkSmartPointer.h"
00027 #include "itkVector.h"
00028 #include "itkCovariantVector.h"
00029 #include "itkExceptionObject.h"
00030 #include <list>
00031 #include "itkSpatialObjectProperty.h"
00032 #include "itkProcessObject.h"
00033 #include "itkIndex.h"
00034 #include "itkSize.h"
00035 #include "itkImageRegion.h"
00036 #include "itkObjectFactory.h"
00037
00038 namespace itk
00039 {
00040
00060 template< unsigned int TDimension = 3>
00061 class SpatialObject
00062 :public DataObject
00063 {
00064
00065 public:
00066
00067 typedef double ScalarType;
00068
00069 itkStaticConstMacro(MaximumDepth, unsigned int, 9999999);
00070
00073 unsigned int GetMaximumDepth() { return MaximumDepth; }
00074
00075 typedef SpatialObject<TDimension> Self;
00076 typedef DataObject Superclass;
00077
00078 typedef SmartPointer< Self > Pointer;
00079 typedef SmartPointer< const Self > ConstPointer;
00080
00081 typedef Point < ScalarType, TDimension > PointType;
00082 typedef Point < ScalarType, TDimension > InputType;
00083 typedef PointType * PointPointer;
00084
00085 typedef Vector< ScalarType, TDimension > VectorType;
00086 typedef CovariantVector<ScalarType, TDimension > CovariantVectorType;
00087 typedef VectorType * VectorPointer;
00088
00089 typedef CovariantVector< double, TDimension > OutputVectorType;
00090 typedef OutputVectorType * OutputVectorPointer;
00091
00092 typedef FixedCenterOfRotationAffineTransform< double, TDimension> TransformType;
00093 typedef typename TransformType::Pointer TransformPointer;
00094 typedef const TransformType* TransformConstPointer;
00095
00096 typedef VectorContainer< unsigned long int, PointType > VectorContainerType;
00097
00098 typedef BoundingBox< unsigned long int, TDimension, ScalarType,
00099 VectorContainerType > BoundingBoxType;
00100 typedef typename BoundingBoxType::Pointer BoundingBoxPointer;
00101
00102 typedef std::list< Pointer > ChildrenListType;
00103 typedef ChildrenListType* ChildrenListPointer;
00104
00106 typedef Index<TDimension> IndexType;
00107 typedef typename IndexType::IndexValueType IndexValueType;
00108
00111 typedef Offset<TDimension> OffsetType;
00112 typedef typename OffsetType::OffsetValueType OffsetValueType;
00113 typedef ImageRegion<TDimension> RegionType;
00114 typedef Size<TDimension> SizeType;
00115 typedef SpatialObjectProperty< float > PropertyType;
00116 typedef typename PropertyType::Pointer PropertyPointer;
00117
00120 virtual bool HasParent( void ) const;
00121
00123 virtual const char* GetTypeName(void) const {return m_TypeName.c_str();}
00124
00128 itkStaticConstMacro(ObjectDimension, unsigned int, TDimension);
00129
00131 itkNewMacro( Self );
00132
00134 itkTypeMacro( Self, Superclass );
00135
00136
00142 void SetIndexToObjectTransform( TransformType * transform );
00143 TransformType * GetIndexToObjectTransform( void );
00144 const TransformType * GetIndexToObjectTransform( void ) const;
00145
00149 void SetObjectToParentTransform( TransformType * transform );
00150 TransformType * GetObjectToParentTransform( void );
00151 const TransformType * GetObjectToParentTransform( void ) const;
00152
00155 void SetObjectToWorldTransform( TransformType * transform );
00156 TransformType * GetObjectToWorldTransform( void );
00157 const TransformType * GetObjectToWorldTransform( void ) const;
00158
00159 TransformType * GetIndexToWorldTransform( void );
00160 const TransformType * GetIndexToWorldTransform( void ) const;
00161
00162 TransformType * GetWorldToIndexTransform( void );
00163 const TransformType * GetWorldToIndexTransform( void ) const;
00164
00166 virtual bool ValueAt( const PointType & point, double & value,
00167 unsigned int depth=0,
00168 char * name = NULL) const;
00169
00176 virtual bool IsEvaluableAt( const PointType & point,
00177 unsigned int depth=0,
00178 char * name = NULL) const;
00179
00181 virtual bool IsInside( const PointType & point,
00182 unsigned int depth=0,
00183 char * name = NULL) const;
00184
00189 bool Evaluate( const PointType & point ) const
00190 {
00191 return this->IsInside( point );
00192 };
00193
00196 void SetParent(const Self * parent);
00197
00199 virtual void DerivativeAt( const PointType & point,
00200 short unsigned int order,
00201 OutputVectorType & value,
00202 unsigned int depth=0,
00203 char * name = NULL);
00204
00226 virtual bool ComputeBoundingBox() const;
00227
00230 virtual BoundingBoxType * GetBoundingBox() const;
00231
00234 unsigned long GetMTime( void ) const;
00235
00239 void ComputeObjectToWorldTransform(void);
00240
00242 void ComputeObjectToParentTransform(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 ) const;
00265
00267 void SetChildren( ChildrenListType & children );
00268
00271 virtual void Clear( void );
00272
00274 unsigned long GetTransformMTime( void );
00275
00277 unsigned long GetWorldTransformMTime( void );
00278
00285 virtual void SetLargestPossibleRegion(const RegionType ®ion);
00286
00293 virtual const RegionType& GetLargestPossibleRegion() const
00294 { return m_LargestPossibleRegion;};
00295
00299 virtual void SetBufferedRegion(const RegionType ®ion);
00300
00304 virtual const RegionType& GetBufferedRegion() const
00305 { return m_BufferedRegion;};
00306
00311 virtual void SetRequestedRegion(const RegionType ®ion);
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
00342 OffsetValueType offset=0;
00343 const IndexType &bufferedRegionIndex = m_BufferedRegion.GetIndex();
00344
00345
00346
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 const PropertyType * GetProperty( void ) const {return m_Property;}
00424
00426 void SetProperty( const PropertyType * property );
00427
00429 itkGetConstMacro(Id,int);
00430 itkSetMacro(Id,int);
00431
00433 virtual void Update(void);
00434
00436 itkSetMacro(BoundingBoxChildrenDepth, unsigned int);
00437 itkGetConstMacro(BoundingBoxChildrenDepth, unsigned int);
00438
00441 itkSetMacro(BoundingBoxChildrenName, std::string);
00442 itkGetMacro(BoundingBoxChildrenName, std::string);
00443
00445 itkSetMacro(ParentId, int);
00446 itkGetMacro(ParentId, int);
00447
00449 void SetSpacing( const double spacing[itkGetStaticConstMacro(ObjectDimension)] )
00450 { m_IndexToObjectTransform->SetScaleComponent(spacing);}
00452 virtual const double* GetSpacing() const
00453 {return m_IndexToObjectTransform->GetScaleComponent();}
00454
00456 itkSetMacro(SceneManageMemory,bool);
00457 itkGetMacro(SceneManageMemory,bool);
00458
00459 protected:
00460
00461 BoundingBoxPointer m_Bounds;
00462 mutable unsigned long m_BoundsMTime;
00463
00464 TransformPointer m_IndexToObjectTransform;
00465 TransformPointer m_ObjectToParentTransform;
00466 TransformPointer m_ObjectToWorldTransform;
00467 TransformPointer m_IndexToWorldTransform;
00468 TransformPointer m_WorldToIndexTransform;
00469
00471 SpatialObject();
00472
00474 virtual ~SpatialObject();
00475
00476 virtual void PrintSelf( std::ostream& os, Indent indent ) const;
00477
00480 ChildrenListType m_Children;
00481
00486 void ComputeOffsetTable();
00487
00488 const Self* m_Parent;
00489
00490 std::string m_TypeName;
00491
00492 unsigned int m_Dimension;
00493
00494 double m_OffsetTable[3+1];
00495
00496 RegionType m_LargestPossibleRegion;
00497 RegionType m_RequestedRegion;
00498 RegionType m_BufferedRegion;
00499
00500 std::string m_BoundingBoxChildrenName;
00501 unsigned int m_BoundingBoxChildrenDepth;
00502 PropertyPointer m_Property;
00503
00505 int m_Id;
00506 int m_ParentId;
00507
00509 bool m_SceneManageMemory;
00510 };
00511
00512 }
00513
00514 #ifndef ITK_MANUAL_INSTANTIATION
00515 #include "itkSpatialObject.txx"
00516 #endif
00517
00518 #endif // __itkSpatialObject_h