| 437 | } |
| 438 | |
| 439 | std::vector<RegionProjection> ComputeRegionProjections( |
| 440 | const PlyMesh& mesh, |
| 441 | const std::vector<FaceRegion>& regions, |
| 442 | const std::vector<Image>& images) { |
| 443 | std::vector<RegionProjection> projections(regions.size()); |
| 444 | |
| 445 | for (size_t ri = 0; ri < regions.size(); ++ri) { |
| 446 | const FaceRegion& region = regions[ri]; |
| 447 | const Image& img = images[region.view_id]; |
| 448 | RegionProjection& rp = projections[ri]; |
| 449 | rp.face_projections.resize(region.face_ids.size()); |
| 450 | |
| 451 | float min_x = std::numeric_limits<float>::max(); |
| 452 | float min_y = std::numeric_limits<float>::max(); |
| 453 | float max_x = std::numeric_limits<float>::lowest(); |
| 454 | float max_y = std::numeric_limits<float>::lowest(); |
| 455 | |
| 456 | for (size_t i = 0; i < region.face_ids.size(); ++i) { |
| 457 | const size_t fi = region.face_ids[i]; |
| 458 | const std::array<size_t, 3> idx = GetFaceIndices(mesh.faces[fi]); |
| 459 | for (int vi = 0; vi < 3; ++vi) { |
| 460 | const Eigen::Vector3f v = GetVertex(mesh, idx[vi]); |
| 461 | const Eigen::Vector2f p = ProjectPoint(img.GetP(), v); |
| 462 | rp.face_projections[i][vi] = p; |
| 463 | min_x = std::min(min_x, p.x()); |
| 464 | min_y = std::min(min_y, p.y()); |
| 465 | max_x = std::max(max_x, p.x()); |
| 466 | max_y = std::max(max_y, p.y()); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | rp.bbox_x = static_cast<int>(std::floor(min_x)); |
| 471 | rp.bbox_y = static_cast<int>(std::floor(min_y)); |
| 472 | rp.bbox_width = static_cast<int>(std::ceil(max_x)) - rp.bbox_x + 1; |
| 473 | rp.bbox_height = static_cast<int>(std::ceil(max_y)) - rp.bbox_y + 1; |
| 474 | } |
| 475 | |
| 476 | return projections; |
| 477 | } |
| 478 | |
| 479 | void ScaleRegionProjections(std::vector<RegionProjection>& projections, |
| 480 | const double scale) { |
no test coverage detected