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-04-07 14:34:17 $
00007   Version:   $Revision: 1.15 $
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 ITK_EXPORT 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(){};
00083   void PrintSelf(std::ostream &os, Indent indent) const
00084     {
00085     this->Superclass::PrintSelf(os, indent);
00086     os << indent << "NodeToParentNodeTransform: "
00087        << m_NodeToParentNodeTransform << std::endl;
00088     os << indent << "NodeToWorldTransform: "
00089        << m_NodeToWorldTransform << std::endl;
00090     }
00092 
00093   TransformPointer m_NodeToParentNodeTransform;
00094   TransformPointer m_NodeToWorldTransform;
00095 
00096 private:
00097 
00098   SpatialObjectTreeNode(const Self&); //purposely not implemented
00099   void operator=(const Self&); //purposely not implemented
00100 
00101 };
00102 
00104 template <unsigned int TDimension>
00105 SpatialObjectTreeNode<TDimension>
00106 ::SpatialObjectTreeNode() : TreeNode<SpatialObject<TDimension> *>()
00107 {
00108   m_NodeToParentNodeTransform = TransformType::New();
00109   m_NodeToParentNodeTransform->SetIdentity();
00110   m_NodeToWorldTransform = TransformType::New();
00111   m_NodeToWorldTransform->SetIdentity();
00112   this->m_Parent = NULL;
00113 }
00115 
00116   
00118 template <unsigned int TDimension>
00119 void
00120 SpatialObjectTreeNode<TDimension>
00121 ::SetData(SpatialObjectType* data)
00122 {
00123   Superclass::Set(data);
00124   data->SetTreeNode(this); // give the pointer to the node to the spatial object
00125 }
00127 
00129 template <unsigned int TDimension>
00130 void SpatialObjectTreeNode<TDimension>
00131 ::ComputeNodeToWorldTransform()
00132 {
00133   m_NodeToWorldTransform->SetMatrix(m_NodeToParentNodeTransform->GetMatrix());
00134   m_NodeToWorldTransform->SetOffset(m_NodeToParentNodeTransform->GetOffset());
00135   if(this->HasParent())
00136     {
00137     static_cast<Self*>(this->GetParent())->ComputeNodeToWorldTransform();
00138     m_NodeToWorldTransform->Compose( static_cast<Self*>(this->GetParent())
00139                                      ->GetNodeToWorldTransform(), false);
00140     }
00141 }
00143 
00144 
00146 #if !defined(CABLE_CONFIGURATION)
00147 template <unsigned int TDimension>
00148 typename SpatialObjectTreeNode<TDimension>::ChildrenListType* 
00149 SpatialObjectTreeNode<TDimension>
00150 ::GetChildren( unsigned int depth, char * name) const
00151 {
00152   ChildrenListType * children = new ChildrenListType;
00153 
00154   typename ChildrenListType::const_iterator childrenListIt = 
00155     this->m_Children.begin();
00156   typename ChildrenListType::const_iterator childrenListEnd = 
00157     this->m_Children.end();
00158 
00159   while( childrenListIt != childrenListEnd )
00160     {
00161     if( name == NULL || strstr(typeid(*((*childrenListIt)->Get())).name(),
00162                                name) )
00163       {
00164       children->push_back(*childrenListIt);
00165       }
00166     if( depth > 0 )
00167       {
00168       ChildrenListType * nextchildren = 
00169                          (**childrenListIt).GetChildren(depth-1, name);  
00170       // Add the child to the current list
00171       typename ChildrenListType::const_iterator nextIt = nextchildren->begin();
00172       while(nextIt != nextchildren->end())
00173         {
00174         children->push_back(*nextIt);
00175         nextIt++;
00176         }
00177       delete nextchildren;
00178       }
00179     childrenListIt++;
00180     }
00181 
00182   return children;
00183 }
00184 #endif
00185 
00186 } // end namespace itk
00187 
00188 
00189 #endif
00190 

Generated at Fri Apr 16 19:44:28 2010 for ITK by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2000