/**************************************************************************** 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_stepaddarbitrarytilexyareas.h" #include "ct_log/ct_logmanager.h" ONF_StepAddArbitraryTileXYAreas::ONF_StepAddArbitraryTileXYAreas() : SuperClass() { _xRefCoordMin = -1000.0; _yRefCoordMin = -1000.0; _xRefCoordMax = 1000.0; _yRefCoordMax = 1000.0; _tileSize = 50.0; _bufferSize = 10.0; } QString ONF_StepAddArbitraryTileXYAreas::description() const { return tr("Création d'un dallage arbitraire"); } QString ONF_StepAddArbitraryTileXYAreas::detailledDescription() const { return tr("Création un dallage basé sur les coordonnées fournies"); } QString ONF_StepAddArbitraryTileXYAreas::inputDescription() const { return SuperClass::inputDescription() + tr("

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

"); } QString ONF_StepAddArbitraryTileXYAreas::detailsDescription() const { return tr(""); } CT_VirtualAbstractStep* ONF_StepAddArbitraryTileXYAreas::createNewInstance() const { // cree une copie de cette etape return new ONF_StepAddArbitraryTileXYAreas(); } //////////////////// PROTECTED ////////////////// void ONF_StepAddArbitraryTileXYAreas::declareInputModels(CT_StepInModelStructureManager& manager) { manager.setNotNeedInputResult(); } void ONF_StepAddArbitraryTileXYAreas::fillPostInputConfigurationDialog(CT_StepConfigurableDialog* postInputConfigDialog) { postInputConfigDialog->addDouble(tr("Coordonnée X minimum"), "m" , -std::numeric_limits::max(), std::numeric_limits::max(), 4, _xRefCoordMin); postInputConfigDialog->addDouble(tr("Coordonnée Y minimum"), "m" , -std::numeric_limits::max(), std::numeric_limits::max(), 4, _yRefCoordMin); postInputConfigDialog->addDouble(tr("Coordonnée X maximum"), "m" , -std::numeric_limits::max(), std::numeric_limits::max(), 4, _xRefCoordMax); postInputConfigDialog->addDouble(tr("Coordonnée Y maximum"), "m" , -std::numeric_limits::max(), std::numeric_limits::max(), 4, _yRefCoordMax); postInputConfigDialog->addDouble(tr("Taille de la dalle unitaire (hors zones tampons)"), "m", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _tileSize); postInputConfigDialog->addDouble(tr("Taille de la zone tampon"), "m", -std::numeric_limits::max(), std::numeric_limits::max(), 4, _bufferSize); } void ONF_StepAddArbitraryTileXYAreas::declareOutputModels(CT_StepOutModelStructureManager& manager) { manager.addResult(_outResult); manager.setRootGroup(_outResult, _outGroup); manager.addItem(_outGroup, _outTileXYArea, tr("Emprise")); manager.addItem(_outGroup, _outBufferTileXYArea, tr("Emprise (zone tampon)")); } void ONF_StepAddArbitraryTileXYAreas::compute() { for(CT_ResultGroup* result : _outResult.iterateOutputs()) { double tmp; if (_xRefCoordMin > _xRefCoordMax) { tmp = _xRefCoordMax; _xRefCoordMax = _xRefCoordMin; _xRefCoordMin = tmp; } if (_yRefCoordMin > _yRefCoordMax) { tmp = _yRefCoordMax; _yRefCoordMax = _yRefCoordMin; _yRefCoordMin = tmp; } int nXTile = std::ceil(std::fabs(_xRefCoordMax - _xRefCoordMin) / _tileSize); int nYTile = std::ceil(std::fabs(_yRefCoordMax - _yRefCoordMin) / _tileSize); Eigen::Vector2d minBB, maxBB; for (int xx = 0 ; xx < nXTile ; xx++) { for (int yy = 0 ; yy < nYTile ; yy++) { minBB(0) = _xRefCoordMin + xx*_tileSize; minBB(1) = _yRefCoordMin + yy*_tileSize; maxBB(0) = minBB(0) + _tileSize; maxBB(1) = minBB(1) + _tileSize; QString name = QString("%1_%2").arg(QString::number(minBB(0), 'f', 0)).arg(QString::number(minBB(1), 'f', 0)); CT_StandardItemGroup* group = new CT_StandardItemGroup(); result->addRootGroup(_outGroup, group); CT_Box2D *box2D = new CT_Box2D(new CT_Box2DData(minBB, maxBB)); box2D->setDisplayableName(name); group->addSingularItem(_outTileXYArea, box2D); minBB(0) -= _bufferSize; minBB(1) -= _bufferSize; maxBB(0) += _bufferSize; maxBB(1) += _bufferSize; CT_Box2D *box2DBuffer = new CT_Box2D(new CT_Box2DData(minBB, maxBB)); box2DBuffer->setDisplayableName(QString("%1_Buffer").arg(name)); group->addSingularItem(_outBufferTileXYArea, box2DBuffer); } } } }