#include "tk_stepextractbox.h" // Utilise le depot #include "ct_global/ct_context.h" #include #include #include "ct_view/ct_stepconfigurabledialog.h" #include "ct_result/model/inModel/ct_inresultmodelgrouptocopy.h" #include "ct_result/model/outModel/ct_outresultmodelgroupcopy.h" #include "ct_result/model/outModel/tools/ct_outresultmodelgrouptocopypossibilities.h" #include "ct_pointcloudindex/ct_pointcloudindexvector.h" // Inclusion of standard result class #include "ct_result/ct_resultgroup.h" // Inclusion of used ItemDrawable classes #include "ct_itemdrawable/ct_scene.h" #include "ct_iterator/ct_pointiterator.h" // Alias for indexing in models #define DEF_resultIn_inputResult "inputResult" #define DEF_groupIn_inputScene "inputGroup" #define DEF_itemIn_scene "inputScene" // Constructor : initialization of parameters TK_StepExtractBox::TK_StepExtractBox(CT_StepInitializeData &dataInit) : CT_AbstractStep(dataInit) { _botX = -10; _botY = -10; _botZ = -10; _topX = 10; _topY = 10; _topZ = 10; } // Step description (tooltip of contextual menu) QString TK_StepExtractBox::getStepDescription() const { return tr("Extraire les points dans une boite englobante"); } // Step copy method CT_VirtualAbstractStep* TK_StepExtractBox::createNewInstance(CT_StepInitializeData &dataInit) { return new TK_StepExtractBox(dataInit); } //////////////////// PROTECTED METHODS ////////////////// // Creation and affiliation of IN models void TK_StepExtractBox::createInResultModelListProtected() { CT_InResultModelGroupToCopy *resultModel = createNewInResultModelForCopy(DEF_resultIn_inputResult, tr("Scene(s)")); resultModel->setZeroOrMoreRootGroup(); resultModel->addGroupModel("", DEF_groupIn_inputScene, CT_AbstractItemGroup::staticGetType(), tr("Group")); resultModel->addItemModel(DEF_groupIn_inputScene, DEF_itemIn_scene, CT_Scene::staticGetType(), tr("Scene(s)")); } // Creation and affiliation of OUT models void TK_StepExtractBox::createOutResultModelListProtected() { CT_OutResultModelGroupToCopyPossibilities *resultModel = createNewOutResultModelToCopy(DEF_resultIn_inputResult); if (resultModel != NULL) { resultModel->addItemModel(DEF_groupIn_inputScene, _outSceneModelName, new CT_Scene(), tr("Extracted Scene (box)")); } } // Semi-automatic creation of step parameters DialogBox void TK_StepExtractBox::createPostConfigurationDialog() { CT_StepConfigurableDialog *configDialog = newStandardPostConfigurationDialog(); configDialog->addText(tr("Coin en bas à gauche"), "", ""); configDialog->addDouble("X", "", -1e+10, 1e+10, 4, _botX); configDialog->addDouble("Y", "", -1e+10, 1e+10, 4, _botY); configDialog->addDouble("Z", "", -1e+10, 1e+10, 4, _botZ); configDialog->addText(tr("Coin en haut à droite"), "", ""); configDialog->addDouble("X", "", -1e+10, 1e+10, 4, _topX); configDialog->addDouble("Y", "", -1e+10, 1e+10, 4, _topY); configDialog->addDouble("Z", "", -1e+10, 1e+10, 4, _topZ); } void TK_StepExtractBox::compute() { assert( _botX <= _topX ); assert( _botY <= _topY ); assert( _botZ <= _topZ ); CT_ResultGroup* resultOut = getOutResultList().first(); CT_ResultGroupIterator it(resultOut, this, DEF_groupIn_inputScene); while (it.hasNext()) { CT_StandardItemGroup *group = (CT_StandardItemGroup*) it.next(); if (group != NULL) { const CT_Scene* itemIn_scene = (const CT_Scene*)group->firstItemByINModelName(this, DEF_itemIn_scene); if (itemIn_scene != NULL) { // On Cree un nouveau nuage CT_PointCloudIndexVector *extractedCloud = new CT_PointCloudIndexVector(); const CT_AbstractPointCloudIndex *pointCloudIndex = itemIn_scene->getPointCloudIndex(); size_t nbPoints = pointCloudIndex->size(); CT_PointIterator itP(pointCloudIndex); size_t i = 0; while (itP.hasNext() && !isStopped()) { const CT_Point &point = itP.next().currentPoint(); size_t index = itP.currentGlobalIndex(); if ( point(0) <= _topX && point(1) <= _topY && point(2) <= _topZ && point(0) >= _botX && point(1) >= _botY && point(2) >= _botZ ) { extractedCloud->addIndex(index); } setProgress( 100.0*i++ /nbPoints ); waitForAckIfInDebugMode(); } if (extractedCloud->size() > 0) { CT_Scene* itemOut_scene = new CT_Scene(_outSceneModelName.completeName(), resultOut, PS_REPOSITORY->registerPointCloudIndex(extractedCloud)); itemOut_scene->updateBoundingBox(); group->addItemDrawable(itemOut_scene); } else { delete extractedCloud; } } } } }