Skip to content
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
9 changes: 5 additions & 4 deletions include/stl_reader/stl_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,9 @@ namespace stl_reader_impl {
typedef typename TNumberContainer1::value_type number_t;
typedef typename TIndexContainer1::value_type index_t;

if (coordsWithIndexInOut.empty ())
return;

sort (coordsWithIndexInOut.begin(), coordsWithIndexInOut.end());

// first count unique indices
Expand Down Expand Up @@ -736,10 +739,8 @@ inline bool StlFileHasASCIIFormat(const char* filename)
in.read (chars, 256);
string buffer (chars, in.gcount());
transform(buffer.begin(), buffer.end(), buffer.begin(), ::tolower);
return buffer.find ("solid") != string::npos &&
buffer.find ("\n") != string::npos &&
buffer.find ("facet") != string::npos &&
buffer.find ("normal") != string::npos;
return buffer.find ("solid") != string::npos && buffer.find ("\n") != string::npos &&
(buffer.find ("facet") != string::npos || buffer.find ("endsolid") != string::npos);
}

} // end of namespace stl_reader
Expand Down
2 changes: 2 additions & 0 deletions tests/data/ascii_empty.stl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
solid emptySTL
endsolid emptySTL
10 changes: 10 additions & 0 deletions tests/read_stl.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@ TEST (readSTL, binarySphere)
EXPECT_EQ (mesh.solid_tris_begin (0), 0);
EXPECT_EQ (mesh.solid_tris_end (0), 20);
}

TEST (readSTL, asciiFileWithoutFaces)
{
stl_reader::StlMesh<> mesh;
mesh.read_file ("data/ascii_empty.stl");

EXPECT_EQ (mesh.num_vrts (), 0);
EXPECT_EQ (mesh.num_tris (), 0);
EXPECT_EQ (mesh.num_solids (), 1);
}
Loading