Skip to content

Commit 0becf2b

Browse files
Lens Distortion - Add ImageDimensions struct
This is intended to reduce tbe amount of parameters passed to functions, and reduce the overall number of lines needed to add a new lens distortion model.
1 parent f6cdeaf commit 0becf2b

File tree

10 files changed

+339
-439
lines changed

10 files changed

+339
-439
lines changed

lib/cppbind/mmlens/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,10 @@ class DistortionExample : public Distortion {
255255
### 4) distortion_process.h/.cpp
256256
257257
- Add new processing functions in `distortion_process.h` and `distortion_process.cpp`.
258-
- Implement both single-threaded and multi-threaded versions.
259-
- Include variants for different precision types (f32/f64).
258+
- Functions use C++ templates, so copy/paste should get you 99% finished.
259+
- Ensure you add functions for both single-threaded and multi-threaded
260+
versions and include variants for different precision types
261+
(f32/f64).
260262
261263
```cpp
262264
void apply_identity_to_f64(...);

lib/cppbind/mmlens/include/mmlens/_cxxbridge.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ namespace mmlens {
375375
enum class DistortionDirection : ::std::uint8_t;
376376
enum class LensModelState : ::std::uint8_t;
377377
enum class LensModelType : ::std::uint8_t;
378+
struct ImageDimensions;
378379
struct CameraParameters;
379380
struct Parameters3deClassic;
380381
struct Parameters3deRadialStdDeg4;
@@ -428,6 +429,26 @@ enum class LensModelType : ::std::uint8_t {
428429
};
429430
#endif // CXXBRIDGE1_ENUM_mmlens$LensModelType
430431

432+
#ifndef CXXBRIDGE1_STRUCT_mmlens$ImageDimensions
433+
#define CXXBRIDGE1_STRUCT_mmlens$ImageDimensions
434+
struct ImageDimensions final {
435+
::std::size_t width;
436+
::std::size_t height;
437+
::std::size_t start_width;
438+
::std::size_t start_height;
439+
::std::size_t end_width;
440+
::std::size_t end_height;
441+
442+
bool operator==(const ImageDimensions &) const noexcept;
443+
bool operator!=(const ImageDimensions &) const noexcept;
444+
bool operator<(const ImageDimensions &) const noexcept;
445+
bool operator<=(const ImageDimensions &) const noexcept;
446+
bool operator>(const ImageDimensions &) const noexcept;
447+
bool operator>=(const ImageDimensions &) const noexcept;
448+
using IsRelocatable = ::std::true_type;
449+
};
450+
#endif // CXXBRIDGE1_STRUCT_mmlens$ImageDimensions
451+
431452
#ifndef CXXBRIDGE1_STRUCT_mmlens$CameraParameters
432453
#define CXXBRIDGE1_STRUCT_mmlens$CameraParameters
433454
struct CameraParameters final {

lib/cppbind/mmlens/include/mmlens/distortion_process.h

Lines changed: 65 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
namespace mmlens {
3636

37+
struct ImageDimensions;
3738
struct CameraParameters;
3839
struct Parameters3deClassic;
3940
struct Parameters3deRadialStdDeg4;
@@ -47,24 +48,22 @@ enum class DistortionDirection : uint8_t;
4748
// 3DE Classic
4849

4950
MMLENS_API_EXPORT
50-
void apply_identity_to_f64(
51-
const DistortionDirection direction, const size_t image_width,
52-
const size_t image_height, const size_t start_image_width,
53-
const size_t start_image_height, const size_t end_image_width,
54-
const size_t end_image_height, double* out_data_ptr,
55-
const size_t out_data_size, const size_t out_data_stride,
56-
const CameraParameters camera_parameters, const double film_back_radius_cm,
57-
Parameters3deClassic lens_parameters);
51+
void apply_identity_to_f64(const DistortionDirection direction,
52+
const ImageDimensions image_dimensions,
53+
double* out_data_ptr, const size_t out_data_size,
54+
const size_t out_data_stride,
55+
const CameraParameters camera_parameters,
56+
const double film_back_radius_cm,
57+
Parameters3deClassic lens_parameters);
5858

5959
MMLENS_API_EXPORT
60-
void apply_identity_to_f32(
61-
const DistortionDirection direction, const size_t image_width,
62-
const size_t image_height, const size_t start_image_width,
63-
const size_t start_image_height, const size_t end_image_width,
64-
const size_t end_image_height, float* out_data_ptr,
65-
const size_t out_data_size, const size_t out_data_stride,
66-
const CameraParameters camera_parameters, const double film_back_radius_cm,
67-
Parameters3deClassic lens_parameters);
60+
void apply_identity_to_f32(const DistortionDirection direction,
61+
const ImageDimensions image_dimensions,
62+
float* out_data_ptr, const size_t out_data_size,
63+
const size_t out_data_stride,
64+
const CameraParameters camera_parameters,
65+
const double film_back_radius_cm,
66+
Parameters3deClassic lens_parameters);
6867

6968
MMLENS_API_EXPORT
7069
void apply_f64_to_f64(const DistortionDirection direction,
@@ -92,24 +91,22 @@ void apply_f64_to_f32(const DistortionDirection direction,
9291
// 3DE Radial Decentered Degree 4 Cylindric
9392

9493
MMLENS_API_EXPORT
95-
void apply_identity_to_f64(
96-
const DistortionDirection direction, const size_t image_width,
97-
const size_t image_height, const size_t start_image_width,
98-
const size_t start_image_height, const size_t end_image_width,
99-
const size_t end_image_height, double* out_data_ptr,
100-
const size_t out_data_size, const size_t out_data_stride,
101-
const CameraParameters camera_parameters, const double film_back_radius_cm,
102-
Parameters3deRadialStdDeg4 lens_parameters);
94+
void apply_identity_to_f64(const DistortionDirection direction,
95+
const ImageDimensions image_dimensions,
96+
double* out_data_ptr, const size_t out_data_size,
97+
const size_t out_data_stride,
98+
const CameraParameters camera_parameters,
99+
const double film_back_radius_cm,
100+
Parameters3deRadialStdDeg4 lens_parameters);
103101

104102
MMLENS_API_EXPORT
105-
void apply_identity_to_f32(
106-
const DistortionDirection direction, const size_t image_width,
107-
const size_t image_height, const size_t start_image_width,
108-
const size_t start_image_height, const size_t end_image_width,
109-
const size_t end_image_height, float* out_data_ptr,
110-
const size_t out_data_size, const size_t out_data_stride,
111-
const CameraParameters camera_parameters, const double film_back_radius_cm,
112-
Parameters3deRadialStdDeg4 lens_parameters);
103+
void apply_identity_to_f32(const DistortionDirection direction,
104+
const ImageDimensions image_dimensions,
105+
float* out_data_ptr, const size_t out_data_size,
106+
const size_t out_data_stride,
107+
const CameraParameters camera_parameters,
108+
const double film_back_radius_cm,
109+
Parameters3deRadialStdDeg4 lens_parameters);
113110

114111
MMLENS_API_EXPORT
115112
void apply_f64_to_f64(const DistortionDirection direction,
@@ -137,24 +134,22 @@ void apply_f64_to_f32(const DistortionDirection direction,
137134
// 3DE Anamorphic Degree 4 Rotate Squeeze XY
138135

139136
MMLENS_API_EXPORT
140-
void apply_identity_to_f64(
141-
const DistortionDirection direction, const size_t image_width,
142-
const size_t image_height, const size_t start_image_width,
143-
const size_t start_image_height, const size_t end_image_width,
144-
const size_t end_image_height, double* out_data_ptr,
145-
const size_t out_data_size, const size_t out_data_stride,
146-
const CameraParameters camera_parameters, const double film_back_radius_cm,
147-
Parameters3deAnamorphicStdDeg4 lens_parameters);
137+
void apply_identity_to_f64(const DistortionDirection direction,
138+
const ImageDimensions image_dimensions,
139+
double* out_data_ptr, const size_t out_data_size,
140+
const size_t out_data_stride,
141+
const CameraParameters camera_parameters,
142+
const double film_back_radius_cm,
143+
Parameters3deAnamorphicStdDeg4 lens_parameters);
148144

149145
MMLENS_API_EXPORT
150-
void apply_identity_to_f32(
151-
const DistortionDirection direction, const size_t image_width,
152-
const size_t image_height, const size_t start_image_width,
153-
const size_t start_image_height, const size_t end_image_width,
154-
const size_t end_image_height, float* out_data_ptr,
155-
const size_t out_data_size, const size_t out_data_stride,
156-
const CameraParameters camera_parameters, const double film_back_radius_cm,
157-
Parameters3deAnamorphicStdDeg4 lens_parameters);
146+
void apply_identity_to_f32(const DistortionDirection direction,
147+
const ImageDimensions image_dimensions,
148+
float* out_data_ptr, const size_t out_data_size,
149+
const size_t out_data_stride,
150+
const CameraParameters camera_parameters,
151+
const double film_back_radius_cm,
152+
Parameters3deAnamorphicStdDeg4 lens_parameters);
158153

159154
MMLENS_API_EXPORT
160155
void apply_f64_to_f64(const DistortionDirection direction,
@@ -183,20 +178,16 @@ void apply_f64_to_f32(const DistortionDirection direction,
183178

184179
MMLENS_API_EXPORT
185180
void apply_identity_to_f64(
186-
const DistortionDirection direction, const size_t image_width,
187-
const size_t image_height, const size_t start_image_width,
188-
const size_t start_image_height, const size_t end_image_width,
189-
const size_t end_image_height, double* out_data_ptr,
181+
const DistortionDirection direction,
182+
const ImageDimensions image_dimensions, double* out_data_ptr,
190183
const size_t out_data_size, const size_t out_data_stride,
191184
const CameraParameters camera_parameters, const double film_back_radius_cm,
192185
Parameters3deAnamorphicStdDeg4Rescaled lens_parameters);
193186

194187
MMLENS_API_EXPORT
195188
void apply_identity_to_f32(
196-
const DistortionDirection direction, const size_t image_width,
197-
const size_t image_height, const size_t start_image_width,
198-
const size_t start_image_height, const size_t end_image_width,
199-
const size_t end_image_height, float* out_data_ptr,
189+
const DistortionDirection direction,
190+
const ImageDimensions image_dimensions, float* out_data_ptr,
200191
const size_t out_data_size, const size_t out_data_stride,
201192
const CameraParameters camera_parameters, const double film_back_radius_cm,
202193
Parameters3deAnamorphicStdDeg4Rescaled lens_parameters);
@@ -227,24 +218,22 @@ void apply_f64_to_f32(const DistortionDirection direction,
227218
// 3DE Anamorphic Degree 6 Rotate Squeeze XY
228219

229220
MMLENS_API_EXPORT
230-
void apply_identity_to_f64(
231-
const DistortionDirection direction, const size_t image_width,
232-
const size_t image_height, const size_t start_image_width,
233-
const size_t start_image_height, const size_t end_image_width,
234-
const size_t end_image_height, double* out_data_ptr,
235-
const size_t out_data_size, const size_t out_data_stride,
236-
const CameraParameters camera_parameters, const double film_back_radius_cm,
237-
Parameters3deAnamorphicStdDeg6 lens_parameters);
221+
void apply_identity_to_f64(const DistortionDirection direction,
222+
const ImageDimensions image_dimensions,
223+
double* out_data_ptr, const size_t out_data_size,
224+
const size_t out_data_stride,
225+
const CameraParameters camera_parameters,
226+
const double film_back_radius_cm,
227+
Parameters3deAnamorphicStdDeg6 lens_parameters);
238228

239229
MMLENS_API_EXPORT
240-
void apply_identity_to_f32(
241-
const DistortionDirection direction, const size_t image_width,
242-
const size_t image_height, const size_t start_image_width,
243-
const size_t start_image_height, const size_t end_image_width,
244-
const size_t end_image_height, float* out_data_ptr,
245-
const size_t out_data_size, const size_t out_data_stride,
246-
const CameraParameters camera_parameters, const double film_back_radius_cm,
247-
Parameters3deAnamorphicStdDeg6 lens_parameters);
230+
void apply_identity_to_f32(const DistortionDirection direction,
231+
const ImageDimensions image_dimensions,
232+
float* out_data_ptr, const size_t out_data_size,
233+
const size_t out_data_stride,
234+
const CameraParameters camera_parameters,
235+
const double film_back_radius_cm,
236+
Parameters3deAnamorphicStdDeg6 lens_parameters);
248237

249238
MMLENS_API_EXPORT
250239
void apply_f64_to_f64(const DistortionDirection direction,
@@ -273,20 +262,16 @@ void apply_f64_to_f32(const DistortionDirection direction,
273262

274263
MMLENS_API_EXPORT
275264
void apply_identity_to_f64(
276-
const DistortionDirection direction, const size_t image_width,
277-
const size_t image_height, const size_t start_image_width,
278-
const size_t start_image_height, const size_t end_image_width,
279-
const size_t end_image_height, double* out_data_ptr,
265+
const DistortionDirection direction,
266+
const ImageDimensions image_dimensions, double* out_data_ptr,
280267
const size_t out_data_size, const size_t out_data_stride,
281268
const CameraParameters camera_parameters, const double film_back_radius_cm,
282269
Parameters3deAnamorphicStdDeg6Rescaled lens_parameters);
283270

284271
MMLENS_API_EXPORT
285272
void apply_identity_to_f32(
286-
const DistortionDirection direction, const size_t image_width,
287-
const size_t image_height, const size_t start_image_width,
288-
const size_t start_image_height, const size_t end_image_width,
289-
const size_t end_image_height, float* out_data_ptr,
273+
const DistortionDirection direction,
274+
const ImageDimensions image_dimensions, float* out_data_ptr,
290275
const size_t out_data_size, const size_t out_data_stride,
291276
const CameraParameters camera_parameters, const double film_back_radius_cm,
292277
Parameters3deAnamorphicStdDeg6Rescaled lens_parameters);

0 commit comments

Comments
 (0)