Region
pub struct Region
A measuring region under construction.
Freed when dropped. Adding it to a camera copies it, so dropping
the builder afterwards does not remove the region; use
crate::Camera::remove_region for that.
Region — methods
pub fn rect(centre: impl Into<Vec2>, size: impl Into<Vec2>, rotation_rad: f32) -> Result<Self>
A rectangle, centred at centre, rotated anticlockwise.
Errors
Returns Status::InvalidArgument if the geometry is
degenerate.
pub fn circle(centre: impl Into<Vec2>, radius: f32) -> Result<Self>
A circle.
Because region coordinates are isotropic this is a true circle in pixels at any sensor resolution.
Errors
As Region::rect.
pub fn ellipse(
An ellipse with the given semi-axes, rotated anticlockwise.
Errors
As Region::rect.
pub fn line(a: impl Into<Vec2>, b: impl Into<Vec2>) -> Result<Self>
A line segment, measured along its length.
Errors
As Region::rect.
pub fn spot(at: impl Into<Vec2>, aperture: Option<Aperture>) -> Result<Self>
A point measurement.
aperture is the sampling neighbourhood, or None for a single
pixel. Anything else changes the reported temperature, see
Aperture.
Errors
As Region::rect.
pub fn polygon(points: &[Vec2]) -> Result<Self>
A closed polygon through points, which needs at least three.
Errors
Returns Status::InvalidArgument if fewer than three points
are given or the geometry is degenerate.
pub fn spline(points: &[Vec2]) -> Result<Self>
A curve through points: a centripetal Catmull-Rom spline,
which passes through every control point it is given.
Open by default, and then it is a path: no area, measuring the
pixels it runs through on the frame's own pixel lattice exactly
as a line does, with arc length in RegionSample::position.
Two control points is a straight line and measures exactly the
pixels Region::line does.
Repeating the first point as the last closes the curve, and a
closed curve is an area: it measures the pixels it encloses
and its position is NaN. Prefer Region::closed_spline,
which appends the repeat, over doing it by hand.
Errors
Returns Status::InvalidArgument if fewer than two points are
given, or more than 64, or the geometry is degenerate.
pub fn closed_spline(points: &[Vec2]) -> Result<Self>
A closed curve through points; do not repeat the first point,
as this appends it.
Region::spline with closure settled. At least three points.
Errors
Returns Status::InvalidArgument if fewer than three points
are given or the geometry is degenerate.
pub fn ring(centre: impl Into<Vec2>, outer: f32, inner: f32) -> Result<Self>
A ring: an outer circle with an inner one subtracted.
Errors
Returns Status::InvalidArgument if inner is not smaller
than outer.
pub fn set_name(&mut self, name: &str) -> Result<&mut Self>
Name the region.
Truncated to 63 bytes plus a terminator. Names need not be
unique, but crate::Camera::region_id_by_name returns the
first match, so unique names are easier to live with.
Errors
Returns Status::InvalidArgument if name contains an
interior NUL byte.
pub fn name(&self) -> Result<String>
What the region is called.
Reads through to the region, so one obtained from
crate::Camera::region reports what the camera holds
rather than an empty string.
Errors
pub fn shapes(&self) -> Result<Vec<RegionShape>>
The placed shapes the geometry is built from, in tree order.
One for every region the constructors build except a ring, which is a circle with a smaller circle subtracted and has two.
Errors
pub fn shape_points(&self, index: usize) -> Result<Vec<Vec2>>
The explicit points of one shape, in region coordinates: a
RegionPrimitive::Polygon's vertices, or a
RegionPrimitive::Spline's control points.
Already placed by the shape's own transform, so for a polygon these are the points to draw rather than the unit-space vertices the region was built from. The outline closes implicitly: the first point is not repeated. Empty, and not an error, for any other primitive.
For a spline these are not the points to draw. They are the
handles the curve passes through, and joining them up draws the
control polygon instead of the curve; use
Region::shape_curve. A closed spline's last control point
repeats its first, visibly, because that repeat is what closes
it.
Errors
Returns Status::InvalidArgument if index is past the end.
pub fn shape_curve(&self, index: usize) -> Result<Vec<Vec2>>
The drawable curve of one RegionPrimitive::Spline shape, in
region coordinates.
A polyline through the curve, already placed: the points to draw, joined in order with straight segments. It is the same polyline the SDK's own containment test walks, produced by the same code, so an overlay drawn from this cannot disagree with what was measured.
An open spline's list is to be drawn unclosed; a closed one's is
to be drawn closed, with the first point not repeated at the
end, the same convention Region::shape_points reports a
polygon's outline in. Empty, and not an error, for any other
primitive.
Errors
Returns Status::InvalidArgument if index is past the end.
pub fn set_kind(&mut self, kind: RegionKind) -> Result<&mut Self>
Set what the region is for.
Errors
Returns Status::InvalidArgument if the kind cannot apply to
this geometry.
pub fn set_emissivity(&mut self, emissivity: f32) -> Result<&mut Self>
Measure this region at its own emissivity rather than the camera's.
Zero, the default, means "use the camera's".
Errors
Returns Status::InvalidArgument for a value outside 0..=1.
pub fn set_enabled(&mut self, enabled: bool) -> Result<&mut Self>
Include the region in measurement.
A disabled region keeps its id and its rules but is not measured, and its statistics report invalid.
Errors
Returns Status::InvalidHandle if the builder is unusable.
pub fn want_percentiles(&mut self, enabled: bool) -> Result<&mut Self>
Compute percentiles as well as the base statistics.
Off by default, because it costs extra work on every frame.
Without it RegionStats::median_c stays zero.
Errors
pub fn want_samples(&mut self, enabled: bool) -> Result<&mut Self>
Keep the individual pixel readings this region takes, so
crate::Camera::region_samples can report them.
Off by default. Without it a region keeps none and the reader reports a count of zero rather than an error, so a caller who forgets this sees an empty profile, not a failure.
Errors
pub fn set_blob_config(&mut self, config: BlobConfig) -> Result<&mut Self>
Configure blob detection.
Meaningful only on a RegionKind::BlobGroup region; on any
other kind the settings are stored, saved and ignored. This does
not change the kind; that is Region::set_kind, and a
region's kind is the caller's decision rather than something a
setter should infer.
Errors
pub fn set_aperture(&mut self, aperture: Aperture) -> Result<&mut Self>
Set the sampling neighbourhood of a point region.
This changes the reported temperature. See Aperture.
Until API version 12 an aperture could only be attached at
construction, by Region::spot, and a tracked spot is built
the SDK's own way -- a point, then a change of kind, hung under
an area -- where there was nowhere to put one. Every hot and
cold spot made that way measured a single pixel and nothing
said so.
Errors
pub fn aperture(&self) -> Result<Aperture>
The region's sampling neighbourhood.
A region that was never given one reports
ApertureShape::Pixel, which is what it will measure.
Errors
pub fn set_search_range(&mut self, range: SpotSearchRange) -> Result<&mut Self>
Confine a tracked spot's search to a temperature band.
See SpotSearchRange. Honoured by RegionKind::HotSpot
and RegionKind::ColdSpot; stored and ignored on every other
kind, the same way a blob configuration is.
Errors
pub fn search_range(&self) -> Result<SpotSearchRange>
The region's search band, whether or not its kind honours one.
Errors
pub fn set_search_mode(&mut self, mode: SpotSearchMode) -> Result<&mut Self>
Whether a tracked spot searches over aperture averages or over single pixels.
See SpotSearchMode. Defaults to
SpotSearchMode::Aperture. With ApertureShape::Pixel the
two are identical, so a spot that was never given a size is
unaffected either way.
Errors
pub fn search_mode(&self) -> Result<SpotSearchMode>
What a tracked spot is looking for.
Errors
pub fn blob_config(&self) -> Result<BlobConfig>
The region's blob detection settings.
Returned whatever the kind, because that is what the region carries; whether they are acted on is what the kind decides.
Errors
pub fn set_style(&mut self, style: RegionStyle) -> Result<&mut Self>
Choose how the region is drawn in the overlay.
The style does not change what the region measures. Before API version 33 it did not cross the C ABI at all, so every region added from Rust drew with the defaults and a hot spot was indistinguishable from a cold spot in the picture.
Errors
pub fn style(&self) -> Result<RegionStyle>
How the region is drawn, as Region::set_style left it.
Reads through to the region itself, so a region this handle did not build reports what it actually carries.
Errors
pub fn set_threshold_config(&mut self, config: ThresholdConfig) -> Result<&mut Self>
Count this region's pixels past a limit, as well as measuring them.
Honoured by every kind that measures pixels, including the point kinds, where it describes the aperture.
Errors
pub fn threshold_config(&self) -> Result<ThresholdConfig>
The region's threshold-counting settings.
Errors
pub fn set_centre(&mut self, centre: impl Into<Vec2>) -> Result<&mut Self>
Move the region.
Errors
pub fn centre(&self) -> Result<Vec2>
Where the region currently is.
Errors
pub fn set_size(&mut self, size: impl Into<Vec2>) -> Result<&mut Self>
Resize the region, keeping its centre and rotation.
Errors
pub fn size(&self) -> Result<Vec2>
How large the region currently is.
Errors
pub fn set_rotation(&mut self, radians: f32) -> Result<&mut Self>
Rotate the region anticlockwise about its centre, in radians.
Errors
pub fn rotation(&self) -> Result<f32>
The region's current rotation, in radians.
Errors
pub fn kind(&self) -> Result<RegionKind>
What this region does with the pixels its shape encloses.
Errors
pub fn emissivity(&self) -> Result<f32>
This region's own emissivity.
Errors
pub fn is_enabled(&self) -> Result<bool>
Whether this region is measured at all.
Errors
pub fn wants_percentiles(&self) -> Result<bool>
Whether this region keeps percentiles.
Errors
pub fn wants_samples(&self) -> Result<bool>
Whether this region keeps its individual pixel readings.
See Region::want_samples.
Errors
pub fn copy_to_canvas(&self, placement: &crate::Placement) -> Result<Self>
This region, mapped through placement into canvas space.
A new region; the original is untouched. Use it for a region that should follow the picture as the view moves. One that should stay put on the canvas while the picture moves under it needs no mapping; that is what a canvas region already is.
A singular placement is accepted here, unlike
Region::copy_to_frame. This direction uses the forward
transform, which is defined even at zoom 0; the region simply
collapses, measured as centre (0.0, 0.0). Only the inverse
direction has nothing to answer.
pub fn copy_to_frame(&self, placement: &crate::Placement) -> Result<Self>
This region, mapped back through placement into the frame.
The inverse of Region::copy_to_canvas, and the direction the
SDK itself takes every time it measures a canvas region.
Errors
Status::InvalidArgument for a singular placement: zoom
0, or a matrix collapsed to a line. Measured: "the placement is
singular, so no canvas point names a frame point and the region
has no form in the frame". This is the asymmetry with
Region::copy_to_canvas, which accepts one.