/**************************************************************************** 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_steprefpointfrombarycenter02.h" ONF_StepRefPointFromBarycenter02::ONF_StepRefPointFromBarycenter02() : SuperClass() { } QString ONF_StepRefPointFromBarycenter02::description() const { return tr("Créer des points de référence à partir de barycentres"); } QString ONF_StepRefPointFromBarycenter02::detailledDescription() const { return tr(""); } QString ONF_StepRefPointFromBarycenter02::inputDescription() const { return SuperClass::inputDescription() + tr("

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

"); } QString ONF_StepRefPointFromBarycenter02::detailsDescription() const { return tr(""); } CT_VirtualAbstractStep* ONF_StepRefPointFromBarycenter02::createNewInstance() const { // cree une copie de cette etape return new ONF_StepRefPointFromBarycenter02(); } //////////////////// PROTECTED ////////////////// void ONF_StepRefPointFromBarycenter02::declareInputModels(CT_StepInModelStructureManager& manager) { manager.addResult(_inResult, tr("Polyligne(s)")); manager.setZeroOrMoreRootGroup(_inResult, _inZeroOrMoreRootGroup); manager.addGroup(_inZeroOrMoreRootGroup, _inGroup); manager.addItem(_inGroup, _inPolyline, tr("Polyligne")); } void ONF_StepRefPointFromBarycenter02::declareOutputModels(CT_StepOutModelStructureManager& manager) { manager.addResultCopy(_inResult); manager.addItem(_inGroup, _outBarycenter, tr("Barycentre")); } void ONF_StepRefPointFromBarycenter02::compute() { for (CT_StandardItemGroup* group : _inGroup.iterateOutputs(_inResult)) { if (isStopped()) {return;} const CT_PointCluster* item = group->singularItem(_inPolyline); if(item != nullptr) { group->addSingularItem(_outBarycenter, ONF_StepRefPointFromBarycenter02::getBarycenter(item)); } } } CT_ReferencePoint* ONF_StepRefPointFromBarycenter02::getBarycenter(const CT_PointCluster *item) { const CT_PointClusterBarycenter barycentre = item->getBarycenter(); // coordonnées du barycentre double xref = barycentre.x(); double yref = barycentre.y(); double zref = barycentre.z(); // calcul du bufferXY // Maximum de la distance point/refPoint pour chaque segment double buffer = 0; CT_PointIterator itPt(item->pointCloudIndex()); while (itPt.hasNext()) { const CT_Point &point = itPt.next().currentPoint(); double distance = pow(xref-point(0), 2) + pow(yref-point(1), 2); if (distance > buffer) {buffer = distance;} } if (buffer > 0) {buffer = sqrt(buffer);} // et on ajoute un referencePoint return new CT_ReferencePoint(xref, yref, zref, buffer); }