/**************************************************************************** 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_stepgeneraterandomcloud.h" #include #include // Constructor : initialization of parameters GEN_StepGenerateRandomCloud::GEN_StepGenerateRandomCloud() : SuperClass() { _nPts = 1000; _botX = -10; _botY = -10; _botZ = -10; _topX = 10; _topY = 10; _topZ = 10; } // Step description (tooltip of contextual menu) QString GEN_StepGenerateRandomCloud::description() const { return tr("Créer des points Aléatoires"); } // Step copy method CT_VirtualAbstractStep* GEN_StepGenerateRandomCloud::createNewInstance() const { return new GEN_StepGenerateRandomCloud(); } void GEN_StepGenerateRandomCloud::fillPostInputConfigurationDialog(CT_StepConfigurableDialog* postInputConfigDialog) { postInputConfigDialog->addInt(tr("Number fo points"), "", 0, 1e+07, _nPts); postInputConfigDialog->addText(tr("Bottom left extremum"),"",""); postInputConfigDialog->addDouble("X", "", -1e+10, 1e+10, 4, _botX); postInputConfigDialog->addDouble("Y", "", -1e+10, 1e+10, 4, _botY); postInputConfigDialog->addDouble("Z", "", -1e+10, 1e+10, 4, _botZ); postInputConfigDialog->addText(tr("Top right extremum"),"",""); postInputConfigDialog->addDouble("X", "", -1e+10, 1e+10, 4, _topX); postInputConfigDialog->addDouble("Y", "", -1e+10, 1e+10, 4, _topY); postInputConfigDialog->addDouble("Z", "", -1e+10, 1e+10, 4, _topZ); } void GEN_StepGenerateRandomCloud::declareInputModels(CT_StepInModelStructureManager& manager) { manager.setNotNeedInputResult(); } void GEN_StepGenerateRandomCloud::declareOutputModels(CT_StepOutModelStructureManager& manager) { manager.addResult(m_hOutResult, tr("Generated Point Cloud")); manager.setRootGroup(m_hOutResult, m_hOutRootGroup); manager.addItem(m_hOutRootGroup, m_hOutScene, tr("Generated Random Cloud")); } void GEN_StepGenerateRandomCloud::compute() { // On initialise l'aleatoire pour le bruit par la suite srand(uint(time(nullptr))); for(CT_ResultGroup* result : m_hOutResult.iterateOutputs()) { CT_StandardItemGroup* rootGroup = m_hOutRootGroup.createInstance(); result->addRootGroup(m_hOutRootGroup, rootGroup); CT_AbstractUndefinedSizePointCloud* undepositPointCloud = PS_REPOSITORY->createNewUndefinedSizePointCloud(); const double sizeX = _topX - _botX; const double sizeY = _topY - _botY; const double sizeZ = _topZ - _botZ; for(int i=0; (i<_nPts) && !isStopped(); ++i) { undepositPointCloud->addPoint(Eigen::Vector3d(_botX + ((double(rand())/RAND_MAX) * sizeX), _botY + ((double(rand())/RAND_MAX) * sizeY), _botZ + ((double(rand())/RAND_MAX) * sizeZ))); // Barre de progression (multiplie par 100/6 parce qu'on a huit face et qu'on est a la premiere setProgress(100.0f * float(i) / float(_nPts)); // On regarde si on est en debug mode waitForAckIfInDebugMode(); } // On enregistre le nuage de points cree dans le depot CT_NMPCIR depositPointCloud = PS_REPOSITORY->registerUndefinedSizePointCloud(undepositPointCloud); if(isStopped()) return; CT_Scene* itemOut_scene = new CT_Scene(depositPointCloud); itemOut_scene->updateBoundingBox(); rootGroup->addSingularItem(m_hOutScene, itemOut_scene); } }