#ifndef _OTB_TRISKELE_MOI_ATTRIBUTES_TPP #define _OTB_TRISKELE_MOI_ATTRIBUTES_TPP inline MoIAttributes::MoIAttributes (const Tree &tree, const AreaAttributes &areaAttributes, const XYAttributes &xyAttributes) : CompAttributeC (tree) { compute (areaAttributes, xyAttributes); } inline MoIAttributes::~MoIAttributes () { } template inline void MoIAttributes::cut (vector > &allBands, const AttributeProfiles &attributeProfiles, const vector &thresholds) const { DEF_LOG ("MoIAttributes::cut", "thresholds:" << thresholds.size ()); double maxValue = CompAttribute::getMaxValue (); cerr << "moi max value:" << maxValue << endl; CompAttributeC::cut (allBands, attributeProfiles, 0, CompAttributeC::getScaledThresholds (thresholds, maxValue)); } 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::values[parentId] = tmpMoI/(card*card); }); } #endif // _OTB_TRISKELE_MOI_ATTRIBUTES_TPP