/**************************************************************************** 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_stepmodifydem.h" #include "ct_math/ct_mathpoint.h" #include "documentinterface.h" #include #include ONF_StepModifyDEM::ONF_StepModifyDEM() : SuperClass() { m_doc = nullptr; setManual(true); } QString ONF_StepModifyDEM::description() const { return tr("Modifier un MNE (MNS, MNT ou autre)"); } QString ONF_StepModifyDEM::detailledDescription() const { return tr(""); } QString ONF_StepModifyDEM::inputDescription() const { return SuperClass::inputDescription() + tr("

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

"); } QString ONF_StepModifyDEM::detailsDescription() const { return tr(""); } QString ONF_StepModifyDEM::URL() const { //return tr("STEP URL HERE"); return SuperClass::URL(); //by default URL of the plugin } CT_VirtualAbstractStep* ONF_StepModifyDEM::createNewInstance() const { return new ONF_StepModifyDEM(); } //////////////////// PROTECTED METHODS ////////////////// void ONF_StepModifyDEM::declareInputModels(CT_StepInModelStructureManager& manager) { manager.addResult(_inResultDEM, tr("DEM"), "", true); manager.setZeroOrMoreRootGroup(_inResultDEM, _inZeroOrMoreRootGroupDEM); manager.addGroup(_inZeroOrMoreRootGroupDEM, _inGroupDEM); manager.addItem(_inGroupDEM, _inDem, tr("DEM à modifier")); manager.addResult(_inResultIMG, tr("2D Images (optionnel)"), "", true); manager.setZeroOrMoreRootGroup(_inResultIMG, _inZeroOrMoreRootGroupIMG); manager.addGroup(_inZeroOrMoreRootGroupIMG, _inGroupIMG); manager.addItem(_inGroupIMG, _inRed, tr("Red band")); manager.addItem(_inGroupIMG, _inGreen, tr("Green band")); manager.addItem(_inGroupIMG, _inBlue, tr("Blue band")); } void ONF_StepModifyDEM::declareOutputModels(CT_StepOutModelStructureManager& manager) { manager.addResultCopy(_inResultDEM); manager.addItem(_inGroupDEM, _outDem, tr("DEM modifié")); } void ONF_StepModifyDEM::fillPostInputConfigurationDialog(CT_StepConfigurableDialog* postInputConfigDialog) { Q_UNUSED(postInputConfigDialog) } void ONF_StepModifyDEM::compute() { _inputRedBand = _inRed.firstInput(_inResultIMG); _inputGreenBand = _inGreen.firstInput(_inResultIMG); _inputBlueBand = _inBlue.firstInput(_inResultIMG); for(CT_StandardItemGroup* grp : _inGroupDEM.iterateOutputs(_inResultDEM)) { _inputDEM = grp->singularItem(_inDem); if (_inputDEM != nullptr) { CT_AbstractUndefinedSizePointCloud* mpcir = PS_REPOSITORY->createNewUndefinedSizePointCloud(); CT_Point point; int col, lin; Eigen::Vector3d cellCenter; for (size_t i = 0 ; i < _inputDEM->nCells() ; i++) { float value = _inputDEM->valueAtIndex(i); if (value != _inputDEM->NA()) { // TODO MK : il ne faut pas modifier un item d'entrée sinon si on rejoue l'étape le résultat sera différent !!! c'est pas normal ça Alex non ? //_inputDEM->setValueAtIndex(i, value); if (_inputDEM->indexToGrid(i, col, lin)) { if (_inputDEM->getCellCenterCoordinates(i, cellCenter)) { point.setValues(cellCenter(0), cellCenter(1), value); mpcir->addPoint(point); } } } } _temporaryScene = new CT_Scene(PS_REPOSITORY->registerUndefinedSizePointCloud(mpcir)); _temporaryScene->updateBoundingBox(); _modifiedDEM = new CT_Image2D(_inputDEM->minX(), _inputDEM->minY(), _inputDEM->xdim(), _inputDEM->ydim(), _inputDEM->resolution(), _inputDEM->minZ(), -9999, -9999); CT_PointIterator itP0(_temporaryScene->pointCloudIndex()); while(itP0.hasNext() && (!isStopped())) { const CT_Point &point = itP0.next().currentPoint(); CT_PointData &pt = itP0.currentInternalPoint(); _modifiedDEM->setValueAtCoords(point(0), point(1), pt(2)); } // Début de la partie interactive m_doc = nullptr; m_status = 0; requestManualMode(); m_status = 1; requestManualMode(); // Fin de la partie interactive _modifiedDEM->computeMinMax(); grp->addSingularItem(_outDem, _modifiedDEM); delete _temporaryScene; } } } void ONF_StepModifyDEM::initManualMode() { QColor color(0, 0, 75); // create a new 3D document if(m_doc == nullptr) m_doc = guiContext()->documentManager()->new3DDocument(4.0, true, &color); 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_ActionModifyDEM(_temporaryScene, _inputDEM, _modifiedDEM, _inputRedBand, _inputGreenBand, _inputBlueBand)); QMessageBox::information(nullptr, tr("Mode manuel"), tr("Bienvenue dans le mode manuel de cette " "étape de modification de MNE."), QMessageBox::Ok); } void ONF_StepModifyDEM::useManualMode(bool quit) { if(m_status == 0) { if(quit) { } } else if(m_status == 1) { if(!quit) { m_doc = nullptr; quitManualMode(); } } }