MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / loadPly

Function loadPly

source/MRMesh/MRPly.cpp:67–276  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65} // anonymous namespace
66
67Expected<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 ) )

Callers 2

fromPlyFunction · 0.70
fromPlyFunction · 0.70

Calls 15

ColorClass · 0.85
reportProgressFunction · 0.85
ignoreCommentFunction · 0.85
get_end_posMethod · 0.80
has_elementMethod · 0.80
next_elementMethod · 0.80
element_isMethod · 0.80
load_elementMethod · 0.80
num_rowsMethod · 0.80
find_posMethod · 0.80
extract_propertiesMethod · 0.80

Tested by

no test coverage detected