Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PointListReader for reading single-element (Point1D case) per line #1708

Merged
merged 7 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/DGtal/io/readers/PointListReader.ih
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ DGtal::PointListReader<TPoint>::getPointsFromInputStream (std::istream &in, std
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;
}
}
}
}
Expand Down Expand Up @@ -132,6 +132,7 @@ DGtal::PointListReader<TPoint>::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];
Expand Down
26 changes: 23 additions & 3 deletions tests/io/readers/testPointListReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 special 1 dimension elements (polygon of 1 dimension point)..." );

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 <aPolygon.size(); j++){
trace.info()<< "Point :" << aPolygon.at(j);
}
trace.info()<< std::endl;
}
Point1D p1, p2, p3, p4, p5, p6; p1[0]=1; p2[0]=2; p3[0]=3; p4[0]=4; p5[0]=5; p6[0]=6;
Point1D p7, p8, p9, p10, p11, p12; p7[0]=0; p8[0]=0; p9[0]=10; p10[0]=0; p11[0]=5; p12[0]=5;

nbok += (vectPt1D.at(0).size()==6 && vectPt1D.at(1).size()==6 && vectPt1D.at(0).at(0) == p1 &&
vectPt1D.at(0).at(1)==p2 && vectPt1D.at(0).at(2) == p3 && vectPt1D.at(0).at(3) == p4
&& vectPt1D.at(0).at(4)==p5 && vectPt1D.at(0).at(5)==p6
&& vectPt1D.at(1).at(0)==p7
&& vectPt1D.at(1).at(1)==p8 && vectPt1D.at(1).at(2)==p9 && vectPt1D.at(1).at(3)==p10
&& vectPt1D.at(1).at(4)==p11 && vectPt1D.at(1).at(5)==p12);


nb++;
trace.endBlock();

Expand Down
2 changes: 1 addition & 1 deletion tests/samples/polygons.dat
Original file line number Diff line number Diff line change
@@ -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
Loading