
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
179 lines
5.5 KiB
C++
179 lines
5.5 KiB
C++
#ifndef _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
|
|
#define _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
|
|
|
|
template<typename AttrT>
|
|
inline
|
|
CompAttribute<AttrT>::CompAttribute (const Tree &tree)
|
|
: tree (tree),
|
|
leafCount (0),
|
|
values (nullptr) {
|
|
updateTranscient ();
|
|
}
|
|
|
|
template<typename AttrT>
|
|
inline
|
|
CompAttribute<AttrT>::~CompAttribute () {
|
|
free ();
|
|
}
|
|
|
|
template<typename AttrT>
|
|
inline void
|
|
CompAttribute<AttrT>::updateTranscient () {
|
|
// XXX max : leafCount-1
|
|
book (tree.getLeafCount ());
|
|
}
|
|
|
|
template<typename AttrT>
|
|
inline const AttrT *
|
|
CompAttribute<AttrT>::getValues () const {
|
|
return values;
|
|
}
|
|
|
|
template<typename AttrT>
|
|
inline AttrT *
|
|
CompAttribute<AttrT>::getValues () {
|
|
return values;
|
|
}
|
|
|
|
template<typename AttrT>
|
|
inline AttrT
|
|
CompAttribute<AttrT>::getMaxValue () const {
|
|
if (!leafCount)
|
|
return 0;
|
|
AttrT max = values[0];
|
|
CompAttribute<AttrT>::tree.forEachComp ([this, &max] (const DimImg &compId) {
|
|
if (values[compId] > max)
|
|
max = values[compId];
|
|
});
|
|
return max;
|
|
}
|
|
|
|
template<typename AttrT>
|
|
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;
|
|
}
|
|
|
|
template<typename AttrT>
|
|
inline void
|
|
CompAttribute<AttrT>::free () {
|
|
if (values)
|
|
delete[] values;
|
|
values = nullptr;
|
|
}
|
|
|
|
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];
|
|
}
|
|
|
|
// ========================================
|
|
template<typename AttrT>
|
|
inline
|
|
CompAttributeC<AttrT>::CompAttributeC (const Tree &tree)
|
|
: CompAttribute<AttrT> (tree) {
|
|
}
|
|
|
|
template<typename AttrT>
|
|
inline
|
|
CompAttributeC<AttrT>::~CompAttributeC () {
|
|
}
|
|
|
|
template<typename AttrT>
|
|
inline vector<AttrT>
|
|
CompAttributeC<AttrT>::getScaledThresholds (const vector<double> &thresholds, const AttrT &maxValue) {
|
|
vector<AttrT> result;
|
|
for (AttrT percent : thresholds)
|
|
result.push_back (percent*maxValue);
|
|
return result;
|
|
}
|
|
|
|
|
|
template<typename AttrT>
|
|
template<typename CumpFunctPSE>
|
|
inline void
|
|
CompAttributeC<AttrT>::computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE) const {
|
|
const vector<DimImg> &weightBounds (CompAttribute<AttrT>::tree.getWeightBounds ());
|
|
unsigned int coreCount = CompAttribute<AttrT>::tree.getCoreCount ();
|
|
DEF_LOG ("CompAttributeC::computeSameCompLevel", "coreCount:" << coreCount);
|
|
if (!weightBounds.size () || CompAttribute<AttrT>::tree.getCompCount ()/weightBounds.size () < coreCount) {
|
|
LOG ("CompAttributeC::computeSameCompLevel: no thread");
|
|
CompAttribute<AttrT>::tree.forEachComp (cumpFunctPSE);
|
|
return;
|
|
}
|
|
DimImg first = weightBounds [0];
|
|
for (DimImg curBound = 1; curBound < weightBounds.size (); curBound++) {
|
|
DimImg next = weightBounds [curBound];
|
|
dealThreadRange (next-first, coreCount, [this, &first, &cumpFunctPSE] (const DimImg &id) {
|
|
const DimImg parentId = id+first;
|
|
cumpFunctPSE (parentId);
|
|
});
|
|
first = next;
|
|
}
|
|
}
|
|
|
|
template<typename AttrT>
|
|
template<typename PixelT>
|
|
inline void
|
|
CompAttributeC<AttrT>::cut (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
|
const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const {
|
|
DEF_LOG ("CompAttributeC::cut", "coreCount:" << CompAttribute<AttrT>::tree.getCoreCount () << " thresholds:" << thresholds.size ());
|
|
dealThreadRange (CompAttribute<AttrT>::leafCount, CompAttribute<AttrT>::tree.getCoreCount (), [this, &allBands, &attributeProfiles, &pixelAttrValue, &thresholds] (const DimImg &leafId) {
|
|
cutOnPos (allBands, attributeProfiles, leafId, pixelAttrValue, thresholds);
|
|
});
|
|
}
|
|
|
|
template<typename AttrT>
|
|
template<typename PixelT>
|
|
inline void
|
|
CompAttributeC<AttrT>::cutOnPos (vector<vector<PixelT> > &allBands, const AttributeProfiles<PixelT> &attributeProfiles,
|
|
const DimImg &leafId, const AttrT &pixelAttrValue, const vector<AttrT> &thresholds) const {
|
|
// no debug (to many pixels)
|
|
DimImg parentId = CompAttribute<AttrT>::tree.getLeafParent (leafId);
|
|
DimChanel thresholdsSize = thresholds.size ();
|
|
if (parentId == DimImg_MAX) {
|
|
for (DimChanel chanel = 0; chanel < thresholdsSize; ++chanel)
|
|
allBands[chanel][leafId] = 0;
|
|
return;
|
|
}
|
|
DimNodeId nodeId = leafId;
|
|
DimImg curId = 0;
|
|
AttrT curValue = pixelAttrValue;
|
|
if (curValue == CompAttribute<AttrT>::values [parentId]) {
|
|
// skip pixel on flat zone
|
|
curId = parentId;
|
|
nodeId = ((DimNodeId)curId)+CompAttribute<AttrT>::leafCount;
|
|
parentId = CompAttribute<AttrT>::tree.getCompParent (curId);
|
|
}
|
|
const PixelT *apValues = attributeProfiles.getValues ();
|
|
DimImg rootId = CompAttribute<AttrT>::tree.getCompRoot ();
|
|
for (DimChanel chanel = 0; chanel < thresholdsSize; ++chanel) {
|
|
AttrT ceil = thresholds[chanel];
|
|
for ( ; curValue < ceil && curId < rootId; ) {
|
|
if (parentId == DimImg_MAX || curId >= parentId) {
|
|
// cerr << "CompAttributeC::cutOnPos find sub-root:" << rootId << " rootId:" << rootId << endl;
|
|
for (; chanel < thresholdsSize; ++chanel)
|
|
allBands[chanel][leafId] = curValue;
|
|
return;
|
|
}
|
|
nodeId = ((DimNodeId) CompAttribute<AttrT>::tree.getLeafParent (nodeId))+CompAttribute<AttrT>::leafCount;
|
|
curId = parentId;
|
|
curValue = CompAttribute<AttrT>::values [curId];
|
|
parentId = CompAttribute<AttrT>::tree.getCompParent (curId);
|
|
}
|
|
// XXX si valeur > root ?
|
|
allBands[chanel][leafId] = apValues [nodeId];
|
|
}
|
|
}
|
|
|
|
#endif // _OTB_TRISKELE_COMP_ATTRIBUTE_TPP
|