Skip to content

Commit 9ca3cb0

Browse files
mmcamerasolve - refine and improve the comments.
1 parent 0161a5d commit 9ca3cb0

File tree

4 files changed

+36
-161
lines changed

4 files changed

+36
-161
lines changed

lib/rust/mmcamerasolve-bin/src/cli.rs

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// along with mmSolver. If not, see <https://www.gnu.org/licenses/>.
1818
// ====================================================================
1919
//
20-
//! Custom CLI argument parsing (no external dependencies).
20+
//! CLI argument parsing without external dependencies.
2121
2222
use crate::parser;
2323

@@ -55,15 +55,15 @@ const ARG_PREFIX: &str = "--prefix";
5555
const ARG_INTERMEDIATE_OUTPUT: &str = "--with-intermediate-output";
5656
const ARG_NUKE_LENS: &str = "--nuke-lens";
5757

58-
/// Solver type for focal length adjustment
58+
/// Solver type for focal length adjustment.
5959
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
6060
pub enum SolverType {
61-
/// Use provided focal length as-is (no adjustment)
61+
/// Use provided focal length as-is.
6262
#[default]
6363
None,
64-
/// Small refinement around provided focal length (±10%)
64+
/// Small refinement around the provided focal length (±20%).
6565
Refine,
66-
/// Large search range for unknown focal length (10-200mm)
66+
/// Large search range for an unknown focal length (10-200mm).
6767
Unknown,
6868
}
6969

@@ -86,63 +86,30 @@ impl std::str::FromStr for SolverType {
8686
/// Parsed command-line arguments.
8787
#[derive(Debug)]
8888
pub struct CliArgs {
89-
/// Path to UV markers file (.uv).
9089
pub uv_file: String,
91-
92-
/// Optional path to an `.mmcamera` file for camera defaults.
9390
pub mmcamera_file: Option<String>,
94-
95-
/// Optional path to an `.mmsettings` file for solver settings.
9691
pub solver_settings_file: Option<String>,
97-
98-
/// Focal length in millimeters.
9992
pub focal_length_mm: f64,
100-
101-
/// Lens center X offset in millimeters.
10293
pub lens_center_x_mm: f64,
103-
104-
/// Lens center Y offset in millimeters.
10594
pub lens_center_y_mm: f64,
106-
107-
/// Image width in pixels.
10895
pub image_width: u32,
109-
110-
/// Image height in pixels.
11196
pub image_height: u32,
112-
113-
/// Film back width in millimeters.
11497
pub film_back_width_mm: f64,
115-
116-
/// Film back height in millimeters.
11798
pub film_back_height_mm: f64,
118-
11999
/// Start frame (None = use UV file default).
120100
pub start_frame: Option<u32>,
121-
122101
/// End frame (None = use UV file default).
123102
pub end_frame: Option<u32>,
124-
125-
/// Solver type for focal length adjustment.
126103
pub solver: SolverType,
127-
128-
/// Thread count (None = auto).
104+
/// Thread count (None = auto-detect).
129105
pub threads: Option<usize>,
130-
131-
/// Output directory for visualizations.
132106
pub output_dir: String,
133-
134-
/// Optional prefix for output filenames.
135107
pub prefix: Option<String>,
136-
137-
/// Quiet mode - suppress progress output.
108+
/// Suppress progress output.
138109
pub quiet: bool,
139-
140110
/// Write intermediate results during solve.
141111
pub intermediate_output: bool,
142-
143-
/// Optional path to a Nuke .nk lens distortion file.
144112
pub nuke_lens_file: Option<String>,
145-
146113
}
147114

148115
impl Default for CliArgs {
@@ -171,7 +138,6 @@ impl Default for CliArgs {
171138
}
172139
}
173140

174-
/// Print help message.
175141
pub fn print_help() {
176142
println!(
177143
"mmSolver Camera Solver - Structure from Motion camera solver.
@@ -226,7 +192,6 @@ HELP:
226192
);
227193
}
228194

229-
/// Print version information.
230195
pub fn print_version() {
231196
println!("mmsfm {}", env!("CARGO_PKG_VERSION"));
232197
}
@@ -240,19 +205,13 @@ macro_rules! try_parse {
240205
};
241206
}
242207

243-
/// Result of argument parsing.
244208
pub enum ParseResult {
245-
/// Successfully parsed arguments.
246209
Args(CliArgs),
247-
/// User requested help.
248210
Help,
249-
/// User requested version.
250211
Version,
251-
/// Parse error with message.
252212
Error(String),
253213
}
254214

