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

View File

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

View File

@ -32,17 +32,12 @@ namespace otb {
const Border &border;
const Connectivity connectivity;
GraphWalker (const Size &size, const Border &border, const Connectivity &connectivity = Connectivity::C4)
: size (size), border (border), connectivity (connectivity) {
BOOST_ASSERT (size.width >= DimImg (0));
BOOST_ASSERT (size.height >= DimImg (0));
}
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 GraphWalker (const Size &size, const Border &border, const Connectivity &connectivity = Connectivity::C4);
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,
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
// ========================================
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
GraphWalker::vertexMaxCount () const {
return vertexMaxCount (size);

View File

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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,8 @@ namespace otb {
protected:
// 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 void setNodeCount (Tree &tree, DimNodeId nodeCount);
@ -27,6 +28,7 @@ namespace otb {
/*! Pointers on the children and count how many children a parents have */
DimNodeId *children, *childCount;
// XXX compWeights ???
};
#include "TreeBuilder.tpp"

View File

@ -20,7 +20,13 @@ TreeBuilder::buildTree (Tree &tree) {
}
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;
nodeCount = tree.nodeCount;
leafParents = tree.leafParents;

View File

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

View File

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

View File

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

View File

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