triskele/include/Tree.hpp
Git Merciol f687310939 modifié : CMakeLists.txt
modifié :         CMakeListsOTB.txt
	modifié :         LICENSE
	modifié :         MakefileNoOTB
	modifié :         Readme.html
	modifié :         Readme.txt
	modifié :         include/Appli/Option.hpp
	modifié :         include/Appli/Selected.hpp
	modifié :         include/Appli/Selected.tpp
	modifié :         include/ArrayTree/ArrayTreeBuilder.hpp
	modifié :         include/ArrayTree/ArrayTreeBuilder.tpp
	modifié :         include/ArrayTree/Border.hpp
	modifié :         include/ArrayTree/Border.tpp
	modifié :         include/ArrayTree/GraphWalker.hpp
	modifié :         include/ArrayTree/GraphWalker.tpp
	modifié :         include/ArrayTree/Leader.hpp
	modifié :         include/ArrayTree/Leader.tpp
	modifié :         include/ArrayTree/Weight.hpp
	modifié :         include/ArrayTree/Weight.tpp
	modifié :         include/ArrayTree/triskeleArrayTreeBase.hpp
	modifié :         include/ArrayTree/triskeleArrayTreeBase.tpp
	modifié :         include/ArrayTree/triskeleSort.hpp
	modifié :         include/ArrayTree/triskeleSort.tpp
	modifié :         include/AttributeProfiles.hpp
	modifié :         include/AttributeProfiles.tpp
	modifié :         include/Attributes/AreaAttributes.hpp
	modifié :         include/Attributes/AreaAttributes.tpp
	modifié :         include/Attributes/AverageAttributes.hpp
	modifié :         include/Attributes/AverageAttributes.tpp
	modifié :         include/Attributes/MoIAttributes.hpp
	modifié :         include/Attributes/MoIAttributes.tpp
	modifié :         include/Attributes/SDAttributes.hpp
	modifié :         include/Attributes/SDAttributes.tpp
	modifié :         include/Attributes/WeightAttributes.hpp
	modifié :         include/Attributes/WeightAttributes.tpp
	modifié :         include/Attributes/XYAttributes.hpp
	modifié :         include/Attributes/XYAttributes.tpp
	modifié :         include/CompAttribute.hpp
	modifié :         include/CompAttribute.tpp
	modifié :         include/IImage.hpp
	modifié :         include/IImage.tpp
	modifié :         include/QuadTree/QuadTreeBuilder.hpp
	modifié :         include/Tree.hpp
	modifié :         include/Tree.tpp
	modifié :         include/TreeBuilder.hpp
	modifié :         include/TreeBuilder.tpp
	modifié :         include/TreeStats.hpp
	modifié :         include/TreeStats.tpp
	modifié :         include/XMLTree/XMLTreeBuilder.hpp
	modifié :         include/triskeleBase.hpp
	modifié :         include/triskeleBase.tpp
	modifié :         include/triskeleDealThreads.hpp
	modifié :         include/triskeleDealThreads.tpp
	modifié :         include/triskeleDebug.hpp
	modifié :         include/triskeleGdalGetType.hpp
	modifié :         otb-module.cmake
	modifié :         src/Appli/Option.cpp
	modifié :         src/Appli/Selected.cpp
	modifié :         src/ArrayTree/triskeleArrayTreeBase.cpp
	modifié :         src/CMakeLists.txt
	modifié :         src/IImage.cpp
	modifié :         src/PerfArrayTreeBuilder.cpp
	modifié :         src/QuadTree/QuadTreeBuilder.cpp
	modifié :         src/TestArrayTreeBuilder.cpp
	modifié :         src/Tree.cpp
	modifié :         src/TreeStats.cpp
	modifié :         src/XMLTree/XMLTreeBuilder.cpp
	modifié :         src/apGenerator.cpp
	modifié :         src/triskeleBase.cpp
	modifié :         src/triskeleDebug.cpp
2018-04-02 19:25:37 +02:00

145 lines
4.6 KiB
C++

#ifndef _OTB_TRISKELE_TREE_HPP
#define _OTB_TRISKELE_TREE_HPP
#include <vector>
#include <map>
#include <string>
#include <numeric>
#include <boost/thread.hpp>
#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;
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<DimImg> leafParents;
DimImg *compParents;
/*! Pointers on the children and count how many children a parents have */
vector<DimImg> childrenStart;
vector<DimNodeId> children;
/*! Pointers of same weight in parents (+1 : last is root)*/
vector<DimImg> 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<DimImg> &getWeightBounds () const;
inline vector<DimImg> &getWeightBounds ();
// Functions to apply to specific entities
template<typename FuncToApply>
void forEachLeaf (const FuncToApply &f /* f (DimImg leafId) */) const;
template<typename FuncToApply>
inline void forEachComp (const FuncToApply &f /* f (DimImg compId) */) const;
template<typename FuncToApply>
inline void forEachNode (const FuncToApply &f /* f (DimNodeId nodeId) */) const;
template<typename FuncToApply>
inline void forEachChild (const DimNodeId &parentId, const FuncToApply &f /* f (DimNodeId childId) */) const;
template<typename FuncToApply>
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;
void check () 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