255-
/// Parse command-line arguments.
256215
pub fn parse_args() -> ParseResult {
257216
let args: Vec<String> = std::env::args().collect();
258217

@@ -452,7 +411,7 @@ pub fn parse_args() -> ParseResult {
452411
ParseResult::Args(cli)
453412
}
454413

455-
/// Tracks which CLI fields were explicitly provided by the user.
414+
/// Tracks which CLI fields were explicitly set, so mmcamera defaults don't override them.
456415
#[derive(Debug, Default)]
457416
struct ExplicitFlags {
458417
focal_length: bool,
@@ -466,8 +425,7 @@ struct ExplicitFlags {
466425
end_frame: bool,
467426
}
468427

469-
/// Read an `.mmcamera` file and apply its values as defaults for any
470-
/// fields that were not explicitly set on the command line.
428+
/// Apply defaults from an .mmcamera file for any fields not explicitly set on the command line.
471429
fn apply_mmcamera_defaults(
472430
cli: &mut CliArgs,
473431
mmcamera_path: &str,

lib/rust/mmcamerasolve-bin/src/defaults.rs

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,69 +22,53 @@
2222
2323
// --- Camera parameters ---
2424

25-
/// Default focal length in millimeters (35mm standard lens).
25+
/// Default focal length in millimeters (standard 35mm lens).
2626
pub const DEFAULT_FOCAL_LENGTH_MM: f64 = 35.0;
2727

28-
/// Default lens center X offset in millimeters.
2928
pub const DEFAULT_LENS_CENTER_X_MM: f64 = 0.0;
30-
31-
/// Default lens center Y offset in millimeters.
3229
pub const DEFAULT_LENS_CENTER_Y_MM: f64 = 0.0;
3330

34-
/// Default image width in pixels.
3531
pub const DEFAULT_IMAGE_WIDTH: u32 = 3600;
36-
37-
/// Default image height in pixels.
3832
pub const DEFAULT_IMAGE_HEIGHT: u32 = 2400;
3933

40-
/// Default film back width in millimeters (full-frame 35mm).
34+
/// Default film back width in millimeters (full-frame 35mm sensor).
4135
pub const DEFAULT_FILM_BACK_WIDTH_MM: f64 = 36.0;
4236

43-
/// Default film back height in millimeters (full-frame 35mm).
37+
/// Default film back height in millimeters (full-frame 35mm sensor).
4438
pub const DEFAULT_FILM_BACK_HEIGHT_MM: f64 = 24.0;
4539

46-
/// Default output directory.
4740
pub const DEFAULT_OUTPUT_DIR: &str = "./output";
4841

4942
// --- Focal length solver bounds ---
5043

51-
/// Absolute minimum focal length (mm) the solver can represent.
44+
/// Minimum focal length the solver can use.
5245
pub const MIN_FOCAL_LENGTH_MM: f64 = 0.1;
5346

54-
/// Absolute maximum focal length (mm) the solver can represent.
47+
/// Maximum focal length the solver can use.
5548
pub const MAX_FOCAL_LENGTH_MM: f64 = 200.0;
5649

57-
/// Lower multiplier for refine mode bounds (relative to input focal length).
50+
/// Lower bound factor for refine mode (multiplied against input focal length).
5851
pub const REFINE_BOUNDS_LOWER_FACTOR: f64 = 0.8;
5952

60-
/// Upper multiplier for refine mode bounds (relative to input focal length).
53+
/// Upper bound factor for refine mode (multiplied against input focal length).
6154
pub const REFINE_BOUNDS_UPPER_FACTOR: f64 = 1.2;
6255

63-
/// Default minimum focal length (mm) for unknown-mode search.
56+
/// Minimum focal length for unknown-mode search.
6457
pub const UNKNOWN_FL_MIN_MM: f64 = 10.0;
6558

66-
/// Default maximum focal length (mm) for unknown-mode search.
59+
/// Maximum focal length for unknown-mode search.
6760
pub const UNKNOWN_FL_MAX_MM: f64 = 120.0;
6861

69-
/// Default minimum focal length (mm) for uniform grid search.
62+
/// Minimum focal length for uniform grid search.
7063
pub const UNIFORM_GRID_FL_MIN_MM: f64 = 0.1;
7164

72-
/// Default maximum focal length (mm) for uniform grid search.
65+
/// Maximum focal length for uniform grid search.
7366
pub const UNIFORM_GRID_FL_MAX_MM: f64 = 120.0;
7467

7568
// --- Differential Evolution parameters ---
7669

77-
/// Number of EVO generations for refine mode.
7870
pub const REFINE_EVO_GENERATIONS: usize = 200;
79-
80-
/// Number of EVO generations for unknown-mode search.
8171
pub const UNKNOWN_EVO_GENERATIONS: usize = 500;
82-
83-
/// EVO random seed for refine mode.
8472
pub const REFINE_EVO_SEED: u64 = 42;
85-
86-
/// EVO random seed for unknown mode.
8773
pub const UNKNOWN_EVO_SEED: u64 = 12345;
88-
89-
/// Default number of samples for uniform grid search.
9074
pub const UNIFORM_GRID_DEFAULT_SAMPLES: usize = 21;

0 commit comments

Comments
 (0)