modifié : MakefileNoOTB

modifié :         include/ArrayTree/ArrayTreeBuilder.hpp
	modifié :         include/ArrayTree/ArrayTreeBuilder.tpp
	modifié :         src/TestArrayTreeBuilder.cpp
This commit is contained in:
Git Merciol 2018-03-08 15:32:11 +01:00
parent 29cfa00201
commit b576488ab7
4 changed files with 112 additions and 38 deletions

View File

@ -18,7 +18,7 @@ TST_OUT = $(patsubst %, $(OUT_DIR)/%, $(TST_PRG))
## FLAGS ###############################
DFLAGS = -O2 -DNDEBUG -DBOOST_DISABLE_ASSERTS -DNO_OTB
#DFLAGS = -g -DENABLE_LOG -DNO_OTB -DTHREAD_DISABLE -DENABLE_SMART_LOG
#DFLAGS = -g -DENABLE_LOG -DNO_OTB -DTHREAD_DISABLE -DENABLE_SMART_LOG
IFLAGS = $(DFLAGS) -MMD -I$(HPP_DIR)
LFLAGS = -L$(LIB_DIR) -ltriskele -lstdc++ -lpthread -lboost_system -lboost_chrono -lboost_thread -lboost_program_options -lboost_date_time -lboost_serialization -lboost_filesystem -lboost_unit_test_framework -lgdal
CC = g++

View File

@ -101,6 +101,8 @@ namespace otb {
inline DimImg
findTopComp (DimImg comp, const WeightT &weight, const WeightFunct &weightFunct);
inline DimImg
findTrueTop (DimImg comp);
inline DimImg
findCompMultiChild (DimImg comp);

View File

@ -195,6 +195,11 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, const WeightFunct &wei
<< printMap (newCompId, size, 0) << endl << endl);
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);
LOG ("nodeCount:" << tree.getNodeCount());
// DimEdge root = compCount-1;
@ -266,7 +271,6 @@ ArrayTreeBuilder<WeightT, PixelT>::buildParents (Edge<WeightT> *edges, const Wei
swap (la, lb);
leader = la;
} else if (rb == DimImg_MAX) {
// XXX ra = top de ra
if (curEdge.weight == compWeights[ra]) {
// rb.weight <= curEdge.weight = ra.weight
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]);
leader = lb;
}
// XXX ra = top de ra
// XXX rb = top de rb
} else if (ra == rb) {
// XXX
BOOST_ASSERT (false);
@ -510,34 +512,26 @@ ArrayTreeBuilder<WeightT, PixelT>::updateNewId (const DimImg curComp, DimImg &co
const DimImg &top = findCompMultiChild (curComp);
BOOST_ASSERT (top != DimImg_MAX);
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) {
// 0 => merge || no more child
// 1 => unnecessary node
BOOST_ASSERT (curComp != DimImg_MAX);
DimImg newTopIdx = newCompId[top];
if (newTopIdx == DimImg_MAX) {
if (newTopIdx == DimImg_MAX)
newTopIdx = newCompId[top] = compCount++;
// if (top == DimImg_MAX)
// // 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 DimNodeId &newTopChildCount = childCount[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; ) {
DimImg nextSibling = compParents[sibling];
newCompId[sibling] = newTopIdx;
childCount[sibling] = newTopChildCountRec;
childCount[sibling] = newTopChildCount;
compParents[sibling] = newTopCompParent;
// only in case of unnecessary comp
compWeights[sibling] = newTopWeight;
// compWeights[sibling] = newTopWeight;
sibling = nextSibling;
}
return;
@ -551,11 +545,17 @@ inline void
ArrayTreeBuilder<WeightT, PixelT>::compress (const DimImg &compTop) {
SMART_DEF_LOG ("ArrayTreeBuilder::compress", " compTop:" << compTop);
dealThreadRange (leafCount, coreCount, [this] (const DimImg &leaf) {
DimImg old = leafParents[leaf];
if (old != DimImg_MAX)
leafParents[leaf] = newCompId[old];
dealThreadRange (compTop, coreCount, [this] (const DimImg &curComp) {
if (newCompId[curComp] || childCount[curComp] > 1)
return;
// reduce lonely nodes (newCompId == 0)
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) {
@ -564,6 +564,12 @@ ArrayTreeBuilder<WeightT, PixelT>::compress (const DimImg &compTop) {
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
for (DimImg curComp = 0; curComp < compTop; ) {
DimImg newIdxComp = newCompId[curComp];
@ -643,7 +649,7 @@ ArrayTreeBuilder<WeightT, PixelT>::findTopComp (DimImg comp, const WeightT &weig
if (comp == DimImg_MAX)
return DimImg_MAX;
if (weightFunct.isWeightInf (weight, compWeights [comp]))
return findTopComp (comp, compWeights [comp], weightFunct);
return findTopComp (comp, compWeights [comp], weightFunct);
DimImg last = comp;
for (;;) {
if (comp == DimImg_MAX)
@ -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>
inline DimImg
@ -666,8 +687,11 @@ ArrayTreeBuilder<WeightT, PixelT>::findCompMultiChild (DimImg comp) {
const DimImg &parent = compParents[comp];
if (parent == DimImg_MAX)
return comp;
if (childCount[comp] > 1 && compWeights[comp] != compWeights[parent])
if (compWeights[comp] != compWeights[parent]) {
BOOST_ASSERT (childCount[comp] > 0);
return comp;
}
BOOST_ASSERT (!childCount[comp]);
comp = parent;
}
}

View File

@ -23,9 +23,9 @@ using namespace otb::triskele;
using namespace otb::triskele::arrayTree;
const unsigned int nbTest = 1;
const TreeType treeType = ALPHA; //TOS; // MIN; // MAX;
const unsigned int coreCount = 5;
const unsigned int nbTest = 1000;
const TreeType treeType = ALPHA; // TOS; // MIN; // MAX;
const unsigned int coreCount = 4;
typedef uint16_t PixelT;
typedef uint16_t WeightT;
@ -161,6 +161,49 @@ PixelT pixelsT3_12x8 [] = {
7, 3, 2, 0, 1, 7, 4, 5, 0, 2, 7, 1,
0, 2, 7, 3, 3, 0, 7, 1, 5, 4, 0, 1
};
PixelT pixelsT4_12x8 [] = {
1, 5, 6, 6, 0, 1, 7, 0, 1, 2, 1, 7 ,
3, 1, 0, 0, 1, 0, 2, 4, 0, 2, 5, 2 ,
6, 3, 3, 7, 0, 6, 0, 2, 3, 6, 0, 3 ,
0, 7, 3, 1, 1, 4, 1, 4, 5, 1, 4, 7 ,
1, 7, 3, 1, 1, 1, 3, 0, 4, 7, 7, 4 ,
5, 7, 6, 0, 6, 6, 3, 6, 6, 6, 7, 7 ,
3, 0, 4, 0, 1, 0, 7, 2, 7, 3, 4, 1 ,
4, 7, 1, 0, 6, 0, 4, 3, 7, 3, 3, 5
};
PixelT pixelsT5_12x8 [] = {
5, 3, 6, 3, 6, 5, 6, 5, 3, 0, 7, 6 ,
2, 7, 2, 2, 5, 4, 5, 7, 6, 2, 7, 0 ,
3, 1, 4, 2, 7, 3, 5, 4, 7, 4, 7, 5 ,
1, 5, 2, 4, 6, 2, 3, 0, 1, 5, 2, 7 ,
1, 7, 6, 7, 2, 5, 7, 5, 6, 3, 7, 6 ,
7, 5, 2, 6, 1, 2, 3, 2, 7, 5, 7, 5 ,
7, 2, 6, 1, 7, 0, 0, 0, 0, 6, 7, 2 ,
4, 6, 7, 2, 2, 7, 0, 1, 4, 3, 7, 5
};
PixelT pixelsT6_12x8 [] = {
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 () {
@ -172,11 +215,16 @@ void test () {
int leafCount = graphWalker.vertexMaxCount ();
// ====================
//PixelT *pixels = pixelsT1_18x12;
PixelT *pixels = pixelsT2_12x8;
// PixelT *pixels = new PixelT [leafCount];
// for (int i = 0; i < leafCount; ++i)
// pixels[i] = std::rand() % 8;
// PixelT *pixels = pixelsT1_18x12;
// PixelT *pixels = pixelsT2_12x8;
// PixelT *pixels = pixelsT3_12x8;
// PixelT *pixels = pixelsT4_12x8;
// 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);