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

Function process

source/MRIOExtras/MRLas.cpp:266–391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

264}
265
266Expected<PointCloud> process( lazperf::reader::basic_file& reader, const PointsLoadSettings& settings )
267{
268 const auto pointCount = reader.pointCount();
269
270 const auto& header = reader.header();
271 const auto pointFormat = header.pointFormat();
272 if ( pointFormat < 0 || pointFormat > 10 )
273 return unexpected( fmt::format( "Unsupported LAS point format: {}", pointFormat ) );
274
275 if ( LasPointSize[pointFormat] > header.point_record_length )
276 return unexpected( fmt::format( "Too short LAS point record length {} for point format {}, expected length {}",
277 header.point_record_length, pointFormat, LasPointSize[pointFormat] ) );
278
279 const auto extraBytesVlr = reader.vlrData( "LASF_Spec", 4 );
280 bool hasNormals = false;
281 if ( extraBytesVlr.size() == 3 * sizeof( ExtraBytes ) )
282 {
283 ExtraBytes extraBytes[3];
284 for ( int i = 0; i < 3; ++i )
285 std::memcpy( extraBytes + i, extraBytesVlr.data() + i * sizeof( ExtraBytes ), sizeof( ExtraBytes ) );
286 if ( extraBytes[0].data_type == 10 && extraBytes[1].data_type == 10 && extraBytes[2].data_type == 10 ) // all extra types are doubles
287 {
288 // https://github.com/ASPRSorg/LAS/issues/37#issuecomment-1695757865
289 // enough to check first field only
290 hasNormals = strcmp( extraBytes[0].name, "NormalX" ) == 0 ||
291 strcmp( extraBytes[0].name, "nx" ) == 0 ||
292 strcmp( extraBytes[0].name, "normal_x" ) == 0 ||
293 strcmp( extraBytes[0].name, "normalx" ) == 0 ||
294 strcmp( extraBytes[0].name, "normal x" ) == 0;
295 }
296 }
297 if ( hasNormals && LasPointSize[pointFormat] + 3 * sizeof( double ) > header.point_record_length )
298 return unexpected( fmt::format( "Too short LAS point+normal record length {} for point format {}, expected length {}",
299 header.point_record_length, pointFormat, LasPointSize[pointFormat] + 3 * sizeof( double ) ) );
300
301 PointCloud result;
302 result.points.reserve( pointCount );
303 if ( settings.colors )
304 settings.colors->reserve( pointCount );
305 if ( hasNormals )
306 result.normals.reserve( pointCount );
307
308 Vector3d offset {
309 header.offset.x,
310 header.offset.y,
311 header.offset.z,
312 };
313 if ( settings.outXf )
314 {
315 const Box3d box {
316 { header.minx, header.miny, header.minz },
317 { header.maxx, header.maxy, header.maxz },
318 };
319 const auto center = box.center();
320 *settings.outXf = AffineXf3f::translation( Vector3f( center ) );
321 offset -= center;
322 }
323

Callers 1

fromLasFunction · 0.85

Calls 15

reportProgressFunction · 0.85
getPointFunction · 0.85
hasColorChannelsFunction · 0.85
getColorChannelsFunction · 0.85
getColorFunction · 0.85
getClassificationFunction · 0.85
push_backMethod · 0.80
unexpectedFunction · 0.50
swapFunction · 0.50
sizeMethod · 0.45
dataMethod · 0.45
reserveMethod · 0.45

Tested by

no test coverage detected