CameraHandle¶
-
template<IsSpectral TSpectral>
class CameraModelHandle : public huira::Handle<CameraModel<TSpectral>>¶ Handle for manipulating a CameraModel in a scene.
Provides a safe, reference-like interface for configuring and querying a CameraModel instance within a scene graph. All operations are forwarded to the underlying CameraModel.
- Template Parameters:
TSpectral – The spectral type (e.g., RGB, Visible8)
Public Functions
-
CameraModelHandle() = delete¶
-
void set_focal_length(units::Millimeter focal_length) const¶
Set the focal length of the camera (in millimeters).
- Parameters:
focal_length – Focal length in millimeters
-
units::Millimeter focal_length() const¶
Get the focal length of the camera (in millimeters).
- Returns:
units::Millimeter Focal length in millimeters
-
void set_fstop(float fstop) const¶
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<TSpectral> TDistortion, typename ...Args>
void set_distortion(Args&&... args) const¶ Set the distortion model for the camera.
- Template Parameters:
TDistortion – Distortion model type
Args – Constructor arguments for the distortion model
- Parameters:
args – Arguments to construct the distortion model
-
void set_brown_conrady_distortion(BrownCoefficients coeffs) const¶
Set Brown-Conrady distortion coefficients.
- Parameters:
coeffs – Brown distortion coefficients
-
void set_opencv_distortion(OpenCVCoefficients coeffs) const¶
Set OpenCV distortion coefficients.
- Parameters:
coeffs – OpenCV distortion coefficients
-
void set_owen_distortion(OwenCoefficients coeffs) const¶
Set Owen distortion coefficients.
- Parameters:
coeffs – Owen distortion coefficients
-
void delete_distortion() const¶
Delete the distortion model from the camera.
-
template<IsSensor<TSpectral> TSensor, typename ...Args>
void set_sensor(Args&&... args) const¶ 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 configure_sensor_from_pitch(const Resolution &resolution, units::Micrometer pitch_x, std::optional<units::Micrometer> pitch_y = std::nullopt, std::optional<float> cx = std::nullopt, std::optional<float> cy = std::nullopt)¶
Configure the sensor using pixel pitch and resolution.
This method sets the sensor resolution, pixel pitch, and principal point. It also computes the intrinsics based on the new configuration.
-
void configure_sensor_from_size(const Resolution &resolution, units::Millimeter width, std::optional<units::Millimeter> height = std::nullopt, std::optional<float> cx = std::nullopt, std::optional<float> cy = std::nullopt)¶
Configure the sensor using physical size and resolution.
This method sets the sensor resolution, physical size, and principal point. It also computes the intrinsics based on the new configuration.
- Parameters:
resolution – Sensor resolution
width – Sensor width in millimeters
height – Sensor height in millimeters
cx – Principal point x coordinate (must be within resolution bounds)
cy – Principal point y coordinate (must be within resolution bounds)
-
void set_intrinsic_matrix(const Mat3<float> &intrinsic_matrix, const Resolution &resolution, units::Millimeter anchor_focal_length)¶
Set the intrinsic matrix for the camera.
- Parameters:
intrinsic_matrix – 3x3 intrinsic matrix
resolution – Sensor resolution
anchor_focal_length – Anchor focal length in millimeters
-
void set_intrinsics(float fx, float fy, float cx, float cy, const Resolution &resolution, units::Millimeter anchor_focal_length)¶
Set the intrinsic parameters for the camera.
- Parameters:
fx – Focal length in x direction
fy – Focal length in y direction
cx – Principal point x coordinate
cy – Principal point y coordinate
resolution – Sensor resolution
anchor_focal_length – Anchor focal length in millimeters
-
void set_sensor_quantum_efficiency(double qe) const¶
Set the sensor quantum efficiency.
- Parameters:
qe – Quantum efficiency value
-
void set_sensor_quantum_efficiency(TSpectral qe) const¶
Set the sensor quantum efficiency.
- Parameters:
qe – Quantum efficiency value
-
void set_sensor_full_well_capacity(float fwc) const¶
Set the sensor full well capacity.
- Parameters:
fwc – Full well capacity value
-
void set_sensor_simulate_noise(bool simulate_noise) const¶
Enable or disable sensor noise simulation.
- Parameters:
simulate_noise – True to enable noise simulation, false to disable
-
void set_sensor_read_noise(float read_noise) const¶
Set the sensor read noise.
- Parameters:
read_noise – Read noise value
-
void set_sensor_dark_current(float dark_current) const¶
Set the sensor dark current.
- Parameters:
dark_current – Dark current value
-
void set_sensor_bias_level(float bias_level) const¶
Set the sensor bias level.
- Parameters:
bias_level – Bias level value
-
void set_sensor_bit_depth(int bit_depth) const¶
Set the sensor bit depth.
- Parameters:
bit_depth – Bit depth value
-
void set_sensor_conversion_gain(float gain) const¶
Set the sensor conversion gain (e-/ADU).
Sets the conversion gain of the sensor, which defines how many electrons correspond to one ADU (Analog-to-Digital Unit). This affects the sensor’s sensitivity and noise characteristics. This value is frequently found on sensor datasheets. A larger value will make the resulting image darker.
See also
- Parameters:
gain – Gain value
- Throws:
std::runtime_error – if gain is not positive or finite.
-
void set_sensor_gain_db(float gain_db) const¶
Set the sensor gain in decibels (dB).
Sets the gain of the sensor in decibels, a logarithmic representation of the sensor’s amplification. A larger value produces a brighter image. This is the convention used by most machine-vision cameras.
The dB value maps onto the conversion gain (e-/ADU) as: conversion_gain = 10^((unity_db - gain_db) / 20) so at gain_db == unity_db the conversion gain is exactly 1 e-/ADU.
- Parameters:
gain_db – Gain in dB
- Throws:
std::runtime_error – if gain_db is not finite.
-
void set_sensor_unity_db(float unity_db) const¶
Set the reference level (in dB) for the sensor’s gain-in-dB scale.
unity_db defines where the dB scale is anchored: it is the gain_db value at which the conversion gain equals exactly 1 e-/ADU (i.e. one electron maps to one ADU, before bias). Changing unity_db shifts the entire dB scale without altering the underlying conversion gain.
This is useful for matching a real camera’s datasheet, where “0 dB” is typically defined relative to the camera’s own baseline analog gain rather than to 1 e-/ADU. For example, if a camera reports a conversion gain of 3.16 e-/ADU at its 0 dB setting, set unity_db to 10 (since 20*log10(3.16) ≈ 10) and set_sensor_gain_db(0) will then reproduce that camera’s 0 dB behavior.
Defaults to 0, meaning gain_db = 0 corresponds to 1 e-/ADU.
See also
- Parameters:
unity_db – Reference level in dB
- Throws:
std::runtime_error – if unity_db is not finite.
-
void set_sensor_rotation(units::Radian angle) const¶
Set the sensor rotation angle.
Rotates the sensor around the optical axis by the specified angle.
- Parameters:
angle – Rotation angle
-
template<IsAperture TAperture, typename ...Args>
void set_aperture(Args&&... args) const¶ Set the aperture model for the camera.
- Template Parameters:
TAperture – Aperture 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) const¶ Set the point spread function (PSF) model for the camera.
-
void set_measured_psf(const Image<TSpectral> &data, float samples_per_pixel, int radius = 0, int banks = 16) const¶
Sets a measured (user-supplied) PSF as the core PSF of the camera.
- Parameters:
data – Measured PSF samples, centered on the image.
samples_per_pixel – Measurement samples per sensor pixel per axis.
radius – Polyphase stamping kernel radius in sensor pixels (0 = auto).
banks – Number of polyphase banks per axis for subpixel stamping.
-
void use_aperture_psf(bool value) const¶
Use the aperture to generate a PSF (point spread function).
- Parameters:
value – True to enable aperture PSF, false to disable
-
void use_aperture_psf(int radius = 64, int banks = 16) const¶
Use the aperture to generate a PSF (point spread function).
-
void enable_psf_convolution(bool convolve_psf = true) const¶
Convolve the specified PSF with rendered extended images.
- Parameters:
convolve_psf – True to enable convolving the PSF with rendered images.
-
void set_psf_convolution_radius(int radius) const¶
-
void set_veiling_glare(float alpha) const¶
Set the veiling glare alpha value.
- Parameters:
alpha – Veiling glare alpha (0 to 1)
-
void disable_veiling_glare() const¶
Disable veiling glare effects.
-
void set_harvey_shack_scatter(float scatter_fraction, float falloff_exponent, float r0 = 0.5f, float radius = 0.f) const¶
Set Harvey-Shack scatter parameters.
- Parameters:
scatter_fraction – Fraction of light scattered (0 to 1)
falloff_exponent – Exponent for scatter falloff (typically > 1)
r0 – Radius at which scatter fraction is measured (default 0.5)
radius – Maximum scatter radius in pixels (default 0, meaning infinite)
-
void disable_harvey_shack_scatter() const¶
Disable Harvey-Shack scatter effects.
-
int get_psf_radius() const¶
-
void enable_depth_of_field(bool depth_of_field = true) const¶
Enable or disable depth of field effects.
- Parameters:
depth_of_field – True to enable depth of field, false to disable
-
void set_focus_distance(units::Meter focus_distance) const¶
Set the focus distance for depth of field calculations.
- Parameters:
focus_distance – Focus distance in meters
-
units::Meter get_focus_distance() const¶
Get the current focus distance for depth of field calculations.
- Returns:
units::Meter Focus distance in meters
-
void set_diopters(units::Diopter diopters) const¶
Set the diopters for depth of field calculations.
- Parameters:
diopters – Diopters value
-
units::Diopter get_diopters() const¶
Get the current diopters value for depth of field calculations.
- Returns:
units::Diopter Diopters value
-
Pixel project_point(const Vec3<float> &point_camera_coords) const¶
Project a 3D point in camera coordinates onto the image plane.
- Parameters:
point_camera_coords – 3D point in camera coordinates (meters)
- Returns:
Pixel 2D point on the image plane (pixels)
-
FrameBuffer<TSpectral> make_frame_buffer() const¶
Create a new frame buffer with the camera’s resolution.
- Returns:
FrameBuffer<TSpectral> Frame buffer
-
void use_blender_convention(bool value = true) const¶
Set whether to use Blender’s camera convention (z forward, y up).
- Parameters:
value – True to use Blender convention
-
void set_sensor_resolution(Resolution resolution) const¶
-
void set_sensor_resolution(int width, int height) const¶
-
void set_sensor_pixel_pitch(units::Millimeter pitch_x, units::Millimeter pitch_y) const¶
-
void set_sensor_pixel_pitch(units::Millimeter pitch) const¶
-
void set_sensor_size(units::Millimeter width, units::Millimeter height) const¶
-
void set_sensor_size(units::Millimeter width) const¶
-
bool valid() const¶
Checks if the handle points to a valid, scene-owned object.
- Returns:
true if valid, false otherwise
-
std::shared_ptr<U> get() const¶
Gets a shared_ptr to the referenced object, optionally downcasting to a derived type.
- Template Parameters:
U – Type to cast to (default: T)
- Throws:
std::runtime_error –
- Returns:
std::shared_ptr
-
inline std::string name() const¶
-
inline std::uint64_t id() const¶
-
inline std::string type() const¶
Protected Functions
-
std::shared_ptr<T> get_() const¶
Gets a shared_ptr to the referenced object, enforcing validity.
- Throws:
std::runtime_error – if the handle is invalid
- Returns:
std::shared_ptr<T> Shared pointer to the object
Protected Attributes
-
std::weak_ptr<T> ptr_¶
Friends
- friend class Scene< TSpectral >
- friend class SceneView< TSpectral >
- friend class FrameHandle< TSpectral >