#ifndef _OTB_TRISKELE_TREE_HPP #define _OTB_TRISKELE_TREE_HPP #include #include #include #include #include "triskeleBase.hpp" #include "triskeleDebug.hpp" namespace otb { namespace triskele { using namespace ::triskele; enum State { Void = 0, Initialized = 1 << 0, Constructed = 1 << 1 }; class Tree { friend class TreeBuilder; protected: /*! Info about the picture */ Size size; /*! Number of pixels / leaf */ DimNodeId leafCount, nodeCount; /*! Pointers on the parents of each leafs / nodes */ DimNodeId *leafParents, *compParents; /*! Pointers on the children and count how many children a parents have */ DimNodeId *children, *childCount; /*! State of the tree */ State state; /*! Allocate the size according to the size previously defined */ void book (const DimImg &leafCount); /*! Free all the memory and set all pointers to nullptr */ void free (); public: // Constructors, destructor and resize method (does the same as the constructors) Tree (const DimSideImg &width, const DimSideImg &height); Tree (const DimImg &leafCount = 0); // XXX ~Tree (); /*! clear values according to the size defined */ void clear (); void resize (const DimSideImg &width, const DimSideImg &height); void resize (const DimImg &leafCount); // XXX // Setter for nodeCount and size inline void setNodeCount (const DimImg &newNodeCount); inline void setSize (const Size &newSize); // Get the tree state and the size inline State getState () const; inline Size getSize () const; // Getters for tree structure inline DimNodeId getRoot () const; inline DimNodeId getAbsRoot () const; inline DimNodeId getCompCount () const; inline const DimNodeId &getParent (const DimNodeId &idx) const; inline const DimNodeId &getLeafParent (const DimNodeId &idx) const; inline const DimNodeId &getCompParent (const DimNodeId &idx) const; inline const DimNodeId &getChildrenCount (const DimImg &idx) const; inline const DimSideImg &getLeafCount () const; inline const DimSideImg &getNodeCount () const; // Functions to apply to specific entities template void forEachLeaf (const FuncToApply &f /* f (DimNodeId leafId) */) const; template inline void forEachComp (const FuncToApply &f /* f (DimNodeId compId) */) const; template inline void forEachChild (const DimNodeId &parentId, const FuncToApply &f /* f (DimNodeId childId) */) const; #ifdef ENABLE_LOG // Print info about the tree void printTree () const; #endif }; #include "Tree.tpp" } // triskele } // otb #endif // _OTB_TRISKELE_TREE_HPP