triskele/include/Tree.tpp
Git Merciol 869eda6449 modifié : include/ArrayTree/ArrayTreeBuilder.tpp
modifié :         include/AttributeProfiles.hpp
	modifié :         include/AttributeProfiles.tpp
	modifié :         include/Attributes/AreaAttributes.hpp
	modifié :         include/Attributes/AreaAttributes.tpp
	modifié :         include/Attributes/WeightAttributes.hpp
	modifié :         include/Attributes/WeightAttributes.tpp
	modifié :         include/Tree.hpp
	modifié :         include/Tree.tpp
	modifié :         include/triskeleBase.tpp
	modifié :         src/Tree.cpp
	modifié :         src/XMLTree/XMLTreeBuilder.cpp
	modifié :         src/testMain.cpp
2018-02-19 16:56:30 +01:00

120 lines
2.9 KiB
C++

#ifndef _OTB_TRISKELE_TREE_TPP
#define _OTB_TRISKELE_TREE_TPP
// ========================================
inline DimNodeId *
Tree::getChildCount () {
return childCount;
}
inline void
Tree::setNodeCount (const DimImg &newNodeCount) {
nodeCount = newNodeCount;
}
inline void
Tree::setSize (const Size &newSize) {
size = newSize;
}
inline State
Tree::getState () const {
return state;
}
inline Size
Tree::getSize () const {
return size;
}
inline const DimSideImg &
Tree::getLeafCount () const {
return leafCount;
}
inline const DimNodeId &
Tree::getNodeCount () const {
return nodeCount;
}
inline DimImg
Tree::getCompCount () const {
return (DimImg) (nodeCount-leafCount);
}
inline DimNodeId
Tree::getNodeRoot () const {
return nodeCount-1;
}
inline DimImg
Tree::getCompRoot () const {
return (DimImg) (nodeCount-1-leafCount);
}
inline const DimImg &
Tree::getParent (const DimNodeId &nodeId) const {
return leafParents[nodeId];
}
inline const DimImg &
Tree::getLeafParent (const DimImg &leafId) const {
return leafParents[leafId];
}
inline const DimImg &
Tree::getCompParent (const DimImg &compId) const {
return compParents[compId];
}
inline const DimImg &
Tree::getChildrenCount (const DimImg &compId) const {
return childCount[compId];
}
inline const DimNodeId &
Tree::getChildren (const DimImg &childId) const {
return children[childId];
}
inline const DimNodeId *
Tree::getChildren () const {
return children;
}
inline const vector<DimImg> &
Tree::getWeightBounds () const {
return weightBounds;
}
inline vector<DimImg> &
Tree::getWeightBounds () {
return weightBounds;
}
// ========================================
template<typename FuncToApply>
inline void
Tree::forEachLeaf (const FuncToApply &f /* f (DimImg leafId) */) const {
for (DimImg leafId = 0; leafId < leafCount; ++leafId)
f (leafId);
}
template<typename FuncToApply>
inline void
Tree::forEachComp (const FuncToApply &f /* f (DimImg compId) */) const {
const DimNodeId compCount = getCompCount ();
for (DimNodeId compId = 0; compId < compCount; ++compId)
f (compId);
}
template<typename FuncToApply>
inline void
Tree::forEachChild (const DimNodeId &parentId, const FuncToApply &f /* f (DimNodeId childId) */) const {
DimNodeId minChild = childCount[parentId], maxChild = childCount[parentId+1];
for (DimNodeId childId = minChild; childId < maxChild; ++childId)
f (children[childId]);
}
template<typename FuncToApply>
inline void
Tree::forEachChildTI (const DimNodeId &parentId, const FuncToApply &f /* f (bool isLeaf, DimImg childId) */) const {
DimNodeId minChild = childCount[parentId], maxChild = childCount[parentId+1];
for (DimNodeId childId = minChild; childId < maxChild; ++childId) {
const DimNodeId &child (getChildren (childId));
const bool isLeaf = child < leafCount;
f (isLeaf, isLeaf ? (DimImg) child : (DimImg) (child-leafCount));
}
}
#endif // _OTB_TRISKELE_TREE_TPP