/**************************************************************************** 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_stepcomputepotentialstartzones.h" #include "ct_log/ct_logmanager.h" ONF_StepComputePotentialStartZones::ONF_StepComputePotentialStartZones() : SuperClass() { } QString ONF_StepComputePotentialStartZones::description() const { return tr("Délimiter les Zones de Départ Potentielles"); } QString ONF_StepComputePotentialStartZones::detailledDescription() const { return tr("Cette étape permet de délimiter les Zones de Départ Potentielles."); } QString ONF_StepComputePotentialStartZones::inputDescription() const { return SuperClass::inputDescription() + tr("

"); } QString ONF_StepComputePotentialStartZones::outputDescription() const { return SuperClass::outputDescription() + tr("

"); } QString ONF_StepComputePotentialStartZones::detailsDescription() const { return tr(""); } CT_VirtualAbstractStep* ONF_StepComputePotentialStartZones::createNewInstance() const { // cree une copie de cette etape return new ONF_StepComputePotentialStartZones(); } /////////////////////// PROTECTED /////////////////////// void ONF_StepComputePotentialStartZones::declareInputModels(CT_StepInModelStructureManager& manager) { manager.addResult(_inResultStartArea, tr("Zones d'intérêt"), "", true); manager.setZeroOrMoreRootGroup(_inResultStartArea, _inZeroOrMoreRootGroupStartArea); manager.addGroup(_inZeroOrMoreRootGroupStartArea, _inGroupStartArea); manager.addItem(_inGroupStartArea, _inStartArea, tr("Zones d'intérêt")); manager.addResult(_inResultWatershed, tr("Watershed"), "", true); manager.setZeroOrMoreRootGroup(_inResultWatershed, _inZeroOrMoreRootGroupWatershed); manager.addGroup(_inZeroOrMoreRootGroupWatershed, _inGroupWatershed); manager.addItem(_inGroupWatershed, _inWatershed, tr("Watershed")); } void ONF_StepComputePotentialStartZones::declareOutputModels(CT_StepOutModelStructureManager& manager) { manager.addResultCopy(_inResultStartArea); manager.addItem(_inGroupStartArea, _outZDPRaster, tr("ZDP Raster")); } void ONF_StepComputePotentialStartZones::compute() { // get watershed raster const CT_AbstractImage2D* watershed = nullptr; for (const CT_StandardItemGroup* grp : _inGroupWatershed.iterateInputs(_inResultWatershed)) { watershed = grp->singularItem(_inWatershed); } if (watershed == nullptr) { PS_LOG->addMessage(LogInterface::warning, LogInterface::step, QString(tr("Pas de raster watershed fourni."))); return; } setProgress(float(10.0)); // compute area of interest mask for (CT_StandardItemGroup* group : _inGroupStartArea.iterateOutputs(_inResultStartArea)) { for (const CT_Image2D* startArea : group->singularItems(_inStartArea)) { if (isStopped()) {return;} // Compute ZDP raster CT_Image2D* outWatershed = new CT_Image2D(startArea->minX(), startArea->minY(), startArea->xdim(), startArea->ydim(), startArea->resolution(), startArea->minZ(), std::numeric_limits::max(), std::numeric_limits::max()); size_t ncells = outWatershed->nCells(); for (size_t index = 0 ; index < ncells ; index++) { Eigen::Vector3d center; outWatershed->getCellCenterCoordinates(index, center); size_t watershedIndex; watershed->indexAtCoords(center(0), center(1), watershedIndex); int wt = int(std::round(watershed->valueAtIndexAsDouble(watershedIndex))); quint8 startAreaVal = startArea->valueAtIndex(index); if (startAreaVal == 1) { outWatershed->setValueAtIndex(index, wt); } } // ajout du raster Masque group->addSingularItem(_outZDPRaster, outWatershed); outWatershed->computeMinMax(); } setProgress(100.0f); } }