| 65 | } // anonymous namespace |
| 66 | |
| 67 | Expected<VertCoords> loadPly( std::istream& in, const PlyLoadParams& params ) |
| 68 | { |
| 69 | MR_TIMER; |
| 70 | |
| 71 | const auto posStart = in.tellg(); |
| 72 | miniply::PLYReader reader( in ); |
| 73 | if ( !reader.valid() ) |
| 74 | return unexpected( std::string( "PLY file open error" ) ); |
| 75 | |
| 76 | uint32_t indecies[3]; |
| 77 | bool gotVerts = false; |
| 78 | |
| 79 | VertCoords res; |
| 80 | const auto posEnd = reader.get_end_pos(); |
| 81 | const float streamSize = float( posEnd - posStart ); |
| 82 | |
| 83 | std::string signalString = "PLY"; |
| 84 | for ( ; reader.has_element(); reader.next_element() ) |
| 85 | { |
| 86 | if ( reader.element_is(miniply::kPLYVertexElement) && reader.load_element() ) |
| 87 | { |
| 88 | signalString += " V"; |
| 89 | auto numVerts = reader.num_rows(); |
| 90 | if ( reader.find_pos( indecies ) ) |
| 91 | { |
| 92 | Timer t( "extractPoints" ); |
| 93 | signalString += 'P'; |
| 94 | res.resize( numVerts ); |
| 95 | reader.extract_properties( indecies, 3, miniply::PLYPropertyType::Float, res.data() ); |
| 96 | gotVerts = true; |
| 97 | } |
| 98 | if ( reader.find_normal( indecies ) ) |
| 99 | { |
| 100 | signalString += 'N'; |
| 101 | if ( params.normals ) |
| 102 | { |
| 103 | Timer t( "extractNormals" ); |
| 104 | params.normals->resize( numVerts ); |
| 105 | reader.extract_properties( indecies, 3, miniply::PLYPropertyType::Float, params.normals->data() ); |
| 106 | } |
| 107 | } |
| 108 | if ( reader.find_color( indecies ) ) |
| 109 | { |
| 110 | signalString += 'C'; |
| 111 | if ( params.colors ) |
| 112 | { |
| 113 | Timer t( "extractVertColors" ); |
| 114 | std::vector<unsigned char> colorsBuffer( 3 * numVerts ); |
| 115 | reader.extract_properties( indecies, 3, miniply::PLYPropertyType::UChar, colorsBuffer.data() ); |
| 116 | params.colors->resize( numVerts ); |
| 117 | for ( VertId v{ 0 }; v < res.size(); ++v ) |
| 118 | { |
| 119 | int ind = 3 * v; |
| 120 | ( *params.colors )[v] = Color( colorsBuffer[ind], colorsBuffer[ind + 1], colorsBuffer[ind + 2] ); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | if ( reader.find_texcoord( indecies ) ) |
no test coverage detected