/**************************************************************************** Copyright (C) 2010-2012 the Office National des Forêts (ONF), France All rights reserved. Contact : alexandre.piboule@onf.fr Developers : Alexandre PIBOULE (ONF) This file is part of PluginONF library. PluginONF 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. PluginONF 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 PluginONF. If not, see . *****************************************************************************/ #include "onf_stepmodifyvoxelsegmentation.h" #include "ct_math/ct_mathpoint.h" #include "documentinterface.h" #include #include ONF_StepModifyVoxelSegmentation::ONF_StepModifyVoxelSegmentation() : SuperClass() { _keepValidatedOnly = false; m_doc = nullptr; setManual(true); } QString ONF_StepModifyVoxelSegmentation::description() const { return tr("Modify voxel grid segmentation"); } QString ONF_StepModifyVoxelSegmentation::detailledDescription() const { return tr(""); } QString ONF_StepModifyVoxelSegmentation::inputDescription() const { return SuperClass::inputDescription() + tr("

"); } QString ONF_StepModifyVoxelSegmentation::outputDescription() const { return SuperClass::outputDescription() + tr("

"); } QString ONF_StepModifyVoxelSegmentation::detailsDescription() const { return tr(""); } QString ONF_StepModifyVoxelSegmentation::URL() const { //return tr("STEP URL HERE"); return SuperClass::URL(); //by default URL of the plugin } CT_VirtualAbstractStep* ONF_StepModifyVoxelSegmentation::createNewInstance() const { return new ONF_StepModifyVoxelSegmentation(); } //////////////////// PROTECTED METHODS ////////////////// void ONF_StepModifyVoxelSegmentation::declareInputModels(CT_StepInModelStructureManager& manager) { manager.addResult(_inResult, tr("Scene(s)")); manager.setZeroOrMoreRootGroup(_inResult, _inZeroOrMoreRootGroup); manager.addGroup(_inZeroOrMoreRootGroup, _inGroup); manager.addItem(_inGroup, _inScene, tr("Scene à segmenter")); manager.addItem(_inGroup, _inGridPoints, tr("Grille de points")); manager.addItem(_inGroup, _inGridSeeds, tr("Grille segmentée")); manager.addItem(_inGroup, _inGridReverseTopology, tr("Grille topologique")); } void ONF_StepModifyVoxelSegmentation::declareOutputModels(CT_StepOutModelStructureManager& manager) { manager.addResultCopy(_inResult); manager.addItem(_inGroup, _outGrid, tr("Grille segmentée corrigée")); manager.addGroup(_inGroup, _outGrpId, tr("IDs")); manager.addItem(_outGrpId, _outIdItem, tr("Labels")); manager.addItemAttribute(_outIdItem, _outAttCluster, CT_AbstractCategory::DATA_ID, tr("VoxelCluster")); manager.addItemAttribute(_outIdItem, _outAttLabel, CT_AbstractCategory::DATA_VALUE, tr("Label")); } void ONF_StepModifyVoxelSegmentation::fillPostInputConfigurationDialog(CT_StepConfigurableDialog* postInputConfigDialog) { postInputConfigDialog->addBool(tr("Ne conserver que les arbres validés ?"), "", "", _keepValidatedOnly); } void ONF_StepModifyVoxelSegmentation::compute() { _positionLabels.clear(); CT_StandardItemGroup* grp = nullptr; for(CT_StandardItemGroup* cGrp : _inGroup.iterateOutputs(_inResult)) { _scene = cGrp->singularItem(_inScene); _pointGrid = cGrp->singularItem(_inGridPoints); const CT_Grid3D_Sparse* seedGrid = cGrp->singularItem(_inGridSeeds); _topologyGrid = cGrp->singularItem(_inGridReverseTopology); if (_scene != nullptr && _pointGrid != nullptr && seedGrid != nullptr && _topologyGrid != nullptr) { _outSegmentationGrid = _outGrid.createInstance(seedGrid->minX(), seedGrid->minY(), seedGrid->minZ(), seedGrid->xdim(), seedGrid->ydim(), seedGrid->zdim(), seedGrid->resolution(), -1, -1); QList list; seedGrid->getIndicesWithData(list); for (int i = 0 ; i < list.size() ; i++) { size_t index = list.at(i); _outSegmentationGrid->setValueAtIndex(index, seedGrid->valueAtIndex(index)); } _outSegmentationGrid->computeMinMax(); grp = cGrp; break; } } if (grp != nullptr) { // Début de la partie interactive m_doc = nullptr; m_status = 0; requestManualMode(); m_status = 1; requestManualMode(); if (_keepValidatedOnly) { QList list; _pointGrid->getIndicesWithPoints(list); for (int i = 0 ; i < list.size() ; i++) { size_t cellIndex = list.at(i); int clusterIndex = _outSegmentationGrid->valueAtIndex(cellIndex); if (!_validated[clusterIndex]) { _outSegmentationGrid->setValueAtIndex(cellIndex, -1); } } } QMapIteratoritLab(_positionLabels); while (itLab.hasNext()) { itLab.next(); int cluster = itLab.key(); QString label = itLab.value(); if (!_keepValidatedOnly || _validated[cluster]) { CT_StandardItemGroup* itemGrp = _outGrpId.createInstance(); grp->addGroup(_outGrpId, itemGrp); CT_ItemAttributeList* attList = _outIdItem.createInstance(); itemGrp->addSingularItem(_outIdItem, attList); attList->addItemAttribute(_outAttCluster, _outAttCluster.createInstance(CT_AbstractCategory::DATA_ID, cluster)); attList->addItemAttribute(_outAttLabel, _outAttLabel.createInstance(CT_AbstractCategory::DATA_VALUE, label)); } } // Fin de la partie interactive // create output segmented scenes _outSegmentationGrid->computeMinMax(); grp->addSingularItem(_outGrid, _outSegmentationGrid); } } void ONF_StepModifyVoxelSegmentation::initManualMode() { // create a new 3D document if(m_doc == nullptr) m_doc = guiContext()->documentManager()->new3DDocument(); m_doc->removeAllItemDrawable(); // set the action (a copy of the action is added at all graphics view, and the action passed in parameter is deleted) m_doc->setCurrentAction(new ONF_ActionModifyVoxelSegmentation(_scene, _pointGrid, _topologyGrid, _outSegmentationGrid, &_validated, &_positionLabels)); QMessageBox::information(nullptr, tr("Mode manuel"), tr("Bienvenue dans le mode manuel de cette " "étape de correction de segmentation."), QMessageBox::Ok); } void ONF_StepModifyVoxelSegmentation::useManualMode(bool quit) { if(m_status == 0) { if(quit) { } } else if(m_status == 1) { if(!quit) { m_doc = nullptr; quitManualMode(); } } }