/**************************************************************************** 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_metricrastergaps.h" #include #include "ct_itemdrawable/ct_image2d.h" ONF_MetricRasterGaps::ONF_MetricRasterGaps(QString pluginName) : CT_AbstractMetric_Raster(pluginName) { declareAttributes(); } ONF_MetricRasterGaps::ONF_MetricRasterGaps(const ONF_MetricRasterGaps &other) : CT_AbstractMetric_Raster(other) { declareAttributes(); m_configAndResults = other.m_configAndResults; } QString ONF_MetricRasterGaps::getShortDisplayableName() const { return tr("Métriques trouées (trouées)"); } QString ONF_MetricRasterGaps::getShortDescription() const { return tr("Calcul de métriques à partir d'une carte de trouées (raster avec identifiants par trouées)."); } QString ONF_MetricRasterGaps::getDetailledDescription() const { return tr("Les valeurs suivantes peuvent être calculées :
" "" "ATTENTION : cette métrique ne fonctionne qu'avec des rasters de trouées (rasters d'entier qint32)" ); } ONF_MetricRasterGaps::Config ONF_MetricRasterGaps::metricConfiguration() const { return m_configAndResults; } void ONF_MetricRasterGaps::setMetricConfiguration(const ONF_MetricRasterGaps::Config &conf) { m_configAndResults = conf; } CT_AbstractConfigurableElement *ONF_MetricRasterGaps::copy() const { return new ONF_MetricRasterGaps(*this); } void ONF_MetricRasterGaps::computeMetric() { m_configAndResults.nGp.value = 0; m_configAndResults.sGp.value = 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); // } QVector pixels(inRaster->dataMax() + 1); pixels.fill(0); 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))) // { qint32 gapID = inRaster->value(xx, yy); if (gapID > 0) {pixels[gapID]++;} // } } } double surfacePixel = inRaster->resolution()*inRaster->resolution(); for (int id = 1 ; id < pixels.size() ; id++) { int n = pixels[id]; if (n > 0) { m_configAndResults.nGp.value ++; m_configAndResults.sGp.value += double(n) * surfacePixel; } } } setAttributeValueVaB(m_configAndResults.nGp); setAttributeValueVaB(m_configAndResults.sGp); } void ONF_MetricRasterGaps::declareAttributes() { registerAttributeVaB(m_configAndResults.nGp, CT_AbstractCategory::DATA_NUMBER, "NGp"); registerAttributeVaB(m_configAndResults.sGp, CT_AbstractCategory::DATA_NUMBER, "SGp"); }