modifié : include/CompAttribute.hpp

modifié :         include/CompAttribute.tpp
This commit is contained in:
Git Merciol 2018-02-19 18:26:51 +01:00
parent e685b9fa49
commit 675b87e17e
2 changed files with 69 additions and 0 deletions

View File

@ -1,8 +1,11 @@
#ifndef _OTB_TRISKELE_COMP_ATTRIBUTE_HPP
#define _OTB_TRISKELE_COMP_ATTRIBUTE_HPP
#include <vector>
#include "triskeleBase.hpp"
#include "Tree.hpp"
#include "AttributeProfiles.hpp"
namespace otb {
namespace triskele {
@ -35,12 +38,27 @@ namespace otb {
namespace otb {
namespace triskele {
template <typename AttrT>
struct ThresholdsChanel {
AttrT threshold;
DimChanel chanel;
ThresholdsChanel (const AttrT &threshold, const DimChanel &chanel) : threshold (threshold), chanel (chanel) {}
};
template<typename AttrT>
class CompAttributeC : public CompAttribute<AttrT> {
public:
inline CompAttributeC (const Tree &tree, const unsigned int &treeCoreCount);
inline ~CompAttributeC ();
template<typename PixelT>
inline void cut (vector<vector<PixelT> > allBands, const AttributeProfiles<PixelT> &attributeProfiles,
const AttrT &pixelAttrValue, const vector<const ThresholdsChanel<AttrT> > &selection);
template<typename PixelT>
inline void cutOnPos (vector<vector<PixelT> > allBands, const AttributeProfiles<PixelT> &attributeProfiles,
const DimImg &pixelId, const AttrT &pixelAttrValue, const vector<const ThresholdsChanel<AttrT> > &selection);
protected:
const unsigned int treeCoreCount;

View File

@ -96,4 +96,55 @@ CompAttributeC<AttrT>::computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE) {
}
}
template<typename AttrT>
template<typename PixelT>
inline void
CompAttributeC<AttrT>::cut (vector<vector<PixelT> > allBands, const AttributeProfiles<PixelT> &attributeProfiles,
const AttrT &pixelAttrValue, const vector<const ThresholdsChanel<AttrT> > &selection) {
dealThreadRange (CompAttribute<AttrT>::leafCount, treeCoreCount, [this, &allBands, &attributeProfiles, &pixelAttrValue, &selection] (const DimImg &leafId) {
cutOnPos (allBands, attributeProfiles, leafId, pixelAttrValue, selection);
});
}
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<const ThresholdsChanel<AttrT> > &selection) {
// no debug (to many pixels)
DimImg parentId = CompAttribute<AttrT>::tree.getLeafParents (leafId);
DimChanel selectionSize = selection.size ();
if (parentId == DimImg_MAX) {
for (DimChanel i = 0; i < selectionSize; ++i)
allBands[leafId][selection[i].chanel] = 0;
return;
}
DimNodeId nodeId = leafId, curId = 0;
AttrT curValue = pixelAttrValue;
if (curValue == CompAttribute<AttrT>::values [parentId]) {
// skip pixel on flat zone
curId = parentId;
nodeId = curId+CompAttribute<AttrT>::leafCount;
parentId = CompAttribute<AttrT>::tree.getCompParent (curId);
}
DimImg rootId = CompAttribute<AttrT>::tree.getCompRoot ();
for (DimChanel i = 0; i < selectionSize; ++i) {
AttrT ceil = selection[i].threshold;
for ( ; curValue < ceil && curId < rootId; ) {
if (parentId == DimImg_MAX || curId >= parentId) {
// XXX root
for (; i < selectionSize; ++i)
allBands[leafId][selection[i].chanel] = 0;
return;
}
nodeId = CompAttribute<AttrT>::tree.getLeafParents (nodeId)+CompAttribute<AttrT>::leafCount;
curId = parentId;
curValue = CompAttribute<AttrT>::values [curId];
parentId = CompAttribute<AttrT>::tree.getCompParents (curId);
}
// XXX si valeur > root ?
allBands[leafId][selection[i].chanel] = attributeProfiles [nodeId];
}
}
#endif // _OTB_TRISKELE_COMP_ATTRIBUTE_TPP