| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkTreeNode.h.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:48 $ |
| 7 |
|
Version: $Revision: 1.4 $ |
| 8 |
|
|
| 9 |
|
Copyright (c) Insight Software Consortium. All rights reserved. |
| 10 |
|
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. |
| 11 |
|
|
| 12 |
|
This software is distributed WITHOUT ANY WARRANTY; without even |
| 13 |
|
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 |
|
PURPOSE. See the above copyright notices for more information. |
| 15 |
|
|
| 16 |
|
=========================================================================*/ |
| 17 |
|
#ifndef __itkTreeNode_h |
| 18 |
|
#define __itkTreeNode_h |
| 19 |
|
|
| 20 |
|
#include <vector> |
| 21 |
|
#include <algorithm> |
| 22 |
|
#include <iostream> |
| 23 |
|
#include <itkObject.h> |
| 24 |
|
|
| 25 |
|
namespace itk |
| 26 |
|
{ |
| 27 |
|
/** \class TreeNode |
| 28 |
|
* \brief TreeNode class |
| 29 |
|
* |
| 30 |
|
* This class derives from the Object class. |
| 31 |
|
* |
| 32 |
|
* The class is templated over the type of the elements. |
| 33 |
|
* |
| 34 |
|
* Template parameters for class TreeNode: |
| 35 |
|
* |
| 36 |
|
* - TValueType = Element type stored in the node |
| 37 |
|
* |
| 38 |
|
* \ingroup DataRepresentation |
| 39 |
|
*/ |
| 40 |
|
template <class TValueType> |
| 41 |
|
class TreeNode : public Object |
| 42 |
|
{ |
| 43 |
|
|
| 44 |
|
public: |
| 45 |
|
|
| 46 |
|
/** Standard typedefs */ |
| 47 |
|
typedef Object Superclass; |
| 48 |
|
typedef TreeNode<TValueType> Self; |
| 49 |
|
typedef SmartPointer<Self> Pointer; |
| 50 |
|
typedef SmartPointer<const Self> ConstPointer; |
| 51 |
|
typedef std::vector<Pointer> ChildrenListType; |
| 52 |
|
|
| 53 |
|
/** Method for creation through the object factory. */ |
| 54 |
|
itkNewMacro( Self ); |
| 55 |
|
|
| 56 |
|
/** Run-time type information (and related methods). */ |
| 57 |
|
itkTypeMacro( TreeNode, Object ); |
| 58 |
|
|
| 59 |
|
/** Get the value of the node */ |
| 60 |
|
const TValueType& Get() const; |
| 61 |
|
|
| 62 |
|
/** Set the current value of the node */ |
| 63 |
|
TValueType Set(const TValueType data); |
| 64 |
|
|
| 65 |
|
/** Get the child node */ |
| 66 |
|
TreeNode<TValueType>* GetChild( int number ) const; |
| 67 |
|
|
| 68 |
|
/** Get the parent node */ |
| 69 |
|
TreeNode<TValueType>* GetParent( ) const; |
| 70 |
|
|
| 71 |
|
/** Return true if the node has children */ |
| 72 |
|
bool HasChildren( ) const; |
| 73 |
|
|
| 74 |
|
/** Return true if the node has a parent */ |
| 75 |
|
bool HasParent( ) const; |
| 76 |
|
|
| 77 |
|
/** Set the parent of the node */ |
| 78 |
|
void SetParent( TreeNode<TValueType>* n ); |
| 79 |
|
|
| 80 |
|
/** Return the number of children */ |
| 81 |
|
int CountChildren( ) const; |
| 82 |
|
|
| 83 |
|
/** Remove a node from the node */ |
| 84 |
|
bool Remove( TreeNode<TValueType> *n ); |
| 85 |
|
|
| 86 |
|
/** Get the number of children given a name and depth */ |
| 87 |
LEN |
unsigned int GetNumberOfChildren(unsigned int depth=0, char * name=NULL ) const; |
| 88 |
|
|
| 89 |
|
/** Replace a given child by a new one */ |
| 90 |
LEN |
bool ReplaceChild( TreeNode<TValueType> *oldChild, TreeNode<TValueType> *newChild ); |
| 91 |
|
|
| 92 |
|
/** Return the child position given a node */ |
| 93 |
|
int ChildPosition( const TreeNode<TValueType> *node ) const; |
| 94 |
|
/** Return the child position given a value */ |
| 95 |
|
int ChildPosition( TValueType node ) const; |
| 96 |
|
|
| 97 |
|
/** Add a child to the node */ |
| 98 |
|
void AddChild( TreeNode<TValueType> *node ); |
| 99 |
|
|
| 100 |
|
/** Add a child to the node and specify the number in the children list */ |
| 101 |
|
virtual void AddChild( int number, TreeNode<TValueType> *node ); |
| 102 |
|
|
| 103 |
|
/** Get the children list */ |
| 104 |
LEN |
virtual ChildrenListType* GetChildren( unsigned int depth=0, char * name=NULL) const; |
| 105 |
|
|
| 106 |
|
/** Get the internal list of children */ |
| 107 |
|
virtual ChildrenListType& GetChildrenList() {return m_Children;} |
| 108 |
|
|
| 109 |
|
/** Set the data of the node */ |
| 110 |
|
//virtual void SetData(TValueType data) {m_Data = data;} |
| 111 |
|
|
| 112 |
|
protected: |
| 113 |
|
|
| 114 |
|
TreeNode(); |
| 115 |
|
virtual ~TreeNode(); |
| 116 |
|
TValueType m_Data; |
| 117 |
|
Self* m_Parent; |
| 118 |
|
ChildrenListType m_Children; |
| 119 |
|
private: |
| 120 |
|
TreeNode(const Self&); //purposely not implemented |
| 121 |
|
void operator=(const Self&); //purposely not implemented |
| 122 |
|
}; |
| 123 |
|
|
| 124 |
|
} // end namespace itk |
| 125 |
|
|
| 126 |
|
#ifndef ITK_MANUAL_INSTANTIATION |
| 127 |
|
#include "itkTreeNode.txx" |
| 128 |
|
#endif |
| 129 |
|
|
| 130 |
|
#endif |
| 131 |
|
|