modifié : ../include/ArrayTree/ArrayTreeBuilder.hpp

modifié :         ../include/ArrayTree/ArrayTreeBuilder.tpp
	modifié :         ../include/ArrayTree/GraphWalker.hpp
	modifié :         ../include/ArrayTree/GraphWalker.tpp
	modifié :         ../include/ArrayTree/Leader.tpp
	modifié :         ../include/IImage.tpp
	modifié :         ../include/Tree.hpp
	modifié :         ../include/Tree.tpp
	modifié :         ../include/TreeBuilder.hpp
	modifié :         ../include/TreeBuilder.tpp
	modifié :         ../src/QuadTree/QuadTreeBuilder.cpp
	modifié :         ../src/Tree.cpp
	modifié :         ../src/XMLTree/XMLTreeBuilder.cpp
	modifié :         ../src/testMain.cpp
This commit is contained in:
Git Merciol 2018-02-18 11:19:40 +01:00
parent eb0e4b26cb
commit bdd6110787
14 changed files with 106 additions and 75 deletions

View File

@ -5,6 +5,7 @@
#include <iostream> #include <iostream>
#endif // ENABLE_LOG #endif // ENABLE_LOG
#include "triskeleDebug.hpp"
#include "triskeleSort.hpp" #include "triskeleSort.hpp"
#include "triskeleDealThreads.hpp" #include "triskeleDealThreads.hpp"
#include "TreeBuilder.hpp" #include "TreeBuilder.hpp"
@ -19,25 +20,27 @@ namespace otb {
template <typename WeightT, typename PixelT> template <typename WeightT, typename PixelT>
class ArrayTreeBuilder : public TreeBuilder { class ArrayTreeBuilder : public TreeBuilder {
protected:
const unsigned int coreCount; const unsigned int coreCount;
const Raster<PixelT> &raster; const Raster<PixelT> &raster;
const GraphWalker &graphWalker; const GraphWalker &graphWalker;
TreeType type; TreeType type;
bool countingFlag; bool countingFlag;
Leader leaders; Leader leaders;
DimNodeId *childCountRec; WeightT *compWeights; // [leafCount] XXX dans TreeBuilder ???
WeightT *compWeights; // [leafCount]
// transcient
DimNodeId *childCountRec;
DimImg *newCompId;
public: public:
ArrayTreeBuilder (const unsigned int &coreCount, inline ArrayTreeBuilder (const unsigned int &coreCount,
Raster<PixelT> &raster, const GraphWalker &graphWalker, Raster<PixelT> &raster, const GraphWalker &graphWalker,
const TreeType &treeType, const bool &countingSort = true); const TreeType &treeType, const bool &countingSort = true);
~ArrayTreeBuilder () {} inline ~ArrayTreeBuilder ();
inline void inline void buildTree (Tree &tree);
buildTree (Tree &tree);
private: protected:
template<typename WeightFunct> template<typename WeightFunct>
inline void inline void
buildTree (Tree &tree, const WeightFunct &weightFunct); buildTree (Tree &tree, const WeightFunct &weightFunct);
@ -64,13 +67,13 @@ namespace otb {
template<typename WeightFunct> template<typename WeightFunct>
inline DimImg inline DimImg
updateNewId (DimImg newCompId[], const vector<DimImg> &compBases, const vector<DimImg> &compTops, const WeightFunct &weightFunct); updateNewId (const vector<DimImg> &compBases, const vector<DimImg> &compTops, const WeightFunct &weightFunct);
inline void inline void
updateNewId (DimImg newCompId[], const DimImg curComp, DimImg &compCount); updateNewId (const DimImg curComp, DimImg &compCount);
inline void inline void
compress (DimImg newCompId[], const DimImg &compTop); compress (const DimImg &compTop);
inline void inline void
createParent (DimImg &topParent, const WeightT &weight, DimImg &childA, DimImg &childB); createParent (DimImg &topParent, const WeightT &weight, DimImg &childA, DimImg &childB);
@ -93,7 +96,7 @@ namespace otb {
findTopComp (DimImg comp, const WeightT &weight, const WeightFunct &weightFunct); findTopComp (DimImg comp, const WeightT &weight, const WeightFunct &weightFunct);
inline DimImg inline DimImg
findCompMultiChild (const DimImg newCompId[], DimImg comp); findCompMultiChild (DimImg comp);
inline void inline void
buildChildren (); buildChildren ();
@ -102,14 +105,14 @@ namespace otb {
inline void inline void
initWeights (const GraphWalker &graphWalker, const WeightFunct &weightFunct); initWeights (const GraphWalker &graphWalker, const WeightFunct &weightFunct);
// #ifdef ENABLE_LOG // #ifdef ENABLE_LOG
// inline void // inline void
// printTree (const Size &size, const bool &rec); // printTree (const Size &size, const bool &rec);
// inline void // inline void
// printLeaders (const Size &size); // printLeaders (const Size &size);
// inline void // inline void
// printNewCompIdx (const Size &size); // printNewCompIdx (const Size &size);
// #endif // #endif
}; };
#include "ArrayTreeBuilder.tpp" #include "ArrayTreeBuilder.tpp"

View File

@ -3,6 +3,7 @@
// ======================================== // ========================================
template<typename WeightT, typename PixelT> template<typename WeightT, typename PixelT>
inline
ArrayTreeBuilder<WeightT, PixelT>::ArrayTreeBuilder (const unsigned int &coreCount, ArrayTreeBuilder<WeightT, PixelT>::ArrayTreeBuilder (const unsigned int &coreCount,
Raster<PixelT> &raster, const GraphWalker &graphWalker, Raster<PixelT> &raster, const GraphWalker &graphWalker,
const TreeType &treeType, const bool &countingSort) : const TreeType &treeType, const bool &countingSort) :
@ -10,23 +11,32 @@ ArrayTreeBuilder<WeightT, PixelT>::ArrayTreeBuilder (const unsigned int &coreCou
raster (raster), raster (raster),
graphWalker (graphWalker), graphWalker (graphWalker),
type (treeType), type (treeType),
countingFlag (countingSort) countingFlag (countingSort),
compWeights (nullptr),
childCountRec (nullptr),
newCompId (nullptr)
{ {
DEF_LOG ("ArrayTreeBuilder::ArrayTreeBuilder", "");
}
// ========================================
template<typename WeightT, typename PixelT>
inline
ArrayTreeBuilder<WeightT, PixelT>::~ArrayTreeBuilder () {
} }
// ======================================== // ========================================
template<typename WeightT, typename PixelT> template<typename WeightT, typename PixelT>
inline void inline void
ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree) { ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree) {
tree.resize (graphWalker.vertexMaxCount ()); DEF_LOG ("ArrayTreeBuilder::buildTree", "size:" << graphWalker.vertexMaxCount ());
// XXX updateAttributes (); setTreeSize (tree, graphWalker.size);
if (!leafCount) if (!leafCount)
return; return;
compWeights = new WeightT[tree.getLeafCount()];
childCountRec = childCount + 2;
leaders.book (leafCount); leaders.book (leafCount);
// XXX dealThreadFill_n leaders childCountRec = childCount+2;
newCompId = leaders.getLeaders ();
compWeights = new WeightT[leafCount];
switch (type) { switch (type) {
// case MIN: // case MIN:
@ -41,8 +51,9 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree) {
// XXX msg // XXX msg
} }
leaders.free (); leaders.free ();
newCompId = nullptr;
buildChildren (); buildChildren ();
childCountRec = nullptr;
// XXX // XXX
// if (compWeights) // if (compWeights)
// delete [] compWeights; // delete [] compWeights;
@ -129,13 +140,12 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, const WeightFunct &wei
} }
// compress // compress
DimImg *newCompId = leaders.getLeaders ();
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);
compCount = updateNewId (newCompId, compBases, compTops, weightFunct); compCount = updateNewId (compBases, compTops, weightFunct);
compress (newCompId, maxUsed); compress (maxUsed);
leaders.free (); leaders.free ();
@ -469,7 +479,7 @@ ArrayTreeBuilder<WeightT, PixelT>::connectComp (DimImg topA, DimImg topB, const
template<typename WeightT, typename PixelT> template<typename WeightT, typename PixelT>
template<typename WeightFunct> template<typename WeightFunct>
inline DimImg inline DimImg
ArrayTreeBuilder<WeightT, PixelT>::updateNewId (DimImg newCompId[], 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];
@ -481,19 +491,19 @@ ArrayTreeBuilder<WeightT, PixelT>::updateNewId (DimImg newCompId[], const vector
[this, &compBases] (const DimImg &vectId, const DimImg &itemId) { [this, &compBases] (const DimImg &vectId, const DimImg &itemId) {
return compWeights[compBases[vectId]+itemId]; }, return compWeights[compBases[vectId]+itemId]; },
weightFunct.isWeightInf, weightFunct.isWeightInf,
[this, &compBases, &compCount, &newCompId] (const DimImg &vectId, const DimImg &itemId) { [this, &compBases, &compCount] (const DimImg &vectId, const DimImg &itemId) {
updateNewId (newCompId, compBases[vectId]+itemId, compCount); }); updateNewId (compBases[vectId]+itemId, compCount); });
return compCount; return compCount;
} }
// ---------------------------------------- // ----------------------------------------
template<typename WeightT, typename PixelT> template<typename WeightT, typename PixelT>
inline void inline void
ArrayTreeBuilder<WeightT, PixelT>::updateNewId (DimImg newCompId[], const DimImg curComp, DimImg &compCount) { ArrayTreeBuilder<WeightT, PixelT>::updateNewId (const DimImg curComp, DimImg &compCount) {
if (newCompId[curComp] != DimImg_MAX) if (newCompId[curComp] != DimImg_MAX)
// top already set // top already set
return; return;
const DimImg &top = findCompMultiChild (newCompId, curComp); const DimImg &top = findCompMultiChild (curComp);
if (curComp != top) { if (curComp != top) {
// 0 => merge || no more child // 0 => merge || no more child
// 1 => unnecessary node // 1 => unnecessary node
@ -531,19 +541,19 @@ ArrayTreeBuilder<WeightT, PixelT>::updateNewId (DimImg newCompId[], const DimImg
// ---------------------------------------- // ----------------------------------------
template<typename WeightT, typename PixelT> template<typename WeightT, typename PixelT>
inline void inline void
ArrayTreeBuilder<WeightT, PixelT>::compress (DimImg newCompId[], const DimImg &compTop) { ArrayTreeBuilder<WeightT, PixelT>::compress (const DimImg &compTop) {
#ifdef SMART_LOG #ifdef SMART_LOG
DEF_LOG ("ArrayTreeBuilder::compress", " compTop:" << compTop); DEF_LOG ("ArrayTreeBuilder::compress", " compTop:" << compTop);
#endif #endif
dealThreadRange (leafCount, coreCount, [this, &newCompId] (const DimImg &leaf) { dealThreadRange (leafCount, coreCount, [this] (const DimImg &leaf) {
DimImg old = leafParents[leaf]; DimImg old = leafParents[leaf];
if (old != DimImg_MAX) if (old != DimImg_MAX)
leafParents[leaf] = newCompId[old]; leafParents[leaf] = newCompId[old];
}); });
dealThreadRange (compTop, coreCount, [this, &newCompId] (const DimImg &curComp) { dealThreadRange (compTop, coreCount, [this] (const DimImg &curComp) {
DimImg old = compParents[curComp]; DimImg old = compParents[curComp];
if (old != DimImg_MAX) if (old != DimImg_MAX)
compParents[curComp] = newCompId[old]; compParents[curComp] = newCompId[old];
@ -641,7 +651,7 @@ ArrayTreeBuilder<WeightT, PixelT>::findTopComp (DimImg comp, const WeightT &weig
// ---------------------------------------- // ----------------------------------------
template<typename WeightT, typename PixelT> template<typename WeightT, typename PixelT>
inline DimImg inline DimImg
ArrayTreeBuilder<WeightT, PixelT>::findCompMultiChild (const DimImg newCompId[], DimImg comp) { ArrayTreeBuilder<WeightT, PixelT>::findCompMultiChild (DimImg comp) {
BOOST_ASSERT (comp != DimImg_MAX); BOOST_ASSERT (comp != DimImg_MAX);
for (;;) { for (;;) {
if (newCompId [comp] != DimImg_MAX) if (newCompId [comp] != DimImg_MAX)

View File

@ -32,17 +32,12 @@ namespace otb {
const Border &border; const Border &border;
const Connectivity connectivity; const Connectivity connectivity;
GraphWalker (const Size &size, const Border &border, const Connectivity &connectivity = Connectivity::C4) inline GraphWalker (const Size &size, const Border &border, const Connectivity &connectivity = Connectivity::C4);
: size (size), border (border), connectivity (connectivity) { inline DimImg vertexMaxCount () const;
BOOST_ASSERT (size.width >= DimImg (0)); inline DimImg vertexMaxCount (const Size &tileSize) const;
BOOST_ASSERT (size.height >= DimImg (0)); inline DimEdge edgeMaxCount () const;
} inline DimEdge edgeMaxCount (const Size &tileSize) const;
inline DimEdge edgeBoundaryMaxCount (const DimSideImg &side) const;
inline DimImg vertexMaxCount () const;
inline DimImg vertexMaxCount (const Size &tileSize) const;
inline DimEdge edgeMaxCount () const;
inline DimEdge edgeMaxCount (const Size &tileSize) 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; std::vector<Rect> &tiles, std::vector<Rect> &boundaries, std::vector<bool> &verticalBoundaries) const;

View File

@ -2,6 +2,15 @@
#define _OTB_TRISKELE_ARRAY_TREE_GRAPHWALKER_TPP #define _OTB_TRISKELE_ARRAY_TREE_GRAPHWALKER_TPP
// ======================================== // ========================================
inline
GraphWalker::GraphWalker (const Size &size, const Border &border, const Connectivity &connectivity)
: size (size), border (border), connectivity (connectivity) {
DEF_LOG ("GraphWalker::GraphWalker", "size: " << size);
BOOST_ASSERT (size.width >= DimImg (0));
BOOST_ASSERT (size.height >= DimImg (0));
}
// ----------------------------------------
inline DimImg inline DimImg
GraphWalker::vertexMaxCount () const { GraphWalker::vertexMaxCount () const {
return vertexMaxCount (size); return vertexMaxCount (size);

View File

@ -48,7 +48,7 @@ inline void
Leader::reset () { Leader::reset () {
if (!size) if (!size)
return; return;
// XXX dealThreadFill_n // XXX dealThreadFill_n avec coreCount
std::fill_n (leaders, size, DimImg_MAX); std::fill_n (leaders, size, DimImg_MAX);
} }

View File

@ -5,6 +5,7 @@
template<typename PixelT> template<typename PixelT>
inline void inline void
Raster<PixelT>::setSize (const Size &size) { Raster<PixelT>::setSize (const Size &size) {
DEF_LOG ("Raster::setSize", "size: " << size);
if (this->size == size) if (this->size == size)
return; return;
if (pixels) if (pixels)

View File

@ -22,7 +22,9 @@ namespace otb {
class Tree { class Tree {
friend class TreeBuilder; friend class TreeBuilder;
private:
inline DimNodeId *getChildCount ();
protected: protected:
/*! Info about the picture */ /*! Info about the picture */
Size size; Size size;
@ -49,14 +51,13 @@ namespace otb {
// Constructors, destructor and resize method (does the same as the constructors) // Constructors, destructor and resize method (does the same as the constructors)
Tree (const DimSideImg &width, const DimSideImg &height); Tree (const DimSideImg &width, const DimSideImg &height);
Tree (const DimImg &leafCount = 0); // XXX Tree ();
~Tree (); ~Tree ();
/*! clear values according to the size defined */ /*! clear values according to the size defined */
void clear (); void clear ();
void resize (const DimSideImg &width, const DimSideImg &height); void resize (const DimSideImg &width, const DimSideImg &height);
void resize (const DimImg &leafCount); // XXX
// Setter for nodeCount and size // Setter for nodeCount and size
inline void setNodeCount (const DimImg &newNodeCount); inline void setNodeCount (const DimImg &newNodeCount);

View File

@ -1,6 +1,11 @@
#ifndef _OTB_TRISKELE_TREE_TPP #ifndef _OTB_TRISKELE_TREE_TPP
#define _OTB_TRISKELE_TREE_TPP #define _OTB_TRISKELE_TREE_TPP
inline DimNodeId *
Tree::getChildCount () {
return childCount;
}
inline void inline void
Tree::setNodeCount (const DimImg &newNodeCount) { Tree::setNodeCount (const DimImg &newNodeCount) {
nodeCount = newNodeCount; nodeCount = newNodeCount;

View File

@ -16,7 +16,8 @@ namespace otb {
protected: protected:
// Used to set the attributes below with the tree // Used to set the attributes below with the tree
inline void updateAttributes (Tree &tree); inline void setTreeSize (Tree &tree, const Size &size);
inline void getTranscient (Tree &tree);
inline DimNodeId getCompCount () const; inline DimNodeId getCompCount () const;
inline void setNodeCount (Tree &tree, DimNodeId nodeCount); inline void setNodeCount (Tree &tree, DimNodeId nodeCount);
@ -27,6 +28,7 @@ namespace otb {
/*! Pointers on the children and count how many children a parents have */ /*! Pointers on the children and count how many children a parents have */
DimNodeId *children, *childCount; DimNodeId *children, *childCount;
// XXX compWeights ???
}; };
#include "TreeBuilder.tpp" #include "TreeBuilder.tpp"

View File

@ -20,7 +20,13 @@ TreeBuilder::buildTree (Tree &tree) {
} }
inline void inline void
TreeBuilder::updateAttributes (Tree &tree) { TreeBuilder::setTreeSize (Tree &tree, const Size &size) {
tree.resize (size.width, size.height);
getTranscient (tree);
}
inline void
TreeBuilder::getTranscient (Tree &tree) {
leafCount = tree.leafCount; leafCount = tree.leafCount;
nodeCount = tree.nodeCount; nodeCount = tree.nodeCount;
leafParents = tree.leafParents; leafParents = tree.leafParents;

View File

@ -5,8 +5,7 @@ using namespace otb::triskele;
void void
QuadTreeBuilder::buildTree (Tree &tree) { QuadTreeBuilder::buildTree (Tree &tree) {
// Building the tree by setting leafs's and components's parents // Building the tree by setting leafs's and components's parents
tree.resize (width, height); setTreeSize (tree, Size (width, height));
updateAttributes (tree);
DimImg parentCount = getStepCount (0, 0, width, height); DimImg parentCount = getStepCount (0, 0, width, height);
DimImg parentUsed = parentCount; DimImg parentUsed = parentCount;

View File

@ -9,7 +9,7 @@ Tree::Tree (const DimSideImg &width, const DimSideImg &height)
size = Size (width, height); size = Size (width, height);
} }
Tree::Tree (const DimImg &leafCount) Tree::Tree ()
: size (), : size (),
leafCount (0), leafCount (0),
nodeCount (0), nodeCount (0),
@ -19,7 +19,6 @@ Tree::Tree (const DimImg &leafCount)
childCount (nullptr), childCount (nullptr),
state (State::Void) state (State::Void)
{ {
book (leafCount);
clear (); clear ();
} }
@ -33,7 +32,7 @@ Tree::clear () {
if (!leafCount) if (!leafCount)
return; return;
childCount[0] = childCount[1] = 0; childCount[0] = childCount[1] = 0;
// XXX fill// // XXX dealThreadFill_n avec coreCount
fill_n (leafParents, leafCount*2, DimImg_MAX); fill_n (leafParents, leafCount*2, DimImg_MAX);
#ifdef SMART_LOG #ifdef SMART_LOG
fill_n (children, (leafCount-1)*2, 0); fill_n (children, (leafCount-1)*2, 0);
@ -43,14 +42,14 @@ Tree::clear () {
void void
Tree::resize (const DimSideImg &width, const DimSideImg &height) { Tree::resize (const DimSideImg &width, const DimSideImg &height) {
resize ((DimImg)width * (DimImg)height); // resize ((DimImg)width * (DimImg)height);
size = Size (width, height); size = Size (width, height);
} // }
void // void
Tree::resize (const DimImg &leafCount) { // Tree::resize (const DimImg &leafCount) {
size = NullSize; // size = NullSize;
book (leafCount); book ((DimImg)width * (DimImg)height);
clear (); clear ();
} }
@ -82,7 +81,7 @@ Tree::book (const DimImg &leafCount) {
children = new DimNodeId[(leafCount-1)*2]; children = new DimNodeId[(leafCount-1)*2];
childCount = new DimNodeId[leafCount+2]; childCount = new DimNodeId[leafCount+2];
clear (); clear ();
} }

View File

@ -12,16 +12,15 @@ XMLTreeBuilder::buildTree (Tree &tree) {
int width, height; int width, height;
if (treeNode->QueryIntAttribute ("width", &width) == TIXML_SUCCESS && if (treeNode->QueryIntAttribute ("width", &width) == TIXML_SUCCESS &&
treeNode->QueryIntAttribute ("height", &height) == TIXML_SUCCESS) treeNode->QueryIntAttribute ("height", &height) == TIXML_SUCCESS)
tree.resize(width, height); setTreeSize (tree, Size (width, height));
else { else {
if (treeNode->QueryIntAttribute ("leafCount", &width) != TIXML_SUCCESS) if (treeNode->QueryIntAttribute ("leafCount", &width) != TIXML_SUCCESS)
return; return;
tree.resize(width); setTreeSize (tree, Size (width, 1));
} }
DimNodeId nodeCount = getNodeCount (treeNode); DimNodeId nodeCount = getNodeCount (treeNode);
tree.setNodeCount (nodeCount); setNodeCount (tree, nodeCount);
updateAttributes (tree);
DimNodeId rootParent = nodeCount; DimNodeId rootParent = nodeCount;
compParents[--rootParent] = nodeCount; compParents[--rootParent] = nodeCount;

View File

@ -31,11 +31,13 @@ void prog (const Option &option) {
Border border; Border border;
GraphWalker graphWalker (raster.getSize (), border); GraphWalker graphWalker (raster.getSize (), border);
//MinWeight<PixelT, PixelT> w (raster.getPixels (), raster.getSize ());
ArrayTreeBuilder<PixelT, PixelT> atb (option.treeCoreCount, raster, graphWalker, TreeType::MAX); ArrayTreeBuilder<PixelT, PixelT> atb (option.treeCoreCount, raster, graphWalker, TreeType::MAX);
Tree tree; Tree tree;
atb.buildTree (tree); atb.buildTree (tree);
// XXX buildAttr
// XXX write
tree.printTree (); tree.printTree ();
cerr << endl << "*** prog ok!" << endl; cerr << endl << "*** prog ok!" << endl;