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:
Git Merciol 2018-03-08 16:02:04 +01:00
parent b576488ab7
commit 56ab83f230
9 changed files with 47 additions and 47 deletions

View File

@ -102,9 +102,9 @@ namespace otb {
findTopComp (DimImg comp, const WeightT &weight, const WeightFunct &weightFunct); findTopComp (DimImg comp, const WeightT &weight, const WeightFunct &weightFunct);
inline DimImg inline DimImg
findTrueTop (DimImg comp); findNotLonelyTop (DimImg comp);
inline DimImg inline DimImg
findCompMultiChild (DimImg comp); findMultiChildrenTop (DimImg comp);
inline void inline void
buildChildren (); buildChildren ();

View File

@ -35,7 +35,7 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, WeightAttributes<Weigh
if (!leafCount) if (!leafCount)
return; return;
leaders.book (leafCount); leaders.book (leafCount);
childCount = childSum+2; childCount = childrenStart+2;
newCompId = leaders.getLeaders (); newCompId = leaders.getLeaders ();
compWeights = weightAttributes.getValues (); compWeights = weightAttributes.getValues ();
SMART_LOG_EXPR (dealThreadFill_n (leafCount-1, coreCount, compWeights, 0)); 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) if (newCompId[curComp] != DimImg_MAX)
// top already set // top already set
return; return;
const DimImg &top = findCompMultiChild (curComp); const DimImg &top = findMultiChildrenTop (curComp);
BOOST_ASSERT (top != DimImg_MAX); BOOST_ASSERT (top != DimImg_MAX);
BOOST_ASSERT (childCount[top]); BOOST_ASSERT (childCount[top]);
if (childCount[top] < 2 && compParents[top] != DimImg_MAX) { 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) if (newCompId[curComp] || childCount[curComp] > 1)
return; return;
// reduce lonely nodes (newCompId == 0) // 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 (top == DimImg_MAX || compParents[top] == DimImg_MAX || childCount[top] > 1);
BOOST_ASSERT (curComp != top); BOOST_ASSERT (curComp != top);
childCount[curComp] = childCount[top]; childCount[curComp] = childCount[top];
@ -664,7 +664,7 @@ ArrayTreeBuilder<WeightT, PixelT>::findTopComp (DimImg comp, const WeightT &weig
// ---------------------------------------- // ----------------------------------------
template<typename WeightT, typename PixelT> template<typename WeightT, typename PixelT>
inline DimImg inline DimImg
ArrayTreeBuilder<WeightT, PixelT>::findTrueTop (DimImg comp) { ArrayTreeBuilder<WeightT, PixelT>::findNotLonelyTop (DimImg comp) {
BOOST_ASSERT (comp != DimImg_MAX); BOOST_ASSERT (comp != DimImg_MAX);
for (;;) { for (;;) {
if (childCount[comp] > 1) if (childCount[comp] > 1)
@ -679,7 +679,7 @@ ArrayTreeBuilder<WeightT, PixelT>::findTrueTop (DimImg comp) {
// ---------------------------------------- // ----------------------------------------
template<typename WeightT, typename PixelT> template<typename WeightT, typename PixelT>
inline DimImg inline DimImg
ArrayTreeBuilder<WeightT, PixelT>::findCompMultiChild (DimImg comp) { ArrayTreeBuilder<WeightT, PixelT>::findMultiChildrenTop (DimImg comp) {
BOOST_ASSERT (comp != DimImg_MAX); BOOST_ASSERT (comp != DimImg_MAX);
for (;;) { for (;;) {
if (newCompId [comp] != DimImg_MAX) if (newCompId [comp] != DimImg_MAX)
@ -703,21 +703,21 @@ ArrayTreeBuilder<WeightT, PixelT>::buildChildren () {
SMART_DEF_LOG ("ArrayTreeBuilder::buildChildren", ""); SMART_DEF_LOG ("ArrayTreeBuilder::buildChildren", "");
BOOST_ASSERT (childSum[0] == 0); BOOST_ASSERT (childrenStart[0] == 0);
BOOST_ASSERT (childSum[1] == 0); BOOST_ASSERT (childrenStart[1] == 0);
DimImg compCount = getCompCount (); DimImg compCount = getCompCount ();
partial_sum (childCount, childCount+compCount, childCount); partial_sum (childCount, childCount+compCount, childCount);
// set // set
DimNodeId *childGetOrder = childSum+1; DimNodeId *childGetOrder = childrenStart+1;
for (DimNodeId i = 0; i < nodeCount-1; ++i) { for (DimNodeId i = 0; i < nodeCount-1; ++i) {
if (leafParents[i] == DimImg_MAX) if (leafParents[i] == DimImg_MAX)
continue; continue;
BOOST_ASSERT (leafParents[i] < compCount); BOOST_ASSERT (leafParents[i] < compCount);
children[childGetOrder[leafParents[i]]++] = i; children[childGetOrder[leafParents[i]]++] = i;
} }
BOOST_ASSERT (childSum[0] == 0); BOOST_ASSERT (childrenStart[0] == 0);
} }
// ======================================== // ========================================

View File

@ -43,7 +43,7 @@ namespace otb {
DimImg *compParents; DimImg *compParents;
/*! Pointers on the children and count how many children a parents have */ /*! Pointers on the children and count how many children a parents have */
vector<DimImg> childSum; vector<DimImg> childrenStart;
vector<DimNodeId> children; vector<DimNodeId> children;
/*! Pointers of same weight in parents (+1 : last is root)*/ /*! Pointers of same weight in parents (+1 : last is root)*/

View File

@ -9,7 +9,7 @@ Tree::getCoreCount () const {
inline DimNodeId * inline DimNodeId *
Tree::getChildSum () { Tree::getChildSum () {
return &childSum[0]; return &childrenStart[0];
} }
inline void inline void
@ -65,7 +65,7 @@ Tree::getCompId (const DimNodeId &nodeId) const {
} }
inline DimNodeId inline DimNodeId
Tree::getChild (const DimImg &compId, const DimImg &childId) const { Tree::getChild (const DimImg &compId, const DimImg &childId) const {
return children [childSum [compId]+childId]; return children [childrenStart [compId]+childId];
} }
inline const DimImg & inline const DimImg &
@ -83,7 +83,7 @@ Tree::getCompParent (const DimImg &compId) const {
inline const DimImg & inline const DimImg &
Tree::getChildrenCount (const DimImg &compId) const { Tree::getChildrenCount (const DimImg &compId) const {
return childSum[compId]; return childrenStart[compId];
} }
inline const DimNodeId & inline const DimNodeId &
Tree::getChildren (const DimImg &childId) const { Tree::getChildren (const DimImg &childId) const {
@ -129,14 +129,14 @@ Tree::forEachNode (const FuncToApply &f /* f (NodeDimImg nodeId) */) const {
template<typename FuncToApply> template<typename FuncToApply>
inline void inline void
Tree::forEachChild (const DimNodeId &parentId, const FuncToApply &f /* f (DimNodeId childId) */) const { 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) for (DimNodeId childId = minChild; childId < maxChild; ++childId)
f (children[childId]); f (children[childId]);
} }
template<typename FuncToApply> template<typename FuncToApply>
inline void inline void
Tree::forEachChildTI (const DimNodeId &parentId, const FuncToApply &f /* f (bool isLeaf, DimImg childId) */) const { 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) { for (DimNodeId childId = minChild; childId < maxChild; ++childId) {
const DimNodeId &child (getChildren (childId)); const DimNodeId &child (getChildren (childId));
const bool isLeaf = child < leafCount; const bool isLeaf = child < leafCount;

View File

@ -27,7 +27,7 @@ namespace otb {
DimNodeId *leafParents, *compParents; DimNodeId *leafParents, *compParents;
/*! Pointers on the children and count how many children a parents have */ /*! Pointers on the children and count how many children a parents have */
DimNodeId *children, *childSum; DimNodeId *children, *childrenStart;
// XXX compWeights ??? // XXX compWeights ???
}; };

View File

@ -32,7 +32,7 @@ TreeBuilder::getTranscient (Tree &tree) {
leafParents = &tree.leafParents[0]; leafParents = &tree.leafParents[0];
compParents = tree.compParents; compParents = tree.compParents;
children = &tree.children[0]; children = &tree.children[0];
childSum = &tree.childSum[0]; childrenStart = &tree.childrenStart[0];
} }
inline DimNodeId inline DimNodeId

View File

@ -15,15 +15,15 @@ QuadTreeBuilder::buildTree (Tree &tree) {
setParents (parentCount, 0, 0, width, height, width, height); setParents (parentCount, 0, 0, width, height, width, height);
// Building children array // 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) { for (DimNodeId i = 0; i < tree.getLeafCount (); ++i) {
DimNodeId idP = leafParents[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) { for (DimNodeId i = tree.getLeafCount (); i < tree.getLeafCount ()+parentUsed-1; ++i) {
DimNodeId idP = compParents[i-tree.getLeafCount ()]; 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++) { for (DimSideImg j = y; j < height + y; j++) {
DimSideImg id = i + j * imgWidth; DimSideImg id = i + j * imgWidth;
leafParents[id] = localId; leafParents[id] = localId;
childSum[localId+2]++; childrenStart[localId+2]++;
} }
return localId; return localId;
} }
@ -75,7 +75,7 @@ QuadTreeBuilder::setParents (DimImg &parentId,
{x , y + dh1, dw1, dh2}, {x , y + dh1, dw1, dh2},
{x + dw1, y + dh1, dw2, dh2} {x + dw1, y + dh1, dw2, dh2}
}; };
childSum[localId+2] = 4; childrenStart[localId+2] = 4;
for (int i = 0; i < 4; i++) 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; compParents[setParents (parentId, coords[i][0], coords[i][1], coords[i][2], coords[i][3], imgWidth, imgHeight, level+1)] = localId;
return localId; return localId;

View File

@ -20,7 +20,7 @@ Tree::Tree (unsigned int coreCount)
leafParents (), leafParents (),
compParents (nullptr), compParents (nullptr),
children (), children (),
childSum (), childrenStart (),
state (State::Void) state (State::Void)
{ {
clear (); clear ();
@ -39,10 +39,10 @@ Tree::clear () {
return; return;
#ifdef USE_SMART_LOG #ifdef USE_SMART_LOG
children.assign ((leafCount-1)*2, 0); children.assign ((leafCount-1)*2, 0);
childSum.assign (leafCount+1, 0); childrenStart.assign (leafCount+1, 0);
#endif #endif
childSum.resize (leafCount+1); childrenStart.resize (leafCount+1);
childSum[0] = childSum[1] = 0; childrenStart[0] = childrenStart[1] = 0;
} }
void void
@ -56,7 +56,7 @@ Tree::free () {
leafParents = vector<DimImg> (); leafParents = vector<DimImg> ();
compParents = nullptr; compParents = nullptr;
children = vector<DimNodeId> (); children = vector<DimNodeId> ();
childSum = vector<DimImg> (); childrenStart = vector<DimImg> ();
weightBounds = vector<DimImg> (); weightBounds = vector<DimImg> ();
} }
@ -66,7 +66,7 @@ Tree::book (const DimImg &leafCount) {
clear (); clear ();
compParents = &leafParents[leafCount]; compParents = &leafParents[leafCount];
children.resize ((leafCount-1)*2); children.resize ((leafCount-1)*2);
childSum.resize (leafCount+1); childrenStart.resize (leafCount+1);
} }
// ======================================== // ========================================
@ -195,7 +195,7 @@ Tree::checkSpare () const {
maxParent = leafParents[leafId]; maxParent = leafParents[leafId];
}); });
} }
DimImg *childCount = (DimImg*)&childSum[2]; DimImg *childCount = (DimImg*)&childrenStart[2];
for (unsigned int i = 0; i < tileCount; ++i) { for (unsigned int i = 0; i < tileCount; ++i) {
DimImg base = vertexMaxBounds [i], maxParent = maxParents [i]; DimImg base = vertexMaxBounds [i], maxParent = maxParents [i];
for (DimImg compId = base; compId < maxParent; ++compId) { for (DimImg compId = base; compId < maxParent; ++compId) {
@ -223,7 +223,7 @@ Tree::checkSpare () const {
// check weight // check weight
// XXX monotone // XXX monotone
// check childSum // check childrenStart
} }
@ -259,25 +259,25 @@ Tree::check () const {
// check weightBounds // check weightBounds
// check childSum // check childrenStart
{ {
vector<DimImg> childSum2 (compCount, 0); vector<DimImg> childrenStart2 (compCount, 0);
forEachLeaf ([this, &childSum2] (const DimImg &leafId) { forEachLeaf ([this, &childrenStart2] (const DimImg &leafId) {
if (leafParents[leafId] == DimImg_MAX) if (leafParents[leafId] == DimImg_MAX)
// boder // boder
return; 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) if (compId == compCount-1)
return; return;
++childSum2 [compParents [compId]]; ++childrenStart2 [compParents [compId]];
}); });
for (DimImg compId = 0; compId < compCount; ++compId) { for (DimImg compId = 0; compId < compCount; ++compId) {
// check count // check count
BOOST_ASSERT (childSum2 [compId] = childSum [compId+1] - childSum[compId]); BOOST_ASSERT (childrenStart2 [compId] = childrenStart [compId+1] - childrenStart[compId]);
// at least 2 children // 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); vector<DimNodeId> childrenMap (nodeCount, DimImg_MAX);
forEachComp ([this, &childrenMap] (const DimImg &compId) { 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) { for (DimNodeId childId = minChild; childId < maxChild; ++childId) {
DimNodeId child = children[childId]; DimNodeId child = children[childId];
BOOST_ASSERT (leafParents [child] == compId); BOOST_ASSERT (leafParents [child] == compId);
@ -315,7 +315,7 @@ Tree::CPrintTree::print (ostream &out) const {
<< " nodeCount:" << (onRecord ? "~" : "") << nodeCount << " compCount:" << nodeCount - tree.leafCount << endl << " nodeCount:" << (onRecord ? "~" : "") << nodeCount << " compCount:" << nodeCount - tree.leafCount << endl
<< "parent count" << (onRecord ? "" : " children") << endl << "parent count" << (onRecord ? "" : " children") << endl
<< printMap (&tree.leafParents[0], doubleSize, nodeCount) << endl << 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) if (!onRecord)
out << printMap (&tree.children[0], doubleSize, nodeCount-1) << endl << endl; out << printMap (&tree.children[0], doubleSize, nodeCount-1) << endl << endl;
if (tree.weightBounds.size ()) { if (tree.weightBounds.size ()) {

View File

@ -26,14 +26,14 @@ XMLTreeBuilder::buildTree (Tree &tree) {
compParents[--rootParent] = nodeCount; compParents[--rootParent] = nodeCount;
readNodeChildren (treeNode->FirstChild ()->ToElement (), rootParent); 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) { for (DimNodeId i = 0; i < tree.getLeafCount (); ++i) {
DimNodeId idP = leafParents[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) { for (DimNodeId i = tree.getLeafCount (); i < tree.getLeafCount ()+nodeCount-1; ++i) {
DimNodeId idP = compParents[i-tree.getLeafCount ()]; 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; compParents[--id] = idP;
std::cout << id << std::endl; std::cout << id << std::endl;
readNodeChildren (child->ToElement (), id); readNodeChildren (child->ToElement (), id);
childSum[idP+2]++; childrenStart[idP+2]++;
} else if (child->Value () == std::string ("Leaf")) { } else if (child->Value () == std::string ("Leaf")) {
int leafId; int leafId;
child->ToElement ()->QueryIntAttribute ("id", &leafId); child->ToElement ()->QueryIntAttribute ("id", &leafId);
leafParents[leafId] = idP; leafParents[leafId] = idP;
childSum[idP+2]++; childrenStart[idP+2]++;
} }
} }
} }