Skip to content

Commit

Permalink
Lens Distortion - Add ImageDimensions struct
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
david-cattermole committed Dec 31, 2024
1 parent f6cdeaf commit 0becf2b
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 439 deletions.
6 changes: 4 additions & 2 deletions lib/cppbind/mmlens/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,10 @@ class DistortionExample : public Distortion {
### 4) distortion_process.h/.cpp
- Add new processing functions in `distortion_process.h` and `distortion_process.cpp`.
- Implement both single-threaded and multi-threaded versions.
- Include variants for different precision types (f32/f64).
- Functions use C++ templates, so copy/paste should get you 99% finished.
- Ensure you add functions for both single-threaded and multi-threaded
versions and include variants for different precision types
(f32/f64).
```cpp
void apply_identity_to_f64(...);
Expand Down
21 changes: 21 additions & 0 deletions lib/cppbind/mmlens/include/mmlens/_cxxbridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ namespace mmlens {
enum class DistortionDirection : ::std::uint8_t;
enum class LensModelState : ::std::uint8_t;
enum class LensModelType : ::std::uint8_t;
struct ImageDimensions;
struct CameraParameters;
struct Parameters3deClassic;
struct Parameters3deRadialStdDeg4;
Expand Down Expand Up @@ -428,6 +429,26 @@ enum class LensModelType : ::std::uint8_t {
};
#endif // CXXBRIDGE1_ENUM_mmlens$LensModelType

#ifndef CXXBRIDGE1_STRUCT_mmlens$ImageDimensions
#define CXXBRIDGE1_STRUCT_mmlens$ImageDimensions
struct ImageDimensions final {
::std::size_t width;
::std::size_t height;
::std::size_t start_width;
::std::size_t start_height;
::std::size_t end_width;
::std::size_t end_height;

bool operator==(const ImageDimensions &) const noexcept;
bool operator!=(const ImageDimensions &) const noexcept;
bool operator<(const ImageDimensions &) const noexcept;
bool operator<=(const ImageDimensions &) const noexcept;
bool operator>(const ImageDimensions &) const noexcept;
bool operator>=(const ImageDimensions &) const noexcept;
using IsRelocatable = ::std::true_type;
};
#endif // CXXBRIDGE1_STRUCT_mmlens$ImageDimensions

#ifndef CXXBRIDGE1_STRUCT_mmlens$CameraParameters
#define CXXBRIDGE1_STRUCT_mmlens$CameraParameters
struct CameraParameters final {
Expand Down
145 changes: 65 additions & 80 deletions lib/cppbind/mmlens/include/mmlens/distortion_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

namespace mmlens {

struct ImageDimensions;
struct CameraParameters;
struct Parameters3deClassic;
struct Parameters3deRadialStdDeg4;
Expand All @@ -47,24 +48,22 @@ enum class DistortionDirection : uint8_t;
// 3DE Classic

MMLENS_API_EXPORT
void apply_identity_to_f64(
const DistortionDirection direction, const size_t image_width,
const size_t image_height, const size_t start_image_width,
const size_t start_image_height, const size_t end_image_width,
const size_t end_image_height, double* out_data_ptr,
const size_t out_data_size, const size_t out_data_stride,
const CameraParameters camera_parameters, const double film_back_radius_cm,
Parameters3deClassic lens_parameters);
void apply_identity_to_f64(const DistortionDirection direction,
const ImageDimensions image_dimensions,
double* out_data_ptr, const size_t out_data_size,
const size_t out_data_stride,
const CameraParameters camera_parameters,
const double film_back_radius_cm,
Parameters3deClassic lens_parameters);

MMLENS_API_EXPORT
void apply_identity_to_f32(
const DistortionDirection direction, const size_t image_width,
const size_t image_height, const size_t start_image_width,
const size_t start_image_height, const size_t end_image_width,
const size_t end_image_height, float* out_data_ptr,
const size_t out_data_size, const size_t out_data_stride,
const CameraParameters camera_parameters, const double film_back_radius_cm,
Parameters3deClassic lens_parameters);
void apply_identity_to_f32(const DistortionDirection direction,
const ImageDimensions image_dimensions,
float* out_data_ptr, const size_t out_data_size,
const size_t out_data_stride,
const CameraParameters camera_parameters,
const double film_back_radius_cm,
Parameters3deClassic lens_parameters);

MMLENS_API_EXPORT
void apply_f64_to_f64(const DistortionDirection direction,
Expand Down Expand Up @@ -92,24 +91,22 @@ void apply_f64_to_f32(const DistortionDirection direction,
// 3DE Radial Decentered Degree 4 Cylindric

MMLENS_API_EXPORT
void apply_identity_to_f64(
const DistortionDirection direction, const size_t image_width,
const size_t image_height, const size_t start_image_width,
const size_t start_image_height, const size_t end_image_width,
const size_t end_image_height, double* out_data_ptr,
const size_t out_data_size, const size_t out_data_stride,
const CameraParameters camera_parameters, const double film_back_radius_cm,
Parameters3deRadialStdDeg4 lens_parameters);
void apply_identity_to_f64(const DistortionDirection direction,
const ImageDimensions image_dimensions,
double* out_data_ptr, const size_t out_data_size,
const size_t out_data_stride,
const CameraParameters camera_parameters,
const double film_back_radius_cm,
Parameters3deRadialStdDeg4 lens_parameters);

MMLENS_API_EXPORT
void apply_identity_to_f32(
const DistortionDirection direction, const size_t image_width,
const size_t image_height, const size_t start_image_width,
const size_t start_image_height, const size_t end_image_width,
const size_t end_image_height, float* out_data_ptr,
const size_t out_data_size, const size_t out_data_stride,
const CameraParameters camera_parameters, const double film_back_radius_cm,
Parameters3deRadialStdDeg4 lens_parameters);
void apply_identity_to_f32(const DistortionDirection direction,
const ImageDimensions image_dimensions,
float* out_data_ptr, const size_t out_data_size,
const size_t out_data_stride,
const CameraParameters camera_parameters,
const double film_back_radius_cm,
Parameters3deRadialStdDeg4 lens_parameters);

MMLENS_API_EXPORT
void apply_f64_to_f64(const DistortionDirection direction,
Expand Down Expand Up @@ -137,24 +134,22 @@ void apply_f64_to_f32(const DistortionDirection direction,
// 3DE Anamorphic Degree 4 Rotate Squeeze XY

MMLENS_API_EXPORT
void apply_identity_to_f64(
const DistortionDirection direction, const size_t image_width,
const size_t image_height, const size_t start_image_width,
const size_t start_image_height, const size_t end_image_width,
const size_t end_image_height, double* out_data_ptr,
const size_t out_data_size, const size_t out_data_stride,
const CameraParameters camera_parameters, const double film_back_radius_cm,
Parameters3deAnamorphicStdDeg4 lens_parameters);
void apply_identity_to_f64(const DistortionDirection direction,
const ImageDimensions image_dimensions,
double* out_data_ptr, const size_t out_data_size,
const size_t out_data_stride,
const CameraParameters camera_parameters,
const double film_back_radius_cm,
Parameters3deAnamorphicStdDeg4 lens_parameters);

MMLENS_API_EXPORT
void apply_identity_to_f32(
const DistortionDirection direction, const size_t image_width,
const size_t image_height, const size_t start_image_width,
const size_t start_image_height, const size_t end_image_width,
const size_t end_image_height, float* out_data_ptr,
const size_t out_data_size, const size_t out_data_stride,
const CameraParameters camera_parameters, const double film_back_radius_cm,
Parameters3deAnamorphicStdDeg4 lens_parameters);
void apply_identity_to_f32(const DistortionDirection direction,
const ImageDimensions image_dimensions,
float* out_data_ptr, const size_t out_data_size,
const size_t out_data_stride,
const CameraParameters camera_parameters,
const double film_back_radius_cm,
Parameters3deAnamorphicStdDeg4 lens_parameters);

MMLENS_API_EXPORT
void apply_f64_to_f64(const DistortionDirection direction,
Expand Down Expand Up @@ -183,20 +178,16 @@ void apply_f64_to_f32(const DistortionDirection direction,

MMLENS_API_EXPORT
void apply_identity_to_f64(
const DistortionDirection direction, const size_t image_width,
const size_t image_height, const size_t start_image_width,
const size_t start_image_height, const size_t end_image_width,
const size_t end_image_height, double* out_data_ptr,
const DistortionDirection direction,
const ImageDimensions image_dimensions, double* out_data_ptr,
const size_t out_data_size, const size_t out_data_stride,
const CameraParameters camera_parameters, const double film_back_radius_cm,
Parameters3deAnamorphicStdDeg4Rescaled lens_parameters);

MMLENS_API_EXPORT
void apply_identity_to_f32(
const DistortionDirection direction, const size_t image_width,
const size_t image_height, const size_t start_image_width,
const size_t start_image_height, const size_t end_image_width,
const size_t end_image_height, float* out_data_ptr,
const DistortionDirection direction,
const ImageDimensions image_dimensions, float* out_data_ptr,
const size_t out_data_size, const size_t out_data_stride,
const CameraParameters camera_parameters, const double film_back_radius_cm,
Parameters3deAnamorphicStdDeg4Rescaled lens_parameters);
Expand Down Expand Up @@ -227,24 +218,22 @@ void apply_f64_to_f32(const DistortionDirection direction,
// 3DE Anamorphic Degree 6 Rotate Squeeze XY

MMLENS_API_EXPORT
void apply_identity_to_f64(
const DistortionDirection direction, const size_t image_width,
const size_t image_height, const size_t start_image_width,
const size_t start_image_height, const size_t end_image_width,
const size_t end_image_height, double* out_data_ptr,
const size_t out_data_size, const size_t out_data_stride,
const CameraParameters camera_parameters, const double film_back_radius_cm,
Parameters3deAnamorphicStdDeg6 lens_parameters);
void apply_identity_to_f64(const DistortionDirection direction,
const ImageDimensions image_dimensions,
double* out_data_ptr, const size_t out_data_size,
const size_t out_data_stride,
const CameraParameters camera_parameters,
const double film_back_radius_cm,
Parameters3deAnamorphicStdDeg6 lens_parameters);

MMLENS_API_EXPORT
void apply_identity_to_f32(
const DistortionDirection direction, const size_t image_width,
const size_t image_height, const size_t start_image_width,
const size_t start_image_height, const size_t end_image_width,
const size_t end_image_height, float* out_data_ptr,
const size_t out_data_size, const size_t out_data_stride,
const CameraParameters camera_parameters, const double film_back_radius_cm,
Parameters3deAnamorphicStdDeg6 lens_parameters);
void apply_identity_to_f32(const DistortionDirection direction,
const ImageDimensions image_dimensions,
float* out_data_ptr, const size_t out_data_size,
const size_t out_data_stride,
const CameraParameters camera_parameters,
const double film_back_radius_cm,
Parameters3deAnamorphicStdDeg6 lens_parameters);

MMLENS_API_EXPORT
void apply_f64_to_f64(const DistortionDirection direction,
Expand Down Expand Up @@ -273,20 +262,16 @@ void apply_f64_to_f32(const DistortionDirection direction,

MMLENS_API_EXPORT
void apply_identity_to_f64(
const DistortionDirection direction, const size_t image_width,
const size_t image_height, const size_t start_image_width,
const size_t start_image_height, const size_t end_image_width,
const size_t end_image_height, double* out_data_ptr,
const DistortionDirection direction,
const ImageDimensions image_dimensions, double* out_data_ptr,
const size_t out_data_size, const size_t out_data_stride,
const CameraParameters camera_parameters, const double film_back_radius_cm,
Parameters3deAnamorphicStdDeg6Rescaled lens_parameters);

MMLENS_API_EXPORT
void apply_identity_to_f32(
const DistortionDirection direction, const size_t image_width,
const size_t image_height, const size_t start_image_width,
const size_t start_image_height, const size_t end_image_width,
const size_t end_image_height, float* out_data_ptr,
const DistortionDirection direction,
const ImageDimensions image_dimensions, float* out_data_ptr,
const size_t out_data_size, const size_t out_data_stride,
const CameraParameters camera_parameters, const double film_back_radius_cm,
Parameters3deAnamorphicStdDeg6Rescaled lens_parameters);
Expand Down
Loading

0 comments on commit 0becf2b

Please sign in to comment.