Camera Model

template<IsSpectral TSpectral>
class CameraModel : public huira::SceneObject<CameraModel<TSpectral>, TSpectral>

CameraModel represents a pinhole or thin-lens camera with configurable sensor, aperture, and distortion models.

This class provides a flexible camera abstraction for rendering and simulation, supporting various sensor types, aperture shapes, and lens distortion models. It allows configuration of focal length, f-stop, sensor resolution, pixel pitch, and more. The camera can project 3D points to the image plane, compute projected aperture area, and supports both analytic and PSF-based point spread functions. All units are SI unless otherwise noted.

Template Parameters:

TSpectral – The spectral type (e.g., float, Vec3f, etc.)

Public Functions

CameraModel()

Construct a new CameraModel with default sensor and aperture.

Initializes the camera with a default focal length, a SimpleSensor, and a CircularAperture. The aperture diameter is set based on the focal length and a default f-stop of 2.8.

CameraModel(const CameraModel&) = delete
CameraModel &operator=(const CameraModel&) = delete
void set_focal_length(units::Millimeter focal_length)

Set the focal length of the camera (in millimeters).

Updates the camera intrinsics and, if using aperture PSF, updates the PSF as well.

Parameters:

focal_length – Focal length in millimeters

inline float focal_length() const
void set_fstop(float fstop)

Set the f-stop (aperture ratio) of the camera.

Parameters:

fstop – F-stop value

float fstop() const

Get the f-stop (aperture ratio) of the camera.

Returns:

float F-stop value

template<IsDistortion TDistortion, typename ...Args>
void set_distortion(Args&&... args)

Set the distortion model for the camera.

Template Parameters:
  • TDistortionDistortion model type

  • Args – Constructor arguments for the distortion model

Parameters:

args – Arguments to construct the distortion model

void set_brown_conrady_distortion(BrownCoefficients coeffs)

Set Brown-Conrady distortion coefficients.

Parameters:

coeffs – Brown distortion coefficients

void set_opencv_distortion(OpenCVCoefficients coeffs)

Set OpenCV distortion coefficients.

Parameters:

coeffs – OpenCV distortion coefficients

void set_owen_distortion(OwenCoefficients coeffs)

Set Owen distortion coefficients.

Parameters:

coeffs – Owen distortion coefficients

inline void delete_distortion()
template<IsSensor TSensor, typename ...Args>
void set_sensor(Args&&... args)

Set the sensor model for the camera.

Template Parameters:
  • TSensor – Sensor model type

  • Args – Constructor arguments for the sensor

Parameters:

args – Arguments to construct the sensor

void set_sensor_resolution(Resolution resolution)

Set the sensor resolution.

Parameters:

resolution – Sensor resolution (width, height)

void set_sensor_resolution(int width, int height)

Set the sensor resolution by width and height.

Parameters:
  • width – Sensor width in pixels

  • height – Sensor height in pixels

void set_sensor_pixel_pitch(units::Micrometer pitch_x, units::Micrometer pitch_y)

Set the sensor pixel pitch in x and y directions.

Parameters:
  • pitch_xPixel pitch in x (micrometers)

  • pitch_yPixel pitch in y (micrometers)

void set_sensor_pixel_pitch(units::Micrometer pitch)

Set the sensor pixel pitch (square pixels).

Parameters:

pitchPixel pitch in both x and y (micrometers)

void set_sensor_size(units::Millimeter width, units::Millimeter height)

Set the physical sensor size.

Parameters:
  • width – Sensor width in millimeters

  • height – Sensor height in millimeters

void set_sensor_size(units::Millimeter width)

Set the sensor width and compute height from aspect ratio.

Parameters:

width – Sensor width in millimeters

Rotation<double> sensor_rotation() const

Get the sensor rotation as a Rotation object.

Returns:

Rotation<double> Sensor rotation

template<IsAperture TAperture, typename ...Args>
void set_aperture(Args&&... args)

Set the aperture model for the camera.

Template Parameters:
  • TApertureAperture model type

  • Args – Constructor arguments for the aperture

Parameters:

args – Arguments to construct the aperture

template<IsPSF TPSF, typename ...Args>
void set_psf(Args&&... args)

Set the point spread function (PSF) model for the camera.

Template Parameters:
  • TPSFPSF model type

  • Args – Constructor arguments for the PSF

Parameters:

args – Arguments to construct the PSF

void use_aperture_psf(int radius = 64, int banks = 16)

Use the aperture to generate a PSF (point spread function).

Parameters:
  • radiusPSF kernel radius

  • banks – Number of PSF banks

void delete_psf()

Delete the PSF and disable aperture PSF usage.

inline bool has_psf() const
inline const Image<TSpectral> &get_psf_kernel(float u, float v) const
inline int get_psf_radius() const
Pixel project_point(const Vec3<float> &point_camera_coords) const

Project a 3D point in camera coordinates onto the image plane.

Uses the pinhole camera model and applies distortion if present.

Parameters:

point_camera_coords – 3D point in camera coordinates (meters)

Returns:

Pixel 2D point on the image plane (pixels)

inline void readout(FrameBuffer<TSpectral> &fb, float exposure_time) const
float get_projected_aperture_area(const Vec3<float> &direction) const

Get the projected aperture area for a given direction.

Parameters:

direction – Direction vector

Returns:

float Projected aperture area

inline Resolution resolution() const
inline virtual std::uint64_t id() const override

Get the object’s unique ID.

Returns:

std::uint64_t ID

inline virtual std::string type() const override

Get the object’s type string.

Returns:

std::string Type

inline FrameBuffer<TSpectral> make_frame_buffer() const
inline void use_blender_convention(bool value = true)
inline bool is_blender_convention() const
inline bool is_scene_owned() const

Check if the object is owned by the scene.

Returns:

bool True if owned

inline void set_scene_owned(bool owned)

Set scene ownership flag.

Parameters:

owned – True if owned

inline std::string name() const

Get the object’s name.

Returns:

std::string Name

inline virtual std::string get_info() const

Get a descriptive info string for the object.

Returns:

std::string Info string

Protected Functions

void compute_intrinsics_()

Compute the camera intrinsic parameters (focal lengths, principal point, resolution).

Protected Attributes

float focal_length_ = .05f
std::unique_ptr<SensorModel<TSpectral>> sensor_
std::unique_ptr<Aperture<TSpectral>> aperture_
std::unique_ptr<Distortion<TSpectral>> distortion_ = nullptr
std::unique_ptr<PSF<TSpectral>> psf_ = nullptr
bool use_aperture_psf_ = false
std::uint64_t id_ = 0
float fx_
float fy_
float cx_
float cy_
float rx_
float ry_
bool blender_convention_ = false

Protected Static Attributes

static std::uint64_t next_id_ = 0

Friends

friend class CameraModelHandle< TSpectral >