triskele/include/Attributes/AverageAttributes.tpp
Git Merciol aff93d5467 modifié : include/Appli/Option.hpp
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/WeightAttributes.hpp
	modifié :         include/Attributes/WeightAttributes.tpp
	modifié :         include/Attributes/XYAttributes.hpp
	modifié :         include/Attributes/XYAttributes.tpp
	modifié :         include/CompAttribute.hpp
	modifié :         include/CompAttribute.tpp
	modifié :         include/triskeleDealThreads.tpp
	modifié :         src/Appli/Option.cpp
	modifié :         src/IImage.cpp
	modifié :         src/apGenerator.cpp
2018-04-20 09:49:46 +02:00

34 lines
1.3 KiB
C++

#ifndef _OTB_TRISKELE_AVERAGE_ATTRIBUTES_TPP
#define _OTB_TRISKELE_AVERAGE_ATTRIBUTES_TPP
using namespace boost::chrono;
template<typename PixelT>
inline
AverageAttributes::AverageAttributes (const Tree &tree, const Raster<PixelT> &raster, const AreaAttributes &areaAttributes)
: CompAttribute<double> (tree) {
compute (raster, areaAttributes);
}
inline
AverageAttributes::~AverageAttributes () {
}
template<typename PixelT>
inline void
AverageAttributes::compute (const Raster<PixelT> &raster, const AreaAttributes &areaAttributes) {
auto start = high_resolution_clock::now ();
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];
});
globalTreeStats.addTime (averageStats, duration_cast<duration<double> > (high_resolution_clock::now ()-start).count ());
}
#endif // _OTB_TRISKELE_AVERAGE_ATTRIBUTES_TPP