triskele/include/CompAttribute.tpp
Git Merciol 675b87e17e modifié : include/CompAttribute.hpp
modifié :         include/CompAttribute.tpp
2018-02-19 18:26:51 +01:00

151 lines
4.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 () {
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 void
CompAttribute<AttrT>::printValues (const string &msg) const {
cout << "values: " << msg << endl;
const Size doubleSize (tree.getSize().width, 2*tree.getSize ().height);
printMap (cout, 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, const unsigned int &treeCoreCount)
: CompAttribute<AttrT> (tree),
treeCoreCount (treeCoreCount) {
}
template<typename AttrT>
inline
CompAttributeC<AttrT>::~CompAttributeC () {
}
template<typename AttrT>
template<typename CumpFunctPSE>
inline void
CompAttributeC<AttrT>::computeSameCompLevel (const CumpFunctPSE &cumpFunctPSE) {
const vector<DimImg> &weightBounds (CompAttribute<AttrT>::tree.getWeightBounds ());
if (!weightBounds.size () || CompAttribute<AttrT>::tree.getCompCount ()/weightBounds.size () < treeCoreCount) {
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, treeCoreCount, [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<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