load and triangulate meshes
| 317 | |
| 318 | /// load and triangulate meshes |
| 319 | void loadMeshes() |
| 320 | { |
| 321 | MR_TIMER; |
| 322 | |
| 323 | ParallelFor( 0, (int)meshTriangulationContexts_.size(), [&] ( int i ) |
| 324 | { |
| 325 | auto& ctx = meshTriangulationContexts_[i]; |
| 326 | // deep-copy the shape for thread safety |
| 327 | { |
| 328 | BRepBuilderAPI_Copy copier; |
| 329 | copier.Perform( ctx.shape, true, false ); // leave geometry, drop triangulation |
| 330 | ctx.shape = copier.Shape(); |
| 331 | } |
| 332 | ctx.shape = triangulateShape_( ctx.shape ); |
| 333 | // reset transformation as it already is loaded |
| 334 | ctx.shape.Location( TopLoc_Location() ); |
| 335 | ctx.triples = loadShape_( ctx.shape ); |
| 336 | } ); |
| 337 | |
| 338 | std::unordered_map<std::shared_ptr<ObjectMesh>, std::vector<MeshTriangulationContext*>> objMeshGroups; |
| 339 | for ( auto& ctx : meshTriangulationContexts_ ) |
| 340 | objMeshGroups[ctx.mesh].emplace_back( &ctx ); |
| 341 | |
| 342 | ParallelFor( 0, (int)objMeshGroups.size(), [&] ( int gi ) |
| 343 | { |
| 344 | auto& [objMesh, ctxs] = *std::next( objMeshGroups.begin(), gi ); |
| 345 | |
| 346 | size_t faceCount = 0; |
| 347 | bool hasCustomColors = false; |
| 348 | for ( const auto* ctx : ctxs ) |
| 349 | { |
| 350 | faceCount += ctx->triples.size(); |
| 351 | hasCustomColors |= ctx->faceColor.has_value(); |
| 352 | } |
| 353 | |
| 354 | std::vector<Triangle3f> triples; |
| 355 | triples.reserve( faceCount ); |
| 356 | FaceColors faceColors; |
| 357 | if ( hasCustomColors ) |
| 358 | faceColors.resize( faceCount, objMesh->getFrontColor( false ) ); |
| 359 | size_t faceOffset = 0; |
| 360 | for ( auto* ctx : ctxs ) |
| 361 | { |
| 362 | std::copy( ctx->triples.begin(), ctx->triples.end(), std::back_inserter( triples ) ); |
| 363 | |
| 364 | if ( ctx->faceColor ) |
| 365 | { |
| 366 | for ( auto fi = 0; fi < ctx->triples.size(); ++fi ) |
| 367 | faceColors[FaceId( faceOffset + fi )] = *ctx->faceColor; |
| 368 | } |
| 369 | faceOffset += ctx->triples.size(); |
| 370 | |
| 371 | ctx->triples.clear(); |
| 372 | ctx->triples.shrink_to_fit(); |
| 373 | } |
| 374 | |
| 375 | *objMesh->varMesh() = Mesh::fromPointTriples( triples, true ); |
| 376 | if ( hasCustomColors ) |
no test coverage detected