
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.tpp modifié : include/ArrayTree/triskeleArrayTreeBase.hpp modifié : include/ArrayTree/triskeleArrayTreeBase.tpp modifié : include/AttributeProfiles.hpp modifié : include/AttributeProfiles.tpp modifié : include/Attributes/AreaAttributes.hpp modifié : include/Attributes/AverageAttributes.hpp modifié : include/Attributes/MoIAttributes.hpp modifié : include/Attributes/SDAttributes.hpp modifié : include/Attributes/WeightAttributes.hpp modifié : include/Attributes/XYAttributes.hpp modifié : include/CompAttribute.hpp modifié : include/CompAttribute.tpp modifié : include/Tree.hpp modifié : include/Tree.tpp modifié : include/TreeStats.hpp modifié : include/triskeleBase.hpp modifié : include/triskeleBase.tpp modifié : include/triskeleDebug.hpp modifié : src/Tree.cpp modifié : src/TreeStats.cpp modifié : src/apGenerator.cpp
138 lines
4.3 KiB
C++
138 lines
4.3 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 *getChildCount ();
|
|
|
|
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 */
|
|
DimImg *leafParents, *compParents;
|
|
|
|
/*! Pointers on the children and count how many children a parents have */
|
|
DimImg *childCount;
|
|
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 DimImg &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 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;
|
|
|
|
|
|
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
|