/**************************************************************************** Copyright (C) 2010-2012 the Office National des Forêts (ONF), France All rights reserved. Contact : alexandre.piboule@onf.fr Developers : Alexandre PIBOULE (ONF) This file is part of PluginONF library. PluginONF is free library: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. PluginONF is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with PluginONF. If not, see . *****************************************************************************/ #include "onf_metriccoverratio.h" #include "ct_pointcloudindex/ct_pointcloudindexvector.h" #include "ct_iterator/ct_pointiterator.h" #include "ct_math/ct_mathstatistics.h" #include "ct_view/ct_genericconfigurablewidget.h" #define checkAndSetValue(ATT, NAME, TYPE) if((value = group->firstValueByTagName(NAME)) == nullptr) { return false; } else { ATT = value->value().value(); } ONF_MetricCoverRatio::ONF_MetricCoverRatio(QString pluginName) : CT_AbstractMetric_LAS(pluginName) { _heightThreshold = 10.0; declareAttributesVaB(); } ONF_MetricCoverRatio::ONF_MetricCoverRatio(const ONF_MetricCoverRatio &other) : CT_AbstractMetric_LAS(other) { declareAttributesVaB(); _heightThreshold = other._heightThreshold; } QString ONF_MetricCoverRatio::getShortDisplayableName() const { return tr("Taux de couvert (LAS, Ht)"); } QString ONF_MetricCoverRatio::getShortDescription() const { return tr("Calcul du taux de couvert, à partir des points first. Taux de couvert = (nombre de points first > seuil / nombre total de points first)."); } QString ONF_MetricCoverRatio::getDetailledDescription() const { return tr(""); } void ONF_MetricCoverRatio::saveSettings(SettingsWriterInterface& writer) const { writer.addParameter(this, "heightThreshold", _heightThreshold); SuperClass::saveSettings(writer); } bool ONF_MetricCoverRatio::restoreSettings(SettingsReaderInterface& reader) { QVariant value; if(reader.parameter(this, "heightThreshold", value, 0)) _heightThreshold = value.toDouble(); return SuperClass::restoreSettings(reader); } CT_AbstractConfigurableWidget* ONF_MetricCoverRatio::createConfigurationWidget() { CT_GenericConfigurableWidget* configDialog = new CT_GenericConfigurableWidget(); configDialog->addDouble(tr("Seuil de hauteur"), "m", 0, 999, 2, _heightThreshold); return configDialog; } void ONF_MetricCoverRatio::createAttributes() { CT_AbstractMetric_XYZ::createAttributes(); } void ONF_MetricCoverRatio::computeMetric() { _coverRatio.value = 0; double nSup = 0; double nTot = 0; CT_AbstractPointAttributesScalar* attributeReturnNumber = static_cast(lasAttributes()->pointsAttributesAt(CT_LasDefine::Return_Number)); if (attributeReturnNumber != nullptr) { CT_PointIterator itP(pointCloud()); while (itP.hasNext()) { const CT_Point& point = itP.next().currentPoint(); size_t index = itP.currentGlobalIndex(); bool rnHasBeenSet; const quint16 returnNumber = quint16(attributeReturnNumber->scalarAsDoubleAt(index, &rnHasBeenSet)); if (rnHasBeenSet && ((plotArea() == nullptr) || plotArea()->contains(point(0), point(1)))) { if (returnNumber == 1) { if (point(2) > _heightThreshold) { nSup += 1.0; } nTot += 1.0; } } } if (nTot > 0) { _coverRatio.value = nSup / nTot; } } setAttributeValueVaB(_coverRatio); } CT_AbstractConfigurableElement* ONF_MetricCoverRatio::copy() const { return new ONF_MetricCoverRatio(*this); } void ONF_MetricCoverRatio::declareAttributesVaB() { registerAttributeVaB(_coverRatio, CT_AbstractCategory::DATA_NUMBER, "CoverRatio"); }