#ifndef _OTB_TRISKELE_TREE_HPP #define _OTB_TRISKELE_TREE_HPP #include #include #include #include #include #include "triskeleBase.hpp" #include "triskeleDebug.hpp" #include "Border.hpp" namespace otb { namespace triskele { using namespace ::triskele; enum State { Void = 0, Initialized = 1 << 0, Constructed = 1 << 1 }; class Tree { friend class TreeBuilder; private: inline DimNodeId *getChildSum (); protected: /*! nb core for build and compute attributes */ const unsigned int coreCount; /*! Info about the picture */ Size size; /*! Number of pixels / leaf */ DimImg leafCount; /*! number of node */ DimNodeId nodeCount; /* nodeCount = leafCount+compCount */ /*! Pointers on the parents of each leafs / nodes */ vector leafParents; DimImg *compParents; /*! Pointers on the children and count how many children a parents have */ vector childrenStart; vector children; /*! Pointers of same weight in parents (+1 : last is root)*/ vector weightBounds; /*! 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) // XXX test sans defaut treeCoreCount Tree (const DimSideImg &width, const DimSideImg &height, unsigned int coreCount = boost::thread::hardware_concurrency ()); Tree (unsigned int coreCount = boost::thread::hardware_concurrency ()); ~Tree (); /*! clear values according to the size defined */ void clear (); void resize (const DimSideImg &width, const DimSideImg &height); // Setter for nodeCount and size inline void setNodeCount (const DimNodeId &newNodeCount); inline void setSize (const Size &newSize); inline unsigned int getCoreCount () const; // Get the tree state and the size inline State getState () const; inline Size getSize () const; // Getters for tree structure inline const DimImg &getLeafCount () const; inline const DimNodeId &getNodeCount () const; inline DimImg getCompCount () const; inline DimNodeId getNodeRoot () const; inline DimImg getCompRoot () const; inline bool isLeaf (const DimNodeId &nodeId) const; inline DimImg getLeafId (const DimNodeId &nodeId) const; inline DimImg getCompId (const DimNodeId &nodeId) const; inline DimNodeId getChild (const DimImg &compId, const DimImg &childId) const; inline const DimImg &getParent (const DimNodeId &nodeId) const; inline const DimImg &getLeafParent (const DimImg &leafId) const; inline const DimImg &getCompParent (const DimImg &compId) const; inline const DimImg &getChildrenCount (const DimImg &CompId) const; inline const DimNodeId &getChildren (const DimImg &childId) const; inline const DimNodeId *getChildren () const; // XXX a virer ? inline const vector &getWeightBounds () const; inline vector &getWeightBounds (); // Functions to apply to specific entities template void forEachLeaf (const FuncToApply &f /* f (DimImg leafId) */) const; template inline void forEachComp (const FuncToApply &f /* f (DimImg compId) */) const; template inline void forEachNode (const FuncToApply &f /* f (DimNodeId nodeId) */) const; template inline void forEachChild (const DimNodeId &parentId, const FuncToApply &f /* f (DimNodeId childId) */) const; template inline void forEachChildTI (const DimNodeId &parentId, const FuncToApply &f /* f (bool isLeaf, DimImg childId) */) const; bool compareTo (const Tree &tree, bool testChildren = false) const; void checkSpare (const Border& border) const; void check (const Border& border) const; // XXX void checkWeightCurve (bool incr) const; // nice ostream struct CPrintTree { const Tree &tree; const bool onRecord; const DimNodeId nodeCount; CPrintTree (const Tree &tree, DimNodeId nodeCount); ostream &print (ostream &out) const; }; CPrintTree printTree (DimNodeId nodeCount = 0) const; friend ostream &operator << (ostream& out, const CPrintTree &cpt) { return cpt.print (out); } }; #include "Tree.tpp" } // triskele } // otb #endif // _OTB_TRISKELE_TREE_HPP