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

Generated at Sat Feb 28 13:36:17 2009 for ITK by doxygen 1.5.6 written by Dimitri van Heesch, © 1997-2000