canvas — functions and constants
Placing a camera's picture in view space, and asking what covers what.
The C ABI gained this whole feature in an earlier release
(optris_sdk_canvas, optris_sdk_placement and forty entry
points around them), and no binding in any language reached one
of them until this one.
It was never a Rust gap: it was an unbound feature, declared at the
ABI, gated, and called from nothing above it. The optris-sdk-sys
crate has carried every one of them from bindgen all along, so a
caller willing to write unsafe could always reach it; this module
is the safe surface over the top.
Three types, mirroring the ABI:
Placement is a value: where one camera's frame sits in view
space, as a 3×3 affine transform. Canvas is a handle owning a
list of placements plus the colour of the space none of them cover.
CanvasMap is a handle holding the answer to "which source
pixel is behind this output pixel", recomputed by
CanvasMap::update.
use optris_sdk::{Canvas, CanvasMap, Placement};
# fn main() -> optris_sdk::Result<()> {
let mut canvas = Canvas::new(640, 480)?;
canvas.add_placement(&Placement::centred(382, 288, (0.0, 0.0), 1.5, 0.0)?)?;
let mut map = CanvasMap::new()?;
map.update(&canvas, 382, 288)?;
println!("{:.3} of the canvas has a camera behind it", map.fill()?);
# Ok(())
# }
Why the frame size is an argument and not state
Six of these calls take frame_width and frame_height. A placement
is stored in a frame-size-independent space, so the same placement
describes a 382×288 camera and a 640×480 one differently, and the ABI
asks for the size at the point of the question. This module does not
cache it: caching would make a placement silently wrong the moment a
camera's mode changed, which is the defect the ABI's shape avoids.
pub const NO_SOURCE: i32 = sys::OPTRIS_SDK_CANVAS_NO_SOURCE;
What CanvasMap::indices carries where the canvas has no camera
behind it.
The ABI's own named value, not a number chosen here. It is -1,
outside the range of any source pixel index, so it cannot be
confused with a real one.
pub fn frame_centre_of(frame_width: u32, frame_height: u32) -> Result<Vec2>
The centre of a frame that size, in frame coordinates.
Not (0.5, 0.5), which is the mistake this call exists to stop.
Both axes are divided by the width, so x runs 0..1 and y runs
0..height / width; the centre of a 382×288 frame is therefore
(0.5, 0.377), and a hand-written (0.5, 0.5) places it below
centre on every camera that is not square.
Errors
Status::InvalidArgument if either
dimension is zero.