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: 2007/07/16 23:15:51 $
00007   Version:   $Revision: 1.12 $
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 #if !defined(CABLE_CONFIGURATION)
00071   virtual ChildrenListType* GetChildren( unsigned int depth=0,
00072                                          char * name=NULL) const;
00073 #endif
00074 
00075 protected:
00076 
00078   SpatialObjectTreeNode();
00079   virtual ~SpatialObjectTreeNode(){};
00081 
00082   TransformPointer m_NodeToParentNodeTransform;
00083   TransformPointer m_NodeToWorldTransform;
00084 
00085 private:
00086 
00087   SpatialObjectTreeNode(const Self&); //purposely not implemented
00088   void operator=(const Self&); //purposely not implemented
00089 
00090 };
00091 
00093 template <unsigned int TDimension>
00094 SpatialObjectTreeNode<TDimension>
00095 ::SpatialObjectTreeNode() : TreeNode<SpatialObject<TDimension> *>()
00096 {
00097   m_NodeToParentNodeTransform = TransformType::New();
00098   m_NodeToParentNodeTransform->SetIdentity();
00099   m_NodeToWorldTransform = TransformType::New();
00100   m_NodeToWorldTransform->SetIdentity();
00101   this->m_Parent = NULL;
00102 }
00104 
00105   
00107 template <unsigned int TDimension>
00108 void
00109 SpatialObjectTreeNode<TDimension>
00110 ::SetData(SpatialObjectType* data)
00111 {
00112   Superclass::Set(data);
00113   data->SetTreeNode(this); // give the pointer to the node to the spatial object
00114 }
00116 
00118 template <unsigned int TDimension>
00119 void SpatialObjectTreeNode<TDimension>
00120 ::ComputeNodeToWorldTransform()
00121 {
00122   m_NodeToWorldTransform->SetMatrix(m_NodeToParentNodeTransform->GetMatrix());
00123   m_NodeToWorldTransform->SetOffset(m_NodeToParentNodeTransform->GetOffset());
00124   if(this->HasParent())
00125     {
00126     static_cast<Self*>(this->GetParent())->ComputeNodeToWorldTransform();
00127     m_NodeToWorldTransform->Compose( static_cast<Self*>(this->GetParent())
00128                                      ->GetNodeToWorldTransform(), false);
00129     }
00130 }
00132 
00133 
00135 #if !defined(CABLE_CONFIGURATION)
00136 template <unsigned int TDimension>
00137 typename SpatialObjectTreeNode<TDimension>::ChildrenListType* 
00138 SpatialObjectTreeNode<TDimension>
00139 ::GetChildren( unsigned int depth, char * name) const
00140 {
00141   ChildrenListType * children = new ChildrenListType;
00142 
00143   typename ChildrenListType::const_iterator childrenListIt = 
00144     this->m_Children.begin();
00145   typename ChildrenListType::const_iterator childrenListEnd = 
00146     this->m_Children.end();
00147 
00148   while( childrenListIt != childrenListEnd )
00149     {
00150     if( name == NULL || strstr(typeid(*((*childrenListIt)->Get())).name(),
00151                                name) )
00152       {
00153       children->push_back(*childrenListIt);
00154       }
00155     if( depth > 0 )
00156       {
00157       ChildrenListType * nextchildren = 
00158                          (**childrenListIt).GetChildren(depth-1, name);  
00159       // Add the child to the current list
00160       typename ChildrenListType::const_iterator nextIt = nextchildren->begin();
00161       while(nextIt != nextchildren->end())
00162         {
00163         children->push_back(*nextIt);
00164         nextIt++;
00165         }
00166       delete nextchildren;
00167       }
00168     childrenListIt++;
00169     }
00170 
00171   return children;
00172 }
00173 #endif
00174 
00175 } // end namespace itk
00176 
00177 
00178 #endif
00179 

Generated at Thu Nov 6 00:17:57 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000