modifié : MakefileNoOTB
modifié : include/ArrayTree/ArrayTreeBuilder.hpp modifié : include/ArrayTree/ArrayTreeBuilder.tpp modifié : include/ArrayTree/Border.hpp modifié : include/ArrayTree/Border.tpp modifié : include/ArrayTree/GraphWalker.hpp modifié : include/ArrayTree/GraphWalker.tpp modifié : include/ArrayTree/Leader.tpp modifié : include/ArrayTree/triskeleArrayTreeBase.hpp modifié : include/ArrayTree/triskeleArrayTreeBase.tpp modifié : include/AttributeProfiles.hpp modifié : include/AttributeProfiles.tpp modifié : include/Attributes/AreaAttributes.hpp modifié : include/Attributes/AverageAttributes.hpp modifié : include/Attributes/MoIAttributes.hpp modifié : include/Attributes/SDAttributes.hpp modifié : include/Attributes/WeightAttributes.hpp modifié : include/Attributes/XYAttributes.hpp modifié : include/CompAttribute.hpp modifié : include/CompAttribute.tpp modifié : include/Tree.hpp modifié : include/Tree.tpp modifié : include/TreeStats.hpp modifié : include/triskeleBase.hpp modifié : include/triskeleBase.tpp modifié : include/triskeleDebug.hpp modifié : src/Tree.cpp modifié : src/TreeStats.cpp modifié : src/apGenerator.cpp
This commit is contained in:
parent
22206596ad
commit
8149f1353b
@ -8,13 +8,17 @@ LIB_DIR = $(BLD_DIR)/lib
|
|||||||
OBJ_DIR = $(BLD_DIR)/obj
|
OBJ_DIR = $(BLD_DIR)/obj
|
||||||
|
|
||||||
## PRG #################################
|
## PRG #################################
|
||||||
TST_PRG = apGenerator
|
APG_PRG = apGenerator
|
||||||
|
APG_SRC = $(patsubst %, $(CPP_DIR)/%.cpp, $(APG_PRG))
|
||||||
|
APG_OUT = $(patsubst %, $(OUT_DIR)/%, $(APG_PRG))
|
||||||
|
|
||||||
|
TST_PRG = TestArrayTreeBuilder
|
||||||
TST_SRC = $(patsubst %, $(CPP_DIR)/%.cpp, $(TST_PRG))
|
TST_SRC = $(patsubst %, $(CPP_DIR)/%.cpp, $(TST_PRG))
|
||||||
TST_OUT = $(patsubst %, $(OUT_DIR)/%, $(TST_PRG))
|
TST_OUT = $(patsubst %, $(OUT_DIR)/%, $(TST_PRG))
|
||||||
|
|
||||||
## FLAGS ###############################
|
## FLAGS ###############################
|
||||||
DFLAGS = -O2 -DNDEBUG -DBOOST_DISABLE_ASSERTS -DNO_OTB
|
DFLAGS = -O2 -DNDEBUG -DBOOST_DISABLE_ASSERTS -DNO_OTB
|
||||||
#DFLAGS = -g -DENABLE_LOG -DNO_OTB # -DSMART_LOG # -DTHREAD_DISABLE
|
#DFLAGS = -g -DENABLE_LOG -DNO_OTB -DTHREAD_DISABLE -DENABLE_SMART_LOG
|
||||||
IFLAGS = $(DFLAGS) -MMD -I$(HPP_DIR)
|
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
|
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++
|
CC = g++
|
||||||
@ -31,7 +35,15 @@ $(OUT_DIR)/%: $(CPP_DIR)/*/%.cpp
|
|||||||
$(CC) $(IFLAGS) $< -L$(LIB_DIR) $(LFLAGS) -cpp -o $@
|
$(CC) $(IFLAGS) $< -L$(LIB_DIR) $(LFLAGS) -cpp -o $@
|
||||||
|
|
||||||
## ENTRIES #############################
|
## ENTRIES #############################
|
||||||
all: init libtriskele apGenerator
|
all: init libtriskele apGenerator test
|
||||||
|
|
||||||
|
testA: all
|
||||||
|
$(TST_OUT)
|
||||||
|
|
||||||
|
testB: all
|
||||||
|
# $(APG_OUT) data/nairobi-byte.tif data/result.tif -b 0 -w 4000 -h 4000 --min-tree -A data/areaThresholds.txt # --debug
|
||||||
|
# $(APG_OUT) data/10m.tif data/result.tif -b 0 --min-tree --max-tree --tos-tree -A data/areaThresholds.txt -S data/sdThresholds.txt -M data/moiThresholds.txt # --debug
|
||||||
|
$(APG_OUT) data/10m.tif data/result.tif --min-tree --max-tree --tos-tree -A data/areaThresholds.txt -S data/sdThresholds.txt -M data/moiThresholds.txt # --debug
|
||||||
|
|
||||||
init:
|
init:
|
||||||
mkdir -p $(OUT_DIR) $(OBJ_DIR) $(LIB_DIR)
|
mkdir -p $(OUT_DIR) $(OBJ_DIR) $(LIB_DIR)
|
||||||
@ -40,19 +52,19 @@ clean:
|
|||||||
|
|
||||||
wipe: clean
|
wipe: clean
|
||||||
rm -rf $(OBJ_DIR)
|
rm -rf $(OBJ_DIR)
|
||||||
rm -f $(TST_OUT) $(LIB_DIR)/libtriskele.a
|
rm -f $(APG_OUT) $(TST_OUT) $(LIB_DIR)/libtriskele.a
|
||||||
|
|
||||||
libtriskele: $(LIB_DIR)/libtriskele.a
|
libtriskele: $(LIB_DIR)/libtriskele.a
|
||||||
|
|
||||||
|
$(APG_OUT): $(APG_SRC) $(LIB_DIR)/libtriskele.a
|
||||||
|
apGenerator: $(APG_OUT)
|
||||||
|
|
||||||
$(TST_OUT): $(TST_SRC) $(LIB_DIR)/libtriskele.a
|
$(TST_OUT): $(TST_SRC) $(LIB_DIR)/libtriskele.a
|
||||||
apGenerator: $(TST_OUT)
|
test: $(TST_OUT)
|
||||||
# $(TST_OUT) data/nairobi-byte.tif data/result.tif -b 0 -w 4000 -h 4000 --min-tree -A data/areaThresholds.txt # --debug
|
|
||||||
# $(TST_OUT) data/10m.tif data/result.tif -b 0 --min-tree --max-tree --tos-tree -A data/areaThresholds.txt -S data/sdThresholds.txt -M data/moiThresholds.txt # --debug
|
|
||||||
$(TST_OUT) data/10m.tif data/result.tif --min-tree --max-tree --tos-tree -A data/areaThresholds.txt -S data/sdThresholds.txt -M data/moiThresholds.txt # --debug
|
|
||||||
|
|
||||||
|
|
||||||
## DEPENDS #############################
|
## DEPENDS #############################
|
||||||
ALL_OUT = $(TST_OUT)
|
ALL_OUT = $(APG_OUT)
|
||||||
ALL_OBJ = $(OBJ_DIR)/IImage.o $(OBJ_DIR)/triskeleArrayTreeBase.o $(OBJ_DIR)/Tree.o $(OBJ_DIR)/triskeleDebug.o $(OBJ_DIR)/TreeStats.o $(OBJ_DIR)/triskeleBase.o $(OBJ_DIR)/QuadTreeBuilder.o $(OBJ_DIR)/Option.o $(OBJ_DIR)/Selected.o
|
ALL_OBJ = $(OBJ_DIR)/IImage.o $(OBJ_DIR)/triskeleArrayTreeBase.o $(OBJ_DIR)/Tree.o $(OBJ_DIR)/triskeleDebug.o $(OBJ_DIR)/TreeStats.o $(OBJ_DIR)/triskeleBase.o $(OBJ_DIR)/QuadTreeBuilder.o $(OBJ_DIR)/Option.o $(OBJ_DIR)/Selected.o
|
||||||
|
|
||||||
ALL_OBJ_XML = $(OBJ_DIR)/IImage.o $(OBJ_DIR)/triskeleArrayTreeBase.o $(OBJ_DIR)/Tree.o $(OBJ_DIR)/triskeleDebug.o $(OBJ_DIR)/TreeStats.o $(OBJ_DIR)/triskeleBase.o $(OBJ_DIR)/QuadTreeBuilder.o $(OBJ_DIR)/XMLTreeBuilder.o $(OBJ_DIR)/Option.o $(OBJ_DIR)/Selected.o
|
ALL_OBJ_XML = $(OBJ_DIR)/IImage.o $(OBJ_DIR)/triskeleArrayTreeBase.o $(OBJ_DIR)/Tree.o $(OBJ_DIR)/triskeleDebug.o $(OBJ_DIR)/TreeStats.o $(OBJ_DIR)/triskeleBase.o $(OBJ_DIR)/QuadTreeBuilder.o $(OBJ_DIR)/XMLTreeBuilder.o $(OBJ_DIR)/Option.o $(OBJ_DIR)/Selected.o
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include <boost/chrono.hpp>
|
#include <boost/chrono.hpp>
|
||||||
|
|
||||||
|
#include "triskeleBase.hpp"
|
||||||
#include "triskeleDebug.hpp"
|
#include "triskeleDebug.hpp"
|
||||||
#include "triskeleSort.hpp"
|
#include "triskeleSort.hpp"
|
||||||
#include "triskeleDealThreads.hpp"
|
#include "triskeleDealThreads.hpp"
|
||||||
@ -51,10 +52,6 @@ namespace otb {
|
|||||||
inline void
|
inline void
|
||||||
setAttributProfiles (AttributeProfiles<PixelT> &attributeProfiles, const WeightFunct &weightFunct);
|
setAttributProfiles (AttributeProfiles<PixelT> &attributeProfiles, const WeightFunct &weightFunct);
|
||||||
|
|
||||||
// template<typename WeightFunct>
|
|
||||||
// inline void
|
|
||||||
// fillAPTree (PixelT *leafAPTree, const WeightFunct &weightFunct);
|
|
||||||
|
|
||||||
template<typename WeightFunct>
|
template<typename WeightFunct>
|
||||||
inline void
|
inline void
|
||||||
buildParents (Edge<WeightT> *edges, const WeightFunct &weightFunct, const Rect &tile, DimImg &topParent);
|
buildParents (Edge<WeightT> *edges, const WeightFunct &weightFunct, const Rect &tile, DimImg &topParent);
|
||||||
@ -63,9 +60,12 @@ namespace otb {
|
|||||||
inline void
|
inline void
|
||||||
connectLeaf (DimImg a, DimImg b, const WeightT &weight, DimImg &parCount, const WeightFunct &weightFunct);
|
connectLeaf (DimImg a, DimImg b, const WeightT &weight, DimImg &parCount, const WeightFunct &weightFunct);
|
||||||
|
|
||||||
|
inline void
|
||||||
|
unlinkParent (const DimImg &par);
|
||||||
|
|
||||||
template<typename WeightFunct>
|
template<typename WeightFunct>
|
||||||
inline void
|
inline void
|
||||||
connectComp (DimImg newComp, DimImg topA, DimImg topB, const WeightFunct &weightFunct);
|
connect3Comp (DimImg newComp, DimImg topA, DimImg topB, const WeightFunct &weightFunct);
|
||||||
|
|
||||||
template<typename WeightFunct>
|
template<typename WeightFunct>
|
||||||
inline void
|
inline void
|
||||||
@ -81,7 +81,7 @@ namespace otb {
|
|||||||
inline void
|
inline void
|
||||||
compress (const DimImg &compTop);
|
compress (const DimImg &compTop);
|
||||||
|
|
||||||
inline void
|
inline DimImg
|
||||||
createParent (DimImg &topParent, const WeightT &weight, DimImg &childA, DimImg &childB);
|
createParent (DimImg &topParent, const WeightT &weight, DimImg &childA, DimImg &childB);
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
@ -107,20 +107,18 @@ namespace otb {
|
|||||||
inline void
|
inline void
|
||||||
buildChildren ();
|
buildChildren ();
|
||||||
|
|
||||||
template<typename WeightFunct>
|
// nice ostream
|
||||||
inline void
|
struct CLogComp {
|
||||||
initWeights (const GraphWalker &graphWalker, const WeightFunct &weightFunct);
|
const ArrayTreeBuilder &atb;
|
||||||
|
const DimImg &compId;
|
||||||
// #ifdef ENABLE_LOG
|
inline CLogComp (const ArrayTreeBuilder &atb, const DimImg &compId);
|
||||||
// inline void
|
inline ostream &print (ostream &out) const;
|
||||||
// printTree (const Size &size, const bool &rec);
|
};
|
||||||
// inline void
|
inline CLogComp logComp (const DimImg &compId) const { return CLogComp (*this, compId); }
|
||||||
// printLeaders (const Size &size);
|
friend inline ostream &operator << (ostream& out, const CLogComp &lc) { return lc.print (out); }
|
||||||
// inline void
|
|
||||||
// printNewCompIdx (const Size &size);
|
|
||||||
// #endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#include "ArrayTreeBuilder.tpp"
|
#include "ArrayTreeBuilder.tpp"
|
||||||
|
|
||||||
} // arrayTree
|
} // arrayTree
|
||||||
|
|||||||
@ -38,6 +38,7 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, WeightAttributes<Weigh
|
|||||||
childCountRec = childCount+2;
|
childCountRec = childCount+2;
|
||||||
newCompId = leaders.getLeaders ();
|
newCompId = leaders.getLeaders ();
|
||||||
compWeights = weightAttributes.getValues ();
|
compWeights = weightAttributes.getValues ();
|
||||||
|
SMART_LOG_EXPR (dealThreadFill_n (leafCount-1, coreCount, compWeights, 0));
|
||||||
|
|
||||||
auto start = high_resolution_clock::now ();
|
auto start = high_resolution_clock::now ();
|
||||||
switch (treeType) {
|
switch (treeType) {
|
||||||
@ -64,6 +65,8 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, WeightAttributes<Weigh
|
|||||||
newCompId = nullptr;
|
newCompId = nullptr;
|
||||||
buildChildren ();
|
buildChildren ();
|
||||||
childCountRec = nullptr;
|
childCountRec = nullptr;
|
||||||
|
|
||||||
|
SMART_LOG (tree.printTree ());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
@ -108,27 +111,31 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, const WeightFunct &wei
|
|||||||
unsigned int tileCount = tiles.size ();
|
unsigned int tileCount = tiles.size ();
|
||||||
unsigned int boundCount = boundaries.size ();
|
unsigned int boundCount = boundaries.size ();
|
||||||
|
|
||||||
|
vector<DimImg> vertexMaxBounds;
|
||||||
|
vector<DimImg> edgesMaxBounds;
|
||||||
|
graphWalker.setMaxBounds (tiles, vertexMaxBounds, edgesMaxBounds);
|
||||||
|
|
||||||
vector<Edge<WeightT> *> tileEdges (tileCount);
|
vector<Edge<WeightT> *> tileEdges (tileCount);
|
||||||
vector<DimImg> compBases (tileCount);
|
vector<DimImg> compBases (tileCount);
|
||||||
vector<DimImg> compTops (tileCount);
|
vector<DimImg> compTops (tileCount);
|
||||||
DimImg compBase = 0;
|
|
||||||
Edge<WeightT> *edgeBase = &allEdges[0];
|
Edge<WeightT> *edgeBase = &allEdges[0];
|
||||||
for (unsigned int i = 0; i < tileCount; ++i) {
|
for (unsigned int i = 0; i < tileCount; ++i) {
|
||||||
tileEdges [i] = edgeBase;
|
tileEdges [i] = &allEdges[edgesMaxBounds[i]];
|
||||||
Size zoneSize (tiles[i].width, tiles[i].height);
|
compBases [i] = compTops [i] = vertexMaxBounds [i];
|
||||||
edgeBase += graphWalker.edgeMaxCount (zoneSize);
|
|
||||||
compBases [i] = compBase;
|
|
||||||
compTops [i] = compBase;
|
|
||||||
compBase += graphWalker.vertexMaxCount (zoneSize); /* -1, but prety LOG */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dealThreadRange (tileCount, coreCount, [this, &tileEdges, &weightFunct, &tiles, &compTops] (DimImg threadId) {
|
dealThreadRange (tileCount, coreCount, [this, &tileEdges, &weightFunct, &tiles, &compTops] (DimImg threadId) {
|
||||||
buildParents (tileEdges [threadId], weightFunct, tiles [threadId], compTops [threadId]);
|
buildParents (tileEdges [threadId], weightFunct, tiles [threadId], compTops [threadId]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
SMART_LOG ("leaders:" << endl
|
||||||
|
<< printMap (leaders.getLeaders (), size, 0) << endl << endl
|
||||||
|
<< "compWeights:" << endl
|
||||||
|
<< printMap (compWeights, size, 0) << endl << endl
|
||||||
|
<< tree.printTree (2*leafCount-1));
|
||||||
// merge sub-tree
|
// merge sub-tree
|
||||||
DimImg compCount = compTops [0];
|
DimImg compCount = compTops [0];
|
||||||
DimImg *topC = NULL;
|
DimImg *topC = NULL;
|
||||||
|
DimImg compBase = vertexMaxBounds[tileCount];
|
||||||
if (boundCount) {
|
if (boundCount) {
|
||||||
vector<Edge<WeightT> *> edgeBounds (boundCount);
|
vector<Edge<WeightT> *> edgeBounds (boundCount);
|
||||||
vector<DimImg> edgeCounts (boundCount);
|
vector<DimImg> edgeCounts (boundCount);
|
||||||
@ -169,20 +176,32 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, const WeightFunct &wei
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SMART_LOG ("compWeights:" << endl
|
||||||
|
<< printMap (compWeights, size, 0) << endl << endl
|
||||||
|
<< tree.printTree (2*leafCount-1));
|
||||||
// compress
|
// compress
|
||||||
DimImg maxUsed = max (compTops[tileCount-1], topC != NULL ? *topC : 0);
|
DimImg maxUsed = max (compTops[tileCount-1], topC != NULL ? *topC : 0);
|
||||||
dealThreadFill_n (maxUsed, coreCount, newCompId, DimImg_MAX);
|
dealThreadFill_n (maxUsed, coreCount, newCompId, DimImg_MAX);
|
||||||
|
|
||||||
|
SMART_LOG ("reuse leaders:" << endl
|
||||||
|
<< printMap (newCompId, size, 0) << endl << endl);
|
||||||
compCount = updateNewId (compBases, compTops, weightFunct);
|
compCount = updateNewId (compBases, compTops, weightFunct);
|
||||||
|
|
||||||
compress (maxUsed);
|
SMART_LOG ("updateNewId:" << endl
|
||||||
|
<< printMap (newCompId, size, 0) << endl << endl);
|
||||||
|
|
||||||
|
compress (maxUsed);
|
||||||
|
SMART_LOG ("compress:" << endl
|
||||||
|
<< printMap (newCompId, size, 0) << endl << endl);
|
||||||
leaders.free ();
|
leaders.free ();
|
||||||
|
|
||||||
setNodeCount (tree, leafCount+compCount);
|
setNodeCount (tree, leafCount+compCount);
|
||||||
LOG ("nodeCount:" << tree.getNodeCount());
|
LOG ("nodeCount:" << tree.getNodeCount());
|
||||||
DimEdge root = compCount-1;
|
// DimEdge root = compCount-1;
|
||||||
compParents[root] = root;
|
// compParents[root] = root;
|
||||||
|
|
||||||
|
SMART_LOG ("compWeights:" << endl
|
||||||
|
<< printMap (compWeights, size, 0) << endl << endl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
@ -200,31 +219,13 @@ ArrayTreeBuilder<WeightT, PixelT>::setAttributProfiles (AttributeProfiles<PixelT
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================================
|
|
||||||
// template<typename WeightT, typename PixelT>
|
|
||||||
// template<typename WeightFunct>
|
|
||||||
// inline void
|
|
||||||
// ArrayTreeBuilder<WeightT, PixelT>::fillAPTree (PixelT *leafAPTree, const WeightFunct &weightFunct) {
|
|
||||||
// DEF_LOG ("ArrayTreeBuilder::fillLeafAPTree", "");
|
|
||||||
// dealThreadBound (leafCount, coreCount, [&weightFunct, &leafAPTree] (const DimImg &minVal, const DimImg &maxVal) {
|
|
||||||
// weightFunct.copyPixelsBound (leafAPTree, minVal, maxVal);
|
|
||||||
// });
|
|
||||||
// PixelT *compAPTree = leafAPTree+leafCount;
|
|
||||||
// dealThreadBound (getCompCount (), coreCount, [this, &weightFunct, &compAPTree] (const DimImg &minVal, const DimImg &maxVal) {
|
|
||||||
// weightFunct.weight2valueBound (compAPTree, compWeights, minVal, maxVal);
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
template<typename WeightT, typename PixelT>
|
template<typename WeightT, typename PixelT>
|
||||||
template<typename WeightFunct>
|
template<typename WeightFunct>
|
||||||
inline void
|
inline void
|
||||||
ArrayTreeBuilder<WeightT, PixelT>::buildParents (Edge<WeightT> *edges, const WeightFunct &weightFunct,
|
ArrayTreeBuilder<WeightT, PixelT>::buildParents (Edge<WeightT> *edges, const WeightFunct &weightFunct,
|
||||||
const Rect &tile, DimImg &topParent) {
|
const Rect &tile, DimImg &topParent) {
|
||||||
#ifdef SMART_LOG
|
SMART_DEF_LOG ("ArrayTreeBuilder::buildParents", " tile:" << tile << " topParent:" << topParent << " counting:" << countingFlag);
|
||||||
DEF_LOG ("ArrayTreeBuilder::buildParents", " tile:" << tile << " topParent:" << topParent << " counting:" << countingFlag);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DimEdge edgeCount = (sizeof (WeightT) < 3 || countingFlag) ?
|
DimEdge edgeCount = (sizeof (WeightT) < 3 || countingFlag) ?
|
||||||
graphWalker.getCountingSortedEdges<WeightT, WeightFunct> (tile, Surface, edges, weightFunct) :
|
graphWalker.getCountingSortedEdges<WeightT, WeightFunct> (tile, Surface, edges, weightFunct) :
|
||||||
graphWalker.getSortedEdges (tile, Surface, edges, weightFunct);
|
graphWalker.getSortedEdges (tile, Surface, edges, weightFunct);
|
||||||
@ -247,9 +248,7 @@ ArrayTreeBuilder<WeightT, PixelT>::buildParents (Edge<WeightT> *edges, const Wei
|
|||||||
BOOST_ASSERT (rb < leafCount || rb == DimImg_MAX);
|
BOOST_ASSERT (rb < leafCount || rb == DimImg_MAX);
|
||||||
// BOOST_ASSERT (ra == DimImg_MAX || compParents [ra] == DimImg_MAX);
|
// BOOST_ASSERT (ra == DimImg_MAX || compParents [ra] == DimImg_MAX);
|
||||||
// BOOST_ASSERT (rb == DimImg_MAX || compParents [rb] == DimImg_MAX);
|
// BOOST_ASSERT (rb == DimImg_MAX || compParents [rb] == DimImg_MAX);
|
||||||
#ifdef SMART_LOG
|
SMART_LOG (" w:" << curEdge.weight << " pa:" << pa << " pb:" << pb << " la:" << la << " lb:" << lb << " ra:" << ra << " rb:" << rb);
|
||||||
LOG (" w:" << curEdge.weight << " pa:" << pa << " pb:" << pb << " la:" << la << " lb:" << lb << " ra:" << ra << " rb:" << rb);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (la == lb)
|
if (la == lb)
|
||||||
continue;
|
continue;
|
||||||
@ -277,7 +276,7 @@ ArrayTreeBuilder<WeightT, PixelT>::buildParents (Edge<WeightT> *edges, const Wei
|
|||||||
} else if (ra == rb) {
|
} else if (ra == rb) {
|
||||||
// XXX
|
// XXX
|
||||||
BOOST_ASSERT (false);
|
BOOST_ASSERT (false);
|
||||||
leader = lb;
|
continue;
|
||||||
} else if (compWeights[ra] == compWeights [rb]) {
|
} else if (compWeights[ra] == compWeights [rb]) {
|
||||||
// ra.weight = rb.weight // XXX ?= curEdge.weight
|
// ra.weight = rb.weight // XXX ?= curEdge.weight
|
||||||
if (childCountRec [ra] < childCountRec [rb]) {
|
if (childCountRec [ra] < childCountRec [rb]) {
|
||||||
@ -303,140 +302,114 @@ ArrayTreeBuilder<WeightT, PixelT>::buildParents (Edge<WeightT> *edges, const Wei
|
|||||||
leaders.link (pa, leader);
|
leaders.link (pa, leader);
|
||||||
leaders.link (pb, leader);
|
leaders.link (pb, leader);
|
||||||
|
|
||||||
#ifdef SMART_LOG
|
SMART_LOG (" leader:" << leader << " w:" << compWeights [leader] << " c:" << childCountRec [leader]);
|
||||||
LOG (" leader:" << leader << " w:" << compWeights [leader] << " c:" << childCountRec [leader]);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SMART_LOG
|
SMART_LOG ("topParent:" << topParent);
|
||||||
LOG ("topParent:" << topParent);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
template<typename WeightT, typename PixelT>
|
template<typename WeightT, typename PixelT>
|
||||||
|
inline void
|
||||||
|
ArrayTreeBuilder<WeightT, PixelT>::unlinkParent (const DimImg &par) {
|
||||||
|
SMART_DEF_LOG ("ArrayTreeBuilder::unlinkParent", "par: " << logComp (par));
|
||||||
|
if (par == DimImg_MAX)
|
||||||
|
return;
|
||||||
|
BOOST_ASSERT (childCountRec [par]);
|
||||||
|
--childCountRec [par];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------
|
||||||
|
template<typename WeightT, typename PixelT>
|
||||||
template<typename WeightFunct>
|
template<typename WeightFunct>
|
||||||
inline void
|
inline void
|
||||||
ArrayTreeBuilder<WeightT, PixelT>::connectLeaf (DimImg a, DimImg b, const WeightT &weight, DimImg &parCount, const WeightFunct &weightFunct) {
|
ArrayTreeBuilder<WeightT, PixelT>::connectLeaf (DimImg a, DimImg b, const WeightT &weight, DimImg &parCount, const WeightFunct &weightFunct) {
|
||||||
|
SMART_DEF_LOG ("ArrayTreeBuilder::connectLeaf", "a:" << a << " b:" << b << " weight:" << weight);
|
||||||
#ifdef SMART_LOG
|
|
||||||
DEF_LOG ("ArrayTreeBuilder::connectLeaf", "a:" << a << " b:" << b << " weight:" << weight);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
BOOST_ASSERT (a < leafCount);
|
BOOST_ASSERT (a < leafCount);
|
||||||
BOOST_ASSERT (b < leafCount);
|
BOOST_ASSERT (b < leafCount);
|
||||||
BOOST_ASSERT (leafParents[a] < leafCount || leafParents[a] == DimImg_MAX);
|
BOOST_ASSERT (leafParents[a] < leafCount || leafParents[a] == DimImg_MAX);
|
||||||
BOOST_ASSERT (leafParents[b] < leafCount || leafParents[b] == DimImg_MAX);
|
BOOST_ASSERT (leafParents[b] < leafCount || leafParents[b] == DimImg_MAX);
|
||||||
DimImg parA = findTopComp (leafParents[a], weightFunct);
|
DimImg parA = findTopComp (leafParents[a], weight, weightFunct);
|
||||||
DimImg parB = findTopComp (leafParents[b], weightFunct);
|
DimImg parB = findTopComp (leafParents[b], weight, weightFunct);
|
||||||
if (parA == DimImg_MAX) {
|
SMART_LOG ("parA: " << logComp (parA) << " parB: " << logComp (parB));
|
||||||
swap (a, b);
|
// upW0 : no parent(s)
|
||||||
swap (parA, parB);
|
// Border case if parX == DimImg_MAX
|
||||||
}
|
if (parA == parB) {
|
||||||
if (parB == DimImg_MAX) {
|
|
||||||
// parA = parB = DimImg_MAX
|
|
||||||
createParent (parCount, weight, leafParents [a], leafParents [b]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (parA == DimImg_MAX) {
|
|
||||||
// parA = DimImg_MAX & parB != DimImg_MAX
|
|
||||||
parB = findTopComp (parB, weight, weightFunct);
|
|
||||||
if (!weightFunct.isWeightInf (compWeights[parB], weight)) {
|
|
||||||
leafParents[a] = parB;
|
|
||||||
++childCountRec[parB];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
parA = findTopComp (compParents[parB], weightFunct);
|
|
||||||
if (parA == DimImg_MAX) {
|
if (parA == DimImg_MAX) {
|
||||||
createParent (parCount, weight, leafParents [a], compParents [parB]);
|
SMART_LOG ("upW0: no parents");
|
||||||
return;
|
createParent (parCount, weight, leafParents [a], leafParents [b]);
|
||||||
|
SMART_LOG ("createParent: " << logComp (leafParents[a]));
|
||||||
}
|
}
|
||||||
createParent (parCount, weight, leafParents [a], compParents [parB]);
|
SMART_LOG ("same parents for: " << a << ", " << b);
|
||||||
compParents[leafParents [a]] = parA;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BOOST_ASSERT (parA < leafCount);
|
if (parA == DimImg_MAX) {
|
||||||
BOOST_ASSERT (parB < leafCount);
|
|
||||||
if (parA == parB)
|
|
||||||
return;
|
|
||||||
if (weightFunct.isWeightInf (compWeights[parA], compWeights[parB])) {
|
|
||||||
swap (a, b);
|
swap (a, b);
|
||||||
swap (parA, parB);
|
swap (parA, parB);
|
||||||
|
SMART_LOG ("swap: " << logComp (parA) << " " << logComp (parB));
|
||||||
}
|
}
|
||||||
if (weightFunct.isWeightInf (weight, compWeights[parB])) {
|
if ((parA == DimImg_MAX || weightFunct.isWeightInf (weight, compWeights[parA])) &&
|
||||||
// 1
|
weightFunct.isWeightInf (weight, compWeights[parB])) {
|
||||||
BOOST_ASSERT (weightFunct.isWeightInf (weight, compWeights[parA]));
|
// upW1 & upW2 : upper
|
||||||
--childCountRec [parA];
|
SMART_LOG ("upW1 | upW2: upper");
|
||||||
--childCountRec [parB];
|
unlinkParent (parA);
|
||||||
|
unlinkParent (parB);
|
||||||
#ifdef SMART_LOG
|
SMART_LOG ("parA: " << logComp (parA) << " parB: " << logComp (parB));
|
||||||
LOG ("connect leaf a:" << a << " b:" << b << " np:" << parCount << " (2)");
|
DimImg newComp = createParent (parCount, weight, leafParents [a], leafParents [b]);
|
||||||
#endif
|
SMART_LOG ("createParent: " << logComp (newComp));
|
||||||
|
connect3Comp (newComp, parA, parB, weightFunct);
|
||||||
// XXX newParent = leafParents[a] => return ?
|
|
||||||
createParent (parCount, weight, leafParents [a], leafParents [b]);
|
|
||||||
connectComp (leafParents [a], parA, parB, weightFunct);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (weightFunct.isWeightInf (weight, compWeights[parA])) {
|
if (parA != DimImg_MAX && weightFunct.isWeightInf (compWeights[parA], compWeights[parB])) {
|
||||||
// 2
|
swap (a, b);
|
||||||
--childCountRec [parA];
|
swap (parA, parB);
|
||||||
parB = findTopComp (parB, weight, weightFunct);
|
SMART_LOG ("swap: " << logComp (parA) << " " << logComp (parB));
|
||||||
BOOST_ASSERT (parB < leafCount);
|
}
|
||||||
if (weight == compWeights[parB]) {
|
if (weightFunct.isWeightInf (compWeights[parB], weight) &&
|
||||||
// 2a
|
(parA == DimImg_MAX ||
|
||||||
++childCountRec[parB];
|
weightFunct.isWeightInf (compWeights[parA], weight) ||
|
||||||
leafParents[a] = parB;
|
weightFunct.isWeightInf (weight, compWeights[parA]))) {
|
||||||
|
// loW0 | loW1 | loW2 : lower
|
||||||
#ifdef SMART_LOG
|
SMART_LOG ("loW0 | loW1 | loW2");
|
||||||
LOG ("connect leaf a:" << a << " p:" << parB << " (" << childCountRec[parB] << ")");
|
if (weightFunct.isWeightInf (compWeights[parA], weight)) {
|
||||||
#endif
|
swap (a, b);
|
||||||
|
swap (parA, parB);
|
||||||
connectComp (parA, parB, weightFunct);
|
SMART_LOG ("swap: " << logComp (parA) << " " << logComp (parB));
|
||||||
|
}
|
||||||
|
DimImg grandParB = findTopComp (compParents[parB], weightFunct);
|
||||||
|
unlinkParent (grandParB);
|
||||||
|
SMART_LOG ("grandParB: " << logComp (grandParB));
|
||||||
|
if (parA == DimImg_MAX || weightFunct.isWeightInf (weight, compWeights[parA])) {
|
||||||
|
// loW1 | loW2
|
||||||
|
SMART_LOG ("loW1 | loW2: lower");
|
||||||
|
unlinkParent (parA);
|
||||||
|
SMART_LOG ("parA: " << logComp (parA));
|
||||||
|
DimImg newComp = createParent (parCount, weight, leafParents [a], compParents [parB]);
|
||||||
|
SMART_LOG ("createParent: " << logComp (newComp));
|
||||||
|
connect3Comp (newComp, parA, grandParB, weightFunct);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 2b compWeights[parB] < weight
|
// loW0
|
||||||
BOOST_ASSERT (weightFunct.isWeightInf (compWeights[parB], weight));
|
SMART_LOG ("loW0: lower");
|
||||||
DimImg grandParB = findTopComp (compParents[parB], weightFunct);
|
|
||||||
--childCountRec [grandParB];
|
|
||||||
|
|
||||||
#ifdef SMART_LOG
|
|
||||||
LOG ("connect leaf a:" << a << " pb:" << parB << " np:" << parCount << " (2)");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// XXX newParent = leafParents[a] => return ?
|
|
||||||
createParent (parCount, weight, leafParents [a], compParents [parB]);
|
|
||||||
connectComp (leafParents [a], grandParB, parA, weightFunct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
parA = findTopComp (parA, weight, weightFunct);
|
|
||||||
parB = findTopComp (parB, weight, weightFunct);
|
|
||||||
BOOST_ASSERT (parA < leafCount);
|
|
||||||
BOOST_ASSERT (parB < leafCount);
|
|
||||||
if (weightFunct.isWeightInf (compWeights[parA], compWeights[parB]))
|
|
||||||
swap (parA, parB);
|
|
||||||
if (weightFunct.isWeightInf (compWeights[parA], weight)) {
|
|
||||||
// 3
|
|
||||||
BOOST_ASSERT (!weightFunct.isWeightInf (weight, compWeights[parA]));
|
|
||||||
//BOOST_ASSERT (compParents[parA] < leafCount); // XXX pas sur !!!
|
|
||||||
//BOOST_ASSERT (compParents[parB] < leafCount); // XXX pas sur !!!
|
|
||||||
DimImg grandParA = findTopComp (compParents[parA], weightFunct);
|
DimImg grandParA = findTopComp (compParents[parA], weightFunct);
|
||||||
DimImg grandParB = findTopComp (compParents[parB], weightFunct);
|
unlinkParent (grandParA);
|
||||||
if (grandParA != DimImg_MAX)
|
SMART_LOG ("grandParA: " << logComp (grandParA));
|
||||||
--childCountRec [grandParA];
|
DimImg newComp = createParent (parCount, weight, compParents [parA], compParents [parB]);
|
||||||
if (grandParB != DimImg_MAX)
|
SMART_LOG ("createParent: " << logComp (newComp));
|
||||||
--childCountRec [grandParB];
|
connect3Comp (newComp, grandParA, grandParB, weightFunct);
|
||||||
|
|
||||||
#ifdef SMART_LOG
|
|
||||||
LOG ("connect leaf pa:" << parA << " pb:" << parB << " np:" << parCount << " (2)");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// XXX newParent = compParents [parA] => return ?
|
|
||||||
createParent (parCount, weight, compParents [parA], compParents [parB]);
|
|
||||||
connectComp (compParents [parA], grandParA, grandParB, weightFunct);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 4
|
// eqW0 | eqW1 | eqW2 : no creation
|
||||||
|
if (parA == DimImg_MAX || weightFunct.isWeightInf (weight, compWeights[parA])) {
|
||||||
|
// eqW1 | eqW2
|
||||||
|
SMART_LOG ("eqW1 | eqW2: incr leaf");
|
||||||
|
unlinkParent (parA);
|
||||||
|
++childCountRec[parB];
|
||||||
|
leafParents[a] = parB;
|
||||||
|
SMART_LOG ("parA: " << logComp (parA) << " parB: " << logComp (parB));
|
||||||
|
}
|
||||||
|
// eqW0 | eqW1 | eqW2
|
||||||
|
SMART_LOG ("eqW0 | eqW1 | eqW2: connect");
|
||||||
connectComp (parA, parB, weightFunct);
|
connectComp (parA, parB, weightFunct);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -444,29 +417,22 @@ ArrayTreeBuilder<WeightT, PixelT>::connectLeaf (DimImg a, DimImg b, const Weight
|
|||||||
template<typename WeightT, typename PixelT>
|
template<typename WeightT, typename PixelT>
|
||||||
template<typename WeightFunct>
|
template<typename WeightFunct>
|
||||||
inline void
|
inline void
|
||||||
ArrayTreeBuilder<WeightT, PixelT>::connectComp (DimImg newComp, DimImg topA, DimImg topB, const WeightFunct &weightFunct) {
|
ArrayTreeBuilder<WeightT, PixelT>::connect3Comp (DimImg newComp, DimImg topA, DimImg topB, const WeightFunct &weightFunct) {
|
||||||
|
SMART_DEF_LOG ("ArrayTreeBuilder::connect3Comp", "newComp:" << newComp << " topA:" << topA << " topB:" << topB);
|
||||||
#ifdef SMART_LOG
|
BOOST_ASSERT (newComp != DimImg_MAX);
|
||||||
DEF_LOG ("ArrayTreeBuilder::connectComp", "newComp:" << newComp << " topA:" << topA << " topB:" << topB);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (topB == DimImg_MAX)
|
if (topB == DimImg_MAX)
|
||||||
swap (topA, topB);
|
swap (topA, topB);
|
||||||
// XXX >>> test alpha
|
if (topB == DimImg_MAX)
|
||||||
// if (topB == DimImg_MAX)
|
return;
|
||||||
// return;
|
|
||||||
// XXX <<<
|
|
||||||
BOOST_ASSERT (topB != DimImg_MAX);
|
BOOST_ASSERT (topB != DimImg_MAX);
|
||||||
if (topA != DimImg_MAX && weightFunct.isWeightInf (compWeights[topA], compWeights[topB]))
|
if (topA != DimImg_MAX && weightFunct.isWeightInf (compWeights[topA], compWeights[topB]))
|
||||||
swap (topA, topB);
|
swap (topA, topB);
|
||||||
BOOST_ASSERT (findTopComp (topB, weightFunct) == topB);
|
BOOST_ASSERT (findTopComp (topB, weightFunct) == topB);
|
||||||
|
BOOST_ASSERT (weightFunct.isWeightInf (compWeights[newComp], compWeights[topB]));
|
||||||
compParents[newComp] = topB;
|
compParents[newComp] = topB;
|
||||||
++childCountRec[topB];
|
++childCountRec[topB];
|
||||||
|
SMART_LOG ("topB: " << logComp (topB));
|
||||||
#ifdef SMART_LOG
|
|
||||||
LOG ("connect comp nc:" << newComp << " tb:" << topB << " (" << childCountRec[topB] << ")");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
connectComp (topA, topB, weightFunct);
|
connectComp (topA, topB, weightFunct);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -475,10 +441,7 @@ template<typename WeightT, typename PixelT>
|
|||||||
template<typename WeightFunct>
|
template<typename WeightFunct>
|
||||||
inline void
|
inline void
|
||||||
ArrayTreeBuilder<WeightT, PixelT>::connectComp (DimImg topA, DimImg topB, const WeightFunct &weightFunct) {
|
ArrayTreeBuilder<WeightT, PixelT>::connectComp (DimImg topA, DimImg topB, const WeightFunct &weightFunct) {
|
||||||
|
SMART_DEF_LOG ("ArrayTreeBuilder::connectComp", "topA:" << topA << " topB:" << topB);
|
||||||
#ifdef SMART_LOG
|
|
||||||
DEF_LOG ("ArrayTreeBuilder::connectComp", "topA:" << topA << " topB:" << topB);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (topA == DimImg_MAX || topB == DimImg_MAX)
|
if (topA == DimImg_MAX || topB == DimImg_MAX)
|
||||||
@ -490,37 +453,24 @@ ArrayTreeBuilder<WeightT, PixelT>::connectComp (DimImg topA, DimImg topB, const
|
|||||||
topB = findTopComp (topB, compWeights[topA], weightFunct);
|
topB = findTopComp (topB, compWeights[topA], weightFunct);
|
||||||
if (topA == topB)
|
if (topA == topB)
|
||||||
return;
|
return;
|
||||||
|
if (compWeights[topA] == compWeights[topB] &&
|
||||||
|
childCountRec[topA] < childCountRec[topB])
|
||||||
|
swap (topA, topB);
|
||||||
|
DimImg grandParB = findTopComp (compParents[topB], weightFunct);
|
||||||
if (compWeights[topA] == compWeights[topB]) {
|
if (compWeights[topA] == compWeights[topB]) {
|
||||||
if (childCountRec[topA] < childCountRec[topB])
|
childCountRec[topA] += childCountRec[topB];
|
||||||
swap (topA, topB);
|
|
||||||
DimImg parB = findTopComp (compParents[topB], weightFunct);
|
|
||||||
if (parB != DimImg_MAX)
|
|
||||||
--childCountRec[parB];
|
|
||||||
childCountRec [topA] += childCountRec[topB];
|
|
||||||
childCountRec[topB] = 0;
|
childCountRec[topB] = 0;
|
||||||
compParents[topB] = topA;
|
} else
|
||||||
|
++childCountRec[topA];
|
||||||
#ifdef SMART_LOG
|
|
||||||
LOG ("connect comp topB:" << topB << " topA:" << topA << " (" << childCountRec [topA] << ")");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
topB = topA;
|
|
||||||
topA = findTopComp (parB, compWeights[topA], weightFunct);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
DimImg parB = findTopComp (compParents[topB], weightFunct);
|
|
||||||
++childCountRec[topA];
|
|
||||||
compParents[topB] = topA;
|
compParents[topB] = topA;
|
||||||
|
SMART_LOG ("topA: " << logComp (topA) << " topB: " << logComp (topB));
|
||||||
#ifdef SMART_LOG
|
if (grandParB == DimImg_MAX)
|
||||||
LOG ("connect comp topB:" << topB << " topA:" << topA << " (" << childCountRec [topA] << ")");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (parB == DimImg_MAX)
|
|
||||||
return;
|
return;
|
||||||
--childCountRec[parB];
|
BOOST_ASSERT (childCountRec [grandParB]);
|
||||||
topB = findTopComp (topA, compWeights[parB], weightFunct);
|
--childCountRec[grandParB];
|
||||||
topA = parB;
|
SMART_LOG ("grandParB: " << logComp (grandParB));
|
||||||
|
topB = topA;
|
||||||
|
topA = findTopComp (grandParB, compWeights[topA], weightFunct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -529,7 +479,7 @@ template<typename WeightT, typename PixelT>
|
|||||||
template<typename WeightFunct>
|
template<typename WeightFunct>
|
||||||
inline DimImg
|
inline DimImg
|
||||||
ArrayTreeBuilder<WeightT, PixelT>::updateNewId (const vector<DimImg> &compBases, const vector<DimImg> &compTops,
|
ArrayTreeBuilder<WeightT, PixelT>::updateNewId (const vector<DimImg> &compBases, const vector<DimImg> &compTops,
|
||||||
const WeightFunct &weightFunct) {
|
const WeightFunct &weightFunct) {
|
||||||
// DEF_LOG ("ArrayTreeBuilder::updateNewId", "");
|
// DEF_LOG ("ArrayTreeBuilder::updateNewId", "");
|
||||||
DimImg compCount = compBases[0];
|
DimImg compCount = compBases[0];
|
||||||
vector<DimImg> sizes (compBases.size ());
|
vector<DimImg> sizes (compBases.size ());
|
||||||
@ -553,6 +503,9 @@ ArrayTreeBuilder<WeightT, PixelT>::updateNewId (const DimImg curComp, DimImg &co
|
|||||||
// top already set
|
// top already set
|
||||||
return;
|
return;
|
||||||
const DimImg &top = findCompMultiChild (curComp);
|
const DimImg &top = findCompMultiChild (curComp);
|
||||||
|
BOOST_ASSERT (top != DimImg_MAX);
|
||||||
|
BOOST_ASSERT (childCountRec[top]);
|
||||||
|
|
||||||
if (curComp != top) {
|
if (curComp != top) {
|
||||||
// 0 => merge || no more child
|
// 0 => merge || no more child
|
||||||
// 1 => unnecessary node
|
// 1 => unnecessary node
|
||||||
@ -592,9 +545,7 @@ template<typename WeightT, typename PixelT>
|
|||||||
inline void
|
inline void
|
||||||
ArrayTreeBuilder<WeightT, PixelT>::compress (const DimImg &compTop) {
|
ArrayTreeBuilder<WeightT, PixelT>::compress (const DimImg &compTop) {
|
||||||
|
|
||||||
#ifdef SMART_LOG
|
SMART_DEF_LOG ("ArrayTreeBuilder::compress", " compTop:" << compTop);
|
||||||
DEF_LOG ("ArrayTreeBuilder::compress", " compTop:" << compTop);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
dealThreadRange (leafCount, coreCount, [this] (const DimImg &leaf) {
|
dealThreadRange (leafCount, coreCount, [this] (const DimImg &leaf) {
|
||||||
DimImg old = leafParents[leaf];
|
DimImg old = leafParents[leaf];
|
||||||
@ -616,9 +567,7 @@ ArrayTreeBuilder<WeightT, PixelT>::compress (const DimImg &compTop) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SMART_LOG
|
SMART_LOG ("comp curComp:" << curComp << " newIdxComp:" << newIdxComp);
|
||||||
LOG ("comp curComp:" << curComp << " newIdxComp:" << newIdxComp);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
swap (compParents[curComp], compParents[newIdxComp]);
|
swap (compParents[curComp], compParents[newIdxComp]);
|
||||||
swap (compWeights[curComp], compWeights[newIdxComp]);
|
swap (compWeights[curComp], compWeights[newIdxComp]);
|
||||||
@ -630,12 +579,11 @@ ArrayTreeBuilder<WeightT, PixelT>::compress (const DimImg &compTop) {
|
|||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
template<typename WeightT, typename PixelT>
|
template<typename WeightT, typename PixelT>
|
||||||
inline void
|
inline DimImg
|
||||||
ArrayTreeBuilder<WeightT, PixelT>::createParent (DimImg &topParent, const WeightT &weight, DimImg &childA, DimImg &childB) {
|
ArrayTreeBuilder<WeightT, PixelT>::createParent (DimImg &topParent, const WeightT &weight, DimImg &parentChildA, DimImg &parentChildB) {
|
||||||
childCountRec [topParent] = 2;
|
childCountRec [topParent] = 2;
|
||||||
compWeights [topParent] = weight;
|
compWeights [topParent] = weight;
|
||||||
childA = childB = topParent;
|
return parentChildA = parentChildB = topParent++;
|
||||||
++topParent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
@ -651,6 +599,7 @@ template<typename WeightT, typename PixelT>
|
|||||||
inline void
|
inline void
|
||||||
ArrayTreeBuilder<WeightT, PixelT>::addChildren (const DimImg &parent, const DimImg &sibling) {
|
ArrayTreeBuilder<WeightT, PixelT>::addChildren (const DimImg &parent, const DimImg &sibling) {
|
||||||
childCountRec [parent] += childCountRec [sibling];
|
childCountRec [parent] += childCountRec [sibling];
|
||||||
|
childCountRec [sibling] = 0;
|
||||||
compParents [sibling] = parent;
|
compParents [sibling] = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -686,6 +635,10 @@ template<typename WeightT, typename PixelT>
|
|||||||
template<typename WeightFunct>
|
template<typename WeightFunct>
|
||||||
inline DimImg
|
inline DimImg
|
||||||
ArrayTreeBuilder<WeightT, PixelT>::findTopComp (DimImg comp, const WeightT &weight, const WeightFunct &weightFunct) {
|
ArrayTreeBuilder<WeightT, PixelT>::findTopComp (DimImg comp, const WeightT &weight, const WeightFunct &weightFunct) {
|
||||||
|
if (comp == DimImg_MAX)
|
||||||
|
return DimImg_MAX;
|
||||||
|
if (weightFunct.isWeightInf (weight, compWeights [comp]))
|
||||||
|
return findTopComp (comp, compWeights [comp], weightFunct);
|
||||||
DimImg last = comp;
|
DimImg last = comp;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (comp == DimImg_MAX)
|
if (comp == DimImg_MAX)
|
||||||
@ -719,9 +672,7 @@ template<typename WeightT, typename PixelT>
|
|||||||
inline void
|
inline void
|
||||||
ArrayTreeBuilder<WeightT, PixelT>::buildChildren () {
|
ArrayTreeBuilder<WeightT, PixelT>::buildChildren () {
|
||||||
|
|
||||||
#ifdef SMART_LOG
|
SMART_DEF_LOG ("ArrayTreeBuilder::buildChildren", "");
|
||||||
DEF_LOG ("ArrayTreeBuilder::buildChildren", "");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
BOOST_ASSERT (childCount[0] == 0);
|
BOOST_ASSERT (childCount[0] == 0);
|
||||||
BOOST_ASSERT (childCount[1] == 0);
|
BOOST_ASSERT (childCount[1] == 0);
|
||||||
@ -740,48 +691,31 @@ ArrayTreeBuilder<WeightT, PixelT>::buildChildren () {
|
|||||||
BOOST_ASSERT (childCount[0] == 0);
|
BOOST_ASSERT (childCount[0] == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------
|
// ========================================
|
||||||
template<typename WeightT, typename PixelT>
|
template<typename WeightT, typename PixelT>
|
||||||
template<typename WeightFunct>
|
ArrayTreeBuilder<WeightT, PixelT>::CLogComp::CLogComp (const ArrayTreeBuilder &atb, const DimImg &compId)
|
||||||
inline void
|
: atb (atb), compId (compId) {
|
||||||
ArrayTreeBuilder<WeightT, PixelT>::initWeights (const GraphWalker &graphWalker, const WeightFunct &weightFunct) {
|
}
|
||||||
|
template<typename WeightT, typename PixelT>
|
||||||
#ifdef SMART_LOG
|
inline ostream &
|
||||||
DEF_LOG ("ArrayTreeBuilder::initCompWeights", "leafCount:" << leafCount);
|
ArrayTreeBuilder<WeightT, PixelT>::CLogComp::print (ostream &out) const {
|
||||||
dealThreadFill_n (leafCount, coreCount, compWeights, 0);
|
if (compId == DimImg_MAX)
|
||||||
#endif
|
return out << "M(-/-)";
|
||||||
|
return out << compId << "(" << atb.childCountRec[compId] << "/" << atb.compWeights [compId] << ")";
|
||||||
// graphWalker.forEachVertexIdx ([this, &weightFunct] (const DimImg &compIdx){
|
|
||||||
// mapWeights[compIdx] = weightFunct.getWeight (compIdx);
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================================
|
|
||||||
// #ifdef ENABLE_LOG
|
|
||||||
// template<typename WeightT, typename PixelT>
|
// template<typename WeightT, typename PixelT>
|
||||||
// inline void
|
// inline ArrayTreeBuilder<WeightT, PixelT>::CLogComp
|
||||||
// ArrayTreeBuilder<WeightT, PixelT>::printTree (const Size &size, const bool &rec) {
|
// ArrayTreeBuilder<WeightT, PixelT>::logComp (const DimImg &compId) const {
|
||||||
// cout << "tree weight parent " << (rec ? "countRec" : "count children") << endl;
|
// return ArrayTreeBuilder<WeightT, PixelT>::CLogComp (*this, compId);
|
||||||
// Size doubleSize (size.width, 2*size.height);
|
|
||||||
// triskele::printMap (cout, compWeights, size, (DimNodeId) getCompCount ()) << endl;
|
|
||||||
// triskele::printMap (cout, leafParents, doubleSize) << endl;
|
|
||||||
// triskele::printMap (cout, rec ? childCountRec : childCount, size) << endl;
|
|
||||||
// if (!rec)
|
|
||||||
// printMap (cout, children, doubleSize, nodeCount) << endl << endl;
|
|
||||||
// }
|
// }
|
||||||
// template<typename WeightT, typename PixelT>
|
|
||||||
// inline void
|
|
||||||
// ArrayTreeBuilder<WeightT, PixelT>::printLeaders (const Size &size) {
|
|
||||||
// cout << "leaders" << endl;
|
|
||||||
// triskele::printMap (cout, newCompId, size) << endl;
|
|
||||||
// }
|
|
||||||
// template<typename WeightT, typename PixelT>
|
|
||||||
// inline void
|
|
||||||
// ArrayTreeBuilder<WeightT, PixelT>::printNewCompId (const Size &size) {
|
|
||||||
// cout << "newCompId" << endl;
|
|
||||||
// triskele::printMap (cout, newCompId, size) << endl;
|
|
||||||
// }
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
|
// template<typename WeightT, typename PixelT>
|
||||||
|
// inline ostream&
|
||||||
|
// operator << (ostream& out, const ArrayTreeBuilder<WeightT, PixelT>::CLogComp &lc) {
|
||||||
|
// return lc.print (out);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
|
||||||
#endif // _OTB_TRISKELE_ARRAY_TREE_BUILDER_TPP
|
#endif // _OTB_TRISKELE_ARRAY_TREE_BUILDER_TPP
|
||||||
|
|||||||
@ -61,6 +61,8 @@ namespace otb {
|
|||||||
|
|
||||||
/*! Tableau "simplifié" des pixels */
|
/*! Tableau "simplifié" des pixels */
|
||||||
uint8_t *map;
|
uint8_t *map;
|
||||||
|
|
||||||
|
friend inline ostream &operator << (ostream &out, const Border &border);
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "Border.tpp"
|
#include "Border.tpp"
|
||||||
|
|||||||
@ -79,4 +79,16 @@ Border::borderCount () {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline ostream &operator << (ostream &out, const Border &border) {
|
||||||
|
if (border.size.width > printMapMaxSide || border.size.height > printMapMaxSide) {
|
||||||
|
return out << "map too big to print!" << std::endl;
|
||||||
|
}
|
||||||
|
for (DimSideImg y = 0, idx = 0; y < border.size.height; ++y) {
|
||||||
|
for (DimSideImg x = 0; x < border.size.width; ++x, ++idx)
|
||||||
|
out << (border.isBorder (idx) ? " B " : " - ");
|
||||||
|
out << endl;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // _OTB_TRISKELE_ARRAY_TREE_BORDER_HPP
|
#endif // _OTB_TRISKELE_ARRAY_TREE_BORDER_HPP
|
||||||
|
|||||||
@ -24,6 +24,7 @@ namespace otb {
|
|||||||
namespace arrayTree {
|
namespace arrayTree {
|
||||||
|
|
||||||
using namespace ::triskele;
|
using namespace ::triskele;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
/** GraphWalker */
|
/** GraphWalker */
|
||||||
class GraphWalker {
|
class GraphWalker {
|
||||||
@ -40,7 +41,8 @@ namespace otb {
|
|||||||
inline DimEdge edgeBoundaryMaxCount (const DimSideImg &side) const;
|
inline DimEdge edgeBoundaryMaxCount (const DimSideImg &side) const;
|
||||||
|
|
||||||
inline void setTiles (const unsigned int &coreCount, const Rect &tile,
|
inline void setTiles (const unsigned int &coreCount, const Rect &tile,
|
||||||
std::vector<Rect> &tiles, std::vector<Rect> &boundaries, std::vector<bool> &verticalBoundaries) const;
|
vector<Rect> &tiles, vector<Rect> &boundaries, vector<bool> &verticalBoundaries) const;
|
||||||
|
inline void setMaxBounds (const vector<Rect> &tiles, vector<DimImg> &vertexMaxBounds, vector<DimImg> &edgesMaxBounds) const;
|
||||||
|
|
||||||
template<typename Funct>
|
template<typename Funct>
|
||||||
inline DimImg forEachVertexIdx (const Funct &lambda /*lambda (idx)*/) const;
|
inline DimImg forEachVertexIdx (const Funct &lambda /*lambda (idx)*/) const;
|
||||||
|
|||||||
@ -65,7 +65,7 @@ GraphWalker::edgeBoundaryMaxCount (const DimSideImg &side) const {
|
|||||||
// ========================================
|
// ========================================
|
||||||
inline void
|
inline void
|
||||||
GraphWalker::setTiles (const unsigned int &coreCount, const Rect &tile,
|
GraphWalker::setTiles (const unsigned int &coreCount, const Rect &tile,
|
||||||
std::vector<Rect> &tiles, std::vector<Rect> &boundaries, std::vector<bool> &verticalBoundaries) const {
|
vector<Rect> &tiles, vector<Rect> &boundaries, vector<bool> &verticalBoundaries) const {
|
||||||
BOOST_ASSERT (coreCount);
|
BOOST_ASSERT (coreCount);
|
||||||
DEF_LOG ("GraphWalker::setTiles", "coreCount:" << coreCount << " tile:" << tile);
|
DEF_LOG ("GraphWalker::setTiles", "coreCount:" << coreCount << " tile:" << tile);
|
||||||
if (coreCount < 2 || max (tile.width, tile.height) < 4 || min (tile.width, tile.height) < 3) {
|
if (coreCount < 2 || max (tile.width, tile.height) < 4 || min (tile.width, tile.height) < 3) {
|
||||||
@ -93,10 +93,24 @@ GraphWalker::setTiles (const unsigned int &coreCount, const Rect &tile,
|
|||||||
setTiles ((odd ? coreCount-1 : coreCount/2), tileB, tiles, boundaries, verticalBoundaries);
|
setTiles ((odd ? coreCount-1 : coreCount/2), tileB, tiles, boundaries, verticalBoundaries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
GraphWalker::setMaxBounds (const vector<Rect> &tiles, vector<DimImg> &vertexMaxBounds, vector<DimImg> &edgesMaxBounds) const {
|
||||||
|
unsigned int tileCount = tiles.size ();
|
||||||
|
vertexMaxBounds.resize (tileCount+1);
|
||||||
|
edgesMaxBounds.resize (tileCount+1);
|
||||||
|
DimImg vertexBase = 0, edgesBase = 0;
|
||||||
|
vertexMaxBounds [0] = edgesMaxBounds [0] = 0;
|
||||||
|
for (unsigned int i = 0; i < tileCount; ++i) {
|
||||||
|
Size zoneSize (tiles[i].width, tiles[i].height);
|
||||||
|
vertexMaxBounds [i+1] = vertexBase += vertexMaxCount (zoneSize); /* -1, but prety LOG */
|
||||||
|
edgesMaxBounds [i+1] = edgesBase += edgeMaxCount (zoneSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
template<typename Funct>
|
template<typename Funct>
|
||||||
inline DimImg
|
inline DimImg
|
||||||
GraphWalker::forEachVertexIdx (const Funct &lambda /*lambda (idx)*/) const {
|
GraphWalker::forEachVertexIdx (const Funct &lambda /*lambda (DimImg idx)*/) const {
|
||||||
DimImg maxCount = vertexMaxCount ();
|
DimImg maxCount = vertexMaxCount ();
|
||||||
DimImg vertexCount = 0;
|
DimImg vertexCount = 0;
|
||||||
for (DimImg idx = 0; idx < maxCount; ++idx)
|
for (DimImg idx = 0; idx < maxCount; ++idx)
|
||||||
@ -106,7 +120,7 @@ GraphWalker::forEachVertexIdx (const Funct &lambda /*lambda (idx)*/) const {
|
|||||||
|
|
||||||
template<typename Funct>
|
template<typename Funct>
|
||||||
inline DimImg
|
inline DimImg
|
||||||
GraphWalker::forEachVertexIdx (const Rect &rect, const Funct &lambda /*lambda (idx)*/) const {
|
GraphWalker::forEachVertexIdx (const Rect &rect, const Funct &lambda /*lambda (DimImg idx)*/) const {
|
||||||
DimImg vertexCount = 0;
|
DimImg vertexCount = 0;
|
||||||
DimSideImg const lastX = rect.x+rect.width;
|
DimSideImg const lastX = rect.x+rect.width;
|
||||||
DimSideImg const lastY = rect.y+rect.height;
|
DimSideImg const lastY = rect.y+rect.height;
|
||||||
@ -121,7 +135,7 @@ GraphWalker::forEachVertexIdx (const Rect &rect, const Funct &lambda /*lambda (i
|
|||||||
|
|
||||||
template<typename Funct>
|
template<typename Funct>
|
||||||
inline DimImg
|
inline DimImg
|
||||||
GraphWalker::forEachVertexPt (const Rect &rect, const Funct &lambda /*lambda (p)*/) const {
|
GraphWalker::forEachVertexPt (const Rect &rect, const Funct &lambda /*lambda (Point p)*/) const {
|
||||||
DimImg vertexCount = 0;
|
DimImg vertexCount = 0;
|
||||||
DimSideImg const lastX = rect.x+rect.width;
|
DimSideImg const lastX = rect.x+rect.width;
|
||||||
DimSideImg const lastY = rect.y+rect.height;
|
DimSideImg const lastY = rect.y+rect.height;
|
||||||
@ -137,7 +151,7 @@ GraphWalker::forEachVertexPt (const Rect &rect, const Funct &lambda /*lambda (p)
|
|||||||
// ========================================
|
// ========================================
|
||||||
template<typename Funct>
|
template<typename Funct>
|
||||||
inline DimEdge
|
inline DimEdge
|
||||||
GraphWalker::forEachEdgePt (const Rect &rect, TileItem tileItem, const Funct &lambda /*lambda (p0, p1)*/) const {
|
GraphWalker::forEachEdgePt (const Rect &rect, TileItem tileItem, const Funct &lambda /*lambda (Point p0, Point p1)*/) const {
|
||||||
DimImg edgeCount = 0;
|
DimImg edgeCount = 0;
|
||||||
if (!rect.width || !rect.height)
|
if (!rect.width || !rect.height)
|
||||||
return edgeCount;
|
return edgeCount;
|
||||||
@ -228,12 +242,12 @@ GraphWalker::getMedian (const EdgeWeightFunction &ef /*ef.getValue (idx)*/) cons
|
|||||||
int bits = 8*sizeof (WeightT);
|
int bits = 8*sizeof (WeightT);
|
||||||
BOOST_ASSERT (bits < 17);
|
BOOST_ASSERT (bits < 17);
|
||||||
DimEdge dim = 1UL << bits;
|
DimEdge dim = 1UL << bits;
|
||||||
std::vector<DimImg> indices (dim+1, 0);
|
vector<DimImg> indices (dim+1, 0);
|
||||||
DimImg *histogram = &indices[1];
|
DimImg *histogram = &indices[1];
|
||||||
forEachVertexIdx ([&histogram, &ef] (const DimImg &idx) {
|
forEachVertexIdx ([&histogram, &ef] (const DimImg &idx) {
|
||||||
++histogram[(size_t) ef.getValue (idx)];
|
++histogram[(size_t) ef.getValue (idx)];
|
||||||
});
|
});
|
||||||
std::partial_sum (histogram, histogram+dim, histogram);
|
partial_sum (histogram, histogram+dim, histogram);
|
||||||
return lower_bound (indices.begin (), indices.end (), indices[dim] >> 1) - indices.begin ();
|
return lower_bound (indices.begin (), indices.end (), indices[dim] >> 1) - indices.begin ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,8 +273,11 @@ GraphWalker::getEdges (const Rect &rect, TileItem tileItem, Edge<WeightT> *edges
|
|||||||
template <typename WeightT, typename EdgeWeightFunction>
|
template <typename WeightT, typename EdgeWeightFunction>
|
||||||
inline DimEdge
|
inline DimEdge
|
||||||
GraphWalker::getSortedEdges (const Rect &rect, TileItem tileItem, Edge<WeightT> *edges, const EdgeWeightFunction &ef /*ef.getWeight (p0, p1) ef.sort ()*/) const {
|
GraphWalker::getSortedEdges (const Rect &rect, TileItem tileItem, Edge<WeightT> *edges, const EdgeWeightFunction &ef /*ef.getWeight (p0, p1) ef.sort ()*/) const {
|
||||||
|
SMART_DEF_LOG ("GraphWalker::getSortedEdges", "");
|
||||||
DimEdge edgeCount = getEdges (rect, tileItem, edges, ef);
|
DimEdge edgeCount = getEdges (rect, tileItem, edges, ef);
|
||||||
|
// SMART_LOG (endl << printEdges (edges, size, edgeCount));
|
||||||
ef.sort (edges, edgeCount);
|
ef.sort (edges, edgeCount);
|
||||||
|
SMART_LOG (endl << printEdges (edges, size, edgeCount))
|
||||||
return edgeCount;
|
return edgeCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,20 +285,21 @@ template <typename WeightT, typename EdgeWeightFunction>
|
|||||||
// template DimImg
|
// template DimImg
|
||||||
inline DimEdge
|
inline DimEdge
|
||||||
GraphWalker::getCountingSortedEdges (const Rect &rect, TileItem tileItem, Edge<WeightT> *edges, const EdgeWeightFunction &ef /*ef.getWeight (p0, p1)*/) const {
|
GraphWalker::getCountingSortedEdges (const Rect &rect, TileItem tileItem, Edge<WeightT> *edges, const EdgeWeightFunction &ef /*ef.getWeight (p0, p1)*/) const {
|
||||||
|
SMART_DEF_LOG ("GraphWalker::getCountingSortedEdges", "");
|
||||||
int bits = 8*sizeof (WeightT);
|
int bits = 8*sizeof (WeightT);
|
||||||
BOOST_ASSERT (bits < 17);
|
BOOST_ASSERT (bits < 17);
|
||||||
DimEdge dim = 1UL << bits;
|
DimEdge dim = 1UL << bits;
|
||||||
DimImg *indices = new DimImg [dim+1];
|
DimImg *indices = new DimImg [dim+1];
|
||||||
DimImg *histogram = indices+1;
|
DimImg *histogram = indices+1;
|
||||||
DimImg sum = 0;
|
DimImg sum = 0;
|
||||||
::std::fill_n (histogram, dim, 0);
|
fill_n (histogram, dim, 0);
|
||||||
forEachEdgePt (rect, tileItem,
|
forEachEdgePt (rect, tileItem,
|
||||||
[&histogram, &ef] (Point const &a, Point const &b) {
|
[&histogram, &ef] (Point const &a, Point const &b) {
|
||||||
++histogram[(size_t) ef.getWeight (a, b)];
|
++histogram[(size_t) ef.getWeight (a, b)];
|
||||||
});
|
});
|
||||||
|
|
||||||
// get indices by prefix sum
|
// get indices by prefix sum
|
||||||
std::partial_sum (histogram, histogram+dim, histogram);
|
partial_sum (histogram, histogram+dim, histogram);
|
||||||
sum = indices[dim];
|
sum = indices[dim];
|
||||||
if (ef.getDecr ()) {
|
if (ef.getDecr ()) {
|
||||||
for (size_t i = 0; i < dim; ++i)
|
for (size_t i = 0; i < dim; ++i)
|
||||||
@ -292,7 +310,7 @@ GraphWalker::getCountingSortedEdges (const Rect &rect, TileItem tileItem, Edge<W
|
|||||||
// extract edges
|
// extract edges
|
||||||
forEachEdgePt (rect, tileItem,
|
forEachEdgePt (rect, tileItem,
|
||||||
[
|
[
|
||||||
#ifdef SMART_LOG
|
#ifdef ENABLE_SMART_LOG
|
||||||
this,
|
this,
|
||||||
#endif
|
#endif
|
||||||
&ef, &edges, &indices] (Point const &a, Point const &b) {
|
&ef, &edges, &indices] (Point const &a, Point const &b) {
|
||||||
@ -301,15 +319,9 @@ GraphWalker::getCountingSortedEdges (const Rect &rect, TileItem tileItem, Edge<W
|
|||||||
edge.points[0] = a;
|
edge.points[0] = a;
|
||||||
edge.points[1] = b;
|
edge.points[1] = b;
|
||||||
edge.weight = weight;
|
edge.weight = weight;
|
||||||
#ifdef SMART_LOG
|
SMART_LOG_EXPR (cerr << printEdge (edge, size) << endl);
|
||||||
printEdge (cerr, edge, size) << endl;
|
|
||||||
#endif
|
|
||||||
});
|
});
|
||||||
#ifdef SMART_LOG
|
SMART_LOG (endl << printEdges (edges, size, sum));
|
||||||
cerr << endl;
|
|
||||||
for (int i = 0; i < sum; ++i)
|
|
||||||
printEdge (cerr, edges[i], size) << endl;
|
|
||||||
#endif
|
|
||||||
delete [] (histogram-1);
|
delete [] (histogram-1);
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,9 +16,7 @@ Leader::~Leader () {
|
|||||||
// ========================================
|
// ========================================
|
||||||
inline void
|
inline void
|
||||||
Leader::book (DimImg vertexCount) {
|
Leader::book (DimImg vertexCount) {
|
||||||
#ifdef SMART_LOG
|
SMART_DEF_LOG ("Leader::book", "vertexCount:" << vertexCount);
|
||||||
DEF_LOG ("Leader::book", "vertexCount:" << vertexCount);
|
|
||||||
#endif
|
|
||||||
if (vertexCount == size) {
|
if (vertexCount == size) {
|
||||||
reset ();
|
reset ();
|
||||||
return;
|
return;
|
||||||
@ -34,9 +32,7 @@ Leader::book (DimImg vertexCount) {
|
|||||||
// ---------------------------------------
|
// ---------------------------------------
|
||||||
inline void
|
inline void
|
||||||
Leader::free () {
|
Leader::free () {
|
||||||
#ifdef SMART_LOG
|
SMART_DEF_LOG ("Leader::free", "");
|
||||||
DEF_LOG ("Leader::free", "");
|
|
||||||
#endif
|
|
||||||
if (leaders)
|
if (leaders)
|
||||||
delete [] leaders;
|
delete [] leaders;
|
||||||
leaders = NULL;
|
leaders = NULL;
|
||||||
|
|||||||
@ -15,6 +15,7 @@ namespace otb {
|
|||||||
|
|
||||||
class GraphWalker;
|
class GraphWalker;
|
||||||
using namespace ::triskele;
|
using namespace ::triskele;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
/*! Nombre de voisins */
|
/*! Nombre de voisins */
|
||||||
typedef uint32_t DimEdge; // ~4*nbPixels (8-connectivity)
|
typedef uint32_t DimEdge; // ~4*nbPixels (8-connectivity)
|
||||||
@ -29,23 +30,23 @@ namespace otb {
|
|||||||
enum TreeType { MIN, MAX, TOS, ALPHA, TreeTypeCard};
|
enum TreeType { MIN, MAX, TOS, ALPHA, TreeTypeCard};
|
||||||
|
|
||||||
/*! Définit les noms des connectivités (utile pour le debug) */
|
/*! Définit les noms des connectivités (utile pour le debug) */
|
||||||
extern std::string connectivityName[];
|
extern string connectivityName[];
|
||||||
|
|
||||||
/*! Définit les noms des tileItem (utile pour le debug) */
|
/*! Définit les noms des tileItem (utile pour le debug) */
|
||||||
extern std::string tileItemName[];
|
extern string tileItemName[];
|
||||||
|
|
||||||
/*! Définit les noms des arbres (utile pour le debug) */
|
/*! Définit les noms des arbres (utile pour le debug) */
|
||||||
extern std::string treeTypeLabels[];
|
extern string treeTypeLabels[];
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Opérateur de flux sur les connectivités
|
* Opérateur de flux sur les connectivités
|
||||||
*/
|
*/
|
||||||
inline std::ostream &operator << (std::ostream &out, const Connectivity &c);
|
inline ostream &operator << (ostream &out, const Connectivity &c);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Opérateur de flux sur les TileItem
|
* Opérateur de flux sur les TileItem
|
||||||
*/
|
*/
|
||||||
inline std::ostream &operator << (std::ostream &out, const TileItem &t);
|
inline ostream &operator << (ostream &out, const TileItem &t);
|
||||||
|
|
||||||
template <typename WeightT> struct Edge {
|
template <typename WeightT> struct Edge {
|
||||||
Point points[2];
|
Point points[2];
|
||||||
@ -58,20 +59,31 @@ namespace otb {
|
|||||||
|
|
||||||
/*! Opérateur de flux sur les voisins */
|
/*! Opérateur de flux sur les voisins */
|
||||||
template <typename WeightT>
|
template <typename WeightT>
|
||||||
inline std::ostream &operator << (std::ostream &out, const Edge<WeightT> &edge);
|
struct CPrintEdge {
|
||||||
|
const Edge<WeightT> &edge;
|
||||||
|
const Size &size;
|
||||||
|
inline CPrintEdge (const Edge<WeightT> &edge, const Size &size);
|
||||||
|
inline ostream &print (ostream &out) const;
|
||||||
|
};
|
||||||
template <typename WeightT>
|
template <typename WeightT>
|
||||||
inline std::ostream &printEdge (std::ostream &out, const Edge<WeightT> &edge, const Size &size);
|
inline CPrintEdge<WeightT> printEdge (const Edge<WeightT> &edge, const Size &size);
|
||||||
|
|
||||||
/*! Affiche tous les voisins d'un ensemble */
|
template <typename WeightT>
|
||||||
template <typename Edge>
|
inline ostream &operator << (ostream& out, const CPrintEdge<WeightT> &cpe) { return cpe.print (out); }
|
||||||
inline std::ostream &printEdges (std::ostream &out, const std::vector<Edge> &edges);
|
|
||||||
|
|
||||||
template <typename Edge>
|
template <typename WeightT>
|
||||||
inline std::ostream &printEdges (std::ostream &out, const Edge edges[], const Size &size, const DimEdge edgesCount);
|
struct CPrintEdges {
|
||||||
|
const Edge<WeightT> *edges;
|
||||||
|
const Size &size;
|
||||||
|
const DimEdge edgesCount;
|
||||||
|
inline CPrintEdges (const Edge<WeightT> edges[], const Size &size, const DimEdge edgesCount);
|
||||||
|
inline ostream &print (ostream &out) const;
|
||||||
|
};
|
||||||
|
template <typename WeightT>
|
||||||
|
inline CPrintEdges<WeightT> printEdges (const Edge<WeightT> edges[], const Size &size, const DimEdge edgesCount);
|
||||||
|
|
||||||
/*! Affiche tous les voisins d'un ensembles à l'aide de leurs coordonnées */
|
template <typename WeightT>
|
||||||
template <typename Edge>
|
inline ostream &operator << (ostream& out, const CPrintEdges<WeightT> &cpe) { return cpe.print (out); }
|
||||||
inline std::ostream &printEdges (std::ostream &out, const std::vector<Edge> &edges, const Size &size);
|
|
||||||
|
|
||||||
#include "triskeleArrayTreeBase.tpp"
|
#include "triskeleArrayTreeBase.tpp"
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
#ifndef _OTB_TRISKELE_ARRAY_TREE_BASE_TPP
|
#ifndef _OTB_TRISKELE_ARRAY_TREE_BASE_TPP
|
||||||
#define _OTB_TRISKELE_ARRAY_TREE_BASE_TPP
|
#define _OTB_TRISKELE_ARRAY_TREE_BASE_TPP
|
||||||
|
|
||||||
inline std::ostream &
|
inline ostream &
|
||||||
operator << (std::ostream &out, const Connectivity &c) {
|
operator << (ostream &out, const Connectivity &c) {
|
||||||
BOOST_ASSERT (c >= 0 && c < 4);
|
BOOST_ASSERT (c >= 0 && c < 4);
|
||||||
return out << connectivityName[c];
|
return out << connectivityName[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::ostream &
|
inline ostream &
|
||||||
operator << (std::ostream &out, const TileItem &t) {
|
operator << (ostream &out, const TileItem &t) {
|
||||||
BOOST_ASSERT (t >= 0 && t < 3);
|
BOOST_ASSERT (t >= 0 && t < 3);
|
||||||
return out << tileItemName[t];
|
return out << tileItemName[t];
|
||||||
}
|
}
|
||||||
@ -21,43 +21,50 @@ swapEdge (Edge<WeightT> &a, Edge<WeightT> &b) {
|
|||||||
b = c;
|
b = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========================================
|
||||||
template <typename WeightT>
|
template <typename WeightT>
|
||||||
inline std::ostream &
|
inline
|
||||||
operator << (std::ostream &out, const Edge<WeightT> &edge) {
|
CPrintEdge<WeightT>::CPrintEdge (const Edge<WeightT> &edge, const Size &size)
|
||||||
return out << edge.points[0] << ":" << edge.points[1] << ":" << edge.weight;
|
: edge (edge),
|
||||||
|
size (size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename WeightT>
|
template <typename WeightT>
|
||||||
inline std::ostream &
|
inline ostream &
|
||||||
printEdge (std::ostream &out, const Edge<WeightT> &edge, const Size &size) {
|
CPrintEdge<WeightT>::print (ostream &out) const {
|
||||||
return out << edge.points[0] << ":" << edge.points[1] << ":" << ((uint32_t) edge.weight) << ":"
|
// XXX if WeightT == uint8_t => print char :-(
|
||||||
|
return out << edge.points[0] << ":" << edge.points[1] << ":" << edge.weight << ":"
|
||||||
<< point2idx (size, edge.points[0]) << ":" << point2idx (size, edge.points[1]);
|
<< point2idx (size, edge.points[0]) << ":" << point2idx (size, edge.points[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Edge>
|
template <typename WeightT>
|
||||||
inline std::ostream &
|
inline CPrintEdge<WeightT>
|
||||||
printEdges (std::ostream &out, const std::vector<Edge> &edges) {
|
printEdge (const Edge<WeightT> &edge, const Size &size) {
|
||||||
for (int i = 0; i < edges.size (); ++i)
|
return CPrintEdge<WeightT> (edge, size);
|
||||||
out << " " << edges [i];
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Edge>
|
// ========================================
|
||||||
inline std::ostream &
|
template <typename WeightT>
|
||||||
printEdges (std::ostream &out, const Edge edges[], const Size &size, const DimEdge edgesCount) {
|
inline
|
||||||
|
CPrintEdges<WeightT>::CPrintEdges (const Edge<WeightT> edges[], const Size &size, const DimEdge edgesCount)
|
||||||
|
: edges (edges),
|
||||||
|
size (size),
|
||||||
|
edgesCount (edgesCount) {
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename WeightT>
|
||||||
|
inline
|
||||||
|
ostream &
|
||||||
|
CPrintEdges<WeightT>::print (ostream &out) const {
|
||||||
for (int i = 0; i < edgesCount; ++i)
|
for (int i = 0; i < edgesCount; ++i)
|
||||||
printEdge (out, edges[i], size) << std::endl;
|
out << printEdge (edges[i], size) << endl;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Edge>
|
template <typename WeightT>
|
||||||
inline std::ostream &
|
inline CPrintEdges<WeightT>
|
||||||
printEdges (std::ostream &out, const std::vector<Edge> &edges, const Size &size) {
|
printEdges (const Edge<WeightT> edges[], const Size &size, const DimEdge edgesCount) {
|
||||||
for (int i = 0; i < edges.size (); ++i)
|
return CPrintEdges<WeightT> (edges, size, edgesCount);
|
||||||
out << " [" << point2idx (size, edges [i].points[0])
|
|
||||||
<< " " << point2idx (size, edges [i].points[1])
|
|
||||||
<< " " << edges [i].weight << "]";
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // _OTB_TRISKELE_ARRAY_TREE_BASE_TPP
|
#endif // _OTB_TRISKELE_ARRAY_TREE_BASE_TPP
|
||||||
|
|||||||
@ -15,7 +15,6 @@ namespace otb {
|
|||||||
inline void updateTranscient ();
|
inline void updateTranscient ();
|
||||||
inline PixelT *getValues ();
|
inline PixelT *getValues ();
|
||||||
inline const PixelT *getValues () const;
|
inline const PixelT *getValues () const;
|
||||||
inline void printValues () const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const Tree &tree;
|
const Tree &tree;
|
||||||
@ -24,8 +23,12 @@ namespace otb {
|
|||||||
|
|
||||||
inline void free ();
|
inline void free ();
|
||||||
inline void book (const DimImg &leafCount);
|
inline void book (const DimImg &leafCount);
|
||||||
|
|
||||||
|
ostream &print (ostream &out) const;
|
||||||
|
friend ostream &operator << (ostream& out, const AttributeProfiles &ap) { return ap.print (out); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#include "AttributeProfiles.tpp"
|
#include "AttributeProfiles.tpp"
|
||||||
} // triskele
|
} // triskele
|
||||||
} // otb
|
} // otb
|
||||||
|
|||||||
@ -34,14 +34,6 @@ AttributeProfiles<PixelT>::getValues () const {
|
|||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename PixelT>
|
|
||||||
inline void
|
|
||||||
AttributeProfiles<PixelT>::printValues () const {
|
|
||||||
cout << "AP" << endl;
|
|
||||||
const Size doubleSize (tree.getSize().width, 2*tree.getSize ().height);
|
|
||||||
printMap (cout, values, doubleSize, tree.getNodeCount ()) << endl << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
inline void
|
inline void
|
||||||
AttributeProfiles<PixelT>::free () {
|
AttributeProfiles<PixelT>::free () {
|
||||||
@ -62,4 +54,13 @@ AttributeProfiles<PixelT>::book (const DimImg &leafCount) {
|
|||||||
values = new PixelT[leafCount*2];
|
values = new PixelT[leafCount*2];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
template<typename PixelT>
|
||||||
|
ostream &
|
||||||
|
AttributeProfiles<PixelT>::print (ostream &out) const {
|
||||||
|
const Size doubleSize (tree.getSize().width, 2*tree.getSize ().height);
|
||||||
|
out << "AP" << endl
|
||||||
|
<< printMap (values, doubleSize, tree.getNodeCount ()) << endl << endl;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP
|
#endif // _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP
|
||||||
|
|||||||
@ -17,6 +17,7 @@ namespace otb {
|
|||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
const vector<DimImg> &thresholds) const;
|
const vector<DimImg> &thresholds) const;
|
||||||
|
virtual inline ostream &print (ostream &out) const { CompAttribute::print (out, "area"); }
|
||||||
protected:
|
protected:
|
||||||
inline void compute ();
|
inline void compute ();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -16,6 +16,7 @@ namespace otb {
|
|||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
inline AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes);
|
inline AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes);
|
||||||
inline ~AverageAttributes ();
|
inline ~AverageAttributes ();
|
||||||
|
virtual inline ostream &print (ostream &out) const { CompAttribute::print (out, "average"); }
|
||||||
protected:
|
protected:
|
||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
inline void compute (const Raster<PixelT> &raster, const AreaAttributes &areaAttributes);
|
inline void compute (const Raster<PixelT> &raster, const AreaAttributes &areaAttributes);
|
||||||
|
|||||||
@ -13,6 +13,7 @@ namespace otb {
|
|||||||
public:
|
public:
|
||||||
inline MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes);
|
inline MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes);
|
||||||
inline ~MoIAttributes ();
|
inline ~MoIAttributes ();
|
||||||
|
virtual inline ostream &print (ostream &out) const { CompAttribute::print (out, "moi"); }
|
||||||
|
|
||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
|
|||||||
@ -15,6 +15,7 @@ namespace otb {
|
|||||||
public:
|
public:
|
||||||
inline SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes);
|
inline SDAttributes (const Tree &tree, const AreaAttributes &areaAttributes);
|
||||||
inline ~SDAttributes ();
|
inline ~SDAttributes ();
|
||||||
|
virtual inline ostream &print (ostream &out) const { CompAttribute::print (out, "sd"); }
|
||||||
|
|
||||||
template<typename PixelT>
|
template<typename PixelT>
|
||||||
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
inline void cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
||||||
|
|||||||
@ -15,6 +15,8 @@ namespace otb {
|
|||||||
inline ~WeightAttributes ();
|
inline ~WeightAttributes ();
|
||||||
|
|
||||||
inline void setWeightBounds (Tree &tree);
|
inline void setWeightBounds (Tree &tree);
|
||||||
|
|
||||||
|
virtual inline ostream &print (ostream &out) const { CompAttribute<WeightT>::print (out, "weight"); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "WeightAttributes.tpp"
|
#include "WeightAttributes.tpp"
|
||||||
|
|||||||
@ -9,15 +9,20 @@
|
|||||||
|
|
||||||
namespace otb {
|
namespace otb {
|
||||||
namespace triskele {
|
namespace triskele {
|
||||||
|
using namespace ::triskele;
|
||||||
|
|
||||||
struct AverageXY {
|
struct AverageXY {
|
||||||
double x, y;
|
double x, y;
|
||||||
inline AverageXY () : x(0), y(0) {}
|
inline AverageXY () : x(0), y(0) {}
|
||||||
|
friend ostream &operator << (ostream& out, const AverageXY &xy) { return out << "(" << xy.x << ", " << xy.y << ")"; }
|
||||||
|
operator DimImg () const { return (DimImg) (x*y); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class XYAttributes : public CompAttributeC<AverageXY> {
|
class XYAttributes : public CompAttributeC<AverageXY> {
|
||||||
public:
|
public:
|
||||||
inline XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes);
|
inline XYAttributes (const Tree &tree, const AreaAttributes &areaAttributes);
|
||||||
inline ~XYAttributes ();
|
inline ~XYAttributes ();
|
||||||
|
virtual inline ostream &print (ostream &out) const { CompAttribute::print (out, "xy"); }
|
||||||
protected:
|
protected:
|
||||||
inline void compute (const AreaAttributes &areaAttributes);
|
inline void compute (const AreaAttributes &areaAttributes);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -21,7 +21,8 @@ namespace otb {
|
|||||||
inline const AttrT *getValues () const;
|
inline const AttrT *getValues () const;
|
||||||
inline AttrT *getValues ();
|
inline AttrT *getValues ();
|
||||||
inline AttrT getMaxValue () const;
|
inline AttrT getMaxValue () const;
|
||||||
inline void printValues (const string &msg) const;
|
|
||||||
|
virtual inline ostream &print (ostream &out) const { print (out, ""); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const Tree &tree;
|
const Tree &tree;
|
||||||
@ -30,6 +31,9 @@ namespace otb {
|
|||||||
|
|
||||||
inline void free ();
|
inline void free ();
|
||||||
inline void book (const DimImg &leafCount);
|
inline void book (const DimImg &leafCount);
|
||||||
|
|
||||||
|
ostream &print (ostream &out, const string &msg) const;
|
||||||
|
friend ostream &operator << (ostream& out, const CompAttribute &ca) { return ca.print (out); }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // triskele
|
} // triskele
|
||||||
|
|||||||
@ -19,6 +19,7 @@ CompAttribute<AttrT>::~CompAttribute () {
|
|||||||
template<typename AttrT>
|
template<typename AttrT>
|
||||||
inline void
|
inline void
|
||||||
CompAttribute<AttrT>::updateTranscient () {
|
CompAttribute<AttrT>::updateTranscient () {
|
||||||
|
// XXX max : leafCount-1
|
||||||
book (tree.getLeafCount ());
|
book (tree.getLeafCount ());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,11 +49,11 @@ CompAttribute<AttrT>::getMaxValue () const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename AttrT>
|
template<typename AttrT>
|
||||||
inline void
|
inline ostream &
|
||||||
CompAttribute<AttrT>::printValues (const string &msg) const {
|
CompAttribute<AttrT>::print (ostream &out, const string &msg) const {
|
||||||
cout << "values: " << msg << endl;
|
cout << "values: " << msg << endl;
|
||||||
const Size doubleSize (tree.getSize().width, 2*tree.getSize ().height);
|
const Size doubleSize (tree.getSize().width, 2*tree.getSize ().height);
|
||||||
printMap (cout, values, doubleSize, tree.getCompCount ()) << endl << endl;
|
cout << printMap (values, doubleSize, tree.getCompCount ()) << endl << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename AttrT>
|
template<typename AttrT>
|
||||||
|
|||||||
@ -96,7 +96,7 @@ namespace otb {
|
|||||||
inline const DimNodeId *getChildren () const; // XXX a virer ?
|
inline const DimNodeId *getChildren () const; // XXX a virer ?
|
||||||
|
|
||||||
inline const vector<DimImg> &getWeightBounds () const;
|
inline const vector<DimImg> &getWeightBounds () const;
|
||||||
inline vector<DimImg> &getWeightBounds ();
|
inline vector<DimImg> &getWeightBounds ();
|
||||||
|
|
||||||
// Functions to apply to specific entities
|
// Functions to apply to specific entities
|
||||||
template<typename FuncToApply>
|
template<typename FuncToApply>
|
||||||
@ -105,15 +105,29 @@ namespace otb {
|
|||||||
template<typename FuncToApply>
|
template<typename FuncToApply>
|
||||||
inline void forEachComp (const FuncToApply &f /* f (DimImg compId) */) const;
|
inline void forEachComp (const FuncToApply &f /* f (DimImg compId) */) const;
|
||||||
|
|
||||||
|
template<typename FuncToApply>
|
||||||
|
inline void forEachNode (const FuncToApply &f /* f (DimNodeId nodeId) */) const;
|
||||||
|
|
||||||
template<typename FuncToApply>
|
template<typename FuncToApply>
|
||||||
inline void forEachChild (const DimNodeId &parentId, const FuncToApply &f /* f (DimNodeId childId) */) const;
|
inline void forEachChild (const DimNodeId &parentId, const FuncToApply &f /* f (DimNodeId childId) */) const;
|
||||||
template<typename FuncToApply>
|
template<typename FuncToApply>
|
||||||
inline void forEachChildTI (const DimNodeId &parentId, const FuncToApply &f /* f (bool isLeaf, DimImg childId) */) const;
|
inline void forEachChildTI (const DimNodeId &parentId, const FuncToApply &f /* f (bool isLeaf, DimImg childId) */) const;
|
||||||
|
|
||||||
#ifdef ENABLE_LOG
|
|
||||||
// Print info about the tree
|
void checkSpare () const;
|
||||||
void printTree () const;
|
void check () const;
|
||||||
#endif
|
// XXX void checkWeightCurve (bool incr) const;
|
||||||
|
|
||||||
|
// nice ostream
|
||||||
|
struct CPrintTree {
|
||||||
|
const Tree &tree;
|
||||||
|
const bool onRecord;
|
||||||
|
const DimNodeId nodeCount;
|
||||||
|
CPrintTree (const Tree &tree, DimNodeId nodeCount);
|
||||||
|
ostream &print (ostream &out) const;
|
||||||
|
};
|
||||||
|
CPrintTree printTree (DimNodeId nodeCount = 0) const;
|
||||||
|
friend ostream &operator << (ostream& out, const CPrintTree &cpt) { return cpt.print (out); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "Tree.tpp"
|
#include "Tree.tpp"
|
||||||
|
|||||||
@ -98,11 +98,18 @@ Tree::forEachLeaf (const FuncToApply &f /* f (DimImg leafId) */) const {
|
|||||||
template<typename FuncToApply>
|
template<typename FuncToApply>
|
||||||
inline void
|
inline void
|
||||||
Tree::forEachComp (const FuncToApply &f /* f (DimImg compId) */) const {
|
Tree::forEachComp (const FuncToApply &f /* f (DimImg compId) */) const {
|
||||||
const DimNodeId compCount = getCompCount ();
|
const DimImg compCount = getCompCount ();
|
||||||
for (DimNodeId compId = 0; compId < compCount; ++compId)
|
for (DimImg compId = 0; compId < compCount; ++compId)
|
||||||
f (compId);
|
f (compId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename FuncToApply>
|
||||||
|
inline void
|
||||||
|
Tree::forEachNode (const FuncToApply &f /* f (NodeDimImg nodeId) */) const {
|
||||||
|
for (DimNodeId nodeId = 0; nodeId < nodeCount; ++nodeId)
|
||||||
|
f (nodeId);
|
||||||
|
}
|
||||||
|
|
||||||
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 {
|
||||||
@ -117,6 +124,10 @@ Tree::forEachChildTI (const DimNodeId &parentId, const FuncToApply &f /* f (bool
|
|||||||
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;
|
||||||
|
if (child >= getNodeCount ()) {
|
||||||
|
cerr << "coucou Tree::forEachChildTI parentId:" << parentId << " compCount:" << getCompCount () << " minChild:" << minChild << " maxChild:" << maxChild << " childId:" << childId << " child:" << child << endl;
|
||||||
|
}
|
||||||
|
BOOST_ASSERT (child < getNodeCount ());
|
||||||
f (isLeaf, isLeaf ? (DimImg) child : (DimImg) (child-leafCount));
|
f (isLeaf, isLeaf ? (DimImg) child : (DimImg) (child-leafCount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,10 +50,25 @@ namespace otb {
|
|||||||
//void reset ();
|
//void reset ();
|
||||||
inline void addDim (const TreeType &treeType, const DimImg& leafCount, const DimImg& compCount);
|
inline void addDim (const TreeType &treeType, const DimImg& leafCount, const DimImg& compCount);
|
||||||
inline void addTime (const TimeType &timeType, const double &duration);
|
inline void addTime (const TimeType &timeType, const double &duration);
|
||||||
ostream &printDim (ostream &out);
|
|
||||||
ostream &printTime (ostream &out);
|
// nice ostream
|
||||||
|
struct CPrintDim {
|
||||||
|
const TreeStats &treeStats;
|
||||||
|
CPrintDim (const TreeStats &treeStats);
|
||||||
|
ostream &print (ostream &out) const;
|
||||||
|
ostream &print (ostream &out, const TreeStatsDim stats[], const string &msg) const;
|
||||||
|
};
|
||||||
|
CPrintDim printDim () const;
|
||||||
|
friend ostream &operator << (ostream& out, const CPrintDim &cpd) { return cpd.print (out); }
|
||||||
|
|
||||||
|
struct CPrintTime {
|
||||||
|
const TreeStats &treeStats;
|
||||||
|
CPrintTime (const TreeStats &treeStats);
|
||||||
|
ostream &print (ostream &out) const;
|
||||||
|
};
|
||||||
|
CPrintTime printTime () const;
|
||||||
|
friend ostream &operator << (ostream& out, const CPrintTime &cpt) { return cpt.print (out); }
|
||||||
private :
|
private :
|
||||||
ostream &printDim (ostream &out, const TreeStatsDim stats[], const string &msg);
|
|
||||||
|
|
||||||
TreeStatsDim leavesStats[TreeTypeCard], compStats[TreeTypeCard];
|
TreeStatsDim leavesStats[TreeTypeCard], compStats[TreeTypeCard];
|
||||||
TreeStatsDouble timeStats[TimeTypeCard];
|
TreeStatsDouble timeStats[TimeTypeCard];
|
||||||
|
|||||||
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace triskele {
|
namespace triskele {
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
/*! Image band type */
|
/*! Image band type */
|
||||||
typedef uint16_t DimChanel; // hyperspectral > 256
|
typedef uint16_t DimChanel; // hyperspectral > 256
|
||||||
|
|
||||||
@ -32,7 +34,7 @@ namespace triskele {
|
|||||||
inline Point (const DimSideImg &abs, const DimSideImg &ord);
|
inline Point (const DimSideImg &abs, const DimSideImg &ord);
|
||||||
};
|
};
|
||||||
inline bool operator== (const Point &p1, const Point &p2);
|
inline bool operator== (const Point &p1, const Point &p2);
|
||||||
inline std::ostream &operator << (std::ostream &out, const Point &p);
|
inline ostream &operator << (ostream &out, const Point &p);
|
||||||
extern Point NullPoint;
|
extern Point NullPoint;
|
||||||
|
|
||||||
struct Size {
|
struct Size {
|
||||||
@ -41,7 +43,7 @@ namespace triskele {
|
|||||||
inline Size (const DimSideImg &w, const DimSideImg &h);
|
inline Size (const DimSideImg &w, const DimSideImg &h);
|
||||||
};
|
};
|
||||||
inline bool operator== (const Size &s1, const Size &s2);
|
inline bool operator== (const Size &s1, const Size &s2);
|
||||||
inline std::ostream &operator << (std::ostream &out, const Size &s);
|
inline ostream &operator << (ostream &out, const Size &s);
|
||||||
extern Size NullSize;
|
extern Size NullSize;
|
||||||
|
|
||||||
inline DimImg pointToId (const Size &size, const Point &p);
|
inline DimImg pointToId (const Size &size, const Point &p);
|
||||||
@ -55,7 +57,7 @@ namespace triskele {
|
|||||||
inline Rect (const DimSideImg &abs, const DimSideImg &ord, const DimSideImg &w, const DimSideImg &h);
|
inline Rect (const DimSideImg &abs, const DimSideImg &ord, const DimSideImg &w, const DimSideImg &h);
|
||||||
};
|
};
|
||||||
inline bool operator== (const Rect &r1, const Rect &r2);
|
inline bool operator== (const Rect &r1, const Rect &r2);
|
||||||
inline std::ostream &operator << (std::ostream &out, const Rect &r);
|
inline ostream &operator << (ostream &out, const Rect &r);
|
||||||
extern Rect NullRect;
|
extern Rect NullRect;
|
||||||
|
|
||||||
/*! Convertit un point d'un tableau (on peut imaginer une image à 2 dimension) en un index */
|
/*! Convertit un point d'un tableau (on peut imaginer une image à 2 dimension) en un index */
|
||||||
@ -64,11 +66,22 @@ namespace triskele {
|
|||||||
/*! Convertit un index d'un tableau (on peut imaginer une image à 2 dimension) en point correspondant à des coordonnées */
|
/*! Convertit un index d'un tableau (on peut imaginer une image à 2 dimension) en point correspondant à des coordonnées */
|
||||||
inline Point idx2point (const Size &size, const DimImg &idx);
|
inline Point idx2point (const Size &size, const DimImg &idx);
|
||||||
|
|
||||||
static const DimSideImg printMapMaxSide = 20;
|
static const DimSideImg printMapMaxSide = 25;
|
||||||
|
|
||||||
/*! Affiche le contenu d'un tableau en spécifiant sa taille */
|
/*! Affiche le contenu d'un tableau en spécifiant sa taille */
|
||||||
template <typename DimImg>
|
template <typename T>
|
||||||
inline std::ostream &printMap (std::ostream &out, const DimImg *map, const Size &size, DimNodeId maxValues);
|
struct CPrintMap {
|
||||||
|
const T *map;
|
||||||
|
const Size &size;
|
||||||
|
DimNodeId maxValues;
|
||||||
|
inline CPrintMap (const T *map, const Size &size, DimNodeId maxValues = 0);
|
||||||
|
inline ostream &print (ostream &out) const;
|
||||||
|
};
|
||||||
|
template <typename T>
|
||||||
|
inline CPrintMap<T> printMap (const T *map, const Size &size, DimNodeId maxValues);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline ostream &operator << (ostream& out, const CPrintMap<T> &cpm) { return cpm.print (out); }
|
||||||
|
|
||||||
#include "triskeleBase.tpp"
|
#include "triskeleBase.tpp"
|
||||||
|
|
||||||
|
|||||||
@ -19,8 +19,8 @@ operator== (const Point &p1, const Point &p2) {
|
|||||||
return p1.x == p2.x && p1.y == p2.y;
|
return p1.x == p2.x && p1.y == p2.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::ostream &
|
inline ostream &
|
||||||
operator << (std::ostream &out, const Point &p) {
|
operator << (ostream &out, const Point &p) {
|
||||||
return out << "(" << p.x << "," << p.y << ")";
|
return out << "(" << p.x << "," << p.y << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,8 +41,8 @@ operator== (const Size &s1, const Size &s2) {
|
|||||||
return s1.width == s2.width && s1.height == s2.height;
|
return s1.width == s2.width && s1.height == s2.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::ostream &
|
inline ostream &
|
||||||
operator << (std::ostream &out, const Size &s) {
|
operator << (ostream &out, const Size &s) {
|
||||||
return out << "[" << s.width << "," << s.height << "]";
|
return out << "[" << s.width << "," << s.height << "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,8 +93,8 @@ operator== (const Rect &r1, const Rect &r2) {
|
|||||||
return r1.x == r2.x && r1.y == r2.y && r1.width == r2.width && r1.height == r2.height;
|
return r1.x == r2.x && r1.y == r2.y && r1.width == r2.width && r1.height == r2.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::ostream &
|
inline ostream &
|
||||||
operator << (std::ostream &out, const Rect &r) {
|
operator << (ostream &out, const Rect &r) {
|
||||||
return out << "[" << r.x << "," << r.y << " " << r.width << "x" << r.height << "]";
|
return out << "[" << r.x << "," << r.y << " " << r.width << "x" << r.height << "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,27 +107,43 @@ idx2point (const Size &size, const DimImg &idx) {
|
|||||||
return Point (idx % size.width, idx / size.width);
|
return Point (idx % size.width, idx / size.width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
template <typename T>
|
||||||
|
inline
|
||||||
|
CPrintMap<T>::CPrintMap (const T *map, const Size &size, DimNodeId maxValues)
|
||||||
|
: map (map),
|
||||||
|
size (size),
|
||||||
|
maxValues (maxValues == 0 ? ((DimNodeId) size.width)*size.height : maxValues) {
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline std::ostream &
|
inline ostream &
|
||||||
printMap (std::ostream &out, const T *map, const Size &size, DimNodeId maxValues) {
|
CPrintMap<T>::print (ostream &out) const {
|
||||||
if (size.width > printMapMaxSide || size.height > printMapMaxSide) {
|
if (size.width > printMapMaxSide || size.height > printMapMaxSide) {
|
||||||
return out << "map too big to print!" << std::endl;
|
return out << "map too big to print!" << endl;
|
||||||
}
|
}
|
||||||
if (maxValues == 0)
|
const T *map2 = map;
|
||||||
maxValues = ((DimNodeId) size.width)*size.height;
|
DimNodeId countDown = maxValues;
|
||||||
for (DimSideImg y = 0; y < size.height; ++y) {
|
for (DimSideImg y = 0; y < size.height; ++y) {
|
||||||
for (DimSideImg x = 0; x < size.width; ++x, ++map, --maxValues) {
|
for (DimSideImg x = 0; x < size.width; ++x, ++map2, --countDown) {
|
||||||
if (!maxValues)
|
if (!countDown)
|
||||||
return out;
|
return out;
|
||||||
if (*map == DimImg_MAX)
|
|
||||||
out << " M ";
|
if ((DimImg (*map2)) == DimImg_MAX)
|
||||||
|
out << " M ";
|
||||||
else
|
else
|
||||||
out << std::setw(3) << ((double) *map) << " ";
|
// XXX if T == uint8_t => print char :-(
|
||||||
|
out << setw(3) << *map2 << " ";
|
||||||
}
|
}
|
||||||
out << std::endl;
|
out << endl;
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
inline CPrintMap<T>
|
||||||
|
printMap (const T *map, const Size &size, DimNodeId maxValues) {
|
||||||
|
return CPrintMap<T> (map, size, maxValues);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // _OTB_TRISKELE_BASE_TPP
|
#endif // _OTB_TRISKELE_BASE_TPP
|
||||||
|
|||||||
@ -7,6 +7,35 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
|
|
||||||
|
#ifdef ENABLE_SMART_LOG
|
||||||
|
|
||||||
|
#ifndef SMART_DEF_LOG
|
||||||
|
#define SMART_DEF_LOG(name, expr) DEF_LOG (name, expr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SMART_LOG
|
||||||
|
#define SMART_LOG(expr) LOG (expr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SMART_LOG_EXPR
|
||||||
|
#define SMART_LOG_EXPR(expr) {if (triskele::debug) expr; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#ifndef SMART_DEF_LOG
|
||||||
|
#define SMART_DEF_LOG(name, expr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SMART_LOG
|
||||||
|
#define SMART_LOG(expr)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SMART_LOG_EXPR
|
||||||
|
#define SMART_LOG_EXPR(expr)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DISABLE_LOG
|
#ifdef DISABLE_LOG
|
||||||
|
|
||||||
#ifndef DEF_LOG
|
#ifndef DEF_LOG
|
||||||
|
|||||||
175
src/Tree.cpp
175
src/Tree.cpp
@ -1,6 +1,9 @@
|
|||||||
#include "Tree.hpp"
|
#include "Tree.hpp"
|
||||||
|
#include "ArrayTree/Border.hpp"
|
||||||
|
#include "ArrayTree/GraphWalker.hpp"
|
||||||
|
|
||||||
using namespace otb::triskele;
|
using namespace otb::triskele;
|
||||||
|
using namespace otb::triskele::arrayTree;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Tree::Tree (const DimSideImg &width, const DimSideImg &height, unsigned int coreCount)
|
Tree::Tree (const DimSideImg &width, const DimSideImg &height, unsigned int coreCount)
|
||||||
@ -35,7 +38,7 @@ Tree::clear () {
|
|||||||
childCount[0] = childCount[1] = 0;
|
childCount[0] = childCount[1] = 0;
|
||||||
// XXX dealThreadFill_n avec coreCount
|
// XXX dealThreadFill_n avec coreCount
|
||||||
fill_n (leafParents, leafCount*2, DimImg_MAX);
|
fill_n (leafParents, leafCount*2, DimImg_MAX);
|
||||||
#ifdef SMART_LOG
|
#ifdef USE_SMART_LOG
|
||||||
fill_n (children, (leafCount-1)*2, 0);
|
fill_n (children, (leafCount-1)*2, 0);
|
||||||
fill_n (childCount, leafCount+1, 0);
|
fill_n (childCount, leafCount+1, 0);
|
||||||
#endif
|
#endif
|
||||||
@ -83,14 +86,168 @@ Tree::book (const DimImg &leafCount) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef ENABLE_LOG
|
|
||||||
void
|
void
|
||||||
Tree::printTree () const {
|
Tree::checkSpare () const {
|
||||||
cout << "tree parent count children" << endl;
|
Border border; // default = no border
|
||||||
Size doubleSize (size.width, 2*size.height);
|
GraphWalker graphWalker (size, border);
|
||||||
printMap (cout, leafParents, doubleSize, nodeCount) << endl << endl;
|
vector<Rect> tiles;
|
||||||
printMap (cout, childCount, size, ((DimNodeId) getCompCount ()) + 1) << endl << endl;
|
vector<Rect> boundaries;
|
||||||
printMap (cout, children, doubleSize, nodeCount) << endl << endl;
|
vector<bool> verticalBoundaries;
|
||||||
|
graphWalker.setTiles (coreCount, Rect (NullPoint, size), tiles, boundaries, verticalBoundaries);
|
||||||
|
|
||||||
|
vector<DimImg> vertexMaxBounds;
|
||||||
|
vector<DimImg> edgesMaxBounds;
|
||||||
|
graphWalker.setMaxBounds (tiles, vertexMaxBounds, edgesMaxBounds);
|
||||||
|
unsigned int tileCount = tiles.size ();
|
||||||
|
vector<DimImg> maxParents (tileCount);
|
||||||
|
|
||||||
|
// check parents
|
||||||
|
for (unsigned int i = 0; i < tileCount; ++i) {
|
||||||
|
DimImg base = vertexMaxBounds [i], top = vertexMaxBounds [i+1];
|
||||||
|
DimImg &maxParent = maxParents [i];
|
||||||
|
graphWalker.forEachVertexIdx (tiles[i], [this, &base, &top, &maxParent] (DimImg leafId) {
|
||||||
|
BOOST_ASSERT (leafParents[leafId] >= base);
|
||||||
|
BOOST_ASSERT (leafParents[leafId] < top);
|
||||||
|
if (maxParent < leafParents[leafId])
|
||||||
|
maxParent = leafParents[leafId];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
DimImg *childCountRec = childCount+2;
|
||||||
|
for (unsigned int i = 0; i < tileCount; ++i) {
|
||||||
|
DimImg base = vertexMaxBounds [i], maxParent = maxParents [i];
|
||||||
|
for (DimImg compId = base; compId < maxParent; ++compId) {
|
||||||
|
BOOST_ASSERT (compParents[compId] > base);
|
||||||
|
BOOST_ASSERT (compParents[compId] != compId);
|
||||||
|
BOOST_ASSERT (compParents[compId] < maxParent);
|
||||||
|
if (compParents[compId] < compId)
|
||||||
|
BOOST_ASSERT (childCountRec[compParents[compId]] > childCountRec[compId]);
|
||||||
|
}
|
||||||
|
BOOST_ASSERT (compParents[maxParent] == DimImg_MAX);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
vector<bool> parentsMap (vertexMaxBounds[tileCount], false);
|
||||||
|
for (unsigned int i = 0; i < tileCount; ++i) {
|
||||||
|
graphWalker.forEachVertexIdx (tiles[i], [this, &parentsMap] (DimImg leafId) {
|
||||||
|
parentsMap [leafParents [leafId]] = true;
|
||||||
|
});
|
||||||
|
DimImg base = vertexMaxBounds [i], maxParent = maxParents [i];
|
||||||
|
for (DimImg compId = base; compId < maxParent; ++compId)
|
||||||
|
parentsMap [compParents [compId]] = true;
|
||||||
|
for (DimImg compId = base; compId < maxParent; ++compId)
|
||||||
|
BOOST_ASSERT (parentsMap [compId]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// check weight
|
||||||
|
// XXX monotone
|
||||||
|
|
||||||
|
// check childCount
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
void
|
||||||
|
Tree::check () const {
|
||||||
|
DimImg compCount = getCompCount ();
|
||||||
|
BOOST_ASSERT (compCount < leafCount);
|
||||||
|
// check parents
|
||||||
|
forEachLeaf ([this, &compCount] (const DimImg &leafId) {
|
||||||
|
// XXX si border => leafParents [leafId] == DimImg_MAX
|
||||||
|
BOOST_ASSERT (leafParents[leafId] < compCount);
|
||||||
|
});
|
||||||
|
forEachComp ([this, &compCount] (const DimImg &compId) {
|
||||||
|
if (compId == compCount-1)
|
||||||
|
BOOST_ASSERT (compParents[compId] == DimImg_MAX);
|
||||||
|
else {
|
||||||
|
BOOST_ASSERT (compParents[compId] > compId);
|
||||||
|
BOOST_ASSERT (compParents[compId] < compCount);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
{
|
||||||
|
vector<bool> parentsMap (compCount, false);
|
||||||
|
//parentsMap.assign (compCount, false);
|
||||||
|
forEachNode ([this, &parentsMap] (const DimNodeId &nodeId) {
|
||||||
|
if (leafParents[nodeId] == DimImg_MAX)
|
||||||
|
return;
|
||||||
|
parentsMap [leafParents [nodeId]] = true;
|
||||||
|
});
|
||||||
|
for (DimImg compId = 0; compId < compCount; ++compId)
|
||||||
|
BOOST_ASSERT (parentsMap [compId]);
|
||||||
|
}
|
||||||
|
// check weight
|
||||||
|
|
||||||
|
// check weightBounds
|
||||||
|
|
||||||
|
// check childCount
|
||||||
|
{
|
||||||
|
vector<DimImg> childCount2 (compCount, 0);
|
||||||
|
forEachLeaf ([this, &childCount2] (const DimImg &leafId) {
|
||||||
|
if (leafParents[leafId] == DimImg_MAX)
|
||||||
|
// boder
|
||||||
|
return;
|
||||||
|
++childCount2 [leafParents [leafId]];
|
||||||
|
});
|
||||||
|
forEachComp ([this, &childCount2, &compCount] (const DimImg &compId) {
|
||||||
|
if (compId == compCount-1)
|
||||||
|
return;
|
||||||
|
++childCount2 [compParents [compId]];
|
||||||
|
});
|
||||||
|
for (DimImg compId = 0; compId < compCount; ++compId) {
|
||||||
|
// check count
|
||||||
|
BOOST_ASSERT (childCount2 [compId] = childCount [compId+1] - childCount[compId]);
|
||||||
|
// at least 2 children
|
||||||
|
BOOST_ASSERT (childCount2 [compId] > 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check children
|
||||||
|
{
|
||||||
|
vector<DimNodeId> childrenMap (nodeCount, DimImg_MAX);
|
||||||
|
forEachComp ([this, &childrenMap] (const DimImg &compId) {
|
||||||
|
DimNodeId minChild = childCount[compId], maxChild = childCount[compId+1];
|
||||||
|
for (DimNodeId childId = minChild; childId < maxChild; ++childId) {
|
||||||
|
DimNodeId child = children[childId];
|
||||||
|
BOOST_ASSERT (leafParents [child] == compId);
|
||||||
|
BOOST_ASSERT (childrenMap [child] == DimImg_MAX);
|
||||||
|
childrenMap [child] = compId;
|
||||||
|
}
|
||||||
|
for (DimNodeId childId = minChild+1; childId < maxChild; ++childId) {
|
||||||
|
BOOST_ASSERT (children[childId-1] < children[childId]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for (DimImg child = 0; child < nodeCount-1; ++child)
|
||||||
|
BOOST_ASSERT (childrenMap [child] != DimImg_MAX);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
Tree::CPrintTree::CPrintTree (const Tree &tree, DimNodeId nodeCount)
|
||||||
|
: tree (tree),
|
||||||
|
onRecord (nodeCount),
|
||||||
|
nodeCount (onRecord ? nodeCount : tree.getNodeCount ()) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ostream &
|
||||||
|
Tree::CPrintTree::print (ostream &out) const {
|
||||||
|
Size doubleSize (tree.size.width, 2*tree.size.height);
|
||||||
|
out << "Tree::printTree: leafCount:" << tree.leafCount
|
||||||
|
<< " nodeCount:" << (onRecord ? "~" : "") << nodeCount << " compCount:" << nodeCount - tree.leafCount << endl
|
||||||
|
<< "parent count" << (onRecord ? "" : " children") << endl
|
||||||
|
<< printMap (tree.leafParents, doubleSize, nodeCount) << endl << endl
|
||||||
|
<< printMap (tree.childCount + (onRecord ? 2 : 0), tree.size, nodeCount - tree.leafCount + 1) << endl << endl;
|
||||||
|
if (!onRecord)
|
||||||
|
out << printMap (tree.children, doubleSize, nodeCount-1) << endl << endl;
|
||||||
|
if (tree.weightBounds.size ()) {
|
||||||
|
out << "weightBounds: " << endl
|
||||||
|
<< printMap (&tree.weightBounds[0], tree.size, tree.weightBounds.size ()) << endl << endl;
|
||||||
|
} else
|
||||||
|
return out << "no weightBounds" << endl << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Tree::CPrintTree
|
||||||
|
Tree::printTree (DimNodeId nodeCount) const {
|
||||||
|
return CPrintTree (*this, nodeCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ostream &
|
||||||
|
// operator << (ostream& out, const Tree::CPrintTree &cpt) {
|
||||||
|
// return cpt.print (out);
|
||||||
|
// }
|
||||||
|
|||||||
@ -22,6 +22,9 @@ static string timeTypeLabels [TimeTypeCard] = {
|
|||||||
"sum All",
|
"sum All",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TreeStats globalTreeStats;
|
||||||
|
|
||||||
|
// ========================================
|
||||||
using namespace boost::chrono;
|
using namespace boost::chrono;
|
||||||
inline string
|
inline string
|
||||||
ns2string (double delta) {
|
ns2string (double delta) {
|
||||||
@ -41,11 +44,25 @@ ns2string (double delta) {
|
|||||||
return oss.str ();
|
return oss.str ();
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeStats globalTreeStats;
|
// ----------------------------------------
|
||||||
|
TreeStats::CPrintDim::CPrintDim (const TreeStats &treeStats)
|
||||||
|
: treeStats (treeStats) {
|
||||||
|
}
|
||||||
|
ostream &
|
||||||
|
TreeStats::CPrintDim::print (ostream &out) const {
|
||||||
|
bool empty = true;
|
||||||
|
for (unsigned int i = 0; i < TreeTypeCard; ++i)
|
||||||
|
if (!(empty = !ba::count (treeStats.leavesStats[i])))
|
||||||
|
break;
|
||||||
|
if (empty)
|
||||||
|
return out;
|
||||||
|
print (out, treeStats.leavesStats, "Leaf");
|
||||||
|
return print (out, treeStats.compStats, "Comp");
|
||||||
|
}
|
||||||
|
|
||||||
ostream &
|
ostream &
|
||||||
TreeStats::printDim (ostream &out, const TreeStatsDim stats[], const string &msg) {
|
TreeStats::CPrintDim::print (ostream &out, const TreeStatsDim stats[], const string &msg) const {
|
||||||
cout << endl
|
out << endl
|
||||||
<< setw (11) << left << msg << "\t"
|
<< setw (11) << left << msg << "\t"
|
||||||
<< setw (3) << left << "Count" << "\t"
|
<< setw (3) << left << "Count" << "\t"
|
||||||
<< setw (9) << left << "Mean" << "\t"
|
<< setw (9) << left << "Mean" << "\t"
|
||||||
@ -54,7 +71,7 @@ TreeStats::printDim (ostream &out, const TreeStatsDim stats[], const string &msg
|
|||||||
for (unsigned int i = 0; i < TreeTypeCard; ++i) {
|
for (unsigned int i = 0; i < TreeTypeCard; ++i) {
|
||||||
if (!ba::count (stats[i]))
|
if (!ba::count (stats[i]))
|
||||||
continue;
|
continue;
|
||||||
cout << setw (11) << right << treeTypeLabels [i] << "\t"
|
out << setw (11) << right << treeTypeLabels [i] << "\t"
|
||||||
<< setw (3) << ba::count (stats[i]) << "\t"
|
<< setw (3) << ba::count (stats[i]) << "\t"
|
||||||
<< setw (9) << DimImg (ba::mean (stats[i])) << "\t"
|
<< setw (9) << DimImg (ba::mean (stats[i])) << "\t"
|
||||||
<< setw (9) << ba::min (stats[i]) << "\t"
|
<< setw (9) << ba::min (stats[i]) << "\t"
|
||||||
@ -64,42 +81,54 @@ TreeStats::printDim (ostream &out, const TreeStatsDim stats[], const string &msg
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
ostream &
|
TreeStats::CPrintDim
|
||||||
TreeStats::printDim (ostream &out) {
|
TreeStats::printDim () const {
|
||||||
bool empty = true;
|
return CPrintDim (*this);
|
||||||
for (unsigned int i = 0; i < TreeTypeCard; ++i)
|
|
||||||
if (!(empty = !ba::count (leavesStats[i])))
|
|
||||||
break;
|
|
||||||
if (empty)
|
|
||||||
return out;
|
|
||||||
printDim (out, leavesStats, "Leaf");
|
|
||||||
return printDim (out, compStats, "Comp");
|
|
||||||
}
|
}
|
||||||
|
// ostream&
|
||||||
|
// operator << (ostream& out, const TreeStats::CPrintDim &cpd) {
|
||||||
|
// return cpd.print (out);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// ----------------------------------------
|
||||||
|
TreeStats::CPrintTime::CPrintTime (const TreeStats &treeStats)
|
||||||
|
: treeStats (treeStats) {
|
||||||
|
}
|
||||||
ostream &
|
ostream &
|
||||||
TreeStats::printTime (ostream &out) {
|
TreeStats::CPrintTime::print (ostream &out) const {
|
||||||
bool empty = true;
|
bool empty = true;
|
||||||
for (unsigned int i = 0; i < TimeTypeCard; ++i)
|
for (unsigned int i = 0; i < TimeTypeCard; ++i)
|
||||||
if (!(empty = !ba::count (timeStats[i])))
|
if (!(empty = !ba::count (treeStats.timeStats[i])))
|
||||||
break;
|
break;
|
||||||
if (empty)
|
if (empty)
|
||||||
return out;
|
return out;
|
||||||
cout << endl
|
out << endl
|
||||||
<< setw (11) << left << "Time" << "\t"
|
<< setw (11) << left << "Time" << "\t"
|
||||||
<< setw (15) << left << "Sum" << "\t"
|
<< setw (15) << left << "Sum" << "\t"
|
||||||
<< setw (3) << left << "Count" << "\t"
|
<< setw (3) << left << "Count" << "\t"
|
||||||
<< setw (15) << left << "Mean" << "\t"
|
<< setw (15) << left << "Mean" << "\t"
|
||||||
<< setw (15) << left << "Min" << "\t"
|
<< setw (15) << left << "Min" << "\t"
|
||||||
<< setw (15) << left << "Max" << endl;
|
<< setw (15) << left << "Max" << endl;
|
||||||
for (unsigned int i = 0; i < TimeTypeCard; ++i) {
|
for (unsigned int i = 0; i < TimeTypeCard; ++i) {
|
||||||
if (!ba::count (timeStats[i]))
|
if (!ba::count (treeStats.timeStats[i]))
|
||||||
continue;
|
continue;
|
||||||
cout << setw (11) << right << timeTypeLabels[i] << "\t"
|
out << setw (11) << right << timeTypeLabels[i] << "\t"
|
||||||
<< ns2string (ba::sum (timeStats[i])) << "\t" << setw (3) << ba::count (timeStats[i]) << "\t"
|
<< ns2string (ba::sum (treeStats.timeStats[i])) << "\t" << setw (3) << ba::count (treeStats.timeStats[i]) << "\t"
|
||||||
<< ns2string (ba::mean (timeStats[i])) << "\t"
|
<< ns2string (ba::mean (treeStats.timeStats[i])) << "\t"
|
||||||
<< ns2string (ba::min (timeStats[i])) << "\t"
|
<< ns2string (ba::min (treeStats.timeStats[i])) << "\t"
|
||||||
<< ns2string (ba::max (timeStats[i]))
|
<< ns2string (ba::max (treeStats.timeStats[i]))
|
||||||
<< endl << flush;
|
<< endl << flush;
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TreeStats::CPrintTime
|
||||||
|
TreeStats::printTime () const {
|
||||||
|
return CPrintTime (*this);
|
||||||
|
}
|
||||||
|
// ostream&
|
||||||
|
// operator << (ostream& out, const TreeStats::CPrintTime &cpt) {
|
||||||
|
// return cpt.print (out);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// ========================================
|
||||||
|
|||||||
@ -113,9 +113,9 @@ void apGenerator (Option &option) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cerr << endl << "*** apGenerator done!" << endl;
|
cerr << endl << "*** apGenerator done!" << endl
|
||||||
globalTreeStats.printDim (cerr);
|
<< globalTreeStats.printDim () << endl
|
||||||
globalTreeStats.printTime (cerr);
|
<< globalTreeStats.printTime ();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user