From 83fca727ddf3d4cbc4d4dfca6c16f99d1bc346a2 Mon Sep 17 00:00:00 2001 From: rahv <karsten.rink@ufz.de> Date: Tue, 3 Feb 2015 15:14:32 +0100 Subject: [PATCH] fixed naming of new surface when generated name already exists --- .../Utils/GeoTools/TriangulatePolyline.cpp | 16 +++++++++++---- GeoLib/Polyline.cpp | 20 +++++++++---------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Applications/Utils/GeoTools/TriangulatePolyline.cpp b/Applications/Utils/GeoTools/TriangulatePolyline.cpp index eb3aceb767d..e61a8b55fd6 100644 --- a/Applications/Utils/GeoTools/TriangulatePolyline.cpp +++ b/Applications/Utils/GeoTools/TriangulatePolyline.cpp @@ -46,8 +46,8 @@ int main(int argc, char *argv[]) TCLAP::CmdLine cmd("Triangulates the specified polyline in the given geometry file.", ' ', BaseLib::BuildInfo::git_describe); TCLAP::ValueArg<std::string> input_arg("i", "input", "GML input file (*.gml)", true, "", "string"); - TCLAP::ValueArg<std::string> name_arg("n", "name", "Name of polyline in given file", true, "", "string"); TCLAP::ValueArg<std::string> output_arg("o", "output", "GML output file (*.gml)", true, "", "string"); + TCLAP::ValueArg<std::string> name_arg("n", "name", "Name of polyline in given file", true, "", "string"); cmd.add( input_arg ); cmd.add( name_arg ); cmd.add( output_arg ); @@ -105,10 +105,18 @@ int main(int argc, char *argv[]) geo_objects.addSurfaceVec(new_sfc, geo_names[0]); else geo_objects.appendSurfaceVec(*new_sfc, geo_names[0]); - std::string const surface_name (polyline_name + "_surface"); std::size_t const sfc_id = geo_objects.getSurfaceVec(geo_names[0])->size() - 1; - sfc_vec->setNameForElement(sfc_id, surface_name); - + std::string const surface_name (polyline_name + "_surface"); + for (std::size_t i=1;;++i) + { + std::string const new_surface_name = (i>1) ? (surface_name + std::to_string(i)) : surface_name; + if (sfc_vec->getElementByName(new_surface_name) == nullptr) + { + sfc_vec->setNameForElement(sfc_id, new_surface_name); + break; + } + } + // write new file xml.setNameForExport(geo_names[0]); xml.writeToFile(output_arg.getValue()); diff --git a/GeoLib/Polyline.cpp b/GeoLib/Polyline.cpp index 000d9bce51b..1436dd1e5d8 100644 --- a/GeoLib/Polyline.cpp +++ b/GeoLib/Polyline.cpp @@ -196,18 +196,18 @@ bool Polyline::isClosed() const bool Polyline::isCoplanar() const { std::size_t const n_points (_ply_pnt_ids.size()); - if (n_points > 3) + if (n_points < 4) + return true; + + GeoLib::Point const& p0 (*this->getPoint(0)); + GeoLib::Point const& p1 (*this->getPoint(1)); + GeoLib::Point const& p2 (*this->getPoint(2)); + for (std::size_t i=3; i<n_points; ++i) { - GeoLib::Point const& p0 (*this->getPoint(0)); - GeoLib::Point const& p1 (*this->getPoint(1)); - GeoLib::Point const& p2 (*this->getPoint(2)); - for (std::size_t i=3; i<n_points; ++i) + if (!GeoLib::isCoplanar(p0, p1, p2, *this->getPoint(i))) { - if (!GeoLib::isCoplanar(p0, p1, p2, *this->getPoint(i))) - { - ERR ("Point %d is not coplanar to the first three points of the line.", i); - return false; - } + ERR ("Point %d is not coplanar to the first three points of the line.", i); + return false; } } return true; -- GitLab