Skip to content

Commit 606c31e

Browse files
Rename Film Back width/height to include millimeters.
1 parent a097be1 commit 606c31e

4 files changed

Lines changed: 51 additions & 41 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ fn write_mmcamera_output_inner(
141141
let (focal_length_mm, _lens_cx, _lens_cy) =
142142
camera_intrinsics.to_physical_parameters();
143143
let focal_length_val = focal_length_mm.value();
144-
let film_back_width_val = film_back.width.value();
145-
let film_back_height_val = film_back.height.value();
144+
let film_back_width_val = film_back.width_mm.value();
145+
let film_back_height_val = film_back.height_mm.value();
146146

147147
let mut translate_x = Vec::with_capacity(frame_list.len());
148148
let mut translate_y = Vec::with_capacity(frame_list.len());

lib/rust/mmsfm/src/datatype/camera_film_back.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,9 @@ use crate::datatype::millimeter_unit::MillimeterUnit;
5656
#[derive(Debug, Copy, Clone, PartialEq)]
5757
pub struct CameraFilmBack<T> {
5858
/// Width of the film back/sensor in millimeters.
59-
// TODO: Change the field name to `width_mm`.
60-
pub width: MillimeterUnit<T>,
59+
pub width_mm: MillimeterUnit<T>,
6160
/// Height of the film back/sensor in millimeters.
62-
// TODO: Change the field name to `height_mm`.
63-
pub height: MillimeterUnit<T>,
61+
pub height_mm: MillimeterUnit<T>,
6462
}
6563

6664
impl<T> CameraFilmBack<T>
@@ -81,11 +79,14 @@ where
8179
/// MillimeterUnit::new(36.0),
8280
/// MillimeterUnit::new(24.0)
8381
/// );
84-
/// assert_eq!(film_back.width.value(), 36.0);
85-
/// assert_eq!(film_back.height.value(), 24.0);
82+
/// assert_eq!(film_back.width_mm.value(), 36.0);
83+
/// assert_eq!(film_back.height_mm.value(), 24.0);
8684
/// ```
8785
pub fn new(width: MillimeterUnit<T>, height: MillimeterUnit<T>) -> Self {
88-
Self { width, height }
86+
Self {
87+
width_mm: width,
88+
height_mm: height,
89+
}
8990
}
9091

9192
/// Create a new camera film back from raw millimeter values.
@@ -99,13 +100,13 @@ where
99100
/// use mmsfm_rust::datatype::*;
100101
///
101102
/// let film_back = CameraFilmBack::from_millimeters(36.0, 24.0);
102-
/// assert_eq!(film_back.width.value(), 36.0);
103-
/// assert_eq!(film_back.height.value(), 24.0);
103+
/// assert_eq!(film_back.width_mm.value(), 36.0);
104+
/// assert_eq!(film_back.height_mm.value(), 24.0);
104105
/// ```
105106
pub fn from_millimeters(width_mm: T, height_mm: T) -> Self {
106107
Self {
107-
width: MillimeterUnit::new(width_mm),
108-
height: MillimeterUnit::new(height_mm),
108+
width_mm: MillimeterUnit::new(width_mm),
109+
height_mm: MillimeterUnit::new(height_mm),
109110
}
110111
}
111112
}
@@ -132,7 +133,7 @@ where
132133
/// assert_eq!(square.aspect_ratio(), 1.0);
133134
/// ```
134135
pub fn aspect_ratio(&self) -> T {
135-
self.width.value() / self.height.value()
136+
self.width_mm.value() / self.height_mm.value()
136137
}
137138
}
138139

@@ -141,7 +142,7 @@ where
141142
T: fmt::Display + Copy + fmt::Debug + PartialEq,
142143
{
143144
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
144-
write!(f, "{}mm x {}mm", self.width, self.height)
145+
write!(f, "{}mm x {}mm", self.width_mm, self.height_mm)
145146
}
146147
}
147148

