triskele/include/Attributes/AverageAttributes.tpp
Git Merciol e09d2793e2 nouveau fichier : MakefileNoOTB
nouveau fichier : include/Attributes/AverageAttributes.hpp
	nouveau fichier : include/Attributes/AverageAttributes.tpp
	nouveau fichier : include/Attributes/SDAttributes.hpp
	nouveau fichier : include/Attributes/SDAttributes.tpp
	nouveau fichier : include/Attributes/XYAttributes.hpp
	nouveau fichier : include/Attributes/XYAttributes.tpp
	nouveau fichier : include/CompAttribute.hpp
	nouveau fichier : include/CompAttribute.tpp
2018-02-19 16:58:11 +01:00

30 lines
1.1 KiB
C++

#ifndef _OTB_TRISKELE_AVERAGE_ATTRIBUTES_TPP
#define _OTB_TRISKELE_AVERAGE_ATTRIBUTES_TPP
template<typename PixelT>
inline
AverageAttributes::AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes, const unsigned int &treeCoreCount)
: CompAttributeC<double> (tree, treeCoreCount) {
compute (raster, areaAttributes);
}
inline
AverageAttributes::~AverageAttributes () {
}
template<typename PixelT>
inline void
AverageAttributes::compute (const Raster<PixelT> &raster, const AreaAttributes &areaAttributes) {
const PixelT *pixels = raster.getPixels ();
const DimImg *areas = areaAttributes.getValues ();
computeSameCompLevel ([this, &pixels, &areas] (const DimImg &parentId) {
double tmpAverage = 0.;
tree.forEachChildTI (parentId, [this, &tmpAverage, &pixels, &areas] (const bool &isLeaf, const DimImg &childId) {
tmpAverage += isLeaf ? pixels[childId] : (CompAttribute<double>::values [childId] * areas[childId]);
});
CompAttribute<double>::values [parentId] = tmpAverage/areas[parentId];
});
}
#endif // _OTB_TRISKELE_AVERAGE_ATTRIBUTES_TPP