triskele/include/Tree.hpp
Git Merciol 273f7d6647 modifié : include/ArrayTree/ArrayTreeBuilder.hpp
modifié :         include/ArrayTree/ArrayTreeBuilder.tpp
	modifié :         include/QuadTree/QuadTreeBuilder.hpp
	modifié :         include/Tree.hpp
	modifié :         include/TreeBuilder.hpp
	modifié :         include/XMLTree/XMLTreeBuilder.hpp
	modifié :         include/triskeleDealThreads.hpp
	modifié :         src/Attributes/AreaAttribute.cpp
	modifié :         src/QuadTree/QuadTreeBuilder.cpp
	modifié :         src/Tree.cpp
	modifié :         src/XMLTree/XMLTreeBuilder.cpp
	modifié :         src/testMain.cpp
2017-11-28 04:31:40 +01:00

102 lines
3.1 KiB
C++

#ifndef _OTB_TRISKELE_TREE_HPP
#define _OTB_TRISKELE_TREE_HPP
#include <vector>
#include <map>
#include <string>
#include <numeric>
#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<typename FuncToApply>
void forEachLeaf (const FuncToApply &f /* f (DimNodeId leafId) */) const;
template<typename FuncToApply>
void forEachComp (const FuncToApply &f /* f (DimNodeId compId) */) const;
template<typename FuncToApply>
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