OptrisOptrisDocumentation

Documentation/OTC SDK/OTC SDK — C++ API referencev12.0

optris::sdk::RegionEngine

The measuring areas on the image.

A handle, not an owner: it refers to the regions of one imager and is only valid while that imager is. Reached through Imager::Regions(), the way Imager::GetPif() reaches the PIF.

Every accessor takes the same lock the frame thread holds while it measures, so editing geometry while frames arrive is safe.

Public functions

RegionEngine

RegionEngine(ClientBridge *bridge)

Add

auto Add(Region region) -> uint64_t

Add a region. Returns its id, or 0 if the geometry is invalid. Children (hot/cold spots, blob groups) get ids of their own, so a rule can name one.

AddChild

auto AddChild(uint64_t parent_id, Region child) -> uint64_t

Add a region as a child of an existing one.

A child is measured through its parent's geometry: a RegionKind::kHotSpot child follows the warmest pixel inside the parent rather than across the whole frame, and a spot's aperture is clipped to it. Without this a hot-spot region could only track the whole scene, which is the scene-wide case and not the one an application usually wants.

The child is a region in every other respect: its own id, its own RegionStats, its own rules, its own name. It is reachable by that id through Get(), Edit(), Remove(), Samples(), Percentiles() and SignalSlot(), all of which already search the whole tree.

A child is not a blob. Blobs are per-frame detection results whose generational ids churn on every frame, which is exactly why they are deliberately not children -- see Blobs(). A child region is declared once and keeps its id until it is removed, so a rule naming one is never orphaned by a frame. The two are different things and the reasoning against one does not carry to the other.

Children do not appear in States(). A child's alarm already rolls up into its parent's RegionState, so listing it separately would count it twice in anything that sums the list. Enumerate them with Children() and read each one through Get().

Parameters

Name Description
parent_id Any existing region, top-level or itself a child.
child The region to nest. A kHotSpot or kColdSpot child needs no geometry -- its position is wherever the extreme turns out to be.

Returns: the child's id, or 0 if parent_id is unknown or the child's geometry is invalid.

Children

auto Children(uint64_t parent_id) const -> std::vector< uint64_t >

The ids of one region's direct children, in the order they were added.

Empty for a region with none, and for an unknown id -- the two are not distinguished, because "this region has no children" is the answer to both as far as a caller walking the tree is concerned. Use Get() when the difference matters.

Remove

auto Remove(uint64_t id) -> bool

Remove a region and every rule attached to it.

Edit

auto Edit(uint64_t id, const std::function< void(Region &)> &mutate) -> bool

Edit a region in place.

This is how a UI drags a region: the callback runs under the same lock the frame thread takes to measure. There is no remove-and-re-add, no id churn, and the region's signal slot -- and therefore every rule on it -- stays valid.

const auto id = imager->Regions().Add(Region::Rect({0.5F, 0.375F},
                                                   {0.2F, 0.2F}));
const Vec2 cursor{0.6F, 0.4F};
imager->Regions().Edit(id, [&](Region &r) { r.SetCentre(cursor); });

The callback must not call back into the imager: it runs with the region lock held.

Returns: false if the id is unknown.

Get

auto Get(uint64_t id) const -> std::optional< Region >

A copy of one region, including its current readings.

FindId

auto FindId(const std::string &name) const -> uint64_t

The id of the region with this name, or 0 if there is none.

List

auto List() const -> std::vector< Region >

Count

auto Count() const -> size_t

The number of regions. Cheaper than List().size(), which copies every region to count them.

Clear

void Clear()

States

auto States() const -> std::vector< RegionState >

Per-frame read-back for a live HUD: one lock, one copy of a dense array. Nothing to walk, nothing to hash.

ReadStates

auto ReadStates(RegionState *out, size_t capacity) const -> size_t

No-allocation overload. Returns the number written.

Samples

auto Samples(uint64_t id) const -> std::optional< std::vector< RegionSample > >

The individual pixel readings one region took on the most recent frame: the temperature profile along a line, for a chart.

Empty unless the region was added with Region::want_samples set; nothing is kept for a region that did not ask, because an area region can cover the whole frame. Ordered along the segment for a line and in scan order otherwise; see RegionSample, which also says how an unmeasurable pixel is reported.

Returns: nullopt if the id is unknown. An empty vector means the region exists and has no samples (because it did not ask for them, because it is disabled, or because no frame has arrived), which is a different answer from "no such region".

ReadSamples

auto ReadSamples(uint64_t id, RegionSample *out, size_t capacity, size_t *out_total) const -> bool

No-allocation overload, taken under the same lock.

Parameters

Name Description
id The region to read.
out Where to write, or nullptr to ask only for the count.
capacity How many samples out holds.
out_total Receives the number the region has, which can exceed capacity; the first capacity are then written.

Returns: false if the id is unknown, leaving out_total alone.

Blobs

auto Blobs(uint64_t id) const -> std::optional< std::vector< RegionBlob > >

The blobs one RegionKind::kBlobGroup region found on the most recent frame.

Empty for any other kind, and empty for a blob group that found nothing or has not yet seen a frame. Configure detection through Region::blobs before adding the region, or through Edit(); see BlobConfig for the band and the size limits, and RegionBlob for the coordinates a result is reported in.

Blobs are results, not children: nothing is added to Region::children, no region id churns, and no rule is orphaned. They also carry no identity across frames -- alarm on SignalField::kBlobCount, which publishes this vector's size, not on an individual blob.

Returns: nullopt if the id is unknown. An empty vector means the region exists and found nothing, which is a different answer from "no such region".

ReadBlobs

auto ReadBlobs(uint64_t id, RegionBlob *out, size_t capacity, size_t *out_total) const -> bool

No-allocation overload, taken under the same lock. Contours are not copied by this form -- a RegionBlob's outline is a vector of its own, and a fixed-size record cannot carry one. Use Blobs() when the outline is wanted.

Parameters

Name Description
id The region to read.
out Where to write, or nullptr to ask only for the count.
capacity How many blobs out holds.
out_total Receives the number the region found, which can exceed capacity; the first capacity are then written.

Returns: false if the id is unknown, leaving out_total alone.

Percentiles

auto Percentiles(uint64_t id) const -> std::optional< RegionPercentiles >

One region's percentiles for the most recent frame.

Computed only when the region was added with Region::want_percentiles set, because it costs extra work per frame; without it the returned RegionPercentiles::valid is false rather than the fields being zeroes that look like temperatures.

Returns: nullopt if the id is unknown.

ThresholdShare

auto ThresholdShare(uint64_t id) const -> std::optional< RegionThresholdShare >

How much of one region was past its threshold on the most recent frame.

Computed only when the region was added with Region::threshold enabled; without it the returned RegionThresholdShare::valid is false rather than a share of zero that reads as "none of it was hot".

Returns: nullopt if the id is unknown.

SignalSlot

auto SignalSlot(uint64_t region_id) const -> std::optional< uint32_t >

The packed generational signal slot of a region, for building a SignalId by hand. Rules added via Rules().Add(region_id, rule) do not need this: their own input is resolved on add and again on update. Reach for it to name a different region -- an inhibit that silences a rule while some other area is hot.

A runtime handle, not an identity: it changes when the region is removed and re-added. Resolve it where you use it. Never zero, which is why zero is usable as "unresolved".

IsFromRecording

auto IsFromRecording(uint64_t id) const -> bool

Whether this region belongs to the recording being replayed, as against having been added on the playback handle afterwards.

The question an application reviewing footage has to answer about every region it is shown: a recorded region is the file's statement about what was measured, and one the operator drew during the review is the operator's. They look identical through Get().

Why this is a call and not arithmetic on the id. Regions added on a replay are numbered from kReplayRegionIdBase, so "a low id is the recording's" happens to be true today -- and it is a numbering convention, not a promise, which is the difference between code that works and code that is right. It is also not the whole answer even now: a region born mid-replay from a per-frame record is the recording's, carries a recorded id, and did not exist when the file was opened; and one the take deleted stops being the recording's on the frame it goes. An id comparison sees neither. This reads the set ApplyFrameState() prunes by, so this answer and the pruning decision cannot disagree.

False on a live camera, on a still and for an unknown id, and in all three cases as a fact rather than a special case: the owned set is engaged only by a Player, so there is nothing a recording owns anywhere else. Regions().IsFromRecording(id) is therefore safe to call from code that does not know which kind of source it is holding, which is the whole point of its being here rather than on Player.

Not a statement about whether the region can be edited: a replay accepts an edit to a recorded region. The next record that names it sets again what the recording states (where the region is, its shape, name, style and emissivity, and its minimum, maximum, mean, coverage and alarm state), so an edit to any of those lasts one frame. Which optional statistics it computes (Region::want_percentiles for the median and percentiles, Region::threshold, Region::want_samples) is the application's once the application changes it: the replay computes them from the recorded temperatures, and no record changes the choice after that, including when a seek removes the region and a later record brings it back. A computed statistic is withheld (NaN, valid false) where it could not be of the same thing as the recorded readings: on a frame the record says the region was not measured, and for a region with an emissivity of its own whose recorded pixels do not carry it. There is no way to detach a region from its record.

BuildFrameRecord

auto BuildFrameRecord() -> std::string

Serialize the current per-frame record: the leaf matrices of any region that moved since the last call, plus every region's readings and alarm state.

Returns an empty string when there are no regions. Stateful: it compares against the previous call, which is what lets a static region cost a couple of dozen bytes a frame instead of a re-dump of the whole model. The recorder calls this once per frame while recording; call it yourself only if you are writing your own capture path.

ApplyFrameRecord

void ApplyFrameRecord(const std::string &record)

Apply a record produced by BuildFrameRecord(), restoring region geometry, readings and alarm state. Used by playback.