/**************************************************************************** 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_stepcomputecumulativenrtable.h" #include #include #include ONF_StepComputeCumulativeNRTable::ONF_StepComputeCumulativeNRTable() : SuperClass() { _mat.resize(1,1); _mat(0,0) = 0; _numberOfHightReturnValues = 0; } QString ONF_StepComputeCumulativeNRTable::description() const { return tr("Exporter la table N-R"); } QString ONF_StepComputeCumulativeNRTable::detailledDescription() const { return tr("Tableau croisé de comptage du nombre de points par croisement Numéro de retour / Nombre de retours. "); } QString ONF_StepComputeCumulativeNRTable::inputDescription() const { return SuperClass::inputDescription() + tr("

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

"); } QString ONF_StepComputeCumulativeNRTable::detailsDescription() const { return tr(""); } QString ONF_StepComputeCumulativeNRTable::URL() const { //return tr("STEP URL HERE"); return SuperClass::URL(); //by default URL of the plugin } CT_VirtualAbstractStep* ONF_StepComputeCumulativeNRTable::createNewInstance() const { return new ONF_StepComputeCumulativeNRTable(); } //////////////////// PROTECTED METHODS ////////////////// void ONF_StepComputeCumulativeNRTable::declareInputModels(CT_StepInModelStructureManager& manager) { manager.addResult(_inResult, tr("Scène(s)"), "", true); manager.setZeroOrMoreRootGroup(_inResult, _inZeroOrMoreRootGroup); manager.addGroup(_inZeroOrMoreRootGroup, _inGroup); manager.addItem(_inGroup, _inLasAtt, tr("Attributs LAS")); manager.addResult(_inResultCounter, tr("Résultat compteur"), "", true); manager.setZeroOrMoreRootGroup(_inResultCounter, _inZeroOrMoreRootGroupCounter); manager.addItem(_inZeroOrMoreRootGroupCounter, _inCounter, tr("Compteur")); } void ONF_StepComputeCumulativeNRTable::declareOutputModels(CT_StepOutModelStructureManager& manager) { manager.addResultCopy(_inResult); } void ONF_StepComputeCumulativeNRTable::fillPostInputConfigurationDialog(CT_StepConfigurableDialog* postInputConfigDialog) { postInputConfigDialog->addFileChoice(tr("Choix du fichier d'export"), CT_FileChoiceButton::OneNewFile, "Fichier texte (*.txt)", _fileName); } void ONF_StepComputeCumulativeNRTable::compute() { const CT_LoopCounter* counter = _inCounter.firstInput(_inResultCounter); const bool counterok = counter != nullptr; const bool last_turn = counterok && (counter->currentTurn() == counter->nTurns()); if (!counterok || counter->currentTurn() == 1) { _mat.resize(1,1); _mat(0,0) = 0; _numberOfHightReturnValues = 0; } if (_fileName.isEmpty() || _fileName.first() == "") { _fileName.clear(); _fileName << "NRTable.txt"; } CT_LASData lasData; for(const CT_StdLASPointsAttributesContainer* lasAtt : _inLasAtt.iterateInputs(_inResult)) { if (isStopped()) return; CT_AbstractPointAttributesScalar* attribute = dynamic_cast(lasAtt->pointsAttributesAt(CT_LasDefine::Return_Number)); if(attribute != nullptr) { attribute->visitLocalIndexesSet([this, lasAtt, &lasData](const size_t& globalIndex) -> bool { lasAtt->getLASDataAt(globalIndex, lasData); if (lasData._Return_Number > 15 || lasData._Number_of_Returns > 15) { _numberOfHightReturnValues++; } else { resizeMatIfNeeded(lasData._Return_Number, lasData._Number_of_Returns); _mat(lasData._Return_Number, lasData._Number_of_Returns) += 1; } return true; }); } } if (_fileName.size() > 0 && _fileName.first() != "" && (counterok == false || last_turn)) { QFile file(_fileName.first()); if(file.open(QFile::WriteOnly)) { QTextStream stream(&file); stream << "\t\tN\n"; stream << "\t\t"; for (int j = 0 ; j < _mat.cols() ; j++) { stream << j << "\t"; } stream << "\n"; for (int i = 0 ; i < _mat.rows() ; i++) { if (i == (_mat.rows() - 1)) { stream << "R\t" << i << "\t"; } else { stream << "\t" << i << "\t"; } for (int j = 0 ; j < _mat.cols() ; j++) { stream << _mat(i,j) << "\t"; } stream << "\n"; } stream << "\n"; stream << tr("Nombre de N ou R > 15 : ") << _numberOfHightReturnValues << "\n"; file.close(); } } } void ONF_StepComputeCumulativeNRTable::resizeMatIfNeeded(int row, int col) { int nrow = int(_mat.rows()); int ncol = int(_mat.cols()); if (row >= nrow) { _mat.conservativeResize(row + 1, ncol); for (int i = nrow ; i <= row ; i++) { for (int j = 0 ; j < ncol ; j++) { _mat(i,j) = 0; } } } nrow = int(_mat.rows()); if (col >= ncol) { _mat.conservativeResize(Eigen::NoChange, col + 1); for (int i = 0 ; i < nrow ; i++) { for (int j = ncol ; j <= col ; j++) { _mat(i,j) = 0; } } } }