Skip to content

Commit

Permalink
More code tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-alexandrov committed Nov 24, 2022
1 parent 5f51ce0 commit 263306a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion graveyard/AdjustRobustSparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace ba {
V_inverse( this->m_model.num_points() ),
epsilon_a( this->m_model.num_cameras() ), epsilon_b( this->m_model.num_points() ) {
vw_out(DebugMessage,"ba") << "Constructed Robust Sparse Bundle Adjuster.\n";
m_crn.read_controlnetwork( *(this->m_control_net).get() );
m_crn.from_cnet( *(this->m_control_net).get() );
m_found_ideal_ordering = false;
}

Expand Down
2 changes: 1 addition & 1 deletion graveyard/AdjustSparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace ba {
V_inverse( this->m_model.num_points() ),
epsilon_a( this->m_model.num_cameras() ), epsilon_b( this->m_model.num_points() ) {
vw_out(DebugMessage,"ba") << "Constructed Sparse Bundle Adjuster.\n";
m_crn.read_controlnetwork( *(this->m_control_net).get() );
m_crn.from_cnet( *(this->m_control_net).get() );
m_found_ideal_ordering = false;
}

Expand Down
4 changes: 3 additions & 1 deletion src/vw/BundleAdjustment/CameraRelation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace ba {
}

template <class FeatureT>
void CameraRelationNetwork<FeatureT>::read_controlnetwork( ControlNetwork const& cnet ) {
void CameraRelationNetwork<FeatureT>::from_cnet( ControlNetwork const& cnet ) {
typedef boost::shared_ptr<FeatureT> f_ptr;
typedef boost::weak_ptr<FeatureT> w_ptr;
m_nodes.clear();
Expand Down Expand Up @@ -137,6 +137,8 @@ namespace ba {
this->build_map();
}

// TODO(oalexan1): This function scaled very badly. It is no longer used
// in build_control_network(). Needs to be wiped.
template <class FeatureT>
bool CameraRelationNetwork<FeatureT>::assemble_cnet(ControlNetwork & cnet) const {

Expand Down
5 changes: 4 additions & 1 deletion src/vw/BundleAdjustment/CameraRelation.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ namespace ba {
// Complex functions
void add_node( cnode const& node );
void build_map();
void read_controlnetwork ( ControlNetwork const& cnet );
void from_cnet ( ControlNetwork const& cnet );

// TODO(oalexan1): This function scaled very badly. It is no longer used
// in build_control_network(). Needs to be wiped.
bool assemble_cnet( ControlNetwork & cnet ) const;
};

Expand Down
23 changes: 13 additions & 10 deletions src/vw/BundleAdjustment/ControlNetworkLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,15 @@ bool vw::ba::build_control_network(bool triangulate_control_points,

image_prefix_map[stripped_path] = count;
// TODO(oalexan1): Using just the stem can cause non-uniqueness!
// TODO(oalexan1): Not sure if cnet actually needs to store image
// names. When saving cnet, the list of images can be used.
cnet.add_image_name(file);
count++;
}

// Iterate through the match files passed in
// Iterate through the match files passed in and record the ones which exist.
// TODO(oalexan1): Likely this loop and the one below can be
// integrated and there is no need for match_files_vec, index1_vec, index2_vec.
std::vector<std::string> match_files_vec;
std::vector<size_t> index1_vec, index2_vec;
typedef std::map<std::string,size_t>::iterator MapIterator;
Expand Down Expand Up @@ -289,7 +293,7 @@ bool vw::ba::build_control_network(bool triangulate_control_points,
for (size_t ip_it = 0; ip_it < ip1.size(); ip_it++) {
auto dist_left_ip = ipTriplet(ip1[ip_it].x, ip1[ip_it].y, ip1[ip_it].scale);
auto dist_right_ip = ipTriplet(ip2[ip_it].x, ip2[ip_it].y, ip2[ip_it].scale);
// Initialize to zero for the moment
// Initialize key keypoint map to zero. Will populate the entities later.
keypoint_map[index1][dist_left_ip] = 0;
keypoint_map[index2][dist_right_ip] = 0;
}
Expand Down Expand Up @@ -342,9 +346,9 @@ bool vw::ba::build_control_network(bool triangulate_control_points,
auto dist_right_ip = ipTriplet(right_ip_vec[ip_it].x, right_ip_vec[ip_it].y,
right_ip_vec[ip_it].scale);

int left_id = keypoint_map[left_cid][dist_left_ip];
int right_id = keypoint_map[right_cid][dist_right_ip];
mvg_matches.push_back(VwOpenMVG::matching::IndMatch(left_id, right_id));
int left_fid = keypoint_map[left_cid][dist_left_ip];
int right_fid = keypoint_map[right_cid][dist_right_ip];
mvg_matches.push_back(VwOpenMVG::matching::IndMatch(left_fid, right_fid));
}
match_map[cid_pair] = mvg_matches;
}
Expand All @@ -371,12 +375,11 @@ bool vw::ba::build_control_network(bool triangulate_control_points,

// Populate the filtered tracks
size_t num_elems = map_tracks.size();
//pid_to_cid_fid.resize(num_elems);
for (auto itr = map_tracks.begin(); itr != map_tracks.end(); itr++) {
for (auto pid = map_tracks.begin(); pid != map_tracks.end(); pid++) {
ControlPoint cpoint(ControlPoint::TiePoint);
for (auto itr2 = (itr->second).begin(); itr2 != (itr->second).end(); itr2++) {
int cid = itr2->first;
int fid = itr2->second;
for (auto cid_fid = (pid->second).begin(); cid_fid != (pid->second).end(); cid_fid++) {
int cid = cid_fid->first;
int fid = cid_fid->second;
auto const& dist_ip = keypoint_vec.at(cid).at(fid);
cpoint.add_measure(ControlMeasure(std::get<0>(dist_ip), // x position
std::get<1>(dist_ip), // y position
Expand Down
4 changes: 2 additions & 2 deletions src/vw/BundleAdjustment/tests/TestCameraRelation.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ TEST_F( CircleTest, IPFeature ) {

// Convert to Camera Relation
CameraRelationNetwork<IPFeature> crn;
crn.read_controlnetwork( cnet );
crn.from_cnet( cnet );
EXPECT_EQ( crn.size(), 4u );
for ( uint32 i = 0; i < crn.size(); i++ )
EXPECT_EQ( crn[i].id, i );
Expand Down Expand Up @@ -115,7 +115,7 @@ TEST_F( CircleTest, JFeature ) {

// Convert to Camera Relation
CameraRelationNetwork<JFeature> crn;
crn.read_controlnetwork( cnet );
crn.from_cnet( cnet );
EXPECT_EQ( crn.size(), 4u );
for ( uint32 i = 0; i < crn.size(); i++ )
EXPECT_EQ( crn[i].id, i );
Expand Down

0 comments on commit 263306a

Please sign in to comment.