modifié : include/ArrayTree/ArrayTreeBuilder.hpp
modifié : include/ArrayTree/ArrayTreeBuilder.tpp modifié : include/ArrayTree/Border.hpp modifié : include/ArrayTree/Border.tpp modifié : include/ArrayTree/GraphWalker.tpp modifié : include/ArrayTree/Leader.hpp modifié : include/ArrayTree/Leader.tpp modifié : include/Attribute.hpp modifié : include/AttributeProfiles.hpp modifié : include/AttributeProfiles.tpp modifié : include/CompAttribute.hpp modifié : include/CompAttribute.tpp modifié : include/IImage.hpp modifié : include/IImage.tpp modifié : include/Tree.hpp modifié : include/Tree.tpp modifié : include/TreeBuilder.hpp modifié : include/TreeBuilder.tpp supprimé : src/Attribute.cpp modifié : src/CMakeLists.txt modifié : src/QuadTree/QuadTreeBuilder.cpp modifié : src/TestArrayTreeBuilder.cpp modifié : src/Tree.cpp modifié : src/XMLTree/XMLTreeBuilder.cpp modifié : src/apGenerator.cpp
This commit is contained in:
parent
5d83342f5f
commit
8ca10923c4
@ -34,7 +34,7 @@ namespace otb {
|
||||
Leader leaders;
|
||||
|
||||
// transcient
|
||||
DimNodeId *childCountRec;
|
||||
DimNodeId *childCount;
|
||||
DimImg *newCompId;
|
||||
WeightT *compWeights;
|
||||
public:
|
||||
|
@ -14,7 +14,7 @@ ArrayTreeBuilder<WeightT, PixelT>::ArrayTreeBuilder (Raster<PixelT> &raster, con
|
||||
treeType (treeType),
|
||||
countingFlag (countingSort),
|
||||
compWeights (nullptr),
|
||||
childCountRec (nullptr),
|
||||
childCount (nullptr),
|
||||
newCompId (nullptr)
|
||||
{
|
||||
DEF_LOG ("ArrayTreeBuilder::ArrayTreeBuilder", "");
|
||||
@ -35,7 +35,7 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, WeightAttributes<Weigh
|
||||
if (!leafCount)
|
||||
return;
|
||||
leaders.book (leafCount);
|
||||
childCountRec = childCount+2;
|
||||
childCount = childSum+2;
|
||||
newCompId = leaders.getLeaders ();
|
||||
compWeights = weightAttributes.getValues ();
|
||||
SMART_LOG_EXPR (dealThreadFill_n (leafCount-1, coreCount, compWeights, 0));
|
||||
@ -64,7 +64,7 @@ ArrayTreeBuilder<WeightT, PixelT>::buildTree (Tree &tree, WeightAttributes<Weigh
|
||||
leaders.free ();
|
||||
newCompId = nullptr;
|
||||
buildChildren ();
|
||||
childCountRec = nullptr;
|
||||
childCount = nullptr;
|
||||
|
||||
SMART_LOG (tree.printTree ());
|
||||
}
|
||||
@ -279,7 +279,7 @@ ArrayTreeBuilder<WeightT, PixelT>::buildParents (Edge<WeightT> *edges, const Wei
|
||||
continue;
|
||||
} else if (compWeights[ra] == compWeights [rb]) {
|
||||
// ra.weight = rb.weight // XXX ?= curEdge.weight
|
||||
if (childCountRec [ra] < childCountRec [rb]) {
|
||||
if (childCount [ra] < childCount [rb]) {
|
||||
swap (la, lb);
|
||||
swap (ra, rb);
|
||||
}
|
||||
@ -302,7 +302,7 @@ ArrayTreeBuilder<WeightT, PixelT>::buildParents (Edge<WeightT> *edges, const Wei
|
||||
leaders.link (pa, leader);
|
||||
leaders.link (pb, leader);
|
||||
|
||||
SMART_LOG (" leader:" << leader << " w:" << compWeights [leader] << " c:" << childCountRec [leader]);
|
||||
SMART_LOG (" leader:" << leader << " w:" << compWeights [leader] << " c:" << childCount [leader]);
|
||||
}
|
||||
|
||||
SMART_LOG ("topParent:" << topParent);
|
||||
@ -315,8 +315,8 @@ 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];
|
||||
BOOST_ASSERT (childCount [par]);
|
||||
--childCount [par];
|
||||
}
|
||||
|
||||
// ----------------------------------------
|
||||
@ -404,7 +404,7 @@ ArrayTreeBuilder<WeightT, PixelT>::connectLeaf (DimImg a, DimImg b, const Weight
|
||||
// eqW1 | eqW2
|
||||
SMART_LOG ("eqW1 | eqW2: incr leaf");
|
||||
unlinkParent (parA);
|
||||
++childCountRec[parB];
|
||||
++childCount[parB];
|
||||
leafParents[a] = parB;
|
||||
SMART_LOG ("parA: " << logComp (parA) << " parB: " << logComp (parB));
|
||||
}
|
||||
@ -431,7 +431,7 @@ ArrayTreeBuilder<WeightT, PixelT>::connect3Comp (DimImg newComp, DimImg topA, Di
|
||||
BOOST_ASSERT (findTopComp (topB, weightFunct) == topB);
|
||||
BOOST_ASSERT (weightFunct.isWeightInf (compWeights[newComp], compWeights[topB]));
|
||||
compParents[newComp] = topB;
|
||||
++childCountRec[topB];
|
||||
++childCount[topB];
|
||||
SMART_LOG ("topB: " << logComp (topB));
|
||||
connectComp (topA, topB, weightFunct);
|
||||
}
|
||||
@ -454,20 +454,20 @@ ArrayTreeBuilder<WeightT, PixelT>::connectComp (DimImg topA, DimImg topB, const
|
||||
if (topA == topB)
|
||||
return;
|
||||
if (compWeights[topA] == compWeights[topB] &&
|
||||
childCountRec[topA] < childCountRec[topB])
|
||||
childCount[topA] < childCount[topB])
|
||||
swap (topA, topB);
|
||||
DimImg grandParB = findTopComp (compParents[topB], weightFunct);
|
||||
if (compWeights[topA] == compWeights[topB]) {
|
||||
childCountRec[topA] += childCountRec[topB];
|
||||
childCountRec[topB] = 0;
|
||||
childCount[topA] += childCount[topB];
|
||||
childCount[topB] = 0;
|
||||
} else
|
||||
++childCountRec[topA];
|
||||
++childCount[topA];
|
||||
compParents[topB] = topA;
|
||||
SMART_LOG ("topA: " << logComp (topA) << " topB: " << logComp (topB));
|
||||
if (grandParB == DimImg_MAX)
|
||||
return;
|
||||
BOOST_ASSERT (childCountRec [grandParB]);
|
||||
--childCountRec[grandParB];
|
||||
BOOST_ASSERT (childCount [grandParB]);
|
||||
--childCount[grandParB];
|
||||
SMART_LOG ("grandParB: " << logComp (grandParB));
|
||||
topB = topA;
|
||||
topA = findTopComp (grandParB, compWeights[topA], weightFunct);
|
||||
@ -504,7 +504,7 @@ ArrayTreeBuilder<WeightT, PixelT>::updateNewId (const DimImg curComp, DimImg &co
|
||||
return;
|
||||
const DimImg &top = findCompMultiChild (curComp);
|
||||
BOOST_ASSERT (top != DimImg_MAX);
|
||||
BOOST_ASSERT (childCountRec[top]);
|
||||
BOOST_ASSERT (childCount[top]);
|
||||
|
||||
if (curComp != top) {
|
||||
// 0 => merge || no more child
|
||||
@ -523,13 +523,13 @@ ArrayTreeBuilder<WeightT, PixelT>::updateNewId (const DimImg curComp, DimImg &co
|
||||
// // XXX arbres non-connexe ?
|
||||
// cerr << "coucou ptop-max: " << curComp << endl;
|
||||
}
|
||||
const DimNodeId &newTopChildCountRec = childCountRec[top];
|
||||
const DimNodeId &newTopChildCountRec = childCount[top];
|
||||
const DimImg &newTopCompParent = compParents[top];
|
||||
const WeightT &newTopWeight = compWeights[top]; // only in case of unnecessary comp
|
||||
for (DimImg sibling = curComp; sibling != top; ) {
|
||||
DimImg nextSibling = compParents[sibling];
|
||||
newCompId[sibling] = newTopIdx;
|
||||
childCountRec[sibling] = newTopChildCountRec;
|
||||
childCount[sibling] = newTopChildCountRec;
|
||||
compParents[sibling] = newTopCompParent;
|
||||
// only in case of unnecessary comp
|
||||
compWeights[sibling] = newTopWeight;
|
||||
@ -571,7 +571,7 @@ ArrayTreeBuilder<WeightT, PixelT>::compress (const DimImg &compTop) {
|
||||
|
||||
swap (compParents[curComp], compParents[newIdxComp]);
|
||||
swap (compWeights[curComp], compWeights[newIdxComp]);
|
||||
swap (childCountRec[curComp], childCountRec[newIdxComp]);
|
||||
swap (childCount[curComp], childCount[newIdxComp]);
|
||||
swap (newCompId[curComp], newCompId[newIdxComp]);
|
||||
}
|
||||
// XXX YYY curComp ? compTop ?
|
||||
@ -581,7 +581,7 @@ ArrayTreeBuilder<WeightT, PixelT>::compress (const DimImg &compTop) {
|
||||
template<typename WeightT, typename PixelT>
|
||||
inline DimImg
|
||||
ArrayTreeBuilder<WeightT, PixelT>::createParent (DimImg &topParent, const WeightT &weight, DimImg &parentChildA, DimImg &parentChildB) {
|
||||
childCountRec [topParent] = 2;
|
||||
childCount [topParent] = 2;
|
||||
compWeights [topParent] = weight;
|
||||
return parentChildA = parentChildB = topParent++;
|
||||
}
|
||||
@ -590,7 +590,7 @@ ArrayTreeBuilder<WeightT, PixelT>::createParent (DimImg &topParent, const Weight
|
||||
template<typename WeightT, typename PixelT>
|
||||
inline void
|
||||
ArrayTreeBuilder<WeightT, PixelT>::addChild (const DimImg &parent, DimImg &child) {
|
||||
++childCountRec [parent];
|
||||
++childCount [parent];
|
||||
child = parent;
|
||||
}
|
||||
|
||||
@ -598,8 +598,8 @@ ArrayTreeBuilder<WeightT, PixelT>::addChild (const DimImg &parent, DimImg &child
|
||||
template<typename WeightT, typename PixelT>
|
||||
inline void
|
||||
ArrayTreeBuilder<WeightT, PixelT>::addChildren (const DimImg &parent, const DimImg &sibling) {
|
||||
childCountRec [parent] += childCountRec [sibling];
|
||||
childCountRec [sibling] = 0;
|
||||
childCount [parent] += childCount [sibling];
|
||||
childCount [sibling] = 0;
|
||||
compParents [sibling] = parent;
|
||||
}
|
||||
|
||||
@ -661,7 +661,7 @@ ArrayTreeBuilder<WeightT, PixelT>::findCompMultiChild (DimImg comp) {
|
||||
const DimImg &parent = compParents[comp];
|
||||
if (parent == DimImg_MAX)
|
||||
return comp;
|
||||
if (childCountRec[comp] > 1 && compWeights[comp] != compWeights[parent])
|
||||
if (childCount[comp] > 1 && compWeights[comp] != compWeights[parent])
|
||||
return comp;
|
||||
comp = parent;
|
||||
}
|
||||
@ -674,21 +674,21 @@ ArrayTreeBuilder<WeightT, PixelT>::buildChildren () {
|
||||
|
||||
SMART_DEF_LOG ("ArrayTreeBuilder::buildChildren", "");
|
||||
|
||||
BOOST_ASSERT (childCount[0] == 0);
|
||||
BOOST_ASSERT (childCount[1] == 0);
|
||||
BOOST_ASSERT (childSum[0] == 0);
|
||||
BOOST_ASSERT (childSum[1] == 0);
|
||||
|
||||
DimImg compCount = getCompCount ();
|
||||
partial_sum (childCountRec, childCountRec+compCount, childCountRec);
|
||||
partial_sum (childCount, childCount+compCount, childCount);
|
||||
|
||||
// set
|
||||
DimNodeId *childGetOrder = childCount+1;
|
||||
DimNodeId *childGetOrder = childSum+1;
|
||||
for (DimNodeId i = 0; i < nodeCount-1; ++i) {
|
||||
if (leafParents[i] == DimImg_MAX)
|
||||
continue;
|
||||
BOOST_ASSERT (leafParents[i] < compCount);
|
||||
children[childGetOrder[leafParents[i]]++] = i;
|
||||
}
|
||||
BOOST_ASSERT (childCount[0] == 0);
|
||||
BOOST_ASSERT (childSum[0] == 0);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
@ -701,7 +701,7 @@ inline ostream &
|
||||
ArrayTreeBuilder<WeightT, PixelT>::CLogComp::print (ostream &out) const {
|
||||
if (compId == DimImg_MAX)
|
||||
return out << "M(-/-)";
|
||||
return out << compId << "(" << atb.childCountRec[compId] << "/" << atb.compWeights [compId] << ")";
|
||||
return out << compId << "(" << atb.childCount[compId] << "/" << atb.compWeights [compId] << ")";
|
||||
}
|
||||
|
||||
// template<typename WeightT, typename PixelT>
|
||||
|
@ -60,7 +60,7 @@ namespace otb {
|
||||
Size size;
|
||||
|
||||
/*! Tableau "simplifié" des pixels */
|
||||
uint8_t *map;
|
||||
vector<uint8_t> map;
|
||||
|
||||
friend inline ostream &operator << (ostream &out, const Border &border);
|
||||
};
|
||||
|
@ -12,12 +12,12 @@ Border::getMapLength (DimImg pixelsCount) {
|
||||
|
||||
inline bool
|
||||
Border::isBorder (DimImg idx) const {
|
||||
return map ? map[idx/8] & (1 << (idx%8)) : false;
|
||||
return map.size () ? map[idx/8] & (1 << (idx%8)) : false;
|
||||
}
|
||||
|
||||
inline bool
|
||||
Border::isBorder (const Point &p) const {
|
||||
return map ? isBorder (pointToId (size, p)) : false;
|
||||
return map.size () ? isBorder (pointToId (size, p)) : false;
|
||||
}
|
||||
|
||||
inline void
|
||||
@ -45,27 +45,24 @@ Border::Border ()
|
||||
: pixelsCount (0),
|
||||
mapLength (0),
|
||||
size (),
|
||||
map (NULL) {
|
||||
}
|
||||
map () {
|
||||
}
|
||||
|
||||
inline
|
||||
Border::Border (const Size &size, bool defaultVal)
|
||||
: pixelsCount (getPixelsCount (size)),
|
||||
mapLength (getMapLength (pixelsCount)),
|
||||
size (size) {
|
||||
map = new uint8_t [mapLength];
|
||||
reset (defaultVal);
|
||||
}
|
||||
|
||||
inline
|
||||
Border::~Border () {
|
||||
if (map)
|
||||
delete [] map;
|
||||
}
|
||||
|
||||
inline void
|
||||
Border::reset (bool defaultVal) {
|
||||
std::fill_n (map, mapLength, defaultVal ? 0xFF : 0);
|
||||
map.assign (mapLength, defaultVal ? 0xFF : 0);
|
||||
if (!(mapLength && defaultVal))
|
||||
return;
|
||||
map[mapLength-1] &= 0xFF >> (8-(pixelsCount%8))%8;
|
||||
|
@ -289,10 +289,10 @@ GraphWalker::getCountingSortedEdges (const Rect &rect, TileItem tileItem, Edge<W
|
||||
int bits = 8*sizeof (WeightT);
|
||||
BOOST_ASSERT (bits < 17);
|
||||
DimEdge dim = 1UL << bits;
|
||||
DimImg *indices = new DimImg [dim+1];
|
||||
DimImg *histogram = indices+1;
|
||||
vector<DimImg> counters (dim+1, 0);
|
||||
DimImg *indices = &counters [0];
|
||||
DimImg *histogram = &indices [1];
|
||||
DimImg sum = 0;
|
||||
fill_n (histogram, dim, 0);
|
||||
forEachEdgePt (rect, tileItem,
|
||||
[&histogram, &ef] (Point const &a, Point const &b) {
|
||||
++histogram[(size_t) ef.getWeight (a, b)];
|
||||
@ -322,7 +322,6 @@ GraphWalker::getCountingSortedEdges (const Rect &rect, TileItem tileItem, Edge<W
|
||||
SMART_LOG_EXPR (cerr << printEdge (edge, size) << endl);
|
||||
});
|
||||
SMART_LOG (endl << printEdges (edges, size, sum));
|
||||
delete [] (histogram-1);
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
#ifndef _OTB_TRISKELE_ARRAY_TREE_LEADER_HPP
|
||||
#define _OTB_TRISKELE_ARRAY_TREE_LEADER_HPP
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
//#include "triskeleDebug.hpp"
|
||||
#include "triskeleDebug.hpp"
|
||||
#include "triskeleBase.hpp"
|
||||
#include "triskeleArrayTreeBase.hpp"
|
||||
|
||||
@ -18,7 +19,7 @@ namespace otb {
|
||||
DimImg size;
|
||||
|
||||
/*! Tableau des leaders, chaque case contient une référence vers principal leader connu */
|
||||
DimImg *leaders;
|
||||
vector<DimImg> leaders;
|
||||
|
||||
public:
|
||||
inline Leader ();
|
||||
@ -30,9 +31,6 @@ namespace otb {
|
||||
/*! Libère la mémoire allouée par les tableaux et met size à 0 */
|
||||
inline void free ();
|
||||
|
||||
/*! Remplit leaders de DimImg_MAX */
|
||||
inline void reset ();
|
||||
|
||||
/*! Cherche le leaders du pixel a, Si a n'en a pas, cela retourne a */
|
||||
inline DimImg find (DimImg a) const;
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
inline
|
||||
Leader::Leader ()
|
||||
: size (0),
|
||||
leaders (NULL) {
|
||||
leaders () {
|
||||
}
|
||||
|
||||
inline
|
||||
@ -17,37 +17,18 @@ Leader::~Leader () {
|
||||
inline void
|
||||
Leader::book (DimImg vertexCount) {
|
||||
SMART_DEF_LOG ("Leader::book", "vertexCount:" << vertexCount);
|
||||
if (vertexCount == size) {
|
||||
reset ();
|
||||
return;
|
||||
}
|
||||
free ();
|
||||
if (!vertexCount)
|
||||
return;
|
||||
size = vertexCount;
|
||||
leaders = new DimImg [vertexCount];
|
||||
reset ();
|
||||
leaders.assign (size, DimImg_MAX);
|
||||
}
|
||||
|
||||
// ---------------------------------------
|
||||
inline void
|
||||
Leader::free () {
|
||||
SMART_DEF_LOG ("Leader::free", "");
|
||||
if (leaders)
|
||||
delete [] leaders;
|
||||
leaders = NULL;
|
||||
leaders = vector<DimImg> ();
|
||||
size = 0;
|
||||
}
|
||||
|
||||
// ---------------------------------------
|
||||
inline void
|
||||
Leader::reset () {
|
||||
if (!size)
|
||||
return;
|
||||
// XXX dealThreadFill_n avec coreCount
|
||||
std::fill_n (leaders, size, DimImg_MAX);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
inline DimImg
|
||||
Leader::find (DimImg a) const {
|
||||
@ -83,7 +64,7 @@ Leader::link (DimImg a, const DimImg &r) {
|
||||
// ========================================
|
||||
inline DimImg *
|
||||
Leader::getLeaders () {
|
||||
return leaders;
|
||||
return &leaders[0];
|
||||
}
|
||||
|
||||
// ========================================
|
||||
|
@ -6,35 +6,35 @@
|
||||
namespace otb {
|
||||
namespace triskele {
|
||||
|
||||
/** Attribute */
|
||||
class Attribute {
|
||||
public:
|
||||
Attribute ();
|
||||
Attribute (const Attribute &o) = delete;
|
||||
// /** Attribute */
|
||||
// class Attribute {
|
||||
// public:
|
||||
// Attribute ();
|
||||
// Attribute (const Attribute &o) = delete;
|
||||
|
||||
void
|
||||
setTree (Tree &treeC);
|
||||
// void
|
||||
// setTree (Tree &treeC);
|
||||
|
||||
template<typename T>
|
||||
void
|
||||
free ();
|
||||
// template<typename T>
|
||||
// void
|
||||
// free ();
|
||||
|
||||
template<typename T>
|
||||
T
|
||||
getAttribute (const DimNodeId &nodeId);
|
||||
// template<typename T>
|
||||
// T
|
||||
// getAttribute (const DimNodeId &nodeId);
|
||||
|
||||
template<typename T>
|
||||
void
|
||||
generate ();
|
||||
// template<typename T>
|
||||
// void
|
||||
// generate ();
|
||||
|
||||
protected:
|
||||
virtual void
|
||||
generate () = 0;
|
||||
// protected:
|
||||
// virtual void
|
||||
// generate () = 0;
|
||||
|
||||
protected:
|
||||
Tree *tree;
|
||||
void *attributes;
|
||||
};
|
||||
// protected:
|
||||
// Tree *tree;
|
||||
// void *attributes;
|
||||
// };
|
||||
} // triskele
|
||||
} // otb
|
||||
|
||||
|
@ -17,9 +17,9 @@ namespace otb {
|
||||
inline const PixelT *getValues () const;
|
||||
|
||||
protected:
|
||||
const Tree &tree;
|
||||
DimNodeId leafCount;
|
||||
PixelT *values;
|
||||
const Tree &tree;
|
||||
DimNodeId leafCount;
|
||||
vector<PixelT> values;
|
||||
|
||||
inline void free ();
|
||||
inline void book (const DimImg &leafCount);
|
||||
|
@ -6,7 +6,7 @@ inline
|
||||
AttributeProfiles<PixelT>::AttributeProfiles (const Tree &tree)
|
||||
: tree (tree),
|
||||
leafCount (0),
|
||||
values (nullptr) {
|
||||
values () {
|
||||
updateTranscient ();
|
||||
}
|
||||
|
||||
@ -25,33 +25,27 @@ AttributeProfiles<PixelT>::updateTranscient () {
|
||||
template<typename PixelT>
|
||||
inline PixelT *
|
||||
AttributeProfiles<PixelT>::getValues () {
|
||||
return values;
|
||||
return &values[0];
|
||||
}
|
||||
|
||||
template<typename PixelT>
|
||||
inline const PixelT *
|
||||
AttributeProfiles<PixelT>::getValues () const {
|
||||
return values;
|
||||
return &values[0];
|
||||
}
|
||||
|
||||
template<typename PixelT>
|
||||
inline void
|
||||
AttributeProfiles<PixelT>::free () {
|
||||
if (values)
|
||||
delete[] values;
|
||||
values = nullptr;
|
||||
values = vector<PixelT> ();
|
||||
}
|
||||
|
||||
template<typename PixelT>
|
||||
inline void
|
||||
AttributeProfiles<PixelT>::book (const DimImg &leafCount) {
|
||||
if (this->leafCount == leafCount)
|
||||
return;
|
||||
free ();
|
||||
if (!leafCount)
|
||||
return;
|
||||
this->leafCount = leafCount;
|
||||
values = new PixelT[leafCount*2];
|
||||
// XXX max : leafCount*2-1
|
||||
values.resize (leafCount*2);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
@ -60,7 +54,7 @@ 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;
|
||||
<< printMap (&values[0], doubleSize, tree.getNodeCount ()) << endl << endl;
|
||||
}
|
||||
|
||||
#endif // _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP
|
||||
|
@ -27,7 +27,7 @@ namespace otb {
|
||||
protected:
|
||||
const Tree &tree;
|
||||
DimNodeId leafCount;
|
||||
AttrT *values;
|
||||
vector<AttrT> values;
|
||||
|
||||
inline void free ();
|
||||
inline void book (const DimImg &leafCount);
|
||||
|
@ -6,14 +6,13 @@ inline
|
||||
CompAttribute<AttrT>::CompAttribute (const Tree &tree)
|
||||
: tree (tree),
|
||||
leafCount (0),
|
||||
values (nullptr) {
|
||||
values () {
|
||||
updateTranscient ();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename AttrT>
|
||||
inline
|
||||
CompAttribute<AttrT>::~CompAttribute () {
|
||||
free ();
|
||||
}
|
||||
|
||||
template<typename AttrT>
|
||||
@ -26,13 +25,13 @@ CompAttribute<AttrT>::updateTranscient () {
|
||||
template<typename AttrT>
|
||||
inline const AttrT *
|
||||
CompAttribute<AttrT>::getValues () const {
|
||||
return values;
|
||||
return &values[0];
|
||||
}
|
||||
|
||||
template<typename AttrT>
|
||||
inline AttrT *
|
||||
CompAttribute<AttrT>::getValues () {
|
||||
return values;
|
||||
return &values[0];
|
||||
}
|
||||
|
||||
template<typename AttrT>
|
||||
@ -53,27 +52,20 @@ inline ostream &
|
||||
CompAttribute<AttrT>::print (ostream &out, const string &msg) const {
|
||||
cout << "values: " << msg << endl;
|
||||
const Size doubleSize (tree.getSize().width, 2*tree.getSize ().height);
|
||||
cout << printMap (values, doubleSize, tree.getCompCount ()) << endl << endl;
|
||||
cout << printMap (&values[0], doubleSize, tree.getCompCount ()) << endl << endl;
|
||||
}
|
||||
|
||||
template<typename AttrT>
|
||||
inline void
|
||||
CompAttribute<AttrT>::free () {
|
||||
if (values)
|
||||
delete[] values;
|
||||
values = nullptr;
|
||||
values = vector<AttrT> ();
|
||||
}
|
||||
|
||||
template<typename AttrT>
|
||||
inline void
|
||||
CompAttribute<AttrT>::book (const DimImg &leafCount) {
|
||||
if (this->leafCount == leafCount)
|
||||
return;
|
||||
free ();
|
||||
if (!leafCount)
|
||||
return;
|
||||
this->leafCount = leafCount;
|
||||
values = new AttrT[leafCount];
|
||||
values.resize (leafCount);
|
||||
}
|
||||
|
||||
// ========================================
|
||||
|
@ -18,7 +18,7 @@ namespace triskele {
|
||||
class Raster {
|
||||
private:
|
||||
Size size;
|
||||
PixelT *pixels;
|
||||
vector<PixelT> pixels;
|
||||
public:
|
||||
inline void setSize (const Size &size);
|
||||
inline const Size &getSize () const;
|
||||
|
@ -8,10 +8,8 @@ Raster<PixelT>::setSize (const Size &size) {
|
||||
DEF_LOG ("Raster::setSize", "size: " << size);
|
||||
if (this->size == size)
|
||||
return;
|
||||
if (pixels)
|
||||
delete [] pixels;
|
||||
pixels.resize (DimImg (size.width)*DimImg (size.height));
|
||||
this->size = size;
|
||||
pixels = new PixelT [DimImg (size.width)*DimImg (size.height)];
|
||||
}
|
||||
|
||||
template<typename PixelT>
|
||||
@ -23,13 +21,13 @@ Raster<PixelT>::getSize () const {
|
||||
template<typename PixelT>
|
||||
inline const PixelT *
|
||||
Raster<PixelT>::getPixels () const {
|
||||
return pixels;
|
||||
return &pixels[0];
|
||||
}
|
||||
|
||||
template<typename PixelT>
|
||||
inline PixelT *
|
||||
Raster<PixelT>::getPixels () {
|
||||
return pixels;
|
||||
return &pixels[0];
|
||||
}
|
||||
|
||||
template<typename PixelT>
|
||||
@ -55,16 +53,13 @@ template<typename PixelT>
|
||||
inline
|
||||
Raster<PixelT>::Raster (const Size &size)
|
||||
: size (NullSize),
|
||||
pixels (nullptr) {
|
||||
pixels () {
|
||||
setSize (size);
|
||||
}
|
||||
|
||||
template<typename PixelT>
|
||||
inline
|
||||
Raster<PixelT>::~Raster () {
|
||||
if (pixels)
|
||||
delete [] pixels;
|
||||
pixels = nullptr;
|
||||
}
|
||||
|
||||
// ========================================
|
||||
|
@ -24,7 +24,7 @@ namespace otb {
|
||||
class Tree {
|
||||
friend class TreeBuilder;
|
||||
private:
|
||||
inline DimNodeId *getChildCount ();
|
||||
inline DimNodeId *getChildSum ();
|
||||
|
||||
protected:
|
||||
/*! nb core for build and compute attributes */
|
||||
@ -39,11 +39,12 @@ namespace otb {
|
||||
DimNodeId nodeCount; /* nodeCount = leafCount+compCount */
|
||||
|
||||
/*! Pointers on the parents of each leafs / nodes */
|
||||
DimImg *leafParents, *compParents;
|
||||
vector<DimImg> leafParents;
|
||||
DimImg *compParents;
|
||||
|
||||
/*! Pointers on the children and count how many children a parents have */
|
||||
DimImg *childCount;
|
||||
DimNodeId *children;
|
||||
vector<DimImg> childSum;
|
||||
vector<DimNodeId> children;
|
||||
|
||||
/*! Pointers of same weight in parents (+1 : last is root)*/
|
||||
vector<DimImg> weightBounds;
|
||||
|
@ -8,8 +8,8 @@ Tree::getCoreCount () const {
|
||||
}
|
||||
|
||||
inline DimNodeId *
|
||||
Tree::getChildCount () {
|
||||
return childCount;
|
||||
Tree::getChildSum () {
|
||||
return &childSum[0];
|
||||
}
|
||||
|
||||
inline void
|
||||
@ -67,7 +67,7 @@ Tree::getCompParent (const DimImg &compId) const {
|
||||
|
||||
inline const DimImg &
|
||||
Tree::getChildrenCount (const DimImg &compId) const {
|
||||
return childCount[compId];
|
||||
return childSum[compId];
|
||||
}
|
||||
inline const DimNodeId &
|
||||
Tree::getChildren (const DimImg &childId) const {
|
||||
@ -75,7 +75,7 @@ Tree::getChildren (const DimImg &childId) const {
|
||||
}
|
||||
inline const DimNodeId *
|
||||
Tree::getChildren () const {
|
||||
return children;
|
||||
return &children[0];
|
||||
}
|
||||
|
||||
inline const vector<DimImg> &
|
||||
@ -113,14 +113,14 @@ Tree::forEachNode (const FuncToApply &f /* f (NodeDimImg nodeId) */) const {
|
||||
template<typename FuncToApply>
|
||||
inline void
|
||||
Tree::forEachChild (const DimNodeId &parentId, const FuncToApply &f /* f (DimNodeId childId) */) const {
|
||||
DimNodeId minChild = childCount[parentId], maxChild = childCount[parentId+1];
|
||||
DimNodeId minChild = childSum[parentId], maxChild = childSum[parentId+1];
|
||||
for (DimNodeId childId = minChild; childId < maxChild; ++childId)
|
||||
f (children[childId]);
|
||||
}
|
||||
template<typename FuncToApply>
|
||||
inline void
|
||||
Tree::forEachChildTI (const DimNodeId &parentId, const FuncToApply &f /* f (bool isLeaf, DimImg childId) */) const {
|
||||
DimNodeId minChild = childCount[parentId], maxChild = childCount[parentId+1];
|
||||
DimNodeId minChild = childSum[parentId], maxChild = childSum[parentId+1];
|
||||
for (DimNodeId childId = minChild; childId < maxChild; ++childId) {
|
||||
const DimNodeId &child (getChildren (childId));
|
||||
const bool isLeaf = child < leafCount;
|
||||
|
@ -27,7 +27,7 @@ namespace otb {
|
||||
DimNodeId *leafParents, *compParents;
|
||||
|
||||
/*! Pointers on the children and count how many children a parents have */
|
||||
DimNodeId *children, *childCount;
|
||||
DimNodeId *children, *childSum;
|
||||
// XXX compWeights ???
|
||||
};
|
||||
|
||||
|
@ -29,10 +29,10 @@ inline void
|
||||
TreeBuilder::getTranscient (Tree &tree) {
|
||||
leafCount = tree.leafCount;
|
||||
nodeCount = tree.nodeCount;
|
||||
leafParents = tree.leafParents;
|
||||
leafParents = &tree.leafParents[0];
|
||||
compParents = tree.compParents;
|
||||
children = tree.children;
|
||||
childCount = tree.childCount;
|
||||
children = &tree.children[0];
|
||||
childSum = &tree.childSum[0];
|
||||
}
|
||||
|
||||
inline DimNodeId
|
||||
|
@ -1,26 +0,0 @@
|
||||
#include "Attribute.hpp"
|
||||
|
||||
using namespace otb::triskele;
|
||||
|
||||
template<typename T>
|
||||
void
|
||||
Attribute::free () {
|
||||
delete[] (T*) attributes;
|
||||
attributes = nullptr;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T
|
||||
Attribute::getAttribute (const DimNodeId &nodeId) {
|
||||
return ((T*)attributes)[nodeId];
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void
|
||||
Attribute::generate () {
|
||||
attributes = new T[tree->getLeafCount () + tree->getNodeCount ()];
|
||||
generate ();
|
||||
}
|
||||
|
||||
void
|
||||
Attribute::setTree (Tree &treeC) { tree = &treeC; }
|
@ -4,7 +4,6 @@ set(OTBTreeBuilder_SRC
|
||||
Tree.cpp
|
||||
XMLTree/XMLTreeBuilder.cpp
|
||||
QuadTree/QuadTreeBuilder.cpp
|
||||
Attribute.cpp
|
||||
Attributes/AreaAttribute.cpp
|
||||
testMain.cpp
|
||||
ArrayTree/triskeleArrayTreeBase.cpp
|
||||
|
@ -15,15 +15,15 @@ QuadTreeBuilder::buildTree (Tree &tree) {
|
||||
setParents (parentCount, 0, 0, width, height, width, height);
|
||||
|
||||
// Building children array
|
||||
std::partial_sum (childCount, childCount+parentUsed+2, childCount);
|
||||
std::partial_sum (childSum, childSum+parentUsed+2, childSum);
|
||||
for (DimNodeId i = 0; i < tree.getLeafCount (); ++i) {
|
||||
DimNodeId idP = leafParents[i];
|
||||
children[childCount[idP+1]++] = i;
|
||||
children[childSum[idP+1]++] = i;
|
||||
}
|
||||
|
||||
for (DimNodeId i = tree.getLeafCount (); i < tree.getLeafCount ()+parentUsed-1; ++i) {
|
||||
DimNodeId idP = compParents[i-tree.getLeafCount ()];
|
||||
children[childCount[idP+1]++] = i;
|
||||
children[childSum[idP+1]++] = i;
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ QuadTreeBuilder::setParents (DimImg &parentId,
|
||||
for (DimSideImg j = y; j < height + y; j++) {
|
||||
DimSideImg id = i + j * imgWidth;
|
||||
leafParents[id] = localId;
|
||||
childCount[localId+2]++;
|
||||
childSum[localId+2]++;
|
||||
}
|
||||
return localId;
|
||||
}
|
||||
@ -75,7 +75,7 @@ QuadTreeBuilder::setParents (DimImg &parentId,
|
||||
{x , y + dh1, dw1, dh2},
|
||||
{x + dw1, y + dh1, dw2, dh2}
|
||||
};
|
||||
childCount[localId+2] = 4;
|
||||
childSum[localId+2] = 4;
|
||||
for (int i = 0; i < 4; i++)
|
||||
compParents[setParents (parentId, coords[i][0], coords[i][1], coords[i][2], coords[i][3], imgWidth, imgHeight, level+1)] = localId;
|
||||
return localId;
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "TreeStats.hpp"
|
||||
#include "TreeBuilder.hpp"
|
||||
#include "IImage.hpp"
|
||||
#include "Attribute.hpp"
|
||||
#include "AttributeProfiles.hpp"
|
||||
#include "ArrayTree/triskeleArrayTreeBase.hpp"
|
||||
#include "ArrayTree/triskeleSort.hpp"
|
||||
|
80
src/Tree.cpp
80
src/Tree.cpp
@ -17,10 +17,10 @@ Tree::Tree (unsigned int coreCount)
|
||||
coreCount (coreCount),
|
||||
leafCount (0),
|
||||
nodeCount (0),
|
||||
leafParents (nullptr),
|
||||
leafParents (),
|
||||
compParents (nullptr),
|
||||
children (nullptr),
|
||||
childCount (nullptr),
|
||||
children (),
|
||||
childSum (),
|
||||
state (State::Void)
|
||||
{
|
||||
clear ();
|
||||
@ -33,56 +33,40 @@ Tree::~Tree () {
|
||||
void
|
||||
Tree::clear () {
|
||||
nodeCount = leafCount;
|
||||
leafParents.assign (leafCount*2, DimImg_MAX);
|
||||
weightBounds.resize (0);
|
||||
if (!leafCount)
|
||||
return;
|
||||
childCount[0] = childCount[1] = 0;
|
||||
// XXX dealThreadFill_n avec coreCount
|
||||
fill_n (leafParents, leafCount*2, DimImg_MAX);
|
||||
#ifdef USE_SMART_LOG
|
||||
fill_n (children, (leafCount-1)*2, 0);
|
||||
fill_n (childCount, leafCount+1, 0);
|
||||
children.assign ((leafCount-1)*2, 0);
|
||||
childSum.assign (leafCount+1, 0);
|
||||
#endif
|
||||
weightBounds.resize (0);
|
||||
childSum.resize (leafCount+1);
|
||||
childSum[0] = childSum[1] = 0;
|
||||
}
|
||||
|
||||
void
|
||||
Tree::resize (const DimSideImg &width, const DimSideImg &height) {
|
||||
size = Size (width, height);
|
||||
book ((DimImg)width * (DimImg)height);
|
||||
clear ();
|
||||
}
|
||||
|
||||
void
|
||||
Tree::free () {
|
||||
if (leafParents)
|
||||
delete[] leafParents;
|
||||
leafParents = compParents = nullptr;
|
||||
if (children)
|
||||
delete[] children;
|
||||
if (childCount)
|
||||
delete[] childCount;
|
||||
children = childCount = nullptr;
|
||||
weightBounds.resize (0);
|
||||
leafParents = vector<DimImg> ();
|
||||
compParents = nullptr;
|
||||
children = vector<DimNodeId> ();
|
||||
childSum = vector<DimImg> ();
|
||||
weightBounds = vector<DimImg> ();
|
||||
}
|
||||
|
||||
void
|
||||
Tree::book (const DimImg &leafCount) {
|
||||
if (this->leafCount == leafCount) {
|
||||
clear ();
|
||||
return;
|
||||
}
|
||||
free ();
|
||||
if (!leafCount)
|
||||
return;
|
||||
|
||||
this->leafCount = leafCount;
|
||||
leafParents = new DimNodeId[leafCount*2];
|
||||
compParents = leafParents + leafCount;
|
||||
|
||||
children = new DimNodeId[(leafCount-1)*2];
|
||||
childCount = new DimNodeId[leafCount+2];
|
||||
|
||||
clear ();
|
||||
compParents = &leafParents[leafCount];
|
||||
children.resize ((leafCount-1)*2);
|
||||
childSum.resize (leafCount+1);
|
||||
}
|
||||
|
||||
|
||||
@ -112,7 +96,7 @@ Tree::checkSpare () const {
|
||||
maxParent = leafParents[leafId];
|
||||
});
|
||||
}
|
||||
DimImg *childCountRec = childCount+2;
|
||||
DimImg *childCount = (DimImg*)&childSum[2];
|
||||
for (unsigned int i = 0; i < tileCount; ++i) {
|
||||
DimImg base = vertexMaxBounds [i], maxParent = maxParents [i];
|
||||
for (DimImg compId = base; compId < maxParent; ++compId) {
|
||||
@ -120,7 +104,7 @@ Tree::checkSpare () const {
|
||||
BOOST_ASSERT (compParents[compId] != compId);
|
||||
BOOST_ASSERT (compParents[compId] < maxParent);
|
||||
if (compParents[compId] < compId)
|
||||
BOOST_ASSERT (childCountRec[compParents[compId]] > childCountRec[compId]);
|
||||
BOOST_ASSERT (childCount[compParents[compId]] > childCount[compId]);
|
||||
}
|
||||
BOOST_ASSERT (compParents[maxParent] == DimImg_MAX);
|
||||
}
|
||||
@ -140,7 +124,7 @@ Tree::checkSpare () const {
|
||||
// check weight
|
||||
// XXX monotone
|
||||
|
||||
// check childCount
|
||||
// check childSum
|
||||
|
||||
}
|
||||
|
||||
@ -176,25 +160,25 @@ Tree::check () const {
|
||||
|
||||
// check weightBounds
|
||||
|
||||
// check childCount
|
||||
// check childSum
|
||||
{
|
||||
vector<DimImg> childCount2 (compCount, 0);
|
||||
forEachLeaf ([this, &childCount2] (const DimImg &leafId) {
|
||||
vector<DimImg> childSum2 (compCount, 0);
|
||||
forEachLeaf ([this, &childSum2] (const DimImg &leafId) {
|
||||
if (leafParents[leafId] == DimImg_MAX)
|
||||
// boder
|
||||
return;
|
||||
++childCount2 [leafParents [leafId]];
|
||||
++childSum2 [leafParents [leafId]];
|
||||
});
|
||||
forEachComp ([this, &childCount2, &compCount] (const DimImg &compId) {
|
||||
forEachComp ([this, &childSum2, &compCount] (const DimImg &compId) {
|
||||
if (compId == compCount-1)
|
||||
return;
|
||||
++childCount2 [compParents [compId]];
|
||||
++childSum2 [compParents [compId]];
|
||||
});
|
||||
for (DimImg compId = 0; compId < compCount; ++compId) {
|
||||
// check count
|
||||
BOOST_ASSERT (childCount2 [compId] = childCount [compId+1] - childCount[compId]);
|
||||
BOOST_ASSERT (childSum2 [compId] = childSum [compId+1] - childSum[compId]);
|
||||
// at least 2 children
|
||||
BOOST_ASSERT (childCount2 [compId] > 1);
|
||||
BOOST_ASSERT (childSum2 [compId] > 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,7 +186,7 @@ Tree::check () const {
|
||||
{
|
||||
vector<DimNodeId> childrenMap (nodeCount, DimImg_MAX);
|
||||
forEachComp ([this, &childrenMap] (const DimImg &compId) {
|
||||
DimNodeId minChild = childCount[compId], maxChild = childCount[compId+1];
|
||||
DimNodeId minChild = childSum[compId], maxChild = childSum[compId+1];
|
||||
for (DimNodeId childId = minChild; childId < maxChild; ++childId) {
|
||||
DimNodeId child = children[childId];
|
||||
BOOST_ASSERT (leafParents [child] == compId);
|
||||
@ -231,10 +215,10 @@ Tree::CPrintTree::print (ostream &out) const {
|
||||
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;
|
||||
<< printMap (&tree.leafParents[0], doubleSize, nodeCount) << endl << endl
|
||||
<< printMap (&tree.childSum[onRecord ? 2 : 0], tree.size, nodeCount - tree.leafCount + 1) << endl << endl;
|
||||
if (!onRecord)
|
||||
out << printMap (tree.children, doubleSize, nodeCount-1) << endl << endl;
|
||||
out << printMap (&tree.children[0], doubleSize, nodeCount-1) << endl << endl;
|
||||
if (tree.weightBounds.size ()) {
|
||||
out << "weightBounds: " << endl
|
||||
<< printMap (&tree.weightBounds[0], tree.size, tree.weightBounds.size ()) << endl << endl;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "XMLTree/XMLTreeBuilder.hpp"
|
||||
<#include "XMLTree/XMLTreeBuilder.hpp"
|
||||
|
||||
using namespace otb::triskele;
|
||||
|
||||
@ -26,14 +26,14 @@ XMLTreeBuilder::buildTree (Tree &tree) {
|
||||
compParents[--rootParent] = nodeCount;
|
||||
readNodeChildren (treeNode->FirstChild ()->ToElement (), rootParent);
|
||||
|
||||
std::partial_sum (childCount, childCount+nodeCount+2, childCount);
|
||||
std::partial_sum (childSum, childSum+nodeCount+2, childSum);
|
||||
for (DimNodeId i = 0; i < tree.getLeafCount (); ++i) {
|
||||
DimNodeId idP = leafParents[i];
|
||||
children[childCount[idP+1]++] = i;
|
||||
children[childSum[idP+1]++] = i;
|
||||
}
|
||||
for (DimNodeId i = tree.getLeafCount (); i < tree.getLeafCount ()+nodeCount-1; ++i) {
|
||||
DimNodeId idP = compParents[i-tree.getLeafCount ()];
|
||||
children[childCount[idP+1]++] = i;
|
||||
children[childSum[idP+1]++] = i;
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,12 +55,12 @@ XMLTreeBuilder::readNodeChildren (const TiXmlElement *node, DimNodeId &id) {
|
||||
compParents[--id] = idP;
|
||||
std::cout << id << std::endl;
|
||||
readNodeChildren (child->ToElement (), id);
|
||||
childCount[idP+2]++;
|
||||
childSum[idP+2]++;
|
||||
} else if (child->Value () == std::string ("Leaf")) {
|
||||
int leafId;
|
||||
child->ToElement ()->QueryIntAttribute ("id", &leafId);
|
||||
leafParents[leafId] = idP;
|
||||
childCount[idP+2]++;
|
||||
childSum[idP+2]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include "QuadTree/QuadTreeBuilder.hpp"
|
||||
//#include "XMLTree/XMLTreeBuilder.hpp"
|
||||
#include "IImage.hpp"
|
||||
#include "Attribute.hpp"
|
||||
|
||||
#include "ArrayTree/triskeleArrayTreeBase.hpp"
|
||||
#include "ArrayTree/triskeleSort.hpp"
|
||||
|
Loading…
Reference in New Issue
Block a user