ug4
stl_reader Namespace Reference

Namespaces

 stl_reader_impl
 

Classes

class  StlMesh
 convenience mesh class which makes accessing the stl data more easy More...
 

Functions

template<class TNumberContainer , class TIndexContainer >
bool ReadStlFile (const char *filename, TNumberContainer &coordsOut, TNumberContainer &normalsOut, TIndexContainer &trisOut, TIndexContainer &solidRangesOut)
 Reads an ASCII or binary stl file into several arrays. More...
 
template<class TNumberContainer , class TIndexContainer >
bool ReadStlFile_ASCII (const char *filename, TNumberContainer &coordsOut, TNumberContainer &normalsOut, TIndexContainer &trisOut, TIndexContainer &solidRangesOut)
 Reads an ASCII stl file into several arrays. More...
 
template<class TNumberContainer , class TIndexContainer >
bool ReadStlFile_BINARY (const char *filename, TNumberContainer &coordsOut, TNumberContainer &normalsOut, TIndexContainer &trisOut, TIndexContainer &solidRangesOut)
 Reads a binary stl file into several arrays. More...
 
bool StlFileHasASCIIFormat (const char *filename)
 Determines whether a stl file has ASCII format. More...
 

Function Documentation

◆ ReadStlFile()

template<class TNumberContainer , class TIndexContainer >
bool stl_reader::ReadStlFile ( const char *  filename,
TNumberContainer &  coordsOut,
TNumberContainer &  normalsOut,
TIndexContainer &  trisOut,
TIndexContainer &  solidRangesOut 
)

Reads an ASCII or binary stl file into several arrays.

Reads a stl file and writes its coordinates, normals and triangle-corner-indices to the provided containers. It also fills a container solidRangesOut, which provides the triangle ranges for individual solids.

Double vertex entries are removed on the fly, so that triangle corners with equal coordinates are represented by a single coordinate entry in coordsOut.

Parameters
filename[in] The name of the file which shall be read
coordsOut[out] Coordinates are written to this container. On termination, it has size numVertices * 3. Each triple of entries forms a 3d coordinate. The type TNumberContainer should have the same interface as std::vector<float>.
normalsOut[out] Face normals are written to this container. On termination, it has size numFaces * 3. Each triple of entries forms a 3d normal. The type TNumberContainer should have the same interface as std::vector<float>.
trisOut[out] Triangle corner indices are written to this container. On termination, it has size numFaces * 3. Each triple of entries defines a triangle. The type TIndexContainer should have the same interface as std::vector<size_t>. Multiply corner indices from trisOut by 3 to obtain the index of the first coordinate of that corner in coordsOut.
solidRangesOut[out] On termination, it holds the ranges of triangle indices for each solid. It has the size numSolids + 1. Each entry can be interpreted as a end/begin triangle index for the previous/next solid. E.g., if there are 3 solids, the returned array would look like this:
{sol1Begin, sol1End/sol2Begin, sol2End/sol3Begin, sol3End}.
The type TIndexContainer should have the same interface as std::vector<size_t>.
Returns
true if the file was successfully read into the provided container.

References ReadStlFile_ASCII(), ReadStlFile_BINARY(), and StlFileHasASCIIFormat().

Referenced by ug::LoadGridFromSTL(), and stl_reader::StlMesh< TNumber, TIndex >::read_file().

◆ ReadStlFile_ASCII()

template<class TNumberContainer , class TIndexContainer >
bool stl_reader::ReadStlFile_ASCII ( const char *  filename,
TNumberContainer &  coordsOut,
TNumberContainer &  normalsOut,
TIndexContainer &  trisOut,
TIndexContainer &  solidRangesOut 
)

Reads an ASCII stl file into several arrays.

Reads a stl file and writes its coordinates, normals and triangle-corner-indices to the provided containers. It also fills a container solidRangesOut, which provides the triangle ranges for individual solids.

