PLYwoot
Header-only C++17 library for parsing and writing PLY files
Loading...
Searching...
No Matches
plywoot::IStream Class Reference

Represents an input PLY data stream that can be queried for data. More...

#include <plywoot.hpp>

Public Member Functions

 IStream (std::istream &is)
 
const std::vector< Comment > & comments () const
 
const std::vector< PlyElement > & elements () const
 
std::optional< PlyElementelement (const std::string &name) const
 
PlyFormat format () const
 
bool find (const std::string &elementName) const
 
PlyElement element () const
 
bool hasElement () const
 
PlyElementData readElement () const
 
template<typename T , typename Layout >
void readElement (T *dest) const
 
template<typename T , typename Layout >
std::vector< T > readElement () const
 
void skipElement () const
 Skips the current element.
 

Detailed Description

Represents an input PLY data stream that can be queried for data.

Definition at line 52 of file plywoot.hpp.

Constructor & Destructor Documentation

◆ IStream()

plywoot::IStream::IStream ( std::istream &  is)
inline

Constructs an input PLY data stream from the given input stream. This will automatically trigger parsing of all PLY data in the input stream.

Parameters
isinput stream containing the PLY data to parse

Definition at line 59 of file plywoot.hpp.

Member Function Documentation

◆ comments()

const std::vector< Comment > & plywoot::IStream::comments ( ) const
inline

Returns all comments embedded in the PLY header.

Returns
all comments embedded in the PLY header

Definition at line 64 of file plywoot.hpp.

◆ element() [1/2]

PlyElement plywoot::IStream::element ( ) const
inline

Returns a copy of the current element that can be either read or skipped. In case no element can be read, returns a default constructed element.

Returns
a copy of the current element that can be either read or skipped

Definition at line 110 of file plywoot.hpp.

◆ element() [2/2]

std::optional< PlyElement > plywoot::IStream::element ( const std::string &  name) const
inline

Returns a pair where the first element is a copy of the element with the given name in case it exists. The second element is a boolean that indicates whether the requested element was found. In case a requested element was not found in the input data, a default constructed element is returned.

Parameters
namename of the element to retrieve
Returns
a pair where the first element is a copy of the element in case it exists, and the second element is a Boolean indicating whether the requested element was found

Definition at line 81 of file plywoot.hpp.

◆ elements()

const std::vector< PlyElement > & plywoot::IStream::elements ( ) const
inline

Returns all elements associated with this PLY file.

Returns
all elements associated with this PLY file

Definition at line 69 of file plywoot.hpp.

◆ find()

bool plywoot::IStream::find ( const std::string &  elementName) const
inline

Positions the read head at the start of the element with the given name, or at the end of the stream in case the given element is not present in the stream, skipping over elements that do not match elementName.

Parameters
elementNamename of the element to find
Returns
true in case an element with the given name was found, false otherwise

Definition at line 100 of file plywoot.hpp.

◆ format()

PlyFormat plywoot::IStream::format ( ) const
inline

Returns the format of the input PLY data stream.

Returns
the format of the input PLY data stream

Definition at line 91 of file plywoot.hpp.

◆ hasElement()

bool plywoot::IStream::hasElement ( ) const
inline

Returns whether there are still elements left to parse.

Returns
true in case there are still elements left to parse, false otherwise

Definition at line 115 of file plywoot.hpp.

◆ readElement() [1/3]

PlyElementData plywoot::IStream::readElement ( ) const
inline

Reads an element to a newly allocated block of memory wrapped by a PlyElementData instance. PLY data types are directly mapped to their corresponding native types. Lists are mapped to an std::vector<T> where T is the type of type of the element in the lists. All data is aligned according to the alignment requirements of the compiler platform.

Precondition
hasElement() must be true
Returns
memory block in the form of a PlyElementData instance representing all data for the active element to be parsed

Definition at line 126 of file plywoot.hpp.

◆ readElement() [2/3]

template<typename T , typename Layout >
std::vector< T > plywoot::IStream::readElement ( ) const
inline

Reads the current element from the PLY input data stream, returning a list of objects of type T, where the Layout type is used to identify how properties from the PLY element are mapped on objects of type T.

Template Parameters
Ttype of objects to be read from the stream
Layoutlayout specifying the mapping of PLY properties to T
Precondition
hasElement() must be true
Returns
a vector of object of type T representing the element that was parsed using the PLY property mapping embedded in the given Layout type

Definition at line 162 of file plywoot.hpp.

◆ readElement() [3/3]

template<typename T , typename Layout >
void plywoot::IStream::readElement ( T *  dest) const
inline

Reads the current element from the PLY input data stream into memory pointed to by dest, where the Layout type is used to identify how properties from the PLY element are mapped on objects of type T.

Parameters
destpointer to the memory where elements of type T need to be written to
Template Parameters
Ttype of objects to be read from the stream
Layoutlayout specifying the mapping of PLY properties to T
Precondition
hasElement() must be true
Note
This assumes that dest points to a block of memory that allows holding at least as many instances of T as the size of the element that is being read!
Returns
a vector of object of type T representing the element that was parsed using the PLY property mapping embedded in the given Layout type

Definition at line 145 of file plywoot.hpp.

◆ skipElement()

void plywoot::IStream::skipElement ( ) const
inline

Skips the current element.

Definition at line 170 of file plywoot.hpp.


The documentation for this class was generated from the following file: