From e685b9fa491ff5642331fe55d38cbc2a36a76511 Mon Sep 17 00:00:00 2001 From: Git Merciol Date: Mon, 19 Feb 2018 17:29:36 +0100 Subject: [PATCH] =?UTF-8?q?=09nouveau=20fichier=C2=A0:=20include/Attribute?= =?UTF-8?q?s/MoIAttributes.hpp=20=09nouveau=20fichier=C2=A0:=20include/Att?= =?UTF-8?q?ributes/MoIAttributes.tpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/Attributes/MoIAttributes.hpp | 22 ++++++++++++++++++ include/Attributes/MoIAttributes.tpp | 34 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 include/Attributes/MoIAttributes.hpp create mode 100644 include/Attributes/MoIAttributes.tpp diff --git a/include/Attributes/MoIAttributes.hpp b/include/Attributes/MoIAttributes.hpp new file mode 100644 index 0000000..aa6902c --- /dev/null +++ b/include/Attributes/MoIAttributes.hpp @@ -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 { + 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 diff --git a/include/Attributes/MoIAttributes.tpp b/include/Attributes/MoIAttributes.tpp new file mode 100644 index 0000000..7083b31 --- /dev/null +++ b/include/Attributes/MoIAttributes.tpp @@ -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 (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::values[parentId] = tmpMoI/(card*card); + }); +} + +#endif // _OTB_TRISKELE_MOI_ATTRIBUTES_TPP