Double vertex entries are removed on the fly, so that triangle corners with equal coordinates are represented by a single coordinate entry in coordsOut.

Parameters
filename[in] The name of the file which shall be read
coordsOut[out] Coordinates are written to this container. On termination, it has size numVertices * 3. Each triple of entries forms a 3d coordinate. The type TNumberContainer should have the same interface as std::vector<float>.
normalsOut[out] Face normals are written to this container. On termination, it has size numFaces * 3. Each triple of entries forms a 3d normal. The type TNumberContainer should have the same interface as std::vector<float>.
trisOut[out] Triangle corner indices are written to this container. On termination, it has size numFaces * 3. Each triple of entries defines a triangle. The type TIndexContainer should have the same interface as std::vector<size_t>. Multiply corner indices from trisOut by 3 to obtain the index of the first coordinate of that corner in coordsOut.
solidRangesOut[out] On termination, it holds the ranges of triangle indices for each solid. It has the size numSolids + 1. Each entry can be interpreted as a end/begin triangle index for the previous/next solid. E.g., if there are 3 solids, the returned array would look like this:
{sol1Begin, sol1End/sol2Begin, sol2End/sol3Begin, sol3End}.
The type TIndexContainer should have the same interface as std::vector<size_t>.
Returns
true if the file was successfully read into the provided container.
See also
ReadStlFile, ReadStlFile_ASCII

References stl_reader::stl_reader_impl::RemoveDoubles(), STL_READER_COND_THROW, and STL_READER_THROW.

Referenced by ReadStlFile().

◆ ReadStlFile_BINARY()

template<class TNumberContainer , class TIndexContainer >
bool stl_reader::ReadStlFile_BINARY ( const char *  filename,
TNumberContainer &  coordsOut,
TNumberContainer &  normalsOut,
TIndexContainer &  trisOut,
TIndexContainer &  solidRangesOut 
)

Reads a binary stl file into several arrays.

Reads a stl file and writes its coordinates, normals and triangle-corner-indices to the provided containers. It also fills a container solidRangesOut, which provides the triangle ranges for individual solids.

Double vertex entries are removed on the fly, so that triangle corners with equal coordinates are represented by a single coordinate entry in coordsOut.

Parameters
filename[in] The name of the file which shall be read
coordsOut[out] Coordinates are written to this container. On termination, it has size numVertices * 3. Each triple of entries forms a 3d coordinate. The type TNumberContainer should have the same interface as std::vector<float>.
normalsOut[out] Face normals are written to this container. On termination, it has size numFaces * 3. Each triple of entries forms a 3d normal. The type TNumberContainer should have the same interface as std::vector<float>.
trisOut[out] Triangle corner indices are written to this container. On termination, it has size numFaces * 3. Each triple of entries defines a triangle. The type TIndexContainer should have the same interface as std::vector<size_t>. Multiply corner indices from trisOut by 3 to obtain the index of the first coordinate of that corner in coordsOut.
solidRangesOut[out] On termination, it holds the ranges of triangle indices for each solid. It has the size numSolids + 1. Each entry can be interpreted as a end/begin triangle index for the previous/next solid. E.g., if there are 3 solids, the returned array would look like this:
{sol1Begin, sol1End/sol2Begin, sol2End/sol3Begin, sol3End}.
The type TIndexContainer should have the same interface as std::vector<size_t>.
Returns
true if the file was successfully read into the provided container.
Todo:
support systems with big endianess
See also
ReadStlFile, ReadStlFile_BINARY

References stl_reader::stl_reader_impl::RemoveDoubles(), and STL_READER_COND_THROW.

Referenced by ReadStlFile().

◆ StlFileHasASCIIFormat()

bool stl_reader::StlFileHasASCIIFormat ( const char *  filename)
inline

Determines whether a stl file has ASCII format.

The underlying mechanism is simply checks whether the provided file starts with the keyword solid. This should work for many stl files, but may fail, of course.

References STL_READER_COND_THROW.

Referenced by ReadStlFile().