@@ -156,15 +157,15 @@ mod tests {
156157
MillimeterUnit::new(36.0),
157158
MillimeterUnit::new(24.0),
158159
);
159-
assert_eq!(film_back.width.value(), 36.0);
160-
assert_eq!(film_back.height.value(), 24.0);
160+
assert_eq!(film_back.width_mm.value(), 36.0);
161+
assert_eq!(film_back.height_mm.value(), 24.0);
161162
}
162163

163164
#[test]
164165
fn test_camera_film_back_from_millimeters() {
165166
let film_back = CameraFilmBack::from_millimeters(36.0, 24.0);
166-
assert_eq!(film_back.width.value(), 36.0);
167-
assert_eq!(film_back.height.value(), 24.0);
167+
assert_eq!(film_back.width_mm.value(), 36.0);
168+
assert_eq!(film_back.height_mm.value(), 24.0);
168169
}
169170

170171
#[test]

lib/rust/mmsfm/src/datatype/camera_intrinsics.rs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ impl CameraIntrinsics {
9393
film_back: CameraFilmBack<f64>,
9494
) -> Self {
9595
// Normalize focal lengths by film back dimensions.
96-
let focal_length_x = focal_length_mm.value() / film_back.width.value();
97-
let focal_length_y = focal_length_mm.value() / film_back.height.value();
96+
let focal_length_x =
97+
focal_length_mm.value() / film_back.width_mm.value();
98+
let focal_length_y =
99+
focal_length_mm.value() / film_back.height_mm.value();
98100

99101
// Convert lens center from film back coordinates to NDC coordinates.
100102
//
@@ -104,10 +106,10 @@ impl CameraIntrinsics {
104106
// normalize by film back dimensions and scale by 2.
105107
let principal_point = NdcPoint2::new(
106108
NdcValue::new(
107-
(2.0 * lens_center_x_mm.value()) / film_back.width.value(),
109+
(2.0 * lens_center_x_mm.value()) / film_back.width_mm.value(),
108110
),
109111
NdcValue::new(
110-
(2.0 * lens_center_y_mm.value()) / film_back.height.value(),
112+
(2.0 * lens_center_y_mm.value()) / film_back.height_mm.value(),
111113
),
112114
);
113115

@@ -160,19 +162,21 @@ impl CameraIntrinsics {
160162
// Convert normalized focal length back to millimeters.
161163
// We use focal_length_x since both should give the same physical focal length.
162164
let focal_length_mm = MillimeterUnit::new(
163-
self.focal_length_x * self.film_back.width.value(),
165+
self.focal_length_x * self.film_back.width_mm.value(),
164166
);
165167

166168
// Convert NDC principal point back to lens center coordinates.
167169
//
168170
// In NDC space, (0,0) is center with range [-1,1], so we
169171
// scale by film back dimensions and divide by 2.
170172
let lens_center_x_mm = MillimeterUnit::new(
171-
self.principal_point.x.value() * self.film_back.width.value() * 0.5,
173+
self.principal_point.x.value()
174+
* self.film_back.width_mm.value()
175+
* 0.5,
172176
);
173177
let lens_center_y_mm = MillimeterUnit::new(
174178
self.principal_point.y.value()
175-
* self.film_back.height.value()
179+
* self.film_back.height_mm.value()
176180
* 0.5,
177181
);
178182

@@ -184,15 +188,19 @@ impl CameraIntrinsics {
184188
/// # Returns
185189
/// Horizontal focal length in millimeters.
186190
pub fn horizontal_focal_length_mm(&self) -> MillimeterUnit<f64> {
187-
MillimeterUnit::new(self.focal_length_x * self.film_back.width.value())
191+
MillimeterUnit::new(
192+
self.focal_length_x * self.film_back.width_mm.value(),
193+
)
188194
}
189195

190196
/// Calculate the vertical focal length in millimeters.
191197
///
192198
/// # Returns
193199
/// Vertical focal length in millimeters.
194200
pub fn vertical_focal_length_mm(&self) -> MillimeterUnit<f64> {
195-
MillimeterUnit::new(self.focal_length_y * self.film_back.height.value())
201+
MillimeterUnit::new(
202+
self.focal_length_y * self.film_back.height_mm.value(),
203+
)
196204
}
197205

198206
/// Calculate the horizontal field of view in radians.
@@ -205,8 +213,8 @@ impl CameraIntrinsics {
205213
// focal_length_x is normalized by width, so we need the actual focal
206214
// length in mm.
207215
let focal_length_mm =
208-
self.focal_length_x * self.film_back.width.value();
209-
2.0 * (self.film_back.width.value() / (2.0 * focal_length_mm)).atan()
216+
self.focal_length_x * self.film_back.width_mm.value();
217+
2.0 * (self.film_back.width_mm.value() / (2.0 * focal_length_mm)).atan()
210218
}
211219

212220
/// Calculate the horizontal field of view in degrees.
@@ -224,8 +232,9 @@ impl CameraIntrinsics {
224232
pub fn vertical_fov_radians(&self) -> f64 {
225233
// FoV = 2 * arctan(sensor_height / (2 * focal_length))
226234
let focal_length_mm =
227-
self.focal_length_y * self.film_back.height.value();
228-
2.0 * (self.film_back.height.value() / (2.0 * focal_length_mm)).atan()
235+
self.focal_length_y * self.film_back.height_mm.value();
236+
2.0 * (self.film_back.height_mm.value() / (2.0 * focal_length_mm))
237+
.atan()
229238
}
230239

231240
/// Calculate the vertical field of view in degrees.
@@ -242,13 +251,13 @@ impl CameraIntrinsics {
242251
/// Diagonal field of view angle in radians
243252
pub fn diagonal_fov_radians(&self) -> f64 {
244253
// Calculate diagonal sensor dimension.
245-
let diagonal_mm = (self.film_back.width.value().powi(2)
246-
+ self.film_back.height.value().powi(2))
254+
let diagonal_mm = (self.film_back.width_mm.value().powi(2)
255+
+ self.film_back.height_mm.value().powi(2))
247256
.sqrt();
248257

249258
// Use horizontal focal length for diagonal calculation.
250259
let focal_length_mm =
251-
self.focal_length_x * self.film_back.width.value();
260+
self.focal_length_x * self.film_back.width_mm.value();
252261
2.0 * (diagonal_mm / (2.0 * focal_length_mm)).atan()
253262
}
254263

@@ -295,8 +304,8 @@ mod tests {
295304
-0.4,
296305
epsilon = 1e-10
297306
);
298-
assert_eq!(intrinsics.film_back.width.value(), 36.0);
299-
assert_eq!(intrinsics.film_back.height.value(), 24.0);
307+
assert_eq!(intrinsics.film_back.width_mm.value(), 36.0);
308+
assert_eq!(intrinsics.film_back.height_mm.value(), 24.0);
300309
}
301310

302311
#[test]

lib/rust/mmsfm/src/visualization/reprojection.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ pub fn visualize_marker_reprojections_2d_scatter(
218218
);
219219
mm_eprintln_debug!(
220220
" Film back A: {:.1}mm x {:.1}mm (aspect: {:.3})",
221-
intrinsics_a.film_back.width.value(),
222-
intrinsics_a.film_back.height.value(),
221+
intrinsics_a.film_back.width_mm.value(),
222+
intrinsics_a.film_back.height_mm.value(),
223223
intrinsics_a.film_back.aspect_ratio()
224224
);
225225

@@ -236,8 +236,8 @@ pub fn visualize_marker_reprojections_2d_scatter(
236236
);
237237
mm_eprintln_debug!(
238238
" Film back B: {:.1}mm x {:.1}mm (aspect: {:.3})",
239-
intrinsics_a.film_back.width.value(),
240-
intrinsics_a.film_back.height.value(),
239+
intrinsics_a.film_back.width_mm.value(),
240+
intrinsics_a.film_back.height_mm.value(),
241241
intrinsics_a.film_back.aspect_ratio()
242242
);
243243

0 commit comments

Comments
 (0)