/**************************************************************************** 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_stepgeneratequadraticsurface.h" #include #include #include "ct_math/ct_mathpoint.h" #define RAD_TO_DEG 57.2957795131 #define DEG_TO_RAD 0.01745329251 GEN_StepGenerateQuadraticSurface::GEN_StepGenerateQuadraticSurface() : SuperClass() { _a = 1; _b = 1; _c = 1; _d = 1; _e = 1; _f = 0; _xMin = -10; _xMax = 10; _yMin = -10; _yMax = 10; _resX = 0.1; _resY = 0.1; } QString GEN_StepGenerateQuadraticSurface::description() const { return tr("Créer une Surface Quadrique de points"); } CT_VirtualAbstractStep* GEN_StepGenerateQuadraticSurface::createNewInstance() const { return new GEN_StepGenerateQuadraticSurface(); } //////////////////// PROTECTED METHODS ////////////////// void GEN_StepGenerateQuadraticSurface::declareInputModels(CT_StepInModelStructureManager& manager) { manager.setNotNeedInputResult(); } void GEN_StepGenerateQuadraticSurface::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 Quadratic surface")); } void GEN_StepGenerateQuadraticSurface::fillPostInputConfigurationDialog(CT_StepConfigurableDialog* postInputConfigDialog) { postInputConfigDialog->addText("ax2 + bxy + cy2 + dx + ey + f", "", ""); postInputConfigDialog->addEmpty(); postInputConfigDialog->addText(tr("Parametres"), "", ""); postInputConfigDialog->addDouble("a", "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _a); postInputConfigDialog->addDouble("b", "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _b); postInputConfigDialog->addDouble("c", "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _c); postInputConfigDialog->addDouble("d", "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _d); postInputConfigDialog->addDouble("e", "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _e); postInputConfigDialog->addDouble("f", "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _f); postInputConfigDialog->addText(tr("Limites"), "", ""); postInputConfigDialog->addDouble("xMin", "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _xMin); postInputConfigDialog->addDouble("xMax", "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _xMax); postInputConfigDialog->addDouble("yMin", "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _yMin); postInputConfigDialog->addDouble("yMax", "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _yMax); postInputConfigDialog->addText(tr("Resolution"), "", ""); postInputConfigDialog->addDouble("X", "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _resX); postInputConfigDialog->addDouble("Y", "", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _resY); } void GEN_StepGenerateQuadraticSurface::compute() { for(CT_ResultGroup* result : m_hOutResult.iterateOutputs()) { CT_StandardItemGroup* rootGroup = m_hOutRootGroup.createInstance(); result->addRootGroup(m_hOutRootGroup, rootGroup); int nbPts = 0; int nbPtsTotal = int(((_xMax - _xMin) / _resX) * ((_yMax - _yMin) / _resY)); CT_AbstractUndefinedSizePointCloud *undepositPointCloud = PS_REPOSITORY->createNewUndefinedSizePointCloud(); // Construction de la surface for (double i = _xMin ; (i < _xMax) && !isStopped() ; i += _resX) { for (double j = _yMin ; (j <= _yMax) && !isStopped() ; j += _resY) { undepositPointCloud->addPoint(Eigen::Vector3d(i, j, _a*i*i + _b*i*j + _c*j*j + _d*i + _e*j + _f)); nbPts++; // Barre de progression (multiplie par 100/6 parce qu'on a huit face et qu'on est a la premiere setProgress(float(nbPts) * 100.0f / float(nbPtsTotal)); // 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()) { CT_Scene* itemOut_scene = new CT_Scene(depositPointCloud); itemOut_scene->updateBoundingBox(); rootGroup->addSingularItem(m_hOutScene, itemOut_scene); } } }