triskele/include/Attributes/AverageAttributes.tpp
Git Merciol 3d46f792d6 modifié : include/ArrayTree/ArrayTreeBuilder.hpp
modifié :         include/ArrayTree/ArrayTreeBuilder.tpp
	modifié :         include/Attributes/AreaAttributes.hpp
	modifié :         include/Attributes/AreaAttributes.tpp
	modifié :         include/Attributes/AverageAttributes.hpp
	modifié :         include/Attributes/AverageAttributes.tpp
	modifié :         include/Attributes/MoIAttributes.hpp
	modifié :         include/Attributes/MoIAttributes.tpp
	modifié :         include/Attributes/SDAttributes.hpp
	modifié :         include/Attributes/SDAttributes.tpp
	modifié :         include/Attributes/XYAttributes.hpp
	modifié :         include/Attributes/XYAttributes.tpp
	modifié :         include/CompAttribute.hpp
	modifié :         include/CompAttribute.tpp
	modifié :         include/IImage.hpp
	modifié :         include/IImage.tpp
	modifié :         include/Tree.hpp
	modifié :         include/Tree.tpp
	modifié :         src/Tree.cpp
	modifié :         src/testMain.cpp
2018-02-19 19:28:52 +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)
: CompAttributeC<double> (tree) {
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