96 lines
2.7 KiB
C++
96 lines
2.7 KiB
C++
#ifndef _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP
|
|
#define _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP
|
|
|
|
// ========================================
|
|
template<typename PixelT>
|
|
inline
|
|
AttributeProfiles<PixelT>::AttributeProfiles (const Tree &tree)
|
|
: tree (tree),
|
|
leafCount (0),
|
|
values () {
|
|
updateTranscient ();
|
|
}
|
|
|
|
template<typename PixelT>
|
|
inline
|
|
AttributeProfiles<PixelT>::~AttributeProfiles () {
|
|
free ();
|
|
}
|
|
|
|
template<typename PixelT>
|
|
inline void
|
|
AttributeProfiles<PixelT>::updateTranscient () {
|
|
book (tree.getLeafCount ());
|
|
}
|
|
|
|
template<typename PixelT>
|
|
inline PixelT *
|
|
AttributeProfiles<PixelT>::getValues () {
|
|
return &values[0];
|
|
}
|
|
|
|
template<typename PixelT>
|
|
inline const PixelT *
|
|
AttributeProfiles<PixelT>::getValues () const {
|
|
return &values[0];
|
|
}
|
|
|
|
// ========================================
|
|
template<typename PixelT>
|
|
template<typename WeightT>
|
|
inline void
|
|
AttributeProfiles<PixelT>::setValues (const PixelT defaultValue, const WeightT *weights) {
|
|
updateTranscient ();
|
|
fill_n (&values[0], tree.getLeafCount (), defaultValue);
|
|
PixelT *compAP = &values[tree.getLeafCount ()];
|
|
dealThreadBound (tree.getCompCount (), tree.getCoreCount (), [&compAP, &weights] (const DimImg &minVal, const DimImg &maxVal) {
|
|
for (DimImg compIdx = minVal; compIdx < maxVal; ++compIdx)
|
|
compAP[compIdx] = weights[compIdx];
|
|
});
|
|
}
|
|
|
|
template<typename PixelT>
|
|
template<typename WeightT>
|
|
inline void
|
|
AttributeProfiles<PixelT>::setValues (const PixelT *pixels, const WeightT *weights) {
|
|
updateTranscient ();
|
|
PixelT *leafAP = &values[0];
|
|
dealThreadBound (tree.getLeafCount (), tree.getCoreCount (), [&leafAP, &pixels] (const DimImg &minVal, const DimImg &maxVal) {
|
|
for (DimImg i = minVal; i < maxVal; ++i)
|
|
leafAP[i] = pixels [i];
|
|
});
|
|
PixelT *compAP = leafAP+tree.getLeafCount ();
|
|
dealThreadBound (tree.getCompCount (), tree.getCoreCount (), [&compAP, &weights] (const DimImg &minVal, const DimImg &maxVal) {
|
|
for (DimImg compIdx = minVal; compIdx < maxVal; ++compIdx)
|
|
compAP[compIdx] = weights[compIdx];
|
|
});
|
|
}
|
|
|
|
|
|
template<typename PixelT>
|
|
inline void
|
|
AttributeProfiles<PixelT>::free () {
|
|
values = vector<PixelT> ();
|
|
}
|
|
|
|
template<typename PixelT>
|
|
inline void
|
|
AttributeProfiles<PixelT>::book (const DimImg &leafCount) {
|
|
this->leafCount = leafCount;
|
|
// XXX max : leafCount*2-1
|
|
values.resize (leafCount*2);
|
|
}
|
|
|
|
// ========================================
|
|
template<typename PixelT>
|
|
ostream &
|
|
AttributeProfiles<PixelT>::print (ostream &out) const {
|
|
const Size doubleSize (tree.getSize().width, 2*tree.getSize ().height);
|
|
out << "AP" << endl
|
|
<< printMap (&values[0], doubleSize, tree.getNodeCount ()) << endl << endl;
|
|
return out;
|
|
}
|
|
|
|
// ========================================
|
|
#endif // _OTB_TRISKELE_ATTRIBUTE_PROFILES_TPP
|