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 (focal ratio) of the camera. The aperture diameter this gives is kept if the focal length later changes; see CameraModel::set_fstop().
- Parameters:
fstop – F-stop value
-
float fstop() const¶
Get the f-stop (focal ratio) of the camera.
- Returns:
float F-stop value
-
void set_aperture_diameter(units::Millimeter diameter) const¶
Set the aperture’s diameter, which is kept if the focal length changes. See CameraModel::set_aperture_diameter().
- Parameters:
diameter – The aperture’s diameter.
-
units::Millimeter aperture_diameter() const¶
Get the aperture’s diameter.
-
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.
- Parameters:
resolution – Sensor resolution
pitch_x – Pixel pitch in x direction (micrometers)
pitch_y – Pixel pitch in y direction (micrometers)
cx – Principal point x coordinate, in the camera’s pixel convention (see set_pixel_convention()). Defaults to the center of the sensor.
cy – Principal point y coordinate, likewise.
-
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, in the camera’s pixel convention (see set_pixel_convention()). Defaults to the center of the sensor.
cy – Principal point y coordinate, likewise.
-
void set_intrinsic_matrix(const Mat3<float> &intrinsic_matrix, const Resolution &resolution, units::Millimeter anchor_focal_length)¶
Set the intrinsic matrix for the camera. Mat3 is indexed K[column][row], so cx is K[2][0]; see CameraModel::set_intrinsic_matrix().
- 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, float skew = 0.f)¶
Set the intrinsic parameters for the camera. See CameraModel::set_intrinsics().
- Parameters:
fx – Focal length in x direction, in pixels
fy – Focal length in y direction, in pixels
cx – Principal point x coordinate, in the camera’s pixel convention
cy – Principal point y coordinate, in the camera’s pixel convention
resolution – Sensor resolution
anchor_focal_length – Anchor focal length in millimeters
skew – Skew, in pixels; 0 for perpendicular pixel axes.
-
Mat3<float> intrinsic_matrix() const¶
Get the camera matrix, in the camera’s pixel convention. See CameraModel::intrinsic_matrix().
-
Resolution resolution() const¶
Get the sensor’s resolution.
-
std::pair<units::Micrometer, units::Micrometer> pixel_pitch() const¶
Get the pixel pitch, along x and along y.
-
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 enable_sensor_noise(bool noise = true) const¶
Turn the sensor’s shot noise and read noise on (the default) or off.
Off, each pixel collects the expected number of electrons. The dark current’s electrons and the bias are still added, since they are not noise.
- Parameters:
noise – True to simulate noise, false not to
-
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_roll(units::Radian angle) const¶
Set the sensor’s roll about the optical axis. See CameraModel::set_sensor_roll().
- Parameters:
angle – The roll angle (any angle unit).
-
void set_sensor_noise_seed(std::uint64_t seed) const¶
Seed the sensor’s noise, so that its frames can be reproduced.
Setting the same seed again repeats the same sequence of frames. Sensors get distinct seeds by default. See SensorModel::set_noise_seed().
- Parameters:
seed – Any value.
-
std::uint64_t sensor_noise_seed() const¶
Get the seed of the sensor’s noise. See set_sensor_noise_seed().
-
float sensor_full_well_capacity() const¶
Get the sensor’s full well capacity, in electrons.
-
bool sensor_noise_enabled() const¶
Whether the sensor’s shot noise and read noise are on (the default). See enable_sensor_noise().
-
float sensor_read_noise() const¶
Get the sensor’s read noise, in electrons.
-
float sensor_dark_current() const¶
Get the sensor’s dark current, in electrons per second.
-
float sensor_bias_level() const¶
Get the sensor’s bias level, in digital numbers.
-
int sensor_bit_depth() const¶
Get the sensor’s bit depth.
-
float sensor_conversion_gain() const¶
Get the sensor’s conversion gain, in electrons per digital number.
-
float sensor_gain_db() const¶
Get the sensor’s gain, in decibels. See set_sensor_gain_db().
-
float sensor_unity_db() const¶
Get the gain, in decibels, at which the sensor’s conversion gain is unity.
-
units::Radian sensor_roll() const¶
The sensor’s roll about the optical axis. See CameraModel::set_sensor_roll().
-
Rotation<double> sensor_orientation() const¶
The sensor’s orientation relative to the camera. See CameraModel::sensor_orientation().
-
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
-
void enable_diffraction(bool diffraction = true) const¶
Turn the aperture’s diffraction pattern on (the default) or off. See CameraModel::enable_diffraction().
- Parameters:
diffraction – True to turn it on, false to turn it off.
-
bool diffraction_enabled() const¶
Whether the aperture’s diffraction pattern is on (the default).
-
template<IsPSF TPSF, typename ...Args>
void set_psf(Args&&... args) const¶ Set a point spread function (PSF) in place of the aperture’s diffraction pattern. See CameraModel::set_psf().
-
void set_measured_psf(const Image<TSpectral> &data, float samples_per_pixel, PSFSampling sampling, PSFFocus focus = PSFFocus::InFocus) const¶
Set a measured (user-supplied) PSF in place of the aperture’s diffraction pattern. See CameraModel::set_measured_psf().
- Parameters:
data – Measured PSF samples, centered on the image, taken whole.
samples_per_pixel – Measurement samples per sensor pixel per axis.
sampling – What the samples are: the PSF’s intensity at points, or the light a pixel centered there receives (see PSFSampling).
focus – Whether the samples are a point’s in focus, which the camera’s focus blurs, or already hold its defocus (see PSFFocus).
-
void clear_psf() const¶
Remove a PSF that was set, going back to the aperture’s diffraction pattern, if it is on.
-
void set_scatter(float fraction, float slope, units::Radian shoulder_angle, std::optional<units::Radian> outer_angle = std::nullopt) const¶
Set scattered light, in angles. See CameraModel::set_scatter().
-
void disable_scatter() const¶
Turn scattered light off (the default).
-
bool scatter_enabled() const¶
Whether scattered light is on.
-
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 enable_psf_convolution(bool convolve_psf = true) const¶
Choose whether the PSF and scattered light blur resolved bodies. See CameraModel::enable_psf_convolution().
- Parameters:
convolve_psf – True (the default) to blur resolved bodies, false to leave them sharp.
-
bool psf_convolution_enabled() const¶
Whether the PSF and scattered light blur resolved bodies (the default).
-
Image<TSpectral> psf_image(int radius, float x_offset = 0.f, float y_offset = 0.f, std::optional<units::Meter> range = std::nullopt) const¶
The light an unresolved source puts in each pixel around it, per channel, as the renderer draws it. See CameraModel::psf_image().
-
Image<TSpectral> diffraction_image(int radius, float x_offset = 0.f, float y_offset = 0.f) const¶
The aperture’s diffraction pattern alone, in focus. See CameraModel::diffraction_image().
-
Image<TSpectral> scatter_image(int radius, float x_offset = 0.f, float y_offset = 0.f) const¶
The scattered light alone, in focus. See CameraModel::scatter_image().
-
Image<TSpectral> defocus_image(int radius, float x_offset = 0.f, float y_offset = 0.f, std::optional<units::Meter> range = std::nullopt) const¶
The defocus blur alone, of a point at a range or a star. See CameraModel::defocus_image().
-
void precompute() const¶
Build everything the camera’s optics need for the next render, now, so that the time is not spent in the render. See CameraModel::precompute().
-
bool is_precomputed() const¶
Whether everything the next render needs from the camera’s optics is built and up to date. See CameraModel::is_precomputed().
-
void enable_auto_precompute(bool auto_precompute = true) const¶
Choose whether a render builds an out-of-date camera itself (the default) or throws. See CameraModel::enable_auto_precompute().
- Parameters:
auto_precompute – True for the render to build what is out of date, false to throw.
-
bool auto_precompute_enabled() const¶
Whether a render builds an out-of-date camera itself. See enable_auto_precompute().
-
void enable_depth_of_field(bool depth_of_field = true) const¶
Turn depth of field on (the default) or off. See CameraModel::enable_depth_of_field().
- Parameters:
depth_of_field – True to turn depth of field on, false to turn it off.
-
bool depth_of_field_enabled() const¶
Whether depth of field is on (the default).
-
void enable_motion_blur(bool motion_blur = true) const¶
Turn motion blur on (the default) or off. See CameraModel::enable_motion_blur().
- Parameters:
motion_blur – True to turn motion blur on, false to turn it off.
-
bool motion_blur_enabled() const¶
Whether motion blur is on (the default).
-
void set_focus_distance(units::Meter focus_distance) const¶
Focus the camera at a distance.
Positive values focus in front of the camera, infinity focuses at infinity, and negative values focus past infinity. See CameraModel::set_focus_distance().
- Parameters:
focus_distance – Focus distance (any length unit).
-
void set_focus_diopters(units::Diopter diopters) const¶
Focus the camera in diopters: the reciprocal of the focus distance.
0 focuses at infinity and negative values focus past infinity. See CameraModel::set_focus_diopters().
- Parameters:
diopters – The reciprocal of the focus distance (diopters).
-
void set_focus_sensor_offset(units::Micrometer offset) const¶
Focus the camera by the sensor’s offset from the infinity-focus position.
0 focuses at infinity, positive values (sensor farther from the lens) focus in front of the camera, and negative values focus past infinity. See CameraModel::set_focus_sensor_offset().
- Parameters:
offset – Sensor offset (any length unit).
-
units::Meter focus_distance() const¶
Get the distance the camera is focused at: negative past infinity, +inf at infinity.
-
units::Diopter focus_diopters() const¶
Get the focus in diopters: the reciprocal of focus_distance(), 0 at infinity.
-
units::Micrometer focus_sensor_offset() const¶
Get the focus as the sensor’s offset from the infinity-focus position.
-
float defocus_blur_radius(std::optional<units::Meter> range = std::nullopt) const¶
The radius, in pixel widths, of the defocus blur of a point at a range, or of a star. See CameraModel::defocus_blur_radius().
-
void set_pixel_convention(PixelConvention convention) const¶
Set the pixel coordinate convention used for the principal point and projected positions. The default is PixelConvention::opencv(). See CameraModel::set_pixel_convention().
- Parameters:
convention – The convention, e.g. PixelConvention::fits().
-
PixelConvention pixel_convention() const¶
Get the pixel coordinate convention used for the principal point and projected positions.
-
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, in the camera’s pixel convention
-
Pixel try_project_point(const Vec3<float> &point_camera_coords) const¶
Project a 3D point in camera coordinates onto the image plane, if it is in the field of view.
- Returns:
The position in the camera’s pixel convention, or NaN in both coordinates for a point outside the field of view.
-
bool in_fov(const Vec3<float> &point_camera_coords) const¶
Whether a point in camera coordinates is in the camera’s field of view.
-
Ray<TSpectral> cast_ray(const Pixel &pixel) const¶
Cast a pinhole camera ray through a position on the image, in the camera’s pixel convention. See CameraModel::cast_ray().
-
Ray<TSpectral> cast_ray(const Pixel &pixel, Sampler<float> &sampler) const¶
Cast a camera ray through a position on the image, sampling the aperture when depth of field is on. See CameraModel::cast_ray().
-
Ray<TSpectral> cast_ray(int x, int y) const¶
Cast a pinhole camera ray through integer coordinates in the camera’s pixel convention. See CameraModel::cast_ray().
-
std::optional<Ray<TSpectral>> try_cast_ray(const Pixel &pixel) const¶
As cast_ray(), but empty where the lens distortion has no inverse, rather than throwing. See CameraModel::try_cast_ray().
-
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
-
bool uses_blender_convention() const¶
Whether the camera uses Blender’s convention (-z forward, y up).
-
std::string describe() const¶
A summary of the camera’s settings, one per line. See CameraModel::describe().
-
template<typename ...Args>
inline void set_measured_psf(const Image<TSpectral>&, float, Args&&...) 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 – if the handle is invalid or the cast fails
- Returns:
std::shared_ptr<U>Shared pointer to the object
-
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 >