modifié : MakefileNoOTB
modifié : include/ArrayTree/ArrayTreeBuilder.hpp modifié : include/ArrayTree/ArrayTreeBuilder.tpp modifié : src/TestArrayTreeBuilder.cpp
This commit is contained in:
parent
29cfa00201
commit
b576488ab7
@ -101,6 +101,8 @@ namespace otb {
|
|||||||
inline DimImg
|
inline DimImg
|
||||||
findTopComp (DimImg comp, const WeightT &weight, const WeightFunct &weightFunct);
|
findTopComp (DimImg comp, const WeightT &weight, const WeightFunct &weightFunct);
|
||||||
|
|
||||||
|
inline DimImg
|
||||||
|
findTrueTop (DimImg comp);
|
||||||
inline DimImg
|
inline DimImg
|
||||||
findCompMultiChild (DimImg comp);
|
findCompMultiChild (DimImg comp);
|
||||||
|
|
||||||
|
|||||||
@ -195,6 +195,11 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, const WeightFunct &wei
|
|||||||
<< printMap (newCompId, size, 0) << endl << endl);
|
<< printMap (newCompId, size, 0) << endl << endl);
|
||||||
leaders.free ();
|
leaders.free ();
|
||||||
|
|
||||||
|
while (compCount > 1 && childCount[compCount-1] == 1) {
|
||||||
|
--compCount;
|
||||||
|
compParents [compCount-1] = DimImg_MAX;
|
||||||
|
SMART_LOG ("reduce lonely root:" << printComp (compCount) << endl);
|
||||||
|
}
|
||||||
setNodeCount (tree, leafCount+compCount);
|
setNodeCount (tree, leafCount+compCount);
|
||||||
LOG ("nodeCount:" << tree.getNodeCount());
|
LOG ("nodeCount:" << tree.getNodeCount());
|
||||||
// DimEdge root = compCount-1;
|
// DimEdge root = compCount-1;
|
||||||
@ -266,7 +271,6 @@ ArrayTreeBuilder<WeightT, PixelT>::buildParents (Edge<WeightT> *edges, const Wei
|
|||||||
swap (la, lb);
|
swap (la, lb);
|
||||||
leader = la;
|
leader = la;
|
||||||
} else if (rb == DimImg_MAX) {
|
} else if (rb == DimImg_MAX) {
|
||||||
// XXX ra = top de ra
|
|
||||||
if (curEdge.weight == compWeights[ra]) {
|
if (curEdge.weight == compWeights[ra]) {
|
||||||
// rb.weight <= curEdge.weight = ra.weight
|
// rb.weight <= curEdge.weight = ra.weight
|
||||||
addChild (ra, leafParents [lb]);
|
addChild (ra, leafParents [lb]);
|
||||||
@ -276,8 +280,6 @@ ArrayTreeBuilder<WeightT, PixelT>::buildParents (Edge<WeightT> *edges, const Wei
|
|||||||
createParent (topParent, curEdge.weight, compParents [ra], leafParents [lb]);
|
createParent (topParent, curEdge.weight, compParents [ra], leafParents [lb]);
|
||||||
leader = lb;
|
leader = lb;
|
||||||
}
|
}
|
||||||
// XXX ra = top de ra
|
|
||||||
// XXX rb = top de rb
|
|
||||||
} else if (ra == rb) {
|
} else if (ra == rb) {
|
||||||
// XXX
|
// XXX
|
||||||
BOOST_ASSERT (false);
|
BOOST_ASSERT (false);
|
||||||
@ -510,34 +512,26 @@ ArrayTreeBuilder<WeightT, PixelT>::updateNewId (const DimImg curComp, DimImg &co
|
|||||||
const DimImg &top = findCompMultiChild (curComp);
|
const DimImg &top = findCompMultiChild (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) {
|
||||||
|
// mark lonely nodes
|
||||||
|
// XXX todo: mark curComp => top
|
||||||
|
newCompId[curComp] = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (curComp != top) {
|
if (curComp != top) {
|
||||||
// 0 => merge || no more child
|
|
||||||
// 1 => unnecessary node
|
|
||||||
BOOST_ASSERT (curComp != DimImg_MAX);
|
BOOST_ASSERT (curComp != DimImg_MAX);
|
||||||
DimImg newTopIdx = newCompId[top];
|
DimImg newTopIdx = newCompId[top];
|
||||||
if (newTopIdx == DimImg_MAX) {
|
if (newTopIdx == DimImg_MAX)
|
||||||
newTopIdx = newCompId[top] = compCount++;
|
newTopIdx = newCompId[top] = compCount++;
|
||||||
// if (top == DimImg_MAX)
|
const DimNodeId &newTopChildCount = childCount[top];
|
||||||
// // XXX arbres non-connexe ?
|
|
||||||
// cerr << "coucou top: " << curComp << endl;
|
|
||||||
// else if (compParents[top] == leafCount)
|
|
||||||
// // XXX arbres non-connexe ?
|
|
||||||
// cerr << "coucou ptop-top: " << curComp << endl;
|
|
||||||
// else if (compParents[top] == DimImg_MAX)
|
|
||||||
// // XXX arbres non-connexe ?
|
|
||||||
// cerr << "coucou ptop-max: " << curComp << endl;
|
|
||||||
}
|
|
||||||
const DimNodeId &newTopChildCountRec = childCount[top];
|
|
||||||
const DimImg &newTopCompParent = compParents[top];
|
const DimImg &newTopCompParent = compParents[top];
|
||||||
const WeightT &newTopWeight = compWeights[top]; // only in case of unnecessary comp
|
//const WeightT &newTopWeight = compWeights[top];
|
||||||
for (DimImg sibling = curComp; sibling != top; ) {
|
for (DimImg sibling = curComp; sibling != top; ) {
|
||||||
DimImg nextSibling = compParents[sibling];
|
DimImg nextSibling = compParents[sibling];
|
||||||
newCompId[sibling] = newTopIdx;
|
newCompId[sibling] = newTopIdx;
|
||||||
childCount[sibling] = newTopChildCountRec;
|
childCount[sibling] = newTopChildCount;
|
||||||
compParents[sibling] = newTopCompParent;
|
compParents[sibling] = newTopCompParent;
|
||||||
// only in case of unnecessary comp
|
// compWeights[sibling] = newTopWeight;
|
||||||
compWeights[sibling] = newTopWeight;
|
|
||||||
sibling = nextSibling;
|
sibling = nextSibling;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -551,11 +545,17 @@ inline void
|
|||||||
ArrayTreeBuilder<WeightT, PixelT>::compress (const DimImg &compTop) {
|
ArrayTreeBuilder<WeightT, PixelT>::compress (const DimImg &compTop) {
|
||||||
|
|
||||||
SMART_DEF_LOG ("ArrayTreeBuilder::compress", " compTop:" << compTop);
|
SMART_DEF_LOG ("ArrayTreeBuilder::compress", " compTop:" << compTop);
|
||||||
|
dealThreadRange (compTop, coreCount, [this] (const DimImg &curComp) {
|
||||||
dealThreadRange (leafCount, coreCount, [this] (const DimImg &leaf) {
|
if (newCompId[curComp] || childCount[curComp] > 1)
|
||||||
DimImg old = leafParents[leaf];
|
return;
|
||||||
if (old != DimImg_MAX)
|
// reduce lonely nodes (newCompId == 0)
|
||||||
leafParents[leaf] = newCompId[old];
|
const DimImg &top = findTrueTop (curComp);
|
||||||
|
BOOST_ASSERT (top == DimImg_MAX || compParents[top] == DimImg_MAX || childCount[top] > 1);
|
||||||
|
BOOST_ASSERT (curComp != top);
|
||||||
|
childCount[curComp] = childCount[top];
|
||||||
|
compParents[curComp] = compParents[top]; // XXX pb if //
|
||||||
|
newCompId[curComp] = newCompId[top];
|
||||||
|
compWeights[curComp] = compWeights[top];
|
||||||
});
|
});
|
||||||
|
|
||||||
dealThreadRange (compTop, coreCount, [this] (const DimImg &curComp) {
|
dealThreadRange (compTop, coreCount, [this] (const DimImg &curComp) {
|
||||||
@ -564,6 +564,12 @@ ArrayTreeBuilder<WeightT, PixelT>::compress (const DimImg &compTop) {
|
|||||||
compParents[curComp] = newCompId[old];
|
compParents[curComp] = newCompId[old];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
dealThreadRange (leafCount, coreCount, [this] (const DimImg &leaf) {
|
||||||
|
DimImg old = leafParents[leaf];
|
||||||
|
if (old != DimImg_MAX)
|
||||||
|
leafParents[leaf] = newCompId[old];
|
||||||
|
});
|
||||||
|
|
||||||
// XXX non parallèle
|
// XXX non parallèle
|
||||||
for (DimImg curComp = 0; curComp < compTop; ) {
|
for (DimImg curComp = 0; curComp < compTop; ) {
|
||||||
DimImg newIdxComp = newCompId[curComp];
|
DimImg newIdxComp = newCompId[curComp];
|
||||||
@ -655,6 +661,21 @@ ArrayTreeBuilder<WeightT, PixelT>::findTopComp (DimImg comp, const WeightT &weig
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------
|
||||||
|
template<typename WeightT, typename PixelT>
|
||||||
|
inline DimImg
|
||||||
|
ArrayTreeBuilder<WeightT, PixelT>::findTrueTop (DimImg comp) {
|
||||||
|
BOOST_ASSERT (comp != DimImg_MAX);
|
||||||
|
for (;;) {
|
||||||
|
if (childCount[comp] > 1)
|
||||||
|
return comp;
|
||||||
|
const DimImg &parent = compParents[comp];
|
||||||
|
if (parent == DimImg_MAX)
|
||||||
|
return comp;
|
||||||
|
comp = parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
template<typename WeightT, typename PixelT>
|
template<typename WeightT, typename PixelT>
|
||||||
inline DimImg
|
inline DimImg
|
||||||
@ -666,8 +687,11 @@ ArrayTreeBuilder<WeightT, PixelT>::findCompMultiChild (DimImg comp) {
|
|||||||
const DimImg &parent = compParents[comp];
|
const DimImg &parent = compParents[comp];
|
||||||
if (parent == DimImg_MAX)
|
if (parent == DimImg_MAX)
|
||||||
return comp;
|
return comp;
|
||||||
if (childCount[comp] > 1 && compWeights[comp] != compWeights[parent])
|
if (compWeights[comp] != compWeights[parent]) {
|
||||||
|
BOOST_ASSERT (childCount[comp] > 0);
|
||||||
return comp;
|
return comp;
|
||||||
|
}
|
||||||
|
BOOST_ASSERT (!childCount[comp]);
|
||||||
comp = parent;
|
comp = parent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,9 +23,9 @@ using namespace otb::triskele;
|
|||||||
using namespace otb::triskele::arrayTree;
|
using namespace otb::triskele::arrayTree;
|
||||||
|
|
||||||
|
|
||||||
const unsigned int nbTest = 1;
|
const unsigned int nbTest = 1000;
|
||||||
const TreeType treeType = ALPHA; //TOS; // MIN; // MAX;
|
const TreeType treeType = ALPHA; // TOS; // MIN; // MAX;
|
||||||
const unsigned int coreCount = 5;
|
const unsigned int coreCount = 4;
|
||||||
|
|
||||||
typedef uint16_t PixelT;
|
typedef uint16_t PixelT;
|
||||||
typedef uint16_t WeightT;
|
typedef uint16_t WeightT;
|
||||||
@ -161,6 +161,49 @@ PixelT pixelsT3_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 [] = {
|
||||||
|
1, 1, 7, 0, 2, 5, 5, 3, 2, 0, 0, 3 ,
|
||||||
|
3, 1, 5, 3, 2, 4, 6, 6, 0, 3, 2, 5 ,
|
||||||
|
0, 1, 5, 1, 1, 2, 7, 2, 3, 6, 3, 5 ,
|
||||||
|
3, 0, 0, 5, 0, 1, 1, 3, 2, 6, 7, 5 ,
|
||||||
|
2, 5, 3, 2, 0, 6, 7, 0, 7, 5, 1, 0 ,
|
||||||
|
7, 1, 3, 2, 7, 6, 0, 3, 6, 0, 0, 6 ,
|
||||||
|
1, 1, 1, 4, 7, 0, 1, 2, 5, 4, 4, 5 ,
|
||||||
|
2, 4, 5, 2, 1, 7, 2, 0, 0, 5, 2, 7
|
||||||
|
};
|
||||||
|
|
||||||
|
PixelT pixelsT7_12x8 [] = {
|
||||||
|
1, 0, 3, 1, 3, 1, 0, 1, 7, 5, 6, 1 ,
|
||||||
|
1, 0, 6, 3, 4, 0, 2, 4, 0, 2, 2, 1 ,
|
||||||
|
1, 2, 5, 1, 3, 5, 7, 4, 5, 3, 5, 1 ,
|
||||||
|
4, 6, 2, 4, 3, 1, 5, 4, 1, 3, 0, 5 ,
|
||||||
|
3, 2, 2, 3, 4, 4, 5, 5, 6, 2, 7, 2 ,
|
||||||
|
0, 6, 6, 5, 1, 4, 6, 6, 2, 1, 2, 5 ,
|
||||||
|
2, 7, 2, 3, 2, 2, 0, 5, 4, 2, 0, 0 ,
|
||||||
|
7, 5, 6, 5, 0, 5, 7, 0, 3, 6, 5, 5
|
||||||
|
};
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
void test () {
|
void test () {
|
||||||
@ -172,11 +215,16 @@ void test () {
|
|||||||
int leafCount = graphWalker.vertexMaxCount ();
|
int leafCount = graphWalker.vertexMaxCount ();
|
||||||
|
|
||||||
// ====================
|
// ====================
|
||||||
//PixelT *pixels = pixelsT1_18x12;
|
// PixelT *pixels = pixelsT1_18x12;
|
||||||
PixelT *pixels = pixelsT2_12x8;
|
// PixelT *pixels = pixelsT2_12x8;
|
||||||
// PixelT *pixels = new PixelT [leafCount];
|
// PixelT *pixels = pixelsT3_12x8;
|
||||||
// for (int i = 0; i < leafCount; ++i)
|
// PixelT *pixels = pixelsT4_12x8;
|
||||||
// pixels[i] = std::rand() % 8;
|
// PixelT *pixels = pixelsT5_12x8;
|
||||||
|
// PixelT *pixels = pixelsT6_12x8;
|
||||||
|
// PixelT *pixels = pixelsT7_12x8;
|
||||||
|
PixelT *pixels = new PixelT [leafCount];
|
||||||
|
for (int i = 0; i < leafCount; ++i)
|
||||||
|
pixels[i] = std::rand() % 8;
|
||||||
// ====================
|
// ====================
|
||||||
|
|
||||||
Raster<PixelT> raster (size);
|
Raster<PixelT> raster (size);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user