/**************************************************************************** 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_stepcomputetin.h" #include "ct_log/ct_logmanager.h" ONF_StepComputeTIN::ONF_StepComputeTIN() : SuperClass() { } QString ONF_StepComputeTIN::description() const { return tr("Créer TIN à partir de points"); } QString ONF_StepComputeTIN::detailledDescription() const { return tr("Créée un Triangulated Irregular Network à partir des points."); } QString ONF_StepComputeTIN::inputDescription() const { return SuperClass::inputDescription() + tr("

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

"); } QString ONF_StepComputeTIN::detailsDescription() const { return tr(""); } CT_VirtualAbstractStep* ONF_StepComputeTIN::createNewInstance() const { // cree une copie de cette etape return new ONF_StepComputeTIN(); } /////////////////////// PROTECTED /////////////////////// void ONF_StepComputeTIN::declareInputModels(CT_StepInModelStructureManager& manager) { manager.addResult(_inResult, tr("Points sol")); manager.setZeroOrMoreRootGroup(_inResult, _inZeroOrMoreRootGroup); manager.addGroup(_inZeroOrMoreRootGroup, _inGroup); manager.addItem(_inGroup, _inScene, tr("Points sol")); manager.addItem(_inGroup, _inRefScene, tr("Scène (emprise, optionnel)")); } void ONF_StepComputeTIN::declareOutputModels(CT_StepOutModelStructureManager& manager) { manager.addResultCopy(_inResult); manager.addItem(_inGroup, _outTIN, tr("TIN")); } void ONF_StepComputeTIN::compute() { for (CT_StandardItemGroup* group : _inGroup.iterateOutputs(_inResult)) { for (const CT_AbstractItemDrawableWithPointCloud* scene : group->singularItems(_inScene)) { if (isStopped()) {return;} if (scene != nullptr) { double minX = scene->minX(); double minY = scene->minY(); double maxX = scene->maxX(); double maxY = scene->maxY(); const CT_AbstractItemDrawableWithPointCloud* completeScene = group->singularItem(_inRefScene); if (completeScene != nullptr) { if (completeScene->minX() < minX) {minX = completeScene->minX();} if (completeScene->minY() < minY) {minY = completeScene->minY();} if (completeScene->maxX() > maxX) {maxX = completeScene->maxX();} if (completeScene->maxY() > maxY) {maxY = completeScene->maxY();} } CT_DelaunayTriangulation *delaunay = new CT_DelaunayTriangulation(); delaunay->init(minX - 1.0, minY - 1.0, maxX + 1.0, maxY + 1.0); CT_PointIterator itP(scene->pointCloudIndex()); while(itP.hasNext()) { const CT_Point &point =itP.next().currentPoint(); Eigen::Vector3d* pt = new Eigen::Vector3d(point); delaunay->addVertex(pt, true); } setProgress(50); delaunay->doInsertion(false, 50); // Points not sorted because this is not optimizing performance delaunay->updateCornersZValues(); setProgress(60); const CT_DelaunayOutline &outline = delaunay->getOutline(); setProgress(70); if (completeScene != nullptr) { CT_DelaunayTriangle *refTriangle = nullptr; CT_PointIterator itP2(completeScene->pointCloudIndex()); while(itP2.hasNext()) { const CT_Point &point = itP2.next().currentPoint(); // test if point contained in convex hull of triangulation if (!outline.contains(point(0), point(1), true)) { double zTri = 0; refTriangle = delaunay->getZCoordForXY(point(0), point(1), zTri, refTriangle, false); if (refTriangle == nullptr) { refTriangle = delaunay->getZCoordForXY(point(0), point(1), zTri, refTriangle, true); if (refTriangle != nullptr) { Eigen::Vector3d* pt = new Eigen::Vector3d(point); (*pt)(2) = zTri; delaunay->addVertex(pt, true); } } } } setProgress(80); delaunay->doInsertion(false, 50); // Points not sorted because this is not optimizing performance delaunay->updateCornersZValues(); delaunay->computeOutline(); setProgress(90); } CT_Triangulation2D* triangulation = new CT_Triangulation2D(delaunay); group->addSingularItem(_outTIN, triangulation); } else { PS_LOG->addErrorMessage(LogInterface::step, tr("Aucun point sol !")); } } setProgress(100); } }