Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | List of all members
bitpit::STLReader Class Reference

Class for reading ASCII and binary STL files. More...

Inheritance diagram for bitpit::STLReader:
Inheritance graph
[legend]
Collaboration diagram for bitpit::STLReader:
Collaboration graph
[legend]

Classes

struct  InspectionInfo
 Structure holding inspection information. More...
 

Public Member Functions

 STLReader (const std::string &filename, Format format=FormatUnknown)
 
void displayInspectionInfo (const InspectionInfo &info, std::ostream &out) const
 
int inspect (InspectionInfo *info)
 
int readBegin ()
 
int readEnd ()
 
int readFacet (std::array< double, 3 > *V0, std::array< double, 3 > *V1, std::array< double, 3 > *V2, std::array< double, 3 > *N)
 
int readFooter ()
 
int readFooter (const std::string &solid)
 
int readHeader (const std::string &solid, std::string *name, std::size_t *nT)
 
int readHeader (std::string *name, std::size_t *nT)
 
int readSolid (const std::string &solid, std::string *name, std::size_t *nV, std::size_t *nT, std::vector< std::array< double, 3 > > *V, std::vector< std::array< double, 3 > > *N, std::vector< std::array< std::size_t, 3 > > *T)
 
int readSolid (std::string *name, std::size_t *nV, std::size_t *nT, std::vector< std::array< double, 3 > > *V, std::vector< std::array< double, 3 > > *N, std::vector< std::array< std::size_t, 3 > > *T)
 
- Public Member Functions inherited from bitpit::STLBase
const std::string & getFilename () const
 
Format getFormat () const
 

Static Public Member Functions

static Format detectFormat (const std::string &filename)
 

Additional Inherited Members

- Public Types inherited from bitpit::STLBase
enum  Format { FormatUnknown = -1 , FormatASCII , FormatBinary }
 
- Protected Types inherited from bitpit::STLBase
typedef float BINARY_REAL32
 
typedef uint16_t BINARY_UINT16
 
typedef uint32_t BINARY_UINT32
 
typedef uint8_t BINARY_UINT8
 
- Protected Member Functions inherited from bitpit::STLBase
 STLBase (const std::string &filename)
 
 STLBase (const std::string &filename, Format format)
 
void setFilename (const std::string &filename)
 
void setFormat (Format format)
 
- Static Protected Attributes inherited from bitpit::STLBase
static const std::string ASCII_FACET_BEGIN = "facet"
 
static const std::string ASCII_FACET_END = "endfacet"
 
static const std::string ASCII_FILE_BEGIN = STLBase::ASCII_SOLID_BEGIN
 
static const std::string ASCII_FILE_END = STLBase::ASCII_SOLID_END
 
static const std::size_t ASCII_MINIMUM_SIZE = STLBase::ASCII_FILE_BEGIN.length() + STLBase::ASCII_FILE_END.length()
 
static const std::string ASCII_SOLID_BEGIN = "solid"
 
static const std::string ASCII_SOLID_END = "endsolid"
 
static const std::size_t BINARY_FACET_SIZE = 3 * sizeof(BINARY_REAL32) + 3 * 3 * sizeof(BINARY_REAL32) + sizeof(BINARY_UINT16)
 
static const std::size_t BINARY_HEADER_SIZE = 80 * sizeof(STLBase::BINARY_UINT8)
 
static const std::size_t BINARY_MINIMUM_SIZE = STLBase::BINARY_HEADER_SIZE + sizeof(STLBase::BINARY_UINT32)
 

Detailed Description

Class for reading ASCII and binary STL files.

Definition at line 83 of file STL.hpp.

Constructor & Destructor Documentation

◆ STLReader()

bitpit::STLReader::STLReader ( const std::string & filename,
Format format = FormatUnknown )

Constructor.

Parameters
filenameis the name of the STL file
formatis the format of the STL file

Definition at line 137 of file STL.cpp.

Member Function Documentation

◆ detectFormat()

STLReader::Format bitpit::STLReader::detectFormat ( const std::string & filename)
static

Detects the format of the specified STL file.

An ASCII STL file begins with the line "solid name" and concludes with the line "endsolid name", where name is an optional string.

A binary STL file has an 80-character header which is ignored, but should never begin with the ASCII representation of the string solid. Following the header is a 4-byte little-endian unsigned integer indicating the number of triangular facets in the file. The size of the binary file should be consistent with the number of factes. No extra data is allowed after the definition of the factes.

Parameters
filenameis the name of the STL file
Returns
The format of the specified STL file.

Definition at line 167 of file STL.cpp.

◆ displayInspectionInfo()

void bitpit::STLReader::displayInspectionInfo ( const InspectionInfo & info,
std::ostream & out ) const

Display inspection information.

Parameters
infoare the information that will be displayed
[in,out]outoutput stream

Definition at line 656 of file STL.cpp.

◆ inspect()

int bitpit::STLReader::inspect ( InspectionInfo * info)

Inspect the STL file.

Parameters
infoon output it will contain the information gathered during the inspection
Returns
Returns a negative number if an error occured, zero otherwise. The meaning of the error codes is the following:
  • error = -1: error opening the STL file
  • error = -2: the file is already open

Definition at line 307 of file STL.cpp.

◆ readBegin()

int bitpit::STLReader::readBegin ( )

Begin reading the file.

Returns
Returns a negative number if an error occured, zero otherwise. The meaning of the error codes is the following:
  • error = -1: error opening the STL file
  • error = -2: the file is already open

