modifié : ../ArrayTree/ArrayTreeBuilder.hpp
modifié : ../ArrayTree/ArrayTreeBuilder.tpp modifié : ../Tree.hpp modifié : ../Tree.tpp modifié : ../TreeBuilder.hpp modifié : ../TreeBuilder.tpp modifié : ../../src/QuadTree/QuadTreeBuilder.cpp modifié : ../../src/Tree.cpp modifié : ../../src/XMLTree/XMLTreeBuilder.cpp
This commit is contained in:
parent
b576488ab7
commit
56ab83f230
@ -102,9 +102,9 @@ namespace otb {
|
||||
findTopComp (DimImg comp, const WeightT &weight, const WeightFunct &weightFunct);
|
||||
|
||||
inline DimImg
|
||||
findTrueTop (DimImg comp);
|
||||
findNotLonelyTop (DimImg comp);
|
||||
inline DimImg
|
||||
findCompMultiChild (DimImg comp);
|
||||
findMultiChildrenTop (DimImg comp);
|
||||
|
||||
inline void
|
||||
buildChildren ();
|
||||
|
@ -35,7 +35,7 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, WeightAttributes<Weigh
|
||||
if (!leafCount)
|
||||
return;
|
||||
leaders.book (leafCount);
|
||||
childCount = childSum+2;
|
||||
childCount = childrenStart+2;
|
||||
newCompId = leaders.getLeaders ();
|
||||
compWeights = weightAttributes.getValues ();
|
||||
SMART_LOG_EXPR (dealThreadFill_n (leafCount-1, coreCount, compWeights, 0));
|
||||
@ -509,7 +509,7 @@ ArrayTreeBuilder<WeightT, PixelT>::updateNewId (const DimImg curComp, DimImg &co
|
||||
if (newCompId[curComp] != DimImg_MAX)
|
||||
// top already set
|
||||
return;
|
||||
const DimImg &top = findCompMultiChild (curComp);
|
||||
const DimImg &top = findMultiChildrenTop (curComp);
|
||||
BOOST_ASSERT (top != DimImg_MAX);
|
||||
BOOST_ASSERT (childCount[top]);
|
||||
if (childCount[top] < 2 && compParents[top] != DimImg_MAX) {
|
||||
@ -549,7 +549,7 @@ ArrayTreeBuilder<WeightT, PixelT>::compress (const DimImg &compTop) {
|
||||
if (newCompId[curComp] || childCount[curComp] > 1)
|
||||
return;
|
||||
// reduce lonely nodes (newCompId == 0)
|
||||
const DimImg &top = findTrueTop (curComp);
|
||||
const DimImg &top = findNotLonelyTop (curComp);
|
||||
BOOST_ASSERT (top == DimImg_MAX || compParents[top] == DimImg_MAX || childCount[top] > 1);
|
||||
BOOST_ASSERT (curComp != top);
|
||||
childCount[curComp] = childCount[top];
|
||||
@ -664,7 +664,7 @@ ArrayTreeBuilder<WeightT, PixelT>::findTopComp (DimImg comp, const WeightT &weig
|
||||
// ----------------------------------------
|
||||
template<typename WeightT, typename PixelT>
|
||||
inline DimImg
|
||||
ArrayTreeBuilder<WeightT, PixelT>::findTrueTop (DimImg comp) {
|
||||
ArrayTreeBuilder<WeightT, PixelT>::findNotLonelyTop (DimImg comp) {
|
||||
BOOST_ASSERT (comp != DimImg_MAX);
|
||||
for (;;) {
|
||||
if (childCount[comp] > 1)
|
||||
@ -679,7 +679,7 @@ ArrayTreeBuilder<WeightT, PixelT>::findTrueTop (DimImg comp) {
|
||||
// ----------------------------------------
|
||||
template<typename WeightT, typename PixelT>
|
||||
inline DimImg
|
||||
ArrayTreeBuilder<WeightT, PixelT>::findCompMultiChild (DimImg comp) {
|
||||
ArrayTreeBuilder<WeightT, PixelT>::findMultiChildrenTop (DimImg comp) {
|
||||
BOOST_ASSERT (comp != DimImg_MAX);
|
||||
for (;;) {
|
||||
if (newCompId [comp] != DimImg_MAX)
|
||||
@ -703,21 +703,21 @@ ArrayTreeBuilder<WeightT, PixelT>::buildChildren () {
|
||||
|
||||
SMART_DEF_LOG ("ArrayTreeBuilder::buildChildren", "");
|
||||
|
||||
BOOST_ASSERT (childSum[0] == 0);
|
||||
BOOST_ASSERT (childSum[1] == 0);
|
||||
BOOST_ASSERT (childrenStart[0] == 0);
|
||||
BOOST_ASSERT (childrenStart[1] == 0);
|
||||
|
||||
DimImg compCount = getCompCount ();
|
||||
partial_sum (childCount, childCount+compCount, childCount);
|
||||
|
||||
// set
|
||||
DimNodeId *childGetOrder = childSum+1;
|
||||
DimNodeId *childGetOrder = childrenStart+1;
|
||||
for (DimNodeId i = 0; i < nodeCount-1; ++i) {
|
||||
if (leafParents[i] == DimImg_MAX)
|
||||
continue;
|
||||
BOOST_ASSERT (leafParents[i] < compCount);
|
||||
children[childGetOrder[leafParents[i]]++] = i;
|
||||
}
|
||||
BOOST_ASSERT (childSum[0] == 0);
|
||||
BOOST_ASSERT (childrenStart[0] == 0);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
|
@ -43,7 +43,7 @@ namespace otb {
|
||||
DimImg *compParents;
|
||||
|
||||
/*! Pointers on the children and count how many children a parents have */
|
||||
vector<DimImg> childSum;
|
||||
vector<DimImg> childrenStart;
|
||||
vector<DimNodeId> children;
|
||||
|
||||
/*! Pointers of same weight in parents (+1 : last is root)*/
|
||||
|
@ -9,7 +9,7 @@ Tree::getCoreCount () const {
|
||||
|
||||
inline DimNodeId *
|
||||
Tree::getChildSum () {
|
||||
return &childSum[0];
|
||||
return &childrenStart[0];
|
||||
}
|
||||
|
||||
inline void
|
||||
@ -65,7 +65,7 @@ Tree::getCompId (const DimNodeId &nodeId) const {
|
||||
}
|
||||
inline DimNodeId
|
||||
Tree::getChild (const DimImg &compId, const DimImg &childId) const {
|
||||
return children [childSum [compId]+childId];
|
||||
return children [childrenStart [compId]+childId];
|
||||
}
|
||||
|
||||
inline const DimImg &
|
||||
@ -83,7 +83,7 @@ Tree::getCompParent (const DimImg &compId) const {
|
||||
|
||||
inline const DimImg &
|
||||
Tree::getChildrenCount (const DimImg &compId) const {
|
||||
return childSum[compId];
|
||||
return childrenStart[compId];
|
||||
}
|
||||
inline const DimNodeId &
|
||||
Tree::getChildren (const DimImg &childId) const {
|
||||
@ -129,14 +129,14 @@ Tree::forEachNode (const FuncToApply &f /* f (NodeDimImg nodeId) */) const {
|
||||
template<typename FuncToApply>
|
||||
inline void
|
||||
Tree::forEachChild (const DimNodeId &parentId, const FuncToApply &f /* f (DimNodeId childId) */) const {
|
||||
DimNodeId minChild = childSum[parentId], maxChild = childSum[parentId+1];
|
||||
DimNodeId minChild = childrenStart[parentId], maxChild = childrenStart[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 = childSum[parentId], maxChild = childSum[parentId+1];
|
||||
DimNodeId minChild = childrenStart[parentId], maxChild = childrenStart[parentId+1];
|
||||
for (DimNodeId childId = minChild; childId < maxChild; ++childId) {
|
||||
const DimNodeId &child (getChildren (childId));
|
||||
const bool isLeaf = child < leafCount;
|
||||
|
@ -27,7 +27,7 @@ namespace otb {
|
||||
DimNodeId *leafParents, *compParents;
|
||||
|
||||
/*! Pointers on the children and count how many children a parents have */
|
||||
DimNodeId *children, *childSum;
|
||||
DimNodeId *children, *childrenStart;
|
||||
// XXX compWeights ???
|
||||
};
|
||||
|
||||
|
@ -32,7 +32,7 @@ TreeBuilder::getTranscient (Tree &tree) {
|
||||
leafParents = &tree.leafParents[0];
|
||||
compParents = tree.compParents;
|
||||
children = &tree.children[0];
|
||||
childSum = &tree.childSum[0];
|
||||
childrenStart = &tree.childrenStart[0];
|
||||
}
|
||||
|
||||
inline DimNodeId
|
||||
|
@ -15,15 +15,15 @@ QuadTreeBuilder::buildTree (Tree &tree) {
|
||||
setParents (parentCount, 0, 0, width, height, width, height);
|
||||
|
||||
// Building children array
|
||||
std::partial_sum (childSum, childSum+parentUsed+2, childSum);
|
||||
std::partial_sum (childrenStart, childrenStart+parentUsed+2, childrenStart);
|
||||
for (DimNodeId i = 0; i < tree.getLeafCount (); ++i) {
|
||||
DimNodeId idP = leafParents[i];
|
||||
children[childSum[idP+1]++] = i;
|
||||
children[childrenStart[idP+1]++] = i;
|
||||
}
|
||||
|
||||
for (DimNodeId i = tree.getLeafCount (); i < tree.getLeafCount ()+parentUsed-1; ++i) {
|
||||
DimNodeId idP = compParents[i-tree.getLeafCount ()];
|
||||
children[childSum[idP+1]++] = i;
|
||||
children[childrenStart[idP+1]++] = i;
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ QuadTreeBuilder::setParents (DimImg &parentId,
|
||||
for (DimSideImg j = y; j < height + y; j++) {
|
||||
DimSideImg id = i + j * imgWidth;
|
||||
leafParents[id] = localId;
|
||||
childSum[localId+2]++;
|
||||
childrenStart[localId+2]++;
|
||||
}
|
||||
return localId;
|
||||
}
|
||||
@ -75,7 +75,7 @@ QuadTreeBuilder::setParents (DimImg &parentId,
|
||||
{x , y + dh1, dw1, dh2},
|
||||
{x + dw1, y + dh1, dw2, dh2}
|
||||
};
|
||||
childSum[localId+2] = 4;
|
||||
childrenStart[localId+2] = 4;
|
||||
for (int i = 0; i < 4; i++)
|
||||
compParents[setParents (parentId, coords[i][0], coords[i][1], coords[i][2], coords[i][3], imgWidth, imgHeight, level+1)] = localId;
|
||||
return localId;
|
||||
|
36
src/Tree.cpp
36
src/Tree.cpp
@ -20,7 +20,7 @@ Tree::Tree (unsigned int coreCount)
|
||||
leafParents (),
|
||||
compParents (nullptr),
|
||||
children (),
|
||||
childSum (),
|
||||
childrenStart (),
|
||||
state (State::Void)
|
||||
{
|
||||
clear ();
|
||||
@ -39,10 +39,10 @@ Tree::clear () {
|
||||
return;
|
||||
#ifdef USE_SMART_LOG
|
||||
children.assign ((leafCount-1)*2, 0);
|
||||
childSum.assign (leafCount+1, 0);
|
||||
childrenStart.assign (leafCount+1, 0);
|
||||
#endif
|
||||
childSum.resize (leafCount+1);
|
||||
childSum[0] = childSum[1] = 0;
|
||||
childrenStart.resize (leafCount+1);
|
||||
childrenStart[0] = childrenStart[1] = 0;
|
||||
}
|
||||
|
||||
void
|
||||
@ -56,7 +56,7 @@ Tree::free () {
|
||||
leafParents = vector<DimImg> ();
|
||||
compParents = nullptr;
|
||||
children = vector<DimNodeId> ();
|
||||
childSum = vector<DimImg> ();
|
||||
childrenStart = vector<DimImg> ();
|
||||
weightBounds = vector<DimImg> ();
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ Tree::book (const DimImg &leafCount) {
|
||||
clear ();
|
||||
compParents = &leafParents[leafCount];
|
||||
children.resize ((leafCount-1)*2);
|
||||
childSum.resize (leafCount+1);
|
||||
childrenStart.resize (leafCount+1);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
@ -195,7 +195,7 @@ Tree::checkSpare () const {
|
||||
maxParent = leafParents[leafId];
|
||||
});
|
||||
}
|
||||
DimImg *childCount = (DimImg*)&childSum[2];
|
||||
DimImg *childCount = (DimImg*)&childrenStart[2];
|
||||
for (unsigned int i = 0; i < tileCount; ++i) {
|
||||
DimImg base = vertexMaxBounds [i], maxParent = maxParents [i];
|
||||
for (DimImg compId = base; compId < maxParent; ++compId) {
|
||||
@ -223,7 +223,7 @@ Tree::checkSpare () const {
|
||||
// check weight
|
||||
// XXX monotone
|
||||
|
||||
// check childSum
|
||||
// check childrenStart
|
||||
|
||||
}
|
||||
|
||||
@ -259,25 +259,25 @@ Tree::check () const {
|
||||
|
||||
// check weightBounds
|
||||
|
||||
// check childSum
|
||||
// check childrenStart
|
||||
{
|
||||
vector<DimImg> childSum2 (compCount, 0);
|
||||
forEachLeaf ([this, &childSum2] (const DimImg &leafId) {
|
||||
vector<DimImg> childrenStart2 (compCount, 0);
|
||||
forEachLeaf ([this, &childrenStart2] (const DimImg &leafId) {
|
||||
if (leafParents[leafId] == DimImg_MAX)
|
||||
// boder
|
||||
return;
|
||||
++childSum2 [leafParents [leafId]];
|
||||
++childrenStart2 [leafParents [leafId]];
|
||||
});
|
||||
forEachComp ([this, &childSum2, &compCount] (const DimImg &compId) {
|
||||
forEachComp ([this, &childrenStart2, &compCount] (const DimImg &compId) {
|
||||
if (compId == compCount-1)
|
||||
return;
|
||||
++childSum2 [compParents [compId]];
|
||||
++childrenStart2 [compParents [compId]];
|
||||
});
|
||||
for (DimImg compId = 0; compId < compCount; ++compId) {
|
||||
// check count
|
||||
BOOST_ASSERT (childSum2 [compId] = childSum [compId+1] - childSum[compId]);
|
||||
BOOST_ASSERT (childrenStart2 [compId] = childrenStart [compId+1] - childrenStart[compId]);
|
||||
// at least 2 children
|
||||
BOOST_ASSERT (childSum2 [compId] > 1);
|
||||
BOOST_ASSERT (childrenStart2 [compId] > 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -285,7 +285,7 @@ Tree::check () const {
|
||||
{
|
||||
vector<DimNodeId> childrenMap (nodeCount, DimImg_MAX);
|
||||
forEachComp ([this, &childrenMap] (const DimImg &compId) {
|
||||
DimNodeId minChild = childSum[compId], maxChild = childSum[compId+1];
|
||||
DimNodeId minChild = childrenStart[compId], maxChild = childrenStart[compId+1];
|
||||
for (DimNodeId childId = minChild; childId < maxChild; ++childId) {
|
||||
DimNodeId child = children[childId];
|
||||
BOOST_ASSERT (leafParents [child] == compId);
|
||||
@ -315,7 +315,7 @@ Tree::CPrintTree::print (ostream &out) const {
|
||||
<< " nodeCount:" << (onRecord ? "~" : "") << nodeCount << " compCount:" << nodeCount - tree.leafCount << endl
|
||||
<< "parent count" << (onRecord ? "" : " children") << endl
|
||||
<< printMap (&tree.leafParents[0], doubleSize, nodeCount) << endl << endl
|
||||
<< printMap (&tree.childSum[onRecord ? 2 : 0], tree.size, nodeCount - tree.leafCount + 1) << endl << endl;
|
||||
<< printMap (&tree.childrenStart[onRecord ? 2 : 0], tree.size, nodeCount - tree.leafCount + 1) << endl << endl;
|
||||
if (!onRecord)
|
||||
out << printMap (&tree.children[0], doubleSize, nodeCount-1) << endl << endl;
|
||||
if (tree.weightBounds.size ()) {
|
||||
|
@ -26,14 +26,14 @@ XMLTreeBuilder::buildTree (Tree &tree) {
|
||||
compParents[--rootParent] = nodeCount;
|
||||
readNodeChildren (treeNode->FirstChild ()->ToElement (), rootParent);
|
||||
|
||||
std::partial_sum (childSum, childSum+nodeCount+2, childSum);
|
||||
std::partial_sum (childrenStart, childrenStart+nodeCount+2, childrenStart);
|
||||
for (DimNodeId i = 0; i < tree.getLeafCount (); ++i) {
|
||||
DimNodeId idP = leafParents[i];
|
||||
children[childSum[idP+1]++] = i;
|
||||
children[childrenStart[idP+1]++] = i;
|
||||
}
|
||||
for (DimNodeId i = tree.getLeafCount (); i < tree.getLeafCount ()+nodeCount-1; ++i) {
|
||||
DimNodeId idP = compParents[i-tree.getLeafCount ()];
|
||||
children[childSum[idP+1]++] = i;
|
||||
children[childrenStart[idP+1]++] = i;
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,12 +55,12 @@ XMLTreeBuilder::readNodeChildren (const TiXmlElement *node, DimNodeId &id) {
|
||||
compParents[--id] = idP;
|
||||
std::cout << id << std::endl;
|
||||
readNodeChildren (child->ToElement (), id);
|
||||
childSum[idP+2]++;
|
||||
childrenStart[idP+2]++;
|
||||
} else if (child->Value () == std::string ("Leaf")) {
|
||||
int leafId;
|
||||
child->ToElement ()->QueryIntAttribute ("id", &leafId);
|
||||
leafParents[leafId] = idP;
|
||||
childSum[idP+2]++;
|
||||
childrenStart[idP+2]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user