00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkSpatialObjectTreeNode_h
00018 #define __itkSpatialObjectTreeNode_h
00019
00020 #include <itkTreeNode.h>
00021 #include <itkSpatialObject.h>
00022 #include <itkScalableAffineTransform.h>
00023
00024 namespace itk
00025 {
00026
00027 template <unsigned int TDimension> class SpatialObject;
00028
00029 template <unsigned int TDimension>
00030 class SpatialObjectTreeNode : public TreeNode< SpatialObject<TDimension> * >
00031 {
00032
00033 public:
00034
00036 typedef SpatialObject<TDimension> SpatialObjectType;
00037
00038 typedef TreeNode< SpatialObject<TDimension> *> Superclass;
00039 typedef SpatialObjectTreeNode<TDimension> Self;
00040 typedef SmartPointer<Self> Pointer;
00041 typedef SmartPointer<const Self> ConstPointer;
00042 typedef ScalableAffineTransform< double, TDimension>
00043 TransformType;
00044 typedef typename TransformType::Pointer TransformPointer;
00045 typedef const TransformType* TransformConstPointer;
00046 typedef typename Superclass::ChildrenListType ChildrenListType;
00047
00049 itkNewMacro( Self );
00050
00052 itkTypeMacro( SpatialObjectTreeNode, TreeNode );
00053
00055 virtual void SetData(SpatialObjectType* data);
00056
00058 itkSetObjectMacro(NodeToParentNodeTransform,TransformType);
00059 itkGetConstReferenceObjectMacro(NodeToParentNodeTransform,TransformType);
00060
00062 itkSetObjectMacro(NodeToWorldTransform,TransformType);
00063 itkGetConstReferenceObjectMacro(NodeToWorldTransform,TransformType);
00064
00066 void ComputeNodeToWorldTransform();
00067
00069 virtual ChildrenListType* GetChildren( unsigned int depth=0,
00070 char * name=NULL) const;
00071
00072 protected:
00073
00075 SpatialObjectTreeNode();
00076 virtual ~SpatialObjectTreeNode(){};
00077
00078 TransformPointer m_NodeToParentNodeTransform;
00079 TransformPointer m_NodeToWorldTransform;
00080 };
00081
00083 template <unsigned int TDimension>
00084 SpatialObjectTreeNode<TDimension>
00085 ::SpatialObjectTreeNode() : TreeNode<SpatialObject<TDimension> *>()
00086 {
00087 m_NodeToParentNodeTransform = TransformType::New();
00088 m_NodeToParentNodeTransform->SetIdentity();
00089 m_NodeToWorldTransform = TransformType::New();
00090 m_NodeToWorldTransform->SetIdentity();
00091 this->m_Parent = NULL;
00092 }
00093
00094
00096 template <unsigned int TDimension>
00097 void
00098 SpatialObjectTreeNode<TDimension>
00099 ::SetData(SpatialObjectType* data)
00100 {
00101 Superclass::Set(data);
00102 data->SetTreeNode(this);
00103 }
00104
00106 template <unsigned int TDimension>
00107 void
00108 SpatialObjectTreeNode<TDimension>
00109 ::ComputeNodeToWorldTransform()
00110 {
00111 m_NodeToWorldTransform->SetMatrix(m_NodeToParentNodeTransform->GetMatrix());
00112 m_NodeToWorldTransform->SetOffset(m_NodeToParentNodeTransform->GetOffset());
00113 if(this->HasParent())
00114 {
00115 static_cast<Self*>(this->GetParent())->ComputeNodeToWorldTransform();
00116 m_NodeToWorldTransform->Compose( static_cast<Self*>(this->GetParent())
00117 ->GetNodeToWorldTransform(), false);
00118 }
00119 }
00120
00121
00123 template <unsigned int TDimension>
00124 typename SpatialObjectTreeNode<TDimension>::ChildrenListType*
00125 SpatialObjectTreeNode<TDimension>
00126 ::GetChildren( unsigned int depth, char * name) const
00127 {
00128 ChildrenListType * children = new ChildrenListType;
00129
00130 typename ChildrenListType::const_iterator childrenListIt =
00131 this->m_Children.begin();
00132 typename ChildrenListType::const_iterator childrenListEnd =
00133 this->m_Children.end();
00134
00135 while( childrenListIt != childrenListEnd )
00136 {
00137 if( name == NULL || strstr(typeid(*((*childrenListIt)->Get())).name(),
00138 name) )
00139 {
00140 children->push_back(*childrenListIt);
00141 }
00142 if( depth > 0 )
00143 {
00144 ChildrenListType * nextchildren =
00145 (**childrenListIt).GetChildren(depth-1, name);
00146
00147 typename ChildrenListType::const_iterator nextIt = nextchildren->begin();
00148 while(nextIt != nextchildren->end())
00149 {
00150 children->push_back(*nextIt);
00151 nextIt++;
00152 }
00153 delete nextchildren;
00154 }
00155 childrenListIt++;
00156 }
00157
00158 return children;
00159 }
00160
00161
00162 }
00163
00164
00165 #endif