From 9e74cebd790a62aa045c805ffe4de12a5c4cf93d Mon Sep 17 00:00:00 2001 From: Sean Gong Date: Thu, 2 Nov 2023 22:44:14 +0100 Subject: [PATCH 1/7] Fix getPolygonsFromInputStream() in single-element case --- src/DGtal/io/readers/PointListReader.ih | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/DGtal/io/readers/PointListReader.ih b/src/DGtal/io/readers/PointListReader.ih index 8745957a9d..5c2ddbac3f 100644 --- a/src/DGtal/io/readers/PointListReader.ih +++ b/src/DGtal/io/readers/PointListReader.ih @@ -79,16 +79,17 @@ DGtal::PointListReader::getPointsFromInputStream (std::istream &in, std TPoint p; while ( !in_str.fail()&& (nbFound>(in_str,val); - if(!in_str.fail()){ + if(!in_str.fail() && val != " "){ std::istringstream valFromStr( val ); typename TPoint::Component valConverted; valFromStr >> valConverted; if(!valFromStr.fail()){ for(unsigned int j=0; j< TPoint::dimension; j++){ - if (idx == aVectPosition.at(j) ){ - nbFound++; - p[j]=valConverted; - } + if (idx == aVectPosition.at(j) ){ + nbFound++; + p[j]=valConverted; + val=""; + } } } } @@ -132,6 +133,7 @@ DGtal::PointListReader::getPolygonsFromInputStream(std::istream & in){ TPoint p; unsigned int index =0; while ( in_str.good() ){ + valStr=""; std::operator>>(in_str, valStr); std::istringstream word_str( valStr ); word_str >> p[index]; From 3777c221c7acf1bea22725c087d7588e1c9011d2 Mon Sep 17 00:00:00 2001 From: Sean Gong Date: Thu, 2 Nov 2023 22:46:37 +0100 Subject: [PATCH 2/7] Add single-element case for getPolygonsFromFile() --- tests/io/readers/testPointListReader.cpp | 26 +++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/tests/io/readers/testPointListReader.cpp b/tests/io/readers/testPointListReader.cpp index e180033ffa..4a96039759 100644 --- a/tests/io/readers/testPointListReader.cpp +++ b/tests/io/readers/testPointListReader.cpp @@ -91,9 +91,29 @@ bool testPointListReader() } trace.info()<< std::endl; } - nbok += (vectPolygons.at(0).size()==2 && vectPolygons.at(1).size()==2 && vectPolygons.at(0).at(0)==Z3i::Point(1,2,3) - && vectPolygons.at(0).at(1)==Z3i::Point(4,5,6) && vectPolygons.at(1).at(0)==Z3i::Point(0,0,10) - && vectPolygons.at(1).at(1)==Z3i::Point(0,5,5)) ? 1 : 0; + trace.beginBlock ( "Testing reading spectial 1 dimension elements (several by lines)..." ); + + typedef PointVector<1, int> Point1D; + std::vector< std::vector< Point1D > > vectPt1D = PointListReader< Point1D >::getPolygonsFromFile(filenamePoly); + for(unsigned int i=0; i< vectPt1D.size(); i++){ + std::vector< Point1D > aPolygon = vectPt1D.at(i); + trace.info() << "Polygon " << i << ": " ; + for(unsigned int j =0; j Date: Thu, 2 Nov 2023 22:47:36 +0100 Subject: [PATCH 3/7] Add extreme case test at the start and end of line --- tests/samples/polygons.dat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/samples/polygons.dat b/tests/samples/polygons.dat index 365dd3e626..4fadb8323e 100644 --- a/tests/samples/polygons.dat +++ b/tests/samples/polygons.dat @@ -1,3 +1,3 @@ # two test polygons -1 2 3 4 5 6 + 1 2 3 4 5 6 0 0 10 0 5 5 From 01e40f5419e605e75f0a1876bfe1f321120995ff Mon Sep 17 00:00:00 2001 From: Sean Gong Date: Mon, 6 Nov 2023 17:39:13 +0100 Subject: [PATCH 4/7] Fix getPolygonsFromInputStream() in single-element case --- src/DGtal/io/readers/PointListReader.ih | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DGtal/io/readers/PointListReader.ih b/src/DGtal/io/readers/PointListReader.ih index 5c2ddbac3f..aedea95f95 100644 --- a/src/DGtal/io/readers/PointListReader.ih +++ b/src/DGtal/io/readers/PointListReader.ih @@ -79,7 +79,7 @@ DGtal::PointListReader::getPointsFromInputStream (std::istream &in, std TPoint p; while ( !in_str.fail()&& (nbFound>(in_str,val); - if(!in_str.fail() && val != " "){ + if(!in_str.fail()){ std::istringstream valFromStr( val ); typename TPoint::Component valConverted; valFromStr >> valConverted; From b31e05921ae63b34b66a536f0213c7bdea9445ab Mon Sep 17 00:00:00 2001 From: Sean Gong Date: Mon, 6 Nov 2023 17:40:31 +0100 Subject: [PATCH 5/7] Fix getPolygonsFromInputStream() in single-element case --- src/DGtal/io/readers/PointListReader.ih | 1 - 1 file changed, 1 deletion(-) diff --git a/src/DGtal/io/readers/PointListReader.ih b/src/DGtal/io/readers/PointListReader.ih index aedea95f95..bc5c7d3a19 100644 --- a/src/DGtal/io/readers/PointListReader.ih +++ b/src/DGtal/io/readers/PointListReader.ih @@ -88,7 +88,6 @@ DGtal::PointListReader::getPointsFromInputStream (std::istream &in, std if (idx == aVectPosition.at(j) ){ nbFound++; p[j]=valConverted; - val=""; } } } From de38c5dd249e03210bbdfe766f9c5790495ae0ef Mon Sep 17 00:00:00 2001 From: Sean Gong Date: Thu, 9 Nov 2023 15:20:48 +0100 Subject: [PATCH 6/7] Update ChangeLog.md --- ChangeLog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index bcfe263b7d..cbd5aeaae7 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -74,6 +74,8 @@ [#1674](https://github.com/DGtal-team/DGtal/pull/1674)) - Fix of `SurfaceMeshWriter::writeIsoLinesOBJ` (Jacques-Olivier Lachaud, [#1701](https://github.com/DGtal-team/DGtal/pull/1701)) + - Fix of the `PointListReader::getPolygonsFromInputStream` (Xun Gong, + [#1708](https://github.com/DGtal-team/DGtal/pull/1708)) - *Examples* - Fix Issue #1675, add missing SymmetricConvexExpander.h file From bf4aed0be84f9c0c30d1adf4de29a919a5c61824 Mon Sep 17 00:00:00 2001 From: Sean Gong Date: Thu, 9 Nov 2023 18:12:16 +0100 Subject: [PATCH 7/7] add test for testPointListReader Co-authored-by: Bertrand Kerautret --- tests/io/readers/testPointListReader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/io/readers/testPointListReader.cpp b/tests/io/readers/testPointListReader.cpp index 4a96039759..d58fe5651e 100644 --- a/tests/io/readers/testPointListReader.cpp +++ b/tests/io/readers/testPointListReader.cpp @@ -91,7 +91,7 @@ bool testPointListReader() } trace.info()<< std::endl; } - trace.beginBlock ( "Testing reading spectial 1 dimension elements (several by lines)..." ); + trace.beginBlock ( "Testing reading special 1 dimension elements (polygon of 1 dimension point)..." ); typedef PointVector<1, int> Point1D; std::vector< std::vector< Point1D > > vectPt1D = PointListReader< Point1D >::getPolygonsFromFile(filenamePoly);