/**************************************************************************** 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_stepcropraster.h" #include "ct_log/ct_logmanager.h" ONF_StepCropRaster::ONF_StepCropRaster() : SuperClass() { _name = tr("Raster (cropped)"); _cropDist = 10.0; } ONF_StepCropRaster::~ONF_StepCropRaster() { qDeleteAll(_outRasterModelMap.values()); } QString ONF_StepCropRaster::description() const { return tr("Rogner un raster"); } QString ONF_StepCropRaster::detailledDescription() const { return tr("Cette étape permet de rogner un raster : les bords du rasters sont éliminés sur une épaisseur égale à la distance de rognage, tout autour."); } QString ONF_StepCropRaster::inputDescription() const { return SuperClass::inputDescription() + tr("

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

"); } QString ONF_StepCropRaster::detailsDescription() const { return tr(""); } CT_VirtualAbstractStep* ONF_StepCropRaster::createNewInstance() const { // cree une copie de cette etape return new ONF_StepCropRaster(); } /////////////////////// PROTECTED /////////////////////// void ONF_StepCropRaster::declareInputModels(CT_StepInModelStructureManager& manager) { manager.addResult(_inResultRaster, tr("Raster")); manager.setZeroOrMoreRootGroup(_inResultRaster, _inZeroOrMoreRootGroupRaster); manager.addGroup(_inZeroOrMoreRootGroupRaster, _inGroupRaster); manager.addItem(_inGroupRaster, _inRaster, tr("Raster")); } void ONF_StepCropRaster::declareOutputModels(CT_StepOutModelStructureManager& manager) { manager.addResultCopy(_inResultRaster); if (_inRaster.hasAtLeastOnePossibilitySelected(_inResultRaster)) { auto it = _inRaster.iterateSelectedOutputModels(_inResultRaster); auto begin = it.begin(); auto end = it.end(); while(begin != end) { const CT_OutAbstractSingularItemModel* inRasterModel = (*begin); CT_HandleOutSingularItem >* handle = new CT_HandleOutSingularItem >(); _outRasterModelMap.insert(inRasterModel->recursiveOriginalModel(), handle); _name = tr("%1 (rogné)").arg(inRasterModel->displayableName()); manager.addItem(_inGroupRaster, *handle, _name); ++begin; } } } void ONF_StepCropRaster::fillPostInputConfigurationDialog(CT_StepConfigurableDialog* postInputConfigDialog) { postInputConfigDialog->addDouble(tr("Distance de rognage"), "m", 0, 999999, 2, _cropDist); } void ONF_StepCropRaster::compute() { for (CT_StandardItemGroup* group : _inGroupRaster.iterateOutputs(_inResultRaster)) { for (const CT_Image2D* inRaster : group->singularItems(_inRaster)) { if (isStopped()) {return;} int cropDistPix = int(_cropDist / inRaster->resolution()); double minX = inRaster->minX() + cropDistPix*inRaster->resolution(); double minY = inRaster->minY() + cropDistPix*inRaster->resolution(); int dimX = inRaster->xdim() - 2 * cropDistPix; int dimY = inRaster->ydim() - 2 * cropDistPix; CT_Image2D* outRaster = new CT_Image2D(minX, minY, dimX, dimY, inRaster->resolution(), inRaster->minZ(), inRaster->NA(), 0); size_t ncells = outRaster->nCells(); for (size_t index = 0 ; index < ncells ; index++) { Eigen::Vector3d center; outRaster->getCellCenterCoordinates(index, center); outRaster->setValueAtIndex(index, inRaster->valueAtCoords(center(0), center(1))); setProgress(float(90.0*index/ncells)); } // ajout du raster CT_OutAbstractSingularItemModel* itemModel = dynamic_cast(inRaster->model()->recursiveOriginalModel()); CT_HandleOutSingularItem >* handle = _outRasterModelMap.value(itemModel); if (handle != nullptr) { group->addSingularItem(*handle, outRaster); outRaster->computeMinMax(); } else { qDebug() << "Erreur ONF_StepCropRaster : cas non prévu !"; PS_LOG->addMessage(LogInterface::error, LogInterface::step, tr("Erreur ONF_StepCropRaster : cas non prévu !")); delete outRaster; } } setProgress(100.0f); } }