Definition at line 714 of file STL.cpp.

◆ readEnd()

int bitpit::STLReader::readEnd ( )

Close the current stream to STL file.

Definition at line 731 of file STL.cpp.

◆ readFacet()

int bitpit::STLReader::readFacet ( std::array< double, 3 > * V0,
std::array< double, 3 > * V1,
std::array< double, 3 > * V2,
std::array< double, 3 > * N )

Read facet data from an ASCII STL file.

This routine assumes that the file stream is already open.

Parameters
[out]V0on output will contain the coordinates of the first vertex
[out]V1on output will contain the coordinates of the second vertex
[out]V2on output will contain the coordinates of the third vertex
[out]Non output will contain the normal
Returns
Returns a negative number if an error occured, zero otherwise. The meaning of the error codes is the following:
  • error = -1: failed to read from input stream
  • error = -2: facet data section is malformed
  • error = -3: the facet has more than 3 vertices

Definition at line 942 of file STL.cpp.

◆ readFooter() [1/2]

int bitpit::STLReader::readFooter ( )

Read the footer of an ASCII STL file.

This routine assumes that the file stream is already open.

Returns
Returns a negative number if an error occured, zero otherwise. The meaning of the error codes is the following:
  • error = -1: failed to read data from output stream
  • error = -2: footer was not found

Definition at line 896 of file STL.cpp.

◆ readFooter() [2/2]

int bitpit::STLReader::readFooter ( const std::string & solid)

Read the footer of an ASCII STL file.

This routine assumes that the file stream is already open.

Parameters
solidis the name of the solid, if the name is empty, the first footer will be read
Returns
Returns a negative number if an error occured, zero otherwise. The meaning of the error codes is the following:
  • error = -1: failed to read data from output stream
  • error = -2: footer was not found

Definition at line 913 of file STL.cpp.

◆ readHeader() [1/2]

int bitpit::STLReader::readHeader ( const std::string & solid,
std::string * name,
std::size_t * nT )

Read the header of the STL file.

This routine assumes that the file stream is already open.

Parameters
[in]solidis the name of the solid, if the name is empty, the first header will be read
[out]nameon output will contain the name of the solid that has been actually read
[out]nTon input will contain the number of factes of the solid
Returns
Returns a negative number if an error occured, zero otherwise. The meaning of the error codes is the following:
  • error = -1: failed to read data from output stream
  • error = -2: header was not found

Definition at line 865 of file STL.cpp.

◆ readHeader() [2/2]

int bitpit::STLReader::readHeader ( std::string * name,
std::size_t * nT )

Read the header of the STL file.

This routine assumes that the file stream is already open.

Parameters
[out]nameon output will contain the name of the solid that has been actually read
[out]nTon input will contain the number of factes of the solid
Returns
Returns a negative number if an error occured, zero otherwise. The meaning of the error codes is the following:
  • error = -1: failed to read data from output stream
  • error = -2: header was not found

Definition at line 845 of file STL.cpp.

◆ readSolid() [1/2]

int bitpit::STLReader::readSolid ( const std::string & solid,
std::string * name,
std::size_t * nV,
std::size_t * nT,
std::vector< std::array< double, 3 > > * V,
std::vector< std::array< double, 3 > > * N,
std::vector< std::array< std::size_t, 3 > > * T )

Read solid data from the STL file.

This routine assumes that the file stream is already open.

Parameters
[in]solidis the name of the solid that will to be read, if the name is empty, the first solid found will be read. Loading solids with a specific name is only supported for ASCII files
[out]nameon output will contain the name of the solid that has been actually read. Solid names are only supported for ASCII files
[in,out]nVon input stores the current number of vertices hosted in V, on output stores the input values incremented by the number of vertices read from the STL file.
[in,out]nTon input stores the number of facet->vertex connectivity entries stores in T, on output stores the input value incremented by the number of facets read from the STL file.
[in,out]Vis the list of vertex coordinates, vertices read from the STL file are appended at the end of V
[in,out]Nis the list of facet normals, normals read from the STL file are appended at the end of V
[in,out]Tis the facet->vertex connectivity, entries read from the STL file are appended at the end of T
Returns
Returns a negative number if an error occured, zero otherwise.

Definition at line 790 of file STL.cpp.

◆ readSolid() [2/2]

int bitpit::STLReader::readSolid ( std::string * name,
std::size_t * nV,
std::size_t * nT,
std::vector< std::array< double, 3 > > * V,
std::vector< std::array< double, 3 > > * N,
std::vector< std::array< std::size_t, 3 > > * T )

Read solid data from the STL file.

This routine assumes that the file stream is already open.

Parameters
[out]nameon output will contain the name of the solid that has been actually read. Solid names are only supported for ASCII files
[in,out]nVon input stores the current number of vertices hosted in V, on output stores the input values incremented by the number of vertices read from the STL file.
[in,out]nTon input stores the number of facet->vertex connectivity entries stores in T, on output stores the input value incremented by the number of facets read from the STL file.
[in,out]Vis the list of vertex coordinates, vertices read from the STL file are appended at the end of V
[in,out]Nis the list of facet normals, normals read from the STL file are appended at the end of V
[in,out]Tis the facet->vertex connectivity, entries read from the STL file are appended at the end of T
Returns
Returns a negative number if an error occured, zero otherwise.

Definition at line 759 of file STL.cpp.


The documentation for this class was generated from the following files:
--- layout: doxygen_footer ---