/**************************************************************************** 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_stepgenerateraster3d.h" #include GEN_StepGenerateRaster3DFloat::GEN_StepGenerateRaster3DFloat() : SuperClass() { _res = 1; _botX = -10; _botY = -10; _botZ = -10; _topX = 10; _topY = 10; _topZ = 10; _valMin = 0; _valMax = 100; } QString GEN_StepGenerateRaster3DFloat::description() const { return tr("Créer une grille Voxel (3D)"); } CT_VirtualAbstractStep* GEN_StepGenerateRaster3DFloat::createNewInstance() const { return new GEN_StepGenerateRaster3DFloat(); } //////////////////// PROTECTED METHODS ////////////////// void GEN_StepGenerateRaster3DFloat::declareInputModels(CT_StepInModelStructureManager& manager) { manager.setNotNeedInputResult(); } void GEN_StepGenerateRaster3DFloat::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 3D Grid")); } void GEN_StepGenerateRaster3DFloat::fillPostInputConfigurationDialog(CT_StepConfigurableDialog* postInputConfigDialog) { 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->addDouble("Z", "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _botZ); 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->addDouble("Z", "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _topZ); 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_StepGenerateRaster3DFloat::compute() { for(CT_ResultGroup* result : m_hOutResult.iterateOutputs()) { CT_StandardItemGroup* rootGroup = m_hOutRootGroup.createInstance(); result->addRootGroup(m_hOutRootGroup, rootGroup); // UNCOMMENT Following lines and complete parameters of the item's contructor CT_Grid3D* itemOut_itemRaster3dFloat = CT_Grid3D::createGrid3DFromXYZCoords(_botX, _botY, _botZ, _topX, _topY, _topZ, _res, -std::numeric_limits::max(), 0); // On initialise l'aleatoire srand(uint(time(nullptr))); size_t nbVoxels = itemOut_itemRaster3dFloat->nCells(); for ( size_t i = 0 ; (i < nbVoxels) && !isStopped() ; i++) { itemOut_itemRaster3dFloat->setValueAtIndex( i, float(_valMin + ( (double(rand())/RAND_MAX) * (_valMax - _valMin)))); } itemOut_itemRaster3dFloat->computeMinMax(); if(!isStopped()) { rootGroup->addSingularItem(m_hOutGrid, itemOut_itemRaster3dFloat); } else { delete itemOut_itemRaster3dFloat; } } }