/**************************************************************************** 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_stepgenerateraster4d.h" #include "ct_log/ct_logmanager.h" #include GEN_StepGenerateRaster4DFloat::GEN_StepGenerateRaster4DFloat() : SuperClass() { _resW = 1; _resX = 1; _resY = 1; _resZ = 1; _botW = -5; _botX = -5; _botY = -5; _botZ = -5; _topW = 5; _topX = 5; _topY = 5; _topZ = 5; _valMin = 0; _valMax = 100; } QString GEN_StepGenerateRaster4DFloat::description() const { return tr("Créer une grille Voxel (4D)"); } CT_VirtualAbstractStep* GEN_StepGenerateRaster4DFloat::createNewInstance() const { return new GEN_StepGenerateRaster4DFloat(); } //////////////////// PROTECTED METHODS ////////////////// void GEN_StepGenerateRaster4DFloat::declareInputModels(CT_StepInModelStructureManager& manager) { manager.setNotNeedInputResult(); } void GEN_StepGenerateRaster4DFloat::declareOutputModels(CT_StepOutModelStructureManager& manager) { manager.addResult(m_hOutResult, tr("Generated Item")); manager.setRootGroup(m_hOutResult, m_hOutRootGroup); manager.addItem(m_hOutRootGroup, m_hOutGrid, tr("Generated 4D Grid")); } void GEN_StepGenerateRaster4DFloat::fillPostInputConfigurationDialog(CT_StepConfigurableDialog* postInputConfigDialog) { postInputConfigDialog->addDouble(tr("Resolution W"), "", 0.0001, std::numeric_limits::max(), 4, _resW); postInputConfigDialog->addDouble(tr("Resolution X"), "", 0.0001, std::numeric_limits::max(), 4, _resX); postInputConfigDialog->addDouble(tr("Resolution Y"), "", 0.0001, std::numeric_limits::max(), 4, _resY); postInputConfigDialog->addDouble(tr("Resolution Z"), "", 0.0001, std::numeric_limits::max(), 4, _resZ); postInputConfigDialog->addDouble(tr("Bot W"), "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _botW); postInputConfigDialog->addDouble(tr("Bot X"), "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _botX); postInputConfigDialog->addDouble(tr("Bot Y"), "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _botY); postInputConfigDialog->addDouble(tr("Bot Z"), "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _botZ); postInputConfigDialog->addDouble(tr("Top W"), "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _topW); postInputConfigDialog->addDouble(tr("Top X"), "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _topX); postInputConfigDialog->addDouble(tr("Top Y"), "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _topY); postInputConfigDialog->addDouble(tr("Top Z"), "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _topZ); postInputConfigDialog->addDouble(tr("Val Min"), "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _valMin); postInputConfigDialog->addDouble(tr("Val Max"), "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _valMax); } void GEN_StepGenerateRaster4DFloat::compute() { for(CT_ResultGroup* result : m_hOutResult.iterateOutputs()) { CT_StandardItemGroup* rootGroup = m_hOutRootGroup.createInstance(); result->addRootGroup(m_hOutRootGroup, rootGroup); CT_Grid4D_Dense* itemOut_itemRaster4dFloat = CT_Grid4D_Dense::createGrid4DFromWXYZCoords(_botW, _botX, _botY, _botZ, _topW, _topX, _topY, _topZ, _resW, _resX, _resY, _resZ, -std::numeric_limits::max(), 0); // Initialise random srand(uint(time(nullptr))); // Fill with random values between min and max size_t nbVoxels = itemOut_itemRaster4dFloat->nCells(); PS_LOG->addMessage( LogInterface::info, LogInterface::step, "Raster avec " + QString::number(nbVoxels) + " cellules"); for ( size_t i = 0 ; (i < nbVoxels) && !isStopped() ; i++) { itemOut_itemRaster4dFloat->setValueAtIndex( i, _valMin + ( (double(rand())/RAND_MAX) * (_valMax - _valMin))); } itemOut_itemRaster4dFloat->computeMinMax(); if(!isStopped()) { rootGroup->addSingularItem(m_hOutGrid, itemOut_itemRaster4dFloat); } else { delete itemOut_itemRaster4dFloat; } } }