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: 2006/01/09 19:23:09 $
00007   Version:   $Revision: 1.9 $
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 TreeNode< SpatialObject<TDimension> *>   Superclass;
00038   typedef SpatialObjectTreeNode<TDimension>        Self;
00039   typedef SmartPointer<Self>                       Pointer;
00040   typedef SmartPointer<const Self>                 ConstPointer;
00041   typedef ScalableAffineTransform< double, TDimension>   
00042                                                    TransformType;
00043   typedef typename TransformType::Pointer          TransformPointer;
00044   typedef const TransformType*                     TransformConstPointer;
00045   typedef typename Superclass::ChildrenListType    ChildrenListType;
00046 
00048   itkNewMacro( Self );
00049 
00051   itkTypeMacro( SpatialObjectTreeNode, TreeNode );
00052 
00054   virtual void SetData(SpatialObjectType* data);
00055 
00057   itkSetObjectMacro(NodeToParentNodeTransform,TransformType);
00058   itkGetConstReferenceObjectMacro(NodeToParentNodeTransform,TransformType);
00060 
00062   itkSetObjectMacro(NodeToWorldTransform,TransformType);
00063   itkGetConstReferenceObjectMacro(NodeToWorldTransform,TransformType);
00065 
00067   void ComputeNodeToWorldTransform();
00068 
00070   virtual ChildrenListType* GetChildren( unsigned int depth=0,
00071                                          char * name=NULL) const;
00072 
00073 protected:
00074 
00076   SpatialObjectTreeNode();
00077   virtual ~SpatialObjectTreeNode(){};
00079 
00080   TransformPointer m_NodeToParentNodeTransform;
00081   TransformPointer m_NodeToWorldTransform;
00082 
00083 private:
00084 
00085   SpatialObjectTreeNode(const Self&); //purposely not implemented
00086   void operator=(const Self&); //purposely not implemented
00087 
00088 };
00089 
00091 template <unsigned int TDimension>
00092 SpatialObjectTreeNode<TDimension>
00093 ::SpatialObjectTreeNode() : TreeNode<SpatialObject<TDimension> *>()
00094 {
00095   m_NodeToParentNodeTransform = TransformType::New();
00096   m_NodeToParentNodeTransform->SetIdentity();
00097   m_NodeToWorldTransform = TransformType::New();
00098   m_NodeToWorldTransform->SetIdentity();
00099   this->m_Parent = NULL;
00100 }
00102 
00103   
00105 template <unsigned int TDimension>
00106 void
00107 SpatialObjectTreeNode<TDimension>
00108 ::SetData(SpatialObjectType* data)
00109 {
00110   Superclass::Set(data);
00111   data->SetTreeNode(this); // give the pointer to the node to the spatial object
00112 }
00114 
00116 template <unsigned int TDimension>
00117 void
00118 SpatialObjectTreeNode<TDimension>
00119 ::ComputeNodeToWorldTransform()
00120 {
00121   m_NodeToWorldTransform->SetMatrix(m_NodeToParentNodeTransform->GetMatrix());
00122   m_NodeToWorldTransform->SetOffset(m_NodeToParentNodeTransform->GetOffset());
00123   if(this->HasParent())
00124     {
00125     static_cast<Self*>(this->GetParent())->ComputeNodeToWorldTransform();
00126     m_NodeToWorldTransform->Compose( static_cast<Self*>(this->GetParent())
00127                                      ->GetNodeToWorldTransform(), false);
00128     }
00129 }
00131 
00132 
00134 template <unsigned int TDimension>
00135 typename SpatialObjectTreeNode<TDimension>::ChildrenListType* 
00136 SpatialObjectTreeNode<TDimension>
00137 ::GetChildren( unsigned int depth, char * name) const
00138 {
00139   ChildrenListType * children = new ChildrenListType;
00140 
00141   typename ChildrenListType::const_iterator childrenListIt = 
00142     this->m_Children.begin();
00143   typename ChildrenListType::const_iterator childrenListEnd = 
00144     this->m_Children.end();
00145 
00146   while( childrenListIt != childrenListEnd )
00147     {
00148     if( name == NULL || strstr(typeid(*((*childrenListIt)->Get())).name(),
00149                                name) )
00150       {
00151       children->push_back(*childrenListIt);
00152       }
00153     if( depth > 0 )
00154       {
00155       ChildrenListType * nextchildren = 
00156                          (**childrenListIt).GetChildren(depth-1, name);  
00157       // Add the child to the current list
00158       typename ChildrenListType::const_iterator nextIt = nextchildren->begin();
00159       while(nextIt != nextchildren->end())
00160         {
00161         children->push_back(*nextIt);
00162         nextIt++;
00163         }
00164       delete nextchildren;
00165       }
00166     childrenListIt++;
00167     }
00168 
00169   return children;
00170 }
00171 
00172 
00173 } // end namespace itk
00174 
00175 
00176 #endif
00177 

Generated at Sat Sep 2 21:09:37 2006 for ITK by doxygen 1.4.7 written by Dimitri van Heesch, © 1997-2000