Skip to content

Commit 188e5e0

Browse files
Break up more code
1 parent 336e9ce commit 188e5e0

File tree

5 files changed

+63
-75
lines changed

5 files changed

+63
-75
lines changed

src/asp/Rig/RigCostFunction.cc

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -28,50 +28,6 @@
2828

2929
namespace rig {
3030

31-
// Set up block sizes for various cost functions
32-
void set_up_block_sizes(int num_depth_params,
33-
RigBlockSizes& block_sizes) {
34-
// Wipe the outputs
35-
block_sizes.image_block_sizes.clear();
36-
block_sizes.depth_block_sizes.clear();
37-
block_sizes.depth_mesh_block_sizes.clear();
38-
block_sizes.xyz_block_sizes.clear();
39-
40-
int num_focal_lengths = 1; // The x and y focal length are assumed to be the same
41-
int num_distortion_params = 1; // will be overwritten later
42-
43-
// Set up the variable blocks to optimize for BracketedCamError
44-
45-
block_sizes.image_block_sizes.push_back(rig::NUM_RIGID_PARAMS);
46-
block_sizes.image_block_sizes.push_back(rig::NUM_RIGID_PARAMS);
47-
block_sizes.image_block_sizes.push_back(rig::NUM_RIGID_PARAMS);
48-
block_sizes.image_block_sizes.push_back(rig::NUM_XYZ_PARAMS);
49-
block_sizes.image_block_sizes.push_back(rig::NUM_SCALAR_PARAMS);
50-
block_sizes.image_block_sizes.push_back(num_focal_lengths);
51-
block_sizes.image_block_sizes.push_back(rig::NUM_OPT_CTR_PARAMS);
52-
block_sizes.image_block_sizes.push_back(num_distortion_params);
53-
54-
// Set up variable blocks to optimize for BracketedDepthError
55-
block_sizes.depth_block_sizes.push_back(rig::NUM_RIGID_PARAMS);
56-
block_sizes.depth_block_sizes.push_back(rig::NUM_RIGID_PARAMS);
57-
block_sizes.depth_block_sizes.push_back(rig::NUM_RIGID_PARAMS);
58-
block_sizes.depth_block_sizes.push_back(num_depth_params);
59-
block_sizes.depth_block_sizes.push_back(rig::NUM_SCALAR_PARAMS);
60-
block_sizes.depth_block_sizes.push_back(rig::NUM_XYZ_PARAMS);
61-
block_sizes.depth_block_sizes.push_back(rig::NUM_SCALAR_PARAMS);
62-
63-
// Set up the variable blocks to optimize for BracketedDepthMeshError
64-
block_sizes.depth_mesh_block_sizes.push_back(rig::NUM_RIGID_PARAMS);
65-
block_sizes.depth_mesh_block_sizes.push_back(rig::NUM_RIGID_PARAMS);
66-
block_sizes.depth_mesh_block_sizes.push_back(rig::NUM_RIGID_PARAMS);
67-
block_sizes.depth_mesh_block_sizes.push_back(num_depth_params);
68-
block_sizes.depth_mesh_block_sizes.push_back(rig::NUM_SCALAR_PARAMS);
69-
block_sizes.depth_mesh_block_sizes.push_back(rig::NUM_SCALAR_PARAMS);
70-
71-
// Set up the variable blocks to optimize for the mesh xyz
72-
block_sizes.xyz_block_sizes.push_back(rig::NUM_XYZ_PARAMS);
73-
}
74-
7531
// If applicable, set up the parameters block to fix the rig translations and/or rotations
7632
void setUpFixRigOptions(bool no_rig, bool fix_rig_translations, bool fix_rig_rotations,
7733
ceres::SubsetManifold*& constant_transform_manifold) {

src/asp/Rig/RigCostFunction.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,6 @@ namespace rig {
4141
class cameraImage;
4242
class RigSet;
4343

44-
// A struct to hold the block sizes for the various cost functions
45-
struct RigBlockSizes {
46-
std::vector<int> image_block_sizes;
47-
std::vector<int> depth_block_sizes;
48-
std::vector<int> depth_mesh_block_sizes;
49-
std::vector<int> xyz_block_sizes;
50-
};
51-
52-
// Set up block sizes for various cost functions
53-
void set_up_block_sizes(int num_depth_params,
54-
RigBlockSizes& block_sizes);
55-
5644
// If applicable, set up the parameters block to fix the rig translations and/or rotations
5745
void setUpFixRigOptions(bool no_rig, bool fix_rig_translations, bool fix_rig_rotations,
5846
ceres::SubsetManifold*& constant_transform_manifold);

src/asp/Rig/RigOptimizer.cc

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// limitations under the License.
1616
// __END_LICENSE__
1717

18+
#include <asp/Rig/RigOptimizer.h>
1819
#include <asp/Rig/RigCostFunction.h>
1920
#include <asp/Rig/camera_image.h>
2021
#include <asp/Rig/rig_config.h>
@@ -35,6 +36,58 @@
3536

3637
namespace rig {
3738

39+
// A struct to hold the block sizes for the various cost functions
40+
struct RigBlockSizes {
41+
std::vector<int> image_block_sizes;
42+
std::vector<int> depth_block_sizes;
43+
std::vector<int> depth_mesh_block_sizes;
44+
std::vector<int> xyz_block_sizes;
45+
};
46+
47+
// Set up block sizes for various cost functions
48+
void set_up_block_sizes(int num_depth_params,
49+
RigBlockSizes& block_sizes) {
50+
// Wipe the outputs
51+
block_sizes.image_block_sizes.clear();
52+
block_sizes.depth_block_sizes.clear();
53+
block_sizes.depth_mesh_block_sizes.clear();
54+
block_sizes.xyz_block_sizes.clear();
55+
56+
int num_focal_lengths = 1; // The x and y focal length are assumed to be the same
57+
int num_distortion_params = 1; // will be overwritten later
58+
59+
// Set up the variable blocks to optimize for BracketedCamError
60+
61+
block_sizes.image_block_sizes.push_back(rig::NUM_RIGID_PARAMS);
62+
block_sizes.image_block_sizes.push_back(rig::NUM_RIGID_PARAMS);
63+
block_sizes.image_block_sizes.push_back(rig::NUM_RIGID_PARAMS);
64+
block_sizes.image_block_sizes.push_back(rig::NUM_XYZ_PARAMS);
65+
block_sizes.image_block_sizes.push_back(rig::NUM_SCALAR_PARAMS);
66+
block_sizes.image_block_sizes.push_back(num_focal_lengths);
67+
block_sizes.image_block_sizes.push_back(rig::NUM_OPT_CTR_PARAMS);
68+
block_sizes.image_block_sizes.push_back(num_distortion_params);
69+
70+
// Set up variable blocks to optimize for BracketedDepthError
71+
block_sizes.depth_block_sizes.push_back(rig::NUM_RIGID_PARAMS);
72+
block_sizes.depth_block_sizes.push_back(rig::NUM_RIGID_PARAMS);
73+
block_sizes.depth_block_sizes.push_back(rig::NUM_RIGID_PARAMS);
74+
block_sizes.depth_block_sizes.push_back(num_depth_params);
75+
block_sizes.depth_block_sizes.push_back(rig::NUM_SCALAR_PARAMS);
76+
block_sizes.depth_block_sizes.push_back(rig::NUM_XYZ_PARAMS);
77+
block_sizes.depth_block_sizes.push_back(rig::NUM_SCALAR_PARAMS);
78+
79+
// Set up the variable blocks to optimize for BracketedDepthMeshError
80+
block_sizes.depth_mesh_block_sizes.push_back(rig::NUM_RIGID_PARAMS);
81+
block_sizes.depth_mesh_block_sizes.push_back(rig::NUM_RIGID_PARAMS);
82+
block_sizes.depth_mesh_block_sizes.push_back(rig::NUM_RIGID_PARAMS);
83+
block_sizes.depth_mesh_block_sizes.push_back(num_depth_params);
84+
block_sizes.depth_mesh_block_sizes.push_back(rig::NUM_SCALAR_PARAMS);
85+
block_sizes.depth_mesh_block_sizes.push_back(rig::NUM_SCALAR_PARAMS);
86+
87+
// Set up the variable blocks to optimize for the mesh xyz
88+
block_sizes.xyz_block_sizes.push_back(rig::NUM_XYZ_PARAMS);
89+
}
90+
3891
// Evaluate the residuals before and after optimization
3992
void evalResiduals(// Inputs
4093
std::string const& tag,
@@ -636,7 +689,6 @@ void runOptPass(int pass,
636689
std::vector<double> const& ref_timestamps,
637690
rig::KeypointVec const& keypoint_vec,
638691
rig::PidCidFid const& pid_to_cid_fid,
639-
rig::RigBlockSizes const& block_sizes,
640692
std::vector<double> const& min_timestamp_offset,
641693
std::vector<double> const& max_timestamp_offset,
642694
mve::TriangleMesh::Ptr const& mesh,
@@ -648,6 +700,10 @@ void runOptPass(int pass,
648700
std::vector<Eigen::Vector3d> & xyz_vec,
649701
rig::PidCidFidMap & pid_cid_fid_inlier) {
650702

703+
// Set up the block sizes
704+
rig::RigBlockSizes block_sizes;
705+
rig::set_up_block_sizes(num_depth_params, block_sizes);
706+
651707
// Optimization state local to this pass. Must update the state from
652708
// extrinsics and rig config, run the optimization, then update back the extrinsics.
653709
rig::OptState state;

src/asp/Rig/RigOptimizer.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@
1515
// limitations under the License.
1616
// __END_LICENSE__
1717

18-
#ifndef ASP_RIG_OPT_H
19-
#define ASP_RIG_OPT_H
18+
#ifndef ASP_RIG_OPTIMIZER_H
19+
#define ASP_RIG_OPTIMIZER_H
2020

2121
#include <asp/Rig/RigCameraParams.h>
22-
#include <asp/Rig/rig_config.h>
23-
#include <asp/Rig/transform_utils.h>
2422
#include <asp/Rig/RigTypeDefs.h>
2523
#include <asp/Rig/RigData.h>
26-
#include <asp/Rig/RigOptions.h>
2724
#include <asp/Rig/texture_processing.h>
2825

2926
#include <Eigen/Core>
@@ -37,6 +34,7 @@ namespace rig {
3734
// Forward declarations
3835
class cameraImage;
3936
class RigSet;
37+
class RigOptions;
4038

4139
// Run an optimization pass for rig calibration
4240
void runOptPass(int pass,
@@ -46,7 +44,6 @@ void runOptPass(int pass,
4644
std::vector<double> const& ref_timestamps,
4745
rig::KeypointVec const& keypoint_vec,
4846
rig::PidCidFid const& pid_to_cid_fid,
49-
rig::RigBlockSizes const& block_sizes,
5047
std::vector<double> const& min_timestamp_offset,
5148
std::vector<double> const& max_timestamp_offset,
5249
mve::TriangleMesh::Ptr const& mesh,
@@ -60,4 +57,4 @@ void runOptPass(int pass,
6057

6158
} // namespace rig
6259

63-
#endif // ASP_RIG_OPT_H
60+
#endif // ASP_RIG_OPTIMIZER_H

src/asp/Tools/rig_calibrator.cc

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,11 @@
4040
#include <asp/Rig/RigData.h>
4141
#include <asp/Rig/rig_io.h>
4242
#include <asp/Rig/RigImageIO.h>
43-
#include <asp/Rig/RigCostFunction.h>
44-
#include <asp/Rig/RigOpt.h>
43+
#include <asp/Rig/RigOptimizer.h>
4544

4645
#include <vw/FileIO/FileUtils.h>
4746
#include <vw/Core/Log.h>
4847

49-
#include <ceres/ceres.h>
50-
#include <ceres/problem.h>
51-
#include <ceres/solver.h>
52-
5348
#include <opencv2/imgproc.hpp>
5449
#include <opencv2/imgcodecs.hpp>
5550
#include <opencv2/highgui.hpp>
@@ -232,10 +227,6 @@ int main(int argc, char** argv) {
232227
LOG(FATAL) << "No interest points were found. Must specify either "
233228
<< "--nvm or positive --num_overlaps.\n";
234229

235-
// Set up the block sizes
236-
rig::RigBlockSizes block_sizes;
237-
rig::set_up_block_sizes(num_depth_params, block_sizes);
238-
239230
// Inlier flag. Once an inlier becomes an outlier, it stays that way
240231
rig::PidCidFidMap pid_cid_fid_inlier;
241232

@@ -256,7 +247,7 @@ int main(int argc, char** argv) {
256247
for (int pass = 0; pass < opt.num_passes; pass++) {
257248
std::cout << "\nOptimization pass " << pass + 1 << " / " << opt.num_passes << "\n";
258249
runOptPass(pass, num_depth_params, opt, imgData, ref_timestamps,
259-
keypoint_vec, pid_to_cid_fid, block_sizes,
250+
keypoint_vec, pid_to_cid_fid,
260251
min_timestamp_offset, max_timestamp_offset, mesh, bvh_tree,
261252
depth_to_image_scales, cams, R, xyz_vec, pid_cid_fid_inlier); // out
262253
} // End optimization passes

0 commit comments

Comments
 (0)