modifié : MakefileNoOTB
modifié : include/ArrayTree/ArrayTreeBuilder.hpp modifié : include/ArrayTree/ArrayTreeBuilder.tpp modifié : include/Tree.hpp modifié : include/Tree.tpp modifié : src/Appli/Option.cpp modifié : src/TestArrayTreeBuilder.cpp modifié : src/Tree.cpp
This commit is contained in:
parent
8ca10923c4
commit
b038206631
@ -53,6 +53,7 @@ clean:
|
||||
wipe: clean
|
||||
rm -rf $(OBJ_DIR)
|
||||
rm -f $(APG_OUT) $(TST_OUT) $(LIB_DIR)/libtriskele.a
|
||||
rm -f $(OUT_DIR)/*.d
|
||||
|
||||
libtriskele: $(LIB_DIR)/libtriskele.a
|
||||
|
||||
|
@ -108,14 +108,14 @@ namespace otb {
|
||||
buildChildren ();
|
||||
|
||||
// nice ostream
|
||||
struct CLogComp {
|
||||
struct CPrintComp {
|
||||
const ArrayTreeBuilder &atb;
|
||||
const DimImg &compId;
|
||||
inline CLogComp (const ArrayTreeBuilder &atb, const DimImg &compId);
|
||||
inline CPrintComp (const ArrayTreeBuilder &atb, const DimImg &compId);
|
||||
inline ostream &print (ostream &out) const;
|
||||
};
|
||||
inline CLogComp logComp (const DimImg &compId) const { return CLogComp (*this, compId); }
|
||||
friend inline ostream &operator << (ostream& out, const CLogComp &lc) { return lc.print (out); }
|
||||
inline CPrintComp printComp (const DimImg &compId) const { return CPrintComp (*this, compId); }
|
||||
friend inline ostream &operator << (ostream& out, const CPrintComp &lc) { return lc.print (out); }
|
||||
};
|
||||
|
||||
|
||||
|
@ -237,8 +237,8 @@ ArrayTreeBuilder<WeightT, PixelT>::buildParents (Edge<WeightT> *edges, const Wei
|
||||
DimImg pb = point2idx (size, curEdge.points[1]);
|
||||
DimImg la = leaders.find (pa);
|
||||
DimImg lb = leaders.find (pb);
|
||||
DimImg ra = leafParents [la];
|
||||
DimImg rb = leafParents [lb];
|
||||
DimImg ra = findRoot (leafParents [la]); // for alphaTree
|
||||
DimImg rb = findRoot (leafParents [lb]); // for alphaTree
|
||||
|
||||
BOOST_ASSERT (pa < leafCount);
|
||||
BOOST_ASSERT (pb < leafCount);
|
||||
@ -246,9 +246,11 @@ ArrayTreeBuilder<WeightT, PixelT>::buildParents (Edge<WeightT> *edges, const Wei
|
||||
BOOST_ASSERT (lb < leafCount);
|
||||
BOOST_ASSERT (ra < leafCount || ra == DimImg_MAX);
|
||||
BOOST_ASSERT (rb < leafCount || rb == DimImg_MAX);
|
||||
// BOOST_ASSERT (ra == DimImg_MAX || compParents [ra] == DimImg_MAX);
|
||||
// BOOST_ASSERT (rb == DimImg_MAX || compParents [rb] == DimImg_MAX);
|
||||
SMART_LOG (" w:" << curEdge.weight << " pa:" << pa << " pb:" << pb << " la:" << la << " lb:" << lb << " ra:" << ra << " rb:" << rb);
|
||||
BOOST_ASSERT (ra == DimImg_MAX || compParents [ra] == DimImg_MAX);
|
||||
BOOST_ASSERT (rb == DimImg_MAX || compParents [rb] == DimImg_MAX);
|
||||
SMART_LOG (" e:" << printEdge (curEdge, size));
|
||||
SMART_LOG ("pa:" << pa << " pb:" << pb << " la:" << la << " lb:" << lb);
|
||||
SMART_LOG ("ra:" << printComp (ra) << " rb:" << printComp (rb));
|
||||
|
||||
if (la == lb)
|
||||
continue;
|
||||
@ -264,6 +266,7 @@ 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]);
|
||||
@ -273,6 +276,8 @@ 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);
|
||||
@ -302,7 +307,7 @@ ArrayTreeBuilder<WeightT, PixelT>::buildParents (Edge<WeightT> *edges, const Wei
|
||||
leaders.link (pa, leader);
|
||||
leaders.link (pb, leader);
|
||||
|
||||
SMART_LOG (" leader:" << leader << " w:" << compWeights [leader] << " c:" << childCount [leader]);
|
||||
SMART_LOG (" leader:" << leader << " ra:" << printComp (ra) << " rb:" << printComp (rb));
|
||||
}
|
||||
|
||||
SMART_LOG ("topParent:" << topParent);
|
||||
@ -312,7 +317,7 @@ ArrayTreeBuilder<WeightT, PixelT>::buildParents (Edge<WeightT> *edges, const Wei
|
||||
template<typename WeightT, typename PixelT>
|
||||
inline void
|
||||
ArrayTreeBuilder<WeightT, PixelT>::unlinkParent (const DimImg &par) {
|
||||
SMART_DEF_LOG ("ArrayTreeBuilder::unlinkParent", "par: " << logComp (par));
|
||||
SMART_DEF_LOG ("ArrayTreeBuilder::unlinkParent", "par: " << printComp (par));
|
||||
if (par == DimImg_MAX)
|
||||
return;
|
||||
BOOST_ASSERT (childCount [par]);
|
||||
@ -331,14 +336,14 @@ ArrayTreeBuilder<WeightT, PixelT>::connectLeaf (DimImg a, DimImg b, const Weight
|
||||
BOOST_ASSERT (leafParents[b] < leafCount || leafParents[b] == DimImg_MAX);
|
||||
DimImg parA = findTopComp (leafParents[a], weight, weightFunct);
|
||||
DimImg parB = findTopComp (leafParents[b], weight, weightFunct);
|
||||
SMART_LOG ("parA: " << logComp (parA) << " parB: " << logComp (parB));
|
||||
SMART_LOG ("parA: " << printComp (parA) << " parB: " << printComp (parB));
|
||||
// upW0 : no parent(s)
|
||||
// Border case if parX == DimImg_MAX
|
||||
if (parA == parB) {
|
||||
if (parA == DimImg_MAX) {
|
||||
SMART_LOG ("upW0: no parents");
|
||||
createParent (parCount, weight, leafParents [a], leafParents [b]);
|
||||
SMART_LOG ("createParent: " << logComp (leafParents[a]));
|
||||
SMART_LOG ("createParent: " << printComp (leafParents[a]));
|
||||
}
|
||||
SMART_LOG ("same parents for: " << a << ", " << b);
|
||||
return;
|
||||
@ -346,7 +351,7 @@ ArrayTreeBuilder<WeightT, PixelT>::connectLeaf (DimImg a, DimImg b, const Weight
|
||||
if (parA == DimImg_MAX) {
|
||||
swap (a, b);
|
||||
swap (parA, parB);
|
||||
SMART_LOG ("swap: " << logComp (parA) << " " << logComp (parB));
|
||||
SMART_LOG ("swap: " << printComp (parA) << " " << printComp (parB));
|
||||
}
|
||||
if ((parA == DimImg_MAX || weightFunct.isWeightInf (weight, compWeights[parA])) &&
|
||||
weightFunct.isWeightInf (weight, compWeights[parB])) {
|
||||
@ -354,16 +359,16 @@ ArrayTreeBuilder<WeightT, PixelT>::connectLeaf (DimImg a, DimImg b, const Weight
|
||||
SMART_LOG ("upW1 | upW2: upper");
|
||||
unlinkParent (parA);
|
||||
unlinkParent (parB);
|
||||
SMART_LOG ("parA: " << logComp (parA) << " parB: " << logComp (parB));
|
||||
SMART_LOG ("parA: " << printComp (parA) << " parB: " << printComp (parB));
|
||||
DimImg newComp = createParent (parCount, weight, leafParents [a], leafParents [b]);
|
||||
SMART_LOG ("createParent: " << logComp (newComp));
|
||||
SMART_LOG ("createParent: " << printComp (newComp));
|
||||
connect3Comp (newComp, parA, parB, weightFunct);
|
||||
return;
|
||||
}
|
||||
if (parA != DimImg_MAX && weightFunct.isWeightInf (compWeights[parA], compWeights[parB])) {
|
||||
swap (a, b);
|
||||
swap (parA, parB);
|
||||
SMART_LOG ("swap: " << logComp (parA) << " " << logComp (parB));
|
||||
SMART_LOG ("swap: " << printComp (parA) << " " << printComp (parB));
|
||||
}
|
||||
if (weightFunct.isWeightInf (compWeights[parB], weight) &&
|
||||
(parA == DimImg_MAX ||
|
||||
@ -374,18 +379,18 @@ ArrayTreeBuilder<WeightT, PixelT>::connectLeaf (DimImg a, DimImg b, const Weight
|
||||
if (weightFunct.isWeightInf (compWeights[parA], weight)) {
|
||||
swap (a, b);
|
||||
swap (parA, parB);
|
||||
SMART_LOG ("swap: " << logComp (parA) << " " << logComp (parB));
|
||||
SMART_LOG ("swap: " << printComp (parA) << " " << printComp (parB));
|
||||
}
|
||||
DimImg grandParB = findTopComp (compParents[parB], weightFunct);
|
||||
unlinkParent (grandParB);
|
||||
SMART_LOG ("grandParB: " << logComp (grandParB));
|
||||
SMART_LOG ("grandParB: " << printComp (grandParB));
|
||||
if (parA == DimImg_MAX || weightFunct.isWeightInf (weight, compWeights[parA])) {
|
||||
// loW1 | loW2
|
||||
SMART_LOG ("loW1 | loW2: lower");
|
||||
unlinkParent (parA);
|
||||
SMART_LOG ("parA: " << logComp (parA));
|
||||
SMART_LOG ("parA: " << printComp (parA));
|
||||
DimImg newComp = createParent (parCount, weight, leafParents [a], compParents [parB]);
|
||||
SMART_LOG ("createParent: " << logComp (newComp));
|
||||
SMART_LOG ("createParent: " << printComp (newComp));
|
||||
connect3Comp (newComp, parA, grandParB, weightFunct);
|
||||
return;
|
||||
}
|
||||
@ -393,9 +398,9 @@ ArrayTreeBuilder<WeightT, PixelT>::connectLeaf (DimImg a, DimImg b, const Weight
|
||||
SMART_LOG ("loW0: lower");
|
||||
DimImg grandParA = findTopComp (compParents[parA], weightFunct);
|
||||
unlinkParent (grandParA);
|
||||
SMART_LOG ("grandParA: " << logComp (grandParA));
|
||||
SMART_LOG ("grandParA: " << printComp (grandParA));
|
||||
DimImg newComp = createParent (parCount, weight, compParents [parA], compParents [parB]);
|
||||
SMART_LOG ("createParent: " << logComp (newComp));
|
||||
SMART_LOG ("createParent: " << printComp (newComp));
|
||||
connect3Comp (newComp, grandParA, grandParB, weightFunct);
|
||||
return;
|
||||
}
|
||||
@ -406,7 +411,7 @@ ArrayTreeBuilder<WeightT, PixelT>::connectLeaf (DimImg a, DimImg b, const Weight
|
||||
unlinkParent (parA);
|
||||
++childCount[parB];
|
||||
leafParents[a] = parB;
|
||||
SMART_LOG ("parA: " << logComp (parA) << " parB: " << logComp (parB));
|
||||
SMART_LOG ("parA: " << printComp (parA) << " parB: " << printComp (parB));
|
||||
}
|
||||
// eqW0 | eqW1 | eqW2
|
||||
SMART_LOG ("eqW0 | eqW1 | eqW2: connect");
|
||||
@ -432,7 +437,7 @@ ArrayTreeBuilder<WeightT, PixelT>::connect3Comp (DimImg newComp, DimImg topA, Di
|
||||
BOOST_ASSERT (weightFunct.isWeightInf (compWeights[newComp], compWeights[topB]));
|
||||
compParents[newComp] = topB;
|
||||
++childCount[topB];
|
||||
SMART_LOG ("topB: " << logComp (topB));
|
||||
SMART_LOG ("topB: " << printComp (topB));
|
||||
connectComp (topA, topB, weightFunct);
|
||||
}
|
||||
|
||||
@ -463,12 +468,12 @@ ArrayTreeBuilder<WeightT, PixelT>::connectComp (DimImg topA, DimImg topB, const
|
||||
} else
|
||||
++childCount[topA];
|
||||
compParents[topB] = topA;
|
||||
SMART_LOG ("topA: " << logComp (topA) << " topB: " << logComp (topB));
|
||||
SMART_LOG ("topA: " << printComp (topA) << " topB: " << printComp (topB));
|
||||
if (grandParB == DimImg_MAX)
|
||||
return;
|
||||
BOOST_ASSERT (childCount [grandParB]);
|
||||
--childCount[grandParB];
|
||||
SMART_LOG ("grandParB: " << logComp (grandParB));
|
||||
SMART_LOG ("grandParB: " << printComp (grandParB));
|
||||
topB = topA;
|
||||
topA = findTopComp (grandParB, compWeights[topA], weightFunct);
|
||||
}
|
||||
@ -693,26 +698,26 @@ ArrayTreeBuilder<WeightT, PixelT>::buildChildren () {
|
||||
|
||||
// ========================================
|
||||
template<typename WeightT, typename PixelT>
|
||||
ArrayTreeBuilder<WeightT, PixelT>::CLogComp::CLogComp (const ArrayTreeBuilder &atb, const DimImg &compId)
|
||||
ArrayTreeBuilder<WeightT, PixelT>::CPrintComp::CPrintComp (const ArrayTreeBuilder &atb, const DimImg &compId)
|
||||
: atb (atb), compId (compId) {
|
||||
}
|
||||
template<typename WeightT, typename PixelT>
|
||||
inline ostream &
|
||||
ArrayTreeBuilder<WeightT, PixelT>::CLogComp::print (ostream &out) const {
|
||||
ArrayTreeBuilder<WeightT, PixelT>::CPrintComp::print (ostream &out) const {
|
||||
if (compId == DimImg_MAX)
|
||||
return out << "M(-/-)";
|
||||
return out << compId << "(" << atb.childCount[compId] << "/" << atb.compWeights [compId] << ")";
|
||||
}
|
||||
|
||||
// template<typename WeightT, typename PixelT>
|
||||
// inline ArrayTreeBuilder<WeightT, PixelT>::CLogComp
|
||||
// ArrayTreeBuilder<WeightT, PixelT>::logComp (const DimImg &compId) const {
|
||||
// return ArrayTreeBuilder<WeightT, PixelT>::CLogComp (*this, compId);
|
||||
// inline ArrayTreeBuilder<WeightT, PixelT>::CPrintComp
|
||||
// ArrayTreeBuilder<WeightT, PixelT>::printComp (const DimImg &compId) const {
|
||||
// return ArrayTreeBuilder<WeightT, PixelT>::CPrintComp (*this, compId);
|
||||
// }
|
||||
|
||||
// template<typename WeightT, typename PixelT>
|
||||
// inline ostream&
|
||||
// operator << (ostream& out, const ArrayTreeBuilder<WeightT, PixelT>::CLogComp &lc) {
|
||||
// operator << (ostream& out, const ArrayTreeBuilder<WeightT, PixelT>::CPrintComp &lc) {
|
||||
// return lc.print (out);
|
||||
// }
|
||||
|
||||
|
@ -87,6 +87,10 @@ namespace otb {
|
||||
inline DimImg getCompCount () const;
|
||||
inline DimNodeId getNodeRoot () const;
|
||||
inline DimImg getCompRoot () const;
|
||||
inline bool isLeaf (const DimNodeId &nodeId) const;
|
||||
inline DimImg getLeafId (const DimNodeId &nodeId) const;
|
||||
inline DimImg getCompId (const DimNodeId &nodeId) const;
|
||||
inline DimNodeId getChild (const DimImg &compId, const DimImg &childId) const;
|
||||
|
||||
inline const DimImg &getParent (const DimNodeId &nodeId) const;
|
||||
inline const DimImg &getLeafParent (const DimImg &leafId) const;
|
||||
@ -115,6 +119,8 @@ namespace otb {
|
||||
inline void forEachChildTI (const DimNodeId &parentId, const FuncToApply &f /* f (bool isLeaf, DimImg childId) */) const;
|
||||
|
||||
|
||||
bool compareTo (const Tree &tree, bool testChildren = false) const;
|
||||
|
||||
void checkSpare () const;
|
||||
void check () const;
|
||||
// XXX void checkWeightCurve (bool incr) const;
|
||||
|
@ -51,6 +51,22 @@ inline DimImg
|
||||
Tree::getCompRoot () const {
|
||||
return (DimImg) (nodeCount-1-leafCount);
|
||||
}
|
||||
inline bool
|
||||
Tree::isLeaf (const DimNodeId &nodeId) const {
|
||||
return nodeId < leafCount;
|
||||
}
|
||||
inline DimImg
|
||||
Tree::getLeafId (const DimNodeId &nodeId) const {
|
||||
return (DimImg) nodeId;
|
||||
}
|
||||
inline DimImg
|
||||
Tree::getCompId (const DimNodeId &nodeId) const {
|
||||
return (DimImg) (nodeId-leafCount);
|
||||
}
|
||||
inline DimNodeId
|
||||
Tree::getChild (const DimImg &compId, const DimImg &childId) const {
|
||||
return children [childSum [compId]+childId];
|
||||
}
|
||||
|
||||
inline const DimImg &
|
||||
Tree::getParent (const DimNodeId &nodeId) const {
|
||||
|
@ -1,4 +1,4 @@
|
||||
#define LAST_VERSION "2018-02-17 (Debian Stretch)"
|
||||
#define LAST_VERSION "2018-03-07 (Debian Stretch)"
|
||||
|
||||
|
||||
#include <iostream>
|
||||
@ -113,6 +113,7 @@ Option::parse (int argc, char** argv) {
|
||||
("max-tree", po::bool_switch (&maxTreeFlag), "build max-tree")
|
||||
("min-tree", po::bool_switch (&minTreeFlag), "build min-tree")
|
||||
("tos-tree", po::bool_switch (&tosTreeFlag), "build tree-of-shape")
|
||||
("alpha-tree", po::bool_switch (&alphaTreeFlag), "build alpha-tree")
|
||||
("area,A", po::value<string> (&areaThresholdsName), "produce area attributs")
|
||||
("standard-deviation,S", po::value<string> (&sdThresholdsName), "produce standard deviation attributs")
|
||||
("moment-of-inertia,M", po::value<string> (&moiThresholdsName), "produce moment of inertia attributs")
|
||||
@ -121,7 +122,6 @@ Option::parse (int argc, char** argv) {
|
||||
("use-the-force-luke", po::bool_switch (&useTheForceLuke), "display hidded options")
|
||||
("tree-core-count", po::value<unsigned int> (&coreCount), "thread used to build tree (default hardware value)")
|
||||
("one-band", po::bool_switch (&oneBand), "split all bands, one band per image")
|
||||
("alpha-tree", po::bool_switch (&alphaTreeFlag), "build alpha-tree")
|
||||
|
||||
// ("no-border", po::bool_switch (&options.noBorder), "build tree with all pixels (included no-data)")
|
||||
// ("dap", po::bool_switch (&options.dapFlag), "produce DAP rather than AP")
|
||||
|
@ -22,7 +22,11 @@
|
||||
using namespace otb::triskele;
|
||||
using namespace otb::triskele::arrayTree;
|
||||
|
||||
//typedef uint16_t WeightT;
|
||||
|
||||
const unsigned int nbTest = 1;
|
||||
const TreeType treeType = ALPHA; //TOS; // MIN; // MAX;
|
||||
const unsigned int coreCount = 5;
|
||||
|
||||
typedef uint16_t PixelT;
|
||||
typedef uint16_t WeightT;
|
||||
|
||||
@ -122,35 +126,57 @@ PixelT pixels4x4_C [] = {
|
||||
};
|
||||
|
||||
PixelT pixelsT1_18x12 [] = {
|
||||
5, 0, 0, 5, 0, 7, 4, 5, 2, 6, 0, 2, 2, 6, 5, 2, 1, 5 ,
|
||||
3, 2, 4, 7, 6, 1, 7, 2, 7, 5, 4, 6, 7, 1, 6, 0, 6, 7 ,
|
||||
7, 2, 4, 1, 1, 4, 3, 3, 3, 0, 5, 4, 5, 1, 6, 2, 0, 5 ,
|
||||
3, 7, 7, 2, 5, 3, 0, 4, 4, 7, 4, 2, 6, 3, 4, 2, 5, 5 ,
|
||||
7, 0, 0, 2, 1, 6, 6, 6, 7, 4, 0, 7, 1, 4, 6, 0, 6, 3 ,
|
||||
3, 7, 0, 7, 6, 4, 1, 4, 0, 6, 6, 5, 3, 5, 5, 4, 7, 6 ,
|
||||
2, 5, 5, 1, 2, 5, 0, 3, 1, 6, 4, 0, 2, 7, 7, 2, 7, 5 ,
|
||||
6, 0, 1, 6, 6, 7, 3, 2, 5, 1, 6, 4, 7, 0, 2, 4, 1, 4 ,
|
||||
2, 1, 7, 3, 7, 3, 3, 1, 3, 2, 3, 2, 7, 2, 2, 0, 0, 1 ,
|
||||
0, 4, 3, 5, 5, 1, 1, 4, 1, 3, 1, 2, 7, 3, 3, 7, 6, 2 ,
|
||||
2, 2, 4, 5, 4, 7, 7, 4, 1, 2, 4, 2, 3, 4, 6, 6, 1, 3 ,
|
||||
5, 0, 0, 5, 0, 7, 4, 5, 2, 6, 0, 2, 2, 6, 5, 2, 1, 5,
|
||||
3, 2, 4, 7, 6, 1, 7, 2, 7, 5, 4, 6, 7, 1, 6, 0, 6, 7,
|
||||
7, 2, 4, 1, 1, 4, 3, 3, 3, 0, 5, 4, 5, 1, 6, 2, 0, 5,
|
||||
3, 7, 7, 2, 5, 3, 0, 4, 4, 7, 4, 2, 6, 3, 4, 2, 5, 5,
|
||||
7, 0, 0, 2, 1, 6, 6, 6, 7, 4, 0, 7, 1, 4, 6, 0, 6, 3,
|
||||
3, 7, 0, 7, 6, 4, 1, 4, 0, 6, 6, 5, 3, 5, 5, 4, 7, 6,
|
||||
2, 5, 5, 1, 2, 5, 0, 3, 1, 6, 4, 0, 2, 7, 7, 2, 7, 5,
|
||||
6, 0, 1, 6, 6, 7, 3, 2, 5, 1, 6, 4, 7, 0, 2, 4, 1, 4,
|
||||
2, 1, 7, 3, 7, 3, 3, 1, 3, 2, 3, 2, 7, 2, 2, 0, 0, 1,
|
||||
0, 4, 3, 5, 5, 1, 1, 4, 1, 3, 1, 2, 7, 3, 3, 7, 6, 2,
|
||||
2, 2, 4, 5, 4, 7, 7, 4, 1, 2, 4, 2, 3, 4, 6, 6, 1, 3,
|
||||
7, 3, 7, 0, 6, 0, 2, 6, 3, 5, 5, 2, 7, 7, 4, 3, 5, 0
|
||||
};
|
||||
|
||||
PixelT pixelsT2_12x8 [] = {
|
||||
0, 5, 4, 6, 4, 2, 5, 1, 7, 6, 7, 4,
|
||||
3, 5, 7, 0, 0, 6, 5, 0, 3, 5, 0, 5,
|
||||
3, 5, 7, 4, 6, 0, 6, 6, 5, 2, 4, 1,
|
||||
4, 2, 3, 3, 0, 2, 7, 4, 7, 6, 4, 0,
|
||||
4, 1, 0, 0, 6, 0, 5, 1, 5, 4, 5, 3,
|
||||
5, 3, 2, 2, 5, 6, 4, 1, 0, 7, 4, 1,
|
||||
1, 3, 5, 0, 1, 1, 0, 6, 2, 0, 6, 0,
|
||||
0, 3, 1, 6, 0, 7, 1, 5, 2, 3, 7, 0
|
||||
};
|
||||
|
||||
PixelT pixelsT3_12x8 [] = {
|
||||
7, 3, 3, 2, 7, 1, 6, 3, 4, 7, 0, 3,
|
||||
0, 5, 5, 5, 3, 7, 3, 1, 5, 0, 1, 2,
|
||||
5, 4, 5, 2, 1, 5, 4, 1, 1, 7, 3, 0,
|
||||
1, 1, 4, 5, 0, 4, 0, 0, 1, 5, 5, 4,
|
||||
4, 1, 5, 1, 1, 6, 3, 6, 2, 0, 0, 4,
|
||||
6, 5, 5, 7, 4, 0, 7, 5, 1, 3, 3, 1,
|
||||
7, 3, 2, 0, 1, 7, 4, 5, 0, 2, 7, 1,
|
||||
0, 2, 7, 3, 3, 0, 7, 1, 5, 4, 0, 1
|
||||
};
|
||||
|
||||
// ========================================
|
||||
void test () {
|
||||
Size size (18, 12);
|
||||
//Size size (6, 4);
|
||||
//Size size (18, 12);
|
||||
Size size (12, 8);
|
||||
Border border (size, false);
|
||||
GraphWalker graphWalker (size, border);
|
||||
int leafCount = graphWalker.vertexMaxCount ();
|
||||
TreeType treeType = MAX;
|
||||
|
||||
// ====================
|
||||
int coreCount = 2;
|
||||
//PixelT *pixels = pixelsT1_18x12;
|
||||
PixelT *pixels = new PixelT [leafCount];
|
||||
srand (time (NULL));
|
||||
for (int i = 0; i < leafCount; ++i)
|
||||
pixels[i] = std::rand() % 8;
|
||||
PixelT *pixels = pixelsT2_12x8;
|
||||
// PixelT *pixels = new PixelT [leafCount];
|
||||
// for (int i = 0; i < leafCount; ++i)
|
||||
// pixels[i] = std::rand() % 8;
|
||||
// ====================
|
||||
|
||||
Raster<PixelT> raster (size);
|
||||
@ -182,7 +208,11 @@ void test () {
|
||||
// ========================================
|
||||
int
|
||||
main (int argc, char **argv, char **envp) {
|
||||
test ();
|
||||
srand (time (NULL));
|
||||
for (unsigned int i = 0; i < nbTest ; ++i) {
|
||||
cout << endl << "========================================" << endl;
|
||||
test ();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
99
src/Tree.cpp
99
src/Tree.cpp
@ -69,7 +69,106 @@ Tree::book (const DimImg &leafCount) {
|
||||
childSum.resize (leafCount+1);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
bool
|
||||
Tree::compareTo (const Tree &tree, bool testChildren) const {
|
||||
const DimImg leafCount = getLeafCount ();
|
||||
const DimImg compCount = getCompCount ();
|
||||
DEF_LOG ("Tree::compareTo", "leafCount: " << leafCount << " compCount: " << compCount);
|
||||
|
||||
if (leafCount != tree.getLeafCount () ||
|
||||
compCount != tree.getCompCount ()) {
|
||||
cerr
|
||||
<< "leafCount: " << leafCount << " ?= " << tree.getLeafCount () << endl
|
||||
<< "compCount: " << compCount << " ?= " << tree.getCompCount () << endl
|
||||
<< flush;
|
||||
return false;
|
||||
}
|
||||
|
||||
vector<DimImg> pearComps (compCount, DimImg_MAX);
|
||||
|
||||
bool result = true;
|
||||
// test parent leaves
|
||||
for (DimImg lId = 0; lId < leafCount; ++lId) {
|
||||
const DimImg parentId = getLeafParent (lId);
|
||||
if (parentId == DimImg_MAX) {
|
||||
cerr
|
||||
<< "leafId: " << lId << " parentId: max value" << endl
|
||||
<< flush;
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
const DimImg pearParentId = tree.getLeafParent (lId);
|
||||
LOG ("leafId: " << lId << " parentId: " << parentId << " pearParentId: " << pearParentId);
|
||||
const DimImg pearCompId = pearComps[parentId];
|
||||
if (pearCompId == DimImg_MAX) {
|
||||
pearComps[parentId] = pearParentId;
|
||||
continue;
|
||||
}
|
||||
if (pearCompId != pearParentId) {
|
||||
cerr
|
||||
<< "leafId: " << lId << " not same parent" << endl
|
||||
<< flush;
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// test parent des comps
|
||||
for (DimImg compId = 0; compId < compCount; ++compId) {
|
||||
const DimImg pearCompId = pearComps[compId];
|
||||
if (pearCompId == DimImg_MAX) {
|
||||
cerr
|
||||
<< "Reference tree may be not ordered (" << compId << ")" << endl
|
||||
<< flush;
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
const DimImg parentId = getCompParent (compId);
|
||||
const DimImg pearParentId = tree.getCompParent (pearCompId);
|
||||
const DimImg pearCompParentId = pearComps[parentId];
|
||||
if (pearCompParentId == DimImg_MAX) {
|
||||
pearComps[compId] = pearParentId;
|
||||
continue;
|
||||
}
|
||||
if (pearCompParentId != pearParentId) {
|
||||
cerr
|
||||
<< "compId: " << compId << " not same parent" << endl
|
||||
<< flush;
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (testChildren && result) {
|
||||
// test children
|
||||
for (DimImg compId = 0; compId < compCount; ++compId) {
|
||||
const DimImg pearCompId = pearComps[compId];
|
||||
const DimImg childrenCount = getChildrenCount (compId);
|
||||
if (childrenCount != tree.getChildrenCount (pearCompId)) {
|
||||
cerr
|
||||
<< "compId: " << pearCompId << " not same childrenCount" << endl
|
||||
<< flush;
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
for (DimImg childId = 0; childId < childrenCount; ++childId) {
|
||||
DimNodeId nodeId = tree.getChild (pearCompId, childId);
|
||||
if (pearCompId != tree.isLeaf (nodeId) ?
|
||||
tree.getLeafParent (tree.getLeafId (nodeId)) :
|
||||
tree.getCompParent (tree.getCompId (nodeId))) {
|
||||
cerr
|
||||
<< "not same child for comp: " << pearCompId << " child: " << childId << endl
|
||||
<< flush;
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// ========================================
|
||||
void
|
||||
Tree::checkSpare () const {
|
||||
Border border; // default = no border
|
||||
|
Loading…
Reference in New Issue
Block a user