nouveau fichier : include/Attributes/MoIAttributes.hpp
nouveau fichier : include/Attributes/MoIAttributes.tpp
This commit is contained in:
parent
3239a3eddd
commit
e685b9fa49
22
include/Attributes/MoIAttributes.hpp
Normal file
22
include/Attributes/MoIAttributes.hpp
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef _OTB_TRISKELE_MOI_ATTRIBUTES_HPP
|
||||
#define _OTB_TRISKELE_MOI_ATTRIBUTES_HPP
|
||||
|
||||
#include "triskeleBase.hpp"
|
||||
#include "CompAttribute.hpp"
|
||||
|
||||
namespace otb {
|
||||
namespace triskele {
|
||||
|
||||
class MoIAttributes : public CompAttributeC<double> {
|
||||
public:
|
||||
inline MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes, const unsigned int &treeCoreCount);
|
||||
inline ~MoIAttributes ();
|
||||
protected:
|
||||
inline void compute (const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes);
|
||||
};
|
||||
|
||||
#include "MoIAttributes.tpp"
|
||||
} // triskele
|
||||
} // otb
|
||||
|
||||
#endif // _OTB_TRISKELE_MOI_ATTRIBUTES_HPP
|
||||
34
include/Attributes/MoIAttributes.tpp
Normal file
34
include/Attributes/MoIAttributes.tpp
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef _OTB_TRISKELE_MOI_ATTRIBUTES_TPP
|
||||
#define _OTB_TRISKELE_MOI_ATTRIBUTES_TPP
|
||||
|
||||
inline
|
||||
MoIAttributes::MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes, const unsigned int &treeCoreCount)
|
||||
: CompAttributeC<double> (tree, treeCoreCount) {
|
||||
compute (areaAttributes, xyAttributes);
|
||||
}
|
||||
|
||||
inline
|
||||
MoIAttributes::~MoIAttributes () {
|
||||
}
|
||||
|
||||
inline void
|
||||
MoIAttributes::compute (const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes) {
|
||||
const AverageXY *xy = xyAttributes.getValues ();
|
||||
const DimImg *areas = areaAttributes.getValues ();
|
||||
computeSameCompLevel ([this, &xy, &areas] (const DimImg &parentId) {
|
||||
double tmpMoI = 0.;
|
||||
const double xa = xy[parentId].x;
|
||||
const double ya = xy[parentId].y;
|
||||
tree.forEachChildTI (parentId, [this, &tmpMoI, &xa, &ya, &xy, &areas, &parentId] (const bool &isLeaf, const DimImg &childId) {
|
||||
if (isLeaf)
|
||||
return;
|
||||
const double dx = xy[childId].x - xa;
|
||||
const double dy = xy[childId].y - ya;
|
||||
tmpMoI += (dx*dx+dy*dy)*areas[childId];
|
||||
});
|
||||
const double card = areas[parentId];
|
||||
CompAttribute<double>::values[parentId] = tmpMoI/(card*card);
|
||||
});
|
||||
}
|
||||
|
||||
#endif // _OTB_TRISKELE_MOI_ATTRIBUTES_TPP
|
||||
Loading…
Reference in New Issue
Block a user