Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkSpatialObjectTreeNode.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkSpatialObjectTreeNode.h,v $
00005   Language:  C++
00006   Date:      $Date: 2005/03/09 16:46:14 $
00007   Version:   $Revision: 1.8 $
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 #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   //typedef typename SpatialObjectType::Pointer    SpatialObjectPointer;
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); // give the pointer to the node to the spatial object
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       // Add the child to the current list
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 } // end namespace itk
00163 
00164 
00165 #endif

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