Struct ply_rs::parser::Parser
[−]
[src]
pub struct Parser<E: PropertyAccess> { /* fields omitted */ }
Reads data given by a Read
trait into Ply
components.
In most cases read_ply()
should suffice.
If you need finer control over the read process,
there are methods down to the line/element level.
Examples
The most common case is probably to read from a file:
// set up a reader, in this case a file. let path = "example_plys/greg_turk_example1_ok_ascii.ply"; let mut f = std::fs::File::open(path).unwrap(); // create a parser let p = parser::Parser::<ply::DefaultElement>::new(); // use the parser: read the entire file let ply = p.read_ply(&mut f); // Did it work? assert!(ply.is_ok());
If you need finer control, you can start splitting the read operations down to the line/element level.
In the follwoing case we first read the header, and then continue with the payload. We need to build a Ply our selves.
// set up a reader as before. // let mut f = ... ; // We need to wrap our `Read` into something providing `BufRead` let mut buf_read = std::io::BufReader::new(f); // create a parser let p = parser::Parser::<ply::DefaultElement>::new(); // use the parser: read the header let header = p.read_header(&mut buf_read); // Did it work? let header = header.unwrap(); // read the payload let payload = p.read_payload(&mut buf_read, &header); // Did it work? let payload = payload.unwrap(); // May be create your own Ply: let ply = ply::Ply { header: header, payload: payload, }; println!("Ply: {:#?}", ply);
Methods
impl<E: PropertyAccess> Parser<E>
[src]
fn new() -> Self
[src]
Creates a new Parser<E>
, where E
is the type to store the element data in.
To get started quickly try DefaultElement
from the ply
module.
fn read_ply<T: Read>(&self, source: &mut T) -> Result<Ply<E>>
[src]
Expects the complete content of a PLY file.
A PLY file starts with "ply\n". read_ply
reads until all elements have been read as
defined in the header of the PLY file.
impl<E: PropertyAccess> Parser<E>
[src]
fn read_header<T: BufRead>(&self, reader: &mut T) -> Result<Header>
[src]
Reads header until and inclusive end_header
.
A ply file starts with "ply\n". The header and the payload are separated by a line end_header\n
.
This method reads all headere elemnts up to end_header
.
fn read_header_line(&self, line: &str) -> Result<Line>
[src]
impl<E: PropertyAccess> Parser<E>
[src]
fn read_payload<T: BufRead>(
&self,
reader: &mut T,
header: &Header
) -> Result<Payload<E>>
[src]
&self,
reader: &mut T,
header: &Header
) -> Result<Payload<E>>
Reads payload. Encoding is chosen according to the encoding field in header
.
fn read_payload_for_element<T: BufRead>(
&self,
reader: &mut T,
element_def: &ElementDef,
header: &Header
) -> Result<Vec<E>>
[src]
&self,
reader: &mut T,
element_def: &ElementDef,
header: &Header
) -> Result<Vec<E>>
Reads entire list of elements from payload. Encoding is chosen according to header
.
Make sure to read the elements in the order as they are defined in the header.
impl<E: PropertyAccess> Parser<E>
[src]
fn read_ascii_element(&self, line: &str, element_def: &ElementDef) -> Result<E>
[src]
Read a single element. Assume it is encoded in ascii.
Make sure all elements are parsed in the order they are defined in the header.
impl<E: PropertyAccess> Parser<E>
[src]
fn read_big_endian_element<T: Read>(
&self,
reader: &mut T,
element_def: &ElementDef
) -> Result<E>
[src]
&self,
reader: &mut T,
element_def: &ElementDef
) -> Result<E>
Reads a single element as declared in èlement_def. Assumes big endian encoding.
Make sure all elements are parsed in the order they are defined in the header.
fn read_little_endian_element<T: Read>(
&self,
reader: &mut T,
element_def: &ElementDef
) -> Result<E>
[src]
&self,
reader: &mut T,
element_def: &ElementDef
) -> Result<E>
Reads a single element as declared in èlement_def. Assumes big endian encoding.
Make sure all elements are parsed in the order they are defined in the header.