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
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 template< unsigned int TDimension = 3>
00069 class SpatialObject
00070 :public DataObject
00071 {
00072
00073 public:
00074
00075 typedef double ScalarType;
00076
00077 itkStaticConstMacro(MaximumDepth, unsigned int, 9999999);
00078
00081 unsigned int GetMaximumDepth() { return MaximumDepth; }
00082
00083 typedef SpatialObject<TDimension> Self;
00084 typedef DataObject Superclass;
00085
00086 typedef SmartPointer< Self > Pointer;
00087 typedef SmartPointer< const Self > ConstPointer;
00088
00089 typedef Point < ScalarType, TDimension > PointType;
00090
00091 typedef Point < ScalarType, TDimension > InputType;
00092 typedef PointType * PointPointer;
00093
00094 typedef Vector< ScalarType, TDimension > VectorType;
00095 typedef CovariantVector<ScalarType, TDimension > CovariantVectorType;
00096 typedef VectorType * VectorPointer;
00097
00098 typedef double * SpacingType;
00099
00100 typedef CovariantVector< double, TDimension > OutputVectorType;
00101 typedef OutputVectorType * OutputVectorPointer;
00102
00103 typedef ScalableAffineTransform< double, TDimension > TransformType;
00104 typedef typename TransformType::Pointer TransformPointer;
00105 typedef const TransformType* TransformConstPointer;
00106
00107 typedef VectorContainer< unsigned long int, PointType > VectorContainerType;
00108
00109 typedef BoundingBox< unsigned long int, TDimension, ScalarType,
00110 VectorContainerType > BoundingBoxType;
00111 typedef typename BoundingBoxType::Pointer BoundingBoxPointer;
00112
00113 typedef AffineGeometryFrame<double,TDimension> AffineGeometryFrameType;
00114 typedef typename AffineGeometryFrameType::Pointer AffineGeometryFramePointer;
00115
00117 typedef std::list< Pointer > ChildrenListType;
00118 typedef ChildrenListType* ChildrenListPointer;
00119
00120
00122 typedef Index<TDimension> IndexType;
00123 typedef typename IndexType::IndexValueType IndexValueType;
00124
00127 typedef Offset<TDimension> OffsetType;
00128 typedef typename OffsetType::OffsetValueType OffsetValueType;
00129 typedef ImageRegion<TDimension> RegionType;
00130 typedef Size<TDimension> SizeType;
00131 typedef SpatialObjectProperty< float > PropertyType;
00132 typedef typename PropertyType::Pointer PropertyPointer;
00133
00134 typedef SpatialObjectTreeNode<TDimension> TreeNodeType;
00135
00138 virtual bool HasParent( void ) const;
00139
00141 virtual const char* GetTypeName(void) const {return m_TypeName.c_str();}
00142
00146 itkStaticConstMacro(ObjectDimension, unsigned int, TDimension);
00147
00149 unsigned int GetObjectDimension(void) const {return TDimension;}
00150
00152 itkNewMacro( Self );
00153
00155 itkTypeMacro( SpatialObject, DataObject );
00156
00158 itkGetConstObjectMacro(AffineGeometryFrame,AffineGeometryFrameType);
00159 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);
00170
00174 void ComputeObjectToWorldTransform(void);
00175
00177 void ComputeObjectToParentTransform(void);
00178
00180 unsigned long GetTransformMTime( void );
00181
00183 unsigned long GetWorldTransformMTime( void );
00184
00186 virtual bool ValueAt( const PointType & point, double & value,
00187 unsigned int depth=0,
00188 char * name = NULL) const;
00189
00196 virtual bool IsEvaluableAt( const PointType & point,
00197 unsigned int depth=0,
00198 char * name = NULL) const;
00199
00201 virtual bool IsInside( const PointType & point,
00202 unsigned int depth=0,
00203 char * name = NULL) const;
00204
00209 bool Evaluate( const PointType & point ) const
00210 {
00211 return this->IsInside( point );
00212 };
00214
00216 virtual void DerivativeAt( const PointType & point,
00217 short unsigned int order,
00218 OutputVectorType & value,
00219 unsigned int depth=0,
00220 char * name = NULL);
00221
00222
00225 unsigned long GetMTime( void ) const;
00226
00229 unsigned long GetObjectMTime( void ) const
00230 {
00231 return Superclass::GetMTime();
00232 }
00233
00240 virtual void SetLargestPossibleRegion(const RegionType ®ion);
00241
00248 virtual const RegionType& GetLargestPossibleRegion() const
00249 { return m_LargestPossibleRegion;};
00250
00254 virtual void SetBufferedRegion(const RegionType ®ion);
00255
00259 virtual const RegionType& GetBufferedRegion() const
00260 { return m_BufferedRegion;};
00261
00266 virtual void SetRequestedRegion(const RegionType ®ion);
00267
00272 virtual void SetRequestedRegion(DataObject *data);
00273
00278 virtual const RegionType& GetRequestedRegion() const
00279 { return m_RequestedRegion;};
00280
00290 const OffsetValueType *GetOffsetTable() const { return m_OffsetTable; };
00292
00295 OffsetValueType ComputeOffset(const IndexType &ind) const
00296 {
00297
00298 OffsetValueType offset=0;
00299 const IndexType &bufferedRegionIndex = m_BufferedRegion.GetIndex();
00301
00302
00303
00304 for (int i=TDimension-1; i > 0; i--)
00305 {
00306 offset += (ind[i] - bufferedRegionIndex[i])*m_OffsetTable[i];
00307 }
00308 offset += (ind[0] - bufferedRegionIndex[0]);
00309
00310 return offset;
00311 }
00312
00315 IndexType ComputeIndex(OffsetValueType offset) const
00316 {
00317 IndexType index;
00318 const IndexType &bufferedRegionIndex = m_BufferedRegion.GetIndex();
00320
00321 for (int i=TDimension-1; i > 0; i--)
00322 {
00323 index[i] = static_cast<IndexValueType>(offset / m_OffsetTable[i]);
00324 offset -= (index[i] * m_OffsetTable[i]);
00325 index[i] += bufferedRegionIndex[i];
00326 }
00327 index[0] = bufferedRegionIndex[0] + static_cast<IndexValueType>(offset);
00328
00329 return index;
00330 }
00331
00341 virtual void CopyInformation(const DataObject *data);
00342
00350 virtual void UpdateOutputInformation();
00351
00355 virtual void SetRequestedRegionToLargestPossibleRegion();
00356
00366 virtual bool RequestedRegionIsOutsideOfTheBufferedRegion();
00367
00376 virtual bool VerifyRequestedRegion();
00377
00378
00380 PropertyType * GetProperty( void );
00381 const PropertyType * GetProperty( void ) const {return m_Property;}
00383
00385 void SetProperty( PropertyType * property );
00386
00388 itkGetConstReferenceMacro(Id,int);
00389 itkSetMacro(Id,int);
00391
00393 itkSetMacro(ParentId, int);
00394 itkGetConstReferenceMacro(ParentId, int);
00396
00398 virtual void Update(void);
00399
00401 itkSetObjectMacro(TreeNode, TreeNodeType)
00402
00403
00404 itkGetObjectMacro(TreeNode, TreeNodeType);
00405 itkGetConstObjectMacro(TreeNode, TreeNodeType);
00407
00411 void SetSpacing( const double
00412 spacing[itkGetStaticConstMacro(ObjectDimension)] )
00413 { this->GetIndexToObjectTransform()->SetScale(spacing);}
00414
00416 virtual const double * GetSpacing() const
00417 {return this->GetIndexToObjectTransform()->GetScale();}
00418
00419
00425 TransformType * GetIndexToObjectTransform( void );
00426 const TransformType * GetIndexToObjectTransform( void ) const;
00428
00432 void SetObjectToParentTransform( TransformType * transform );
00433 TransformType * GetObjectToParentTransform( void );
00434 const TransformType * GetObjectToParentTransform( void ) const;
00436
00440 TransformType * GetObjectToNodeTransform( void );
00441 const TransformType * GetObjectToNodeTransform( void ) const;
00443
00448 void AddSpatialObject( Self * pointer );
00449
00454 void RemoveSpatialObject( Self * object );
00455
00457 virtual const Self * GetParent( void ) const;
00458
00460 virtual Self * GetParent( void );
00461
00467 virtual ChildrenListType * GetChildren( unsigned int depth=0,
00468 char * name=NULL ) const;
00469
00471 unsigned int GetNumberOfChildren( unsigned int depth=0,
00472 char * name=NULL ) const;
00473
00475 void SetChildren( ChildrenListType & children );
00476
00479 virtual void Clear( void );
00480
00503 virtual bool ComputeBoundingBox() const;
00504 virtual bool ComputeLocalBoundingBox() const
00505 {
00506 std::cerr << "SpatialObject::ComputeLocalBoundingBox Not Implemented!"
00507 << std::endl;
00508 return false;
00509 }
00511
00514 virtual BoundingBoxType * GetBoundingBox() const;
00515
00516
00518 itkSetMacro(BoundingBoxChildrenDepth, unsigned int);
00519 itkGetConstReferenceMacro(BoundingBoxChildrenDepth, unsigned int);
00521
00524 itkSetMacro(BoundingBoxChildrenName, std::string);
00525 itkGetConstReferenceMacro(BoundingBoxChildrenName, std::string);
00527
00530 void SetParent(Self * parent);
00531
00532
00534 void SetNodeToParentNodeTransform( TransformType * transform );
00535 TransformType * GetNodeToParentNodeTransform( void );
00536 const TransformType * GetNodeToParentNodeTransform( void ) const;
00538
00541 itkSetMacro(DefaultInsideValue,double);
00542 itkGetConstMacro(DefaultInsideValue,double);
00544
00547 itkSetMacro(DefaultOutsideValue,double);
00548 itkGetConstMacro(DefaultOutsideValue,double);
00550
00553 virtual std::string GetSpatialObjectTypeAsString() const;
00554
00555 protected:
00556
00558 SpatialObject();
00559
00561 virtual ~SpatialObject();
00562
00563 virtual void PrintSelf( std::ostream& os, Indent indent ) const;
00564
00569 void ComputeOffsetTable();
00570
00571 itkSetMacro(Dimension,unsigned int);
00572 itkGetConstReferenceMacro(Dimension,unsigned int)
00573 itkSetMacro(TypeName,std::string);
00574 itkGetConstObjectMacro(Bounds,BoundingBoxType);
00575 itkGetConstObjectMacro(InternalInverseTransform,TransformType);
00576
00583 bool SetInternalInverseTransformToWorldToIndexTransform() const;
00584
00585 private:
00586
00587 SpatialObject(const Self&);
00588 void operator=(const Self&);
00589
00590 BoundingBoxPointer m_Bounds;
00591 mutable unsigned long m_BoundsMTime;
00592
00593 TransformPointer m_ObjectToParentTransform;
00594 TransformPointer m_ObjectToWorldTransform;
00595 TransformPointer m_IndexToWorldTransform;
00596
00598 std::string m_TypeName;
00599
00600 unsigned int m_Dimension;
00601
00602 OffsetValueType m_OffsetTable[3+1];
00603
00604 RegionType m_LargestPossibleRegion;
00605 RegionType m_RequestedRegion;
00606 RegionType m_BufferedRegion;
00607
00608 std::string m_BoundingBoxChildrenName;
00609 unsigned int m_BoundingBoxChildrenDepth;
00610 PropertyPointer m_Property;
00611
00613 int m_Id;
00614 int m_ParentId;
00615
00617 typename TreeNodeType::Pointer m_TreeNode;
00618
00620 AffineGeometryFramePointer m_AffineGeometryFrame;
00621
00624 ChildrenListType m_InternalChildrenList;
00625
00628 TransformPointer m_InternalInverseTransform;
00629
00631 double m_DefaultInsideValue;
00632
00634 double m_DefaultOutsideValue;
00635 };
00636
00637 }
00638
00639 #if !defined(CABLE_CONFIGURATION)
00640 #ifndef ITK_MANUAL_INSTANTIATION
00641 #include "itkSpatialObject.txx"
00642 #endif
00643 #endif
00644
00645 #endif // __itkSpatialObject_h
00646