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 bug caused by negative weight when calculating mst #90

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions glomap/math/tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ image_t MaximumSpanningTree(const ViewGraph& view_graph,
image_id_to_idx[image_id] = image_id_to_idx.size();
}

int max_weight = 0;
for (auto& [pair_id, image_pair] : view_graph.image_pairs) {
if (image_pair.is_valid == false) continue;
if (type == INLIER_RATIO)
max_weight = max_weight > image_pair.weight ? max_weight : image_pair.weight;
else
max_weight = max_weight > image_pair.inliers.size() ? max_weight : image_pair.inliers.size();
}
cre185 marked this conversation as resolved.
Show resolved Hide resolved

// establish graph
weighted_graph G(image_id_to_idx.size());
weight_map weights_boost = boost::get(boost::edge_weight, G);
Expand All @@ -111,11 +120,11 @@ image_t MaximumSpanningTree(const ViewGraph& view_graph,
// spanning tree
e = boost::add_edge(idx1, idx2, G).first;
if (type == INLIER_NUM)
weights_boost[e] = -image_pair.inliers.size();
weights_boost[e] = max_weight - image_pair.inliers.size();
else if (type == INLIER_RATIO)
weights_boost[e] = -image_pair.weight;
weights_boost[e] = max_weight - image_pair.weight;
else
weights_boost[e] = -image_pair.inliers.size();
weights_boost[e] = max_weight - image_pair.inliers.size();
}

std::vector<edge_desc>
Expand Down
Loading