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

Function parsePtsCoordinate

source/MRMesh/MRIOParsing.cpp:220–275  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

218
219template <typename T>
220Expected<void> parsePtsCoordinate( const std::string_view& str, Vector3<T>& v, Color* c, Vector3<T>* n )
221{
222 using namespace boost::spirit::x3;
223
224 int vi = 0, ci = 0, ni = 0;
225 auto coord = [&] ( auto& ctx ) { v[vi++] = _attr( ctx ); };
226 auto intensity = [&] ( auto& ctx ) { (void)ctx; }; // value not used
227 auto color = [&] ( auto& ctx ) { ((uint8_t*)c)[ci++] = _attr( ctx ); };
228 auto normal = [&] ( auto& ctx ) { (*n)[ni++] = _attr( ctx ); };
229
230 using uint8_type = uint_parser<uint8_t>;
231 constexpr uint8_type uint8_ = {};
232 bool r;
233 if ( n != nullptr )
234 {
235 r = phrase_parse(
236 str.begin(),
237 str.end(),
238 (
239 floatT[coord] >> floatT[coord] >> floatT[coord] >>
240 -( floatT[intensity] >>
241 -( uint8_[color] >> uint8_[color] >> uint8_[color] >>
242 -( floatT[normal] >> floatT[normal] >> floatT[normal] ) ) )
243 ),
244 ascii::space
245 );
246 }
247 else if ( c != nullptr )
248 {
249 r = phrase_parse(
250 str.begin(),
251 str.end(),
252 (
253 floatT[coord] >> floatT[coord] >> floatT[coord] >>
254 -( floatT[intensity] >>
255 -( uint8_[color] >> uint8_[color] >> uint8_[color] ) )
256 ),
257 ascii::space
258 );
259 }
260 else
261 {
262 r = phrase_parse(
263 str.begin(),
264 str.end(),
265 (
266 floatT[coord] >> floatT[coord] >> floatT[coord]
267 ),
268 ascii::space
269 );
270 }
271 if ( !r )
272 return unexpected( "Failed to parse vertex: " + std::string( trimRight( str.substr( 0, MaxErrorStringLen ) ) ) );
273
274 return {};
275}
276
277template<typename T>

Callers

nothing calls this directly

Calls 4

trimRightFunction · 0.85
unexpectedFunction · 0.70
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected