| 99 | } |
| 100 | |
| 101 | TwoViewGeometry BuildTwoViewGeometry(bool has_relative_pose, |
| 102 | const Reconstruction& reconstruction, |
| 103 | const image_pair_t pair_id) { |
| 104 | const auto [image_id1, image_id2] = PairIdToImagePair(pair_id); |
| 105 | |
| 106 | const auto& image1 = reconstruction.Image(image_id1); |
| 107 | const auto num_points2D1 = image1.NumPoints2D(); |
| 108 | const auto& image2 = reconstruction.Image(image_id2); |
| 109 | const auto num_points2D2 = image2.NumPoints2D(); |
| 110 | |
| 111 | TwoViewGeometry two_view_geometry; |
| 112 | const Rigid3d cam2_from_cam1 = |
| 113 | image2.CamFromWorld() * Inverse(image1.CamFromWorld()); |
| 114 | if (has_relative_pose) { |
| 115 | two_view_geometry.cam2_from_cam1 = cam2_from_cam1; |
| 116 | } |
| 117 | SetTwoViewGeometryModel(*image1.CameraPtr(), |
| 118 | *image2.CameraPtr(), |
| 119 | cam2_from_cam1, |
| 120 | &two_view_geometry); |
| 121 | |
| 122 | for (point2D_t point2D_idx1 = 0; point2D_idx1 < num_points2D1; |
| 123 | ++point2D_idx1) { |
| 124 | const auto& point2D1 = image1.Point2D(point2D_idx1); |
| 125 | if (!point2D1.HasPoint3D()) { |
| 126 | continue; |
| 127 | } |
| 128 | for (point2D_t point2D_idx2 = 0; point2D_idx2 < num_points2D2; |
| 129 | ++point2D_idx2) { |
| 130 | const auto& point2D2 = image2.Point2D(point2D_idx2); |
| 131 | if (point2D1.point3D_id == point2D2.point3D_id) { |
| 132 | two_view_geometry.inlier_matches.emplace_back(point2D_idx1, |
| 133 | point2D_idx2); |
| 134 | break; |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | return two_view_geometry; |
| 139 | } |
| 140 | |
| 141 | void WriteTwoViewGeometryToDatabase(const image_pair_t pair_id, |
| 142 | const TwoViewGeometry& two_view_geometry, |
no test coverage detected