MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/splashsurf / parse_points

Function parse_points

splashsurf_lib/src/io/bgeo_format.rs:561–626  ·  view source on GitHub ↗

Parses all attribute values for points

(
        input: &'a [u8],
        num_points: usize,
        special_attribs: &[AttribDefinition],
        named_attribs: &[AttribDefinition],
    )

Source from the content-addressed store, hash-verified

559
560 /// Parses all attribute values for points
561 fn parse_points<'a>(
562 input: &'a [u8],
563 num_points: usize,
564 special_attribs: &[AttribDefinition],
565 named_attribs: &[AttribDefinition],
566 ) -> IResult<
567 &'a [u8],
568 (Vec<AttributeStorage>, Vec<(String, AttributeStorage)>),
569 BgeoParserError<&'a [u8]>,
570 > {
571 // Construct a parser for each attribute
572 let mut parsers: Vec<_> = special_attribs
573 .iter()
574 .chain(named_attribs.iter())
575 .cloned()
576 .map(|attrib| {
577 // Allocate storage for the attribute
578 let storage = AttributeStorage::with_capacity(num_points, &attrib)
579 .expect("Unimplemented attribute storage");
580 AttributeParser::new(attrib, storage)
581 })
582 .collect();
583
584 // Run the parsers alternating
585 let input = {
586 let mut input = input;
587
588 // Get the parser functions
589 //let mut parser_funs: Vec<_> = parsers.iter_mut().map(|p| p.parser()).collect();
590 // For each point...
591 for _ in 0..num_points {
592 // ...apply all parsers in succession
593 for parser in parsers.iter_mut() {
594 let (i, _) = parser.parse(input)?;
595 input = i;
596 }
597 }
598
599 input
600 };
601
602 // Collect the individual attribute storages
603 let mut special_attrib_data = Vec::new();
604 let mut named_attrib_data = Vec::new();
605
606 for parser in parsers.into_iter() {
607 assert_eq!(
608 num_points * parser.attrib.size,
609 parser.storage.len(),
610 "failed to read attribute \"{}\" (type {:?}): number of read attribute values ({}) does not match expected number of attribute values ({} = {} points * {} attribute components)",
611 parser.attrib.name,
612 parser.attrib.attr_type,
613 parser.storage.len(),
614 num_points * parser.attrib.size,
615 num_points,
616 parser.attrib.size
617 );
618 if special_attrib_data.len() < special_attribs.len() {

Callers 1

bgeo_parserFunction · 0.85

Calls 5

collectMethod · 0.80
iter_mutMethod · 0.80
parseMethod · 0.80
iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected