/**************************************************************************** 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_stepselectgroupsbyreferenceheight.h" #include ONF_StepSelectGroupsByReferenceHeight::ONF_StepSelectGroupsByReferenceHeight() : SuperClass() { _hRef = 1.3; } QString ONF_StepSelectGroupsByReferenceHeight::description() const { return tr("Filter des items dans une tranche de hauteur depuis un MNT"); } QString ONF_StepSelectGroupsByReferenceHeight::detailledDescription() const { return tr(""); } QString ONF_StepSelectGroupsByReferenceHeight::inputDescription() const { return SuperClass::inputDescription() + tr("

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

"); } QString ONF_StepSelectGroupsByReferenceHeight::detailsDescription() const { return tr(""); } CT_VirtualAbstractStep* ONF_StepSelectGroupsByReferenceHeight::createNewInstance() const { return new ONF_StepSelectGroupsByReferenceHeight(); } //////////////////// PROTECTED METHODS ////////////////// void ONF_StepSelectGroupsByReferenceHeight::declareInputModels(CT_StepInModelStructureManager& manager) { manager.addResult(_inResult, tr("Items")); manager.setZeroOrMoreRootGroup(_inResult, _inZeroOrMoreRootGroup); manager.addGroup(_inZeroOrMoreRootGroup, _inGroup); manager.addItem(_inScBase, _inDtmValue, tr("MNT")); manager.addGroup(_inScBase, _inGroup); manager.addItem(_inGroup, _inItem, tr("Item")); } void ONF_StepSelectGroupsByReferenceHeight::declareOutputModels(CT_StepOutModelStructureManager& manager) { manager.addResultCopy(_inResult); } void ONF_StepSelectGroupsByReferenceHeight::fillPostInputConfigurationDialog(CT_StepConfigurableDialog* postInputConfigDialog) { postInputConfigDialog->addDouble(tr("Hauteur de référence"), "m", 0, std::numeric_limits::max(), 2, _hRef); } void ONF_StepSelectGroupsByReferenceHeight::compute() { QList groupsToRemove; for (CT_StandardItemGroup* baseGroup : _inScBase.iterateOutputs(_inResult)) { const CT_ReferencePoint *dtmRefPoint = baseGroup->singularItem(_inDtmValue); if (dtmRefPoint != nullptr) { double href = dtmRefPoint->centerZ() + _hRef; double zmin = std::numeric_limits::max(); double zmax = -std::numeric_limits::max(); for (const CT_StandardItemGroup* group : baseGroup->groups(_inGroup)) { for (const CT_AbstractSingularItemDrawable* item : group->singularItems(_inItem)) { if (isStopped()) {return;} if (item != nullptr) { if (item->centerZ() < zmin) {zmin = item->centerZ();} if (item->centerZ() > zmax) {zmax = item->centerZ();} } } } if (zmin > href || zmax < href) { groupsToRemove.append(baseGroup); } } } // we remove the parent group of all ItemDrawable that must be deleted from the out result // and all groups that don't contains a ItemDrawable researched QListIterator itE(groupsToRemove); while(itE.hasNext()) { CT_StandardItemGroup *group = itE.next(); group->removeFromParent(false); } }