#include "gen_stepgeneratecone.h" #include #define DEG_TO_RAD 0.01745329251 GEN_StepGenerateCone::GEN_StepGenerateCone() : SuperClass() { _botX = 0; _botY = 0; _botZ = 0; _height = 10; _alpha = 45; _resAlpha = 1; _resH = 0.5; } QString GEN_StepGenerateCone::description() const { return tr("Créer un Cône de points"); } CT_VirtualAbstractStep* GEN_StepGenerateCone::createNewInstance() const { return new GEN_StepGenerateCone(); } //////////////////// PROTECTED METHODS ////////////////// void GEN_StepGenerateCone::declareInputModels(CT_StepInModelStructureManager& manager) { manager.setNotNeedInputResult(); } void GEN_StepGenerateCone::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 Cone cloud")); } void GEN_StepGenerateCone::fillPostInputConfigurationDialog(CT_StepConfigurableDialog* postInputConfigDialog) { postInputConfigDialog->addText(tr("Sommet"), "", ""); 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("Resolutions"), "", ""); postInputConfigDialog->addDouble(tr("Hauteur"), "", 0.0001, std::numeric_limits::max(), 4, _resH); postInputConfigDialog->addDouble(tr("Rayon"), "°", 0.0001, std::numeric_limits::max(), 4, _resAlpha, DEG_TO_RAD); postInputConfigDialog->addText(tr("Angle du cone"), "", ""); postInputConfigDialog->addDouble(tr("Rayon"), "", 0.0001, std::numeric_limits::max(), 4, _alpha); postInputConfigDialog->addText(tr("Hauteur du cone"), "", ""); postInputConfigDialog->addDouble(tr("Hauteur"), "", 0.0001, std::numeric_limits::max(), 4, _height); } void GEN_StepGenerateCone::compute() { for(CT_ResultGroup* result : m_hOutResult.iterateOutputs()) { CT_StandardItemGroup* rootGroup = m_hOutRootGroup.createInstance(); result->addRootGroup(m_hOutRootGroup, rootGroup); // On initialise l'aleatoire pour le bruit par la suite srand(uint(time(nullptr))); int nbPts = 0; int nbPtsAlpha = int(ceil(2*M_PI / _resAlpha)); int nbPtsHeight = int(ceil(_height / _resH)); int nbPtsTotal = nbPtsAlpha*nbPtsHeight; CT_AbstractUndefinedSizePointCloud *undepositPointCloud = PS_REPOSITORY->createNewUndefinedSizePointCloud(); // Construction du cote du cylindre vertical qui a pour base 0,0,0 for (double i = 0 ; (i <= 2*M_PI) && !isStopped(); i += _resAlpha) { for (double j = 0 ; j <= _height ; j += _resH) { undepositPointCloud->addPoint(Eigen::Vector3d(cos(i) * tan(_alpha) * j + _botX, sin(i) * tan(_alpha) * j + _botY, -j + _botZ)); nbPts++; 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); } } }