/**************************************************************************** Copyright (C) 2010-2021 the Office National des Forêts (ONF), France All rights reserved. Contact : alexandre.piboule@onf.fr Developers : Michael Krebbs (Independant) Alexandre PIBOULE (ONF) This file is part of PluginGenerate library. PluginGenerate 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. PluginGenerate 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 PluginGenerate. If not, see . *****************************************************************************/ #include "gen_stepgenerateraster2d.h" #include GEN_StepGenerateRaster2DFloat::GEN_StepGenerateRaster2DFloat() : SuperClass() { _height = 0; _botX = -10; _botY = -10; _topX = 10; _topY = 10; _res = 1; _valMin = 0; _valMax = 100; } QString GEN_StepGenerateRaster2DFloat::description() const { return tr("Créer un Raster (2D)"); } CT_VirtualAbstractStep* GEN_StepGenerateRaster2DFloat::createNewInstance() const { return new GEN_StepGenerateRaster2DFloat(); } //////////////////// PROTECTED METHODS ////////////////// void GEN_StepGenerateRaster2DFloat::declareInputModels(CT_StepInModelStructureManager& manager) { manager.setNotNeedInputResult(); } void GEN_StepGenerateRaster2DFloat::declareOutputModels(CT_StepOutModelStructureManager& manager) { manager.addResult(m_hOutResult, tr("Generated Item")); manager.setRootGroup(m_hOutResult, m_hOutRootGroup); manager.addItem(m_hOutRootGroup, m_hOutRaster, tr("Generated 2D Raster")); } void GEN_StepGenerateRaster2DFloat::fillPostInputConfigurationDialog(CT_StepConfigurableDialog* postInputConfigDialog) { postInputConfigDialog->addDouble(tr("Raster height"), "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _height); postInputConfigDialog->addDouble(tr("Resolution"), "", 0.0001, std::numeric_limits::max(), 4, _res); postInputConfigDialog->addText(tr("Bottom left point"), "", ""); postInputConfigDialog->addDouble("X", "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _botX); postInputConfigDialog->addDouble("Y", "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _botY); postInputConfigDialog->addText(tr("Top right point"), "", ""); postInputConfigDialog->addDouble("X", "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _topX); postInputConfigDialog->addDouble("Y", "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _topY); postInputConfigDialog->addText(tr("Value range"), "", ""); postInputConfigDialog->addDouble(tr("Min"), "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _valMin); postInputConfigDialog->addDouble(tr("Max"), "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _valMax); } void GEN_StepGenerateRaster2DFloat::compute() { for(CT_ResultGroup* result : m_hOutResult.iterateOutputs()) { CT_StandardItemGroup* rootGroup = m_hOutRootGroup.createInstance(); result->addRootGroup(m_hOutRootGroup, rootGroup); CT_Image2D* itemOut_itemRaster2dFloat = CT_Image2D::createImage2DFromXYCoords(_botX, _botY, _topX, _topY, _res, _height, -999, 0); // On initialise l'aleatoire srand(uint(time(nullptr))); int nbCellsX = itemOut_itemRaster2dFloat->xdim(); int nbCellsY = itemOut_itemRaster2dFloat->ydim(); for (int i = 0 ; (i < nbCellsX) && !isStopped() ; i++) { for (int j = 0 ; (j < nbCellsY) && !isStopped() ; j++) { itemOut_itemRaster2dFloat->setValue(i,j, float(_valMin + ((double(rand())/RAND_MAX) * (_valMax - _valMin)))); } } itemOut_itemRaster2dFloat->computeMinMax(); if(!isStopped()) { rootGroup->addSingularItem(m_hOutRaster, itemOut_itemRaster2dFloat); } else { delete itemOut_itemRaster2dFloat; } } }