#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, Constructed = 1 << 1 }; class Tree { friend class TreeBuilder; protected: /*! Info about the picture */ Size size; /*! Number of pixels / leaf */ DimImg 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); ~Tree (); /*! clear values according to the size defined */ void clear (); void resize (const DimSideImg &width, const DimSideImg &height); void resize (const DimImg &leafCount); // Setter for nodeCount and size void setNodeCount (const DimImg &newNodeCount) { nodeCount = newNodeCount; } void setSize (const Size &newSize) { size = newSize; } // Get the tree state and the size State getState () const { return state; } Size getSize () const { return size; } // Getters for tree structure DimNodeId getRoot () const { return nodeCount-1; } DimNodeId getAbsRoot () const { return nodeCount-1+leafCount; } DimNodeId getCompCount () const { return nodeCount-leafCount; } // XXX const DimNodeId &getParent (const DimNodeId &idx) const { return leafParents[idx]; } const DimNodeId &getLeafParent (const DimNodeId &idx) const { return leafParents[idx]; } const DimNodeId &getCompParent (const DimNodeId &idx) const { return compParents[idx]; } const DimNodeId &getChildrenCount (const DimImg &idx) const { return childCount[idx]; } const DimSideImg &getLeafCount () const { return leafCount; } const DimSideImg &getNodeCount () const { return nodeCount; } // Functions to apply to specific entities template void forEachLeaf (const FuncToApply &f /* f (DimNodeId leafId) */) const; template void forEachComp (const FuncToApply &f /* f (DimNodeId compId) */) const; template void forEachChild (const DimNodeId &parentId, const FuncToApply &f /* f (DimNodeId childId) */) const; #ifdef SMART_LOG // Print info about the tree void printTree (const Size &size, const bool &rec); #endif }; #include "Tree.tpp" } // triskele } // otb #endif // _OTB_TRISKELE_TREE_HPP