/**************************************************************************** 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_metricrastercoverratio.h" #include #include "ct_itemdrawable/ct_image2d.h" ONF_MetricRasterCoverRatio::ONF_MetricRasterCoverRatio(QString pluginName) : CT_AbstractMetric_Raster(pluginName) { _heightThreshold = 10.0; declareAttributes(); } ONF_MetricRasterCoverRatio::ONF_MetricRasterCoverRatio(const ONF_MetricRasterCoverRatio &other) : CT_AbstractMetric_Raster(other) { declareAttributes(); _heightThreshold = other._heightThreshold; } QString ONF_MetricRasterCoverRatio::getShortDisplayableName() const { return tr("Taux de couvert (Ht)"); } QString ONF_MetricRasterCoverRatio::getShortDescription() const { return tr("Taux de couvert en pourcents (proportion de pixels au dessus du seuil de hauteur fixé).
" "Cette métrique nécessite que le raster soit en hauteur. Un calcul sur des altitudes sera faux.
"); } QString ONF_MetricRasterCoverRatio::getDetailledDescription() const { return tr("Les valeurs suivantes peuvent être calculées :
" "" ); } void ONF_MetricRasterCoverRatio::saveSettings(SettingsWriterInterface& writer) const { writer.addParameter(this, "heightThreshold", _heightThreshold); CT_AbstractMetric_Raster::saveSettings(writer); } bool ONF_MetricRasterCoverRatio::restoreSettings(SettingsReaderInterface& reader) { QVariant value; if(reader.parameter(this, "heightThreshold", value, 0)) _heightThreshold = value.toDouble(); return CT_AbstractMetric_Raster::restoreSettings(reader); } CT_AbstractConfigurableWidget* ONF_MetricRasterCoverRatio::createConfigurationWidget() { CT_GenericConfigurableWidget* configDialog = new CT_GenericConfigurableWidget(); configDialog->addDouble(tr("Seuil de hauteur"), "m", 0, 999, 2, _heightThreshold); return configDialog; } CT_AbstractConfigurableElement *ONF_MetricRasterCoverRatio::copy() const { return new ONF_MetricRasterCoverRatio(*this); } void ONF_MetricRasterCoverRatio::computeMetric() { txCo.value = 0; coverArea.value = 0; gapArea.value = 0; double nSup = 0; double nTot = 0; const CT_Image2D *inRaster = dynamic_cast*>(_inRaster); if (inRaster != nullptr) { int xxmin = 0; int yymin = 0; int xxmax = inRaster->xdim() - 1; int yymax = inRaster->ydim() - 1; if (_plotArea != nullptr) { Eigen::Vector3d min, max; _plotArea->getBoundingBox(min, max); inRaster->getROIIndices(min(0), min(1), max(0), max(1), xxmin, yymin, xxmax, yymax); } for (int xx = xxmin ; xx <= xxmax ; xx++) { for (int yy = yymin ; yy <= yymax ; yy++) { Eigen::Vector3d center; inRaster->getCellCenterCoordinates(xx, yy, center); if (_plotArea == nullptr || _plotArea->contains(center(0), center(1))) { float val = inRaster->value(xx,yy); if (val != inRaster->NA()) { if (val > _heightThreshold) { nSup += 1.0; } nTot += 1.0; } } } } if (nTot > 0) { double pixelArea = inRaster->resolution()*inRaster->resolution(); txCo.value = 100.0*nSup / nTot; coverArea.value = nSup * pixelArea; gapArea.value = (nTot - nSup) * pixelArea; } } setAttributeValueVaB(txCo); setAttributeValueVaB(coverArea); setAttributeValueVaB(gapArea); } void ONF_MetricRasterCoverRatio::declareAttributes() { registerAttributeVaB(txCo, CT_AbstractCategory::DATA_NUMBER, "CovRatR"); registerAttributeVaB(coverArea, CT_AbstractCategory::DATA_NUMBER, "CoArea"); registerAttributeVaB(gapArea, CT_AbstractCategory::DATA_NUMBER, "GapArea"); }