Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix model_cropper not resetting image.num_points3D of cropped_rec #2557

Merged
merged 3 commits into from
May 9, 2024

Conversation

ArneSchulzTUBS
Copy link
Contributor

While investigating the model_splitter issue for the current revision 1f95f3e described in #2096 I found a code regression introduced with commit 67029ad

This affects model_cropper and model_splitter tools.

As the previous implementation used the Image::ResetPoint3DForPoint2D method inside the loop, the num_points3D member was reset to 0 correctly.

void Image::ResetPoint3DForPoint2D(const point2D_t point2D_idx) {
struct Point2D& point2D = points2D_.at(point2D_idx);
if (point2D.HasPoint3D()) {
point2D.point3D_id = kInvalidPoint3DId;
num_points3D_ -= 1;
}
}

When directly assigning the kInvalidPoint3DId value, new_image keeps the value of the source num_points3D representing an incorrect state of the newly created cropped_reconstruction and finally leads to a failing check at

THROW_CHECK_LE(image.NumPoints3D(), image.NumPoints2D());

Fixing this by adding the call to Image::ResetPoint3DForPoint2D inside the loop again as it was first implemented in 99c7904.

Debugger screenshots:

Current Revision 1f95f3e :

colmap_crop_debug_faulty

Old implementation:
colmap_crop_debug_pre_change

@ahojnnes ahojnnes self-requested a review May 8, 2024 18:26
Copy link
Contributor

@ahojnnes ahojnnes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. Small suggestions for consistency in the code base.

@@ -452,8 +452,8 @@ Reconstruction Reconstruction::Crop(
for (const auto& image : images_) {
auto new_image = image.second;
new_image.SetRegistered(false);
for (auto& point2D : new_image.Points2D()) {
point2D.point3D_id = kInvalidPoint3DId;
for (point2D_t pid = 0; pid < new_image.NumPoints2D(); ++pid) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (point2D_t pid = 0; pid < new_image.NumPoints2D(); ++pid) {
const num_points2D = new_image.NumPoints2D();
for (point2D_t point2D_idx = 0; point2D_idx < num_points2D; ++point2D_idx) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added with type specifier in 6f716b8

for (auto& point2D : new_image.Points2D()) {
point2D.point3D_id = kInvalidPoint3DId;
for (point2D_t pid = 0; pid < new_image.NumPoints2D(); ++pid) {
new_image.ResetPoint3DForPoint2D(pid);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new_image.ResetPoint3DForPoint2D(pid);
new_image.ResetPoint3DForPoint2D(p oint2D_idx);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed and removed white space in 6f716b8

@ahojnnes ahojnnes enabled auto-merge (squash) May 8, 2024 20:53
@ahojnnes ahojnnes merged commit eaffee3 into colmap:main May 9, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants