OptrisOptrisDocumentation

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

optris::sdk::RegionStore

Public types

ReparentResult

enum ReparentResult

Why a reparent was refused.

Value Initialiser Description
kOk
kNoSuchRegion The region does not exist.
kNoSuchParent
kWouldCycle
kAlreadyThere It is already there. Not an error; nothing was changed.

Public functions

RegionStore

RegionStore()

~RegionStore

~RegionStore()

RegionStore

RegionStore(RegionStore &&) noexcept

operator=

auto operator=(RegionStore &&) noexcept -> RegionStore &

RegionStore

RegionStore(const RegionStore &)=delete

operator=

auto operator=(const RegionStore &) -> RegionStore &=delete

Add

auto Add(Region region) -> uint64_t

Add a region. Returns its id, or 0 if the geometry is invalid or exceeds the depth/node caps.

Adopt

auto Adopt(Region region) -> uint64_t

Add a region keeping the ids it already carries, for restoring a set that was numbered somewhere else -- the regions a recording was made with.

Add() mints the next id for the region and for every child, so restoring a recording's regions meant adding them and then rewriting the ids through Edit(). That left the store's own bookkeeping addressing the minted ids: the signal slot map stayed keyed on them, so SlotOf() answered for an id Get() could not find and missed the one it could, and the next-id counter was never moved past the file's ids. A recording whose regions were 3 and 7 restored as 1 and 2, was rewritten to 3 and 7, and left the counter at 3 -- so the first region the application added on that replay was handed id 3 as well, collided with a recorded region, and was overwritten by its record every frame.

This claims each id as it is: the slot map is keyed on it, and the counter is advanced past every id in the tree, so nothing minted afterwards can collide with the file.

An id of 0 is not a usable id -- it is the store's "no such region" value -- so a region or child carrying 0 is minted an id as Add() would. A document written by something that serialized a region before it was in a store holds exactly that.

Returns: the region's id, or 0 if the geometry is invalid, or if any id in the tree is already in this store. Adopting a duplicate id is refused rather than accepted, because the second one would be unreachable through Get() and would take the first one's signal slot with it.

AdoptId

void AdoptId(uint64_t id)

Claim an id that already sits in All() but did not go through Add() or Adopt(), so that it has a signal slot and the next minted id is above it.

Playback is the one caller: ApplyFrameState() pushes a region drawn while recording straight into the vector All() hands out, which is the only route into the store that does not pass through the id allocator. Such a region had no slot at all, so a rule could not reference it -- SignalSlot() answered nullopt for a region plainly present.

Does nothing for an id of 0 or one that already has a slot.

ReleaseId

void ReleaseId(uint64_t id)

Release the id and signal slot of a region that is no longer in All().

The counterpart of AdoptId(), for the same one caller: the playback prune erases from the vector All() returns, which does not go through Remove() and so never reached ReleaseIds(). The slot stayed claimed for a region that no longer existed, and SlotOf() went on answering for an id Get() could not find.

Does nothing for an id with no slot.

ReserveIdsBelow

void ReserveIdsBelow(uint64_t first_id)

Mint every id from here on at or above first_id.

For a store with two writers that must not meet: the regions a recording names, and the regions an application adds on the replay of it. Those are different id spaces that happened to share one counter, and an earlier fix covered only the part of the overlap that was visible at the moment the file opened.

Adopt() moves the counter past the ids the file opened with, which is every id the store can see. It cannot move it past the ids the take uses later -- a region drawn while recording is in the per-frame records and nowhere a reader can cheaply enumerate, and reading the whole record track at open is the whole-file read that was taken out of Open(). So an application's first region on a replay of a take that drew its fourth region mid-file was handed id 4, and on that frame it was renamed, moved and given the recorded readings.

Raising the floor instead is the reporter's own second suggestion and needs nothing read: ids the record can name come from the recorder's counter, which starts at 1 and steps once per region created, so a floor above anything that counter can reach cannot be named by any file. See kReplayRegionIdBase for the floor and why it is out of reach.

Monotonic, like every other mutation of the counter: a floor below where the store already is does nothing. Ids already in the store keep theirs.

AddChild

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

Add a region as a child of an existing one.

The child is measured through its parent's geometry: a RegionKind::kHotSpot child searches for the warmest pixel inside the parent rather than across the whole frame, and a spot's aperture is clipped to it. That is what makes "a spot that follows the hottest point inside this area" a region of its own, with its own id, its own statistics and its own alarm rules.

The child gets a stable id from the same allocator as a top-level region, keeps it until it is removed, and is reachable by it through Get(), Remove() and every per-id accessor. It is not a blob: blobs are per-frame detection results whose generational ids churn on every frame, which is why they are deliberately not children (see RegionEngine::Blobs). A child region is declared once, so a rule naming one is never orphaned by a frame.

Parameters

Name Description
parent_id Any existing region, top-level or itself a child.
child The region to nest. It is copied into the parent.

Returns: the child's id, or 0 if parent_id is unknown or the child's geometry is invalid. A kHotSpot or kColdSpot child carries no geometry of its own -- its position is wherever the extreme turns out to be -- and is exempt from that check.

ChildIds

auto ChildIds(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.

Remove

auto Remove(uint64_t id) -> bool

Reparent

auto Reparent(uint64_t id, uint64_t new_parent_id) -> ReparentResult

Move a region to a different parent, keeping its id.

Why this exists: Why this exists Before it, the only way to nest a region was to remove it and call AddChild() with a copy -- and AddChild() mints a fresh id. Every Rule naming the old id was then orphaned, silently, so nesting a measuring area quietly disabled its alarms. That made "reparenting changes the id" look like a rule of the design. It is not: RegionStore assigns ids from a counter that encodes nothing about parentage, and the generational signal slot is keyed by id rather than by position, so an id that does not change keeps its slot and its rules with it.

What is preserved: What is preserved The region's id, its signal slot, its rules, its children and its geometry. Geometry is in frame coordinates, not parent-relative -- a parent is the domain a tracked spot searches within and clips its aperture to, not a coordinate frame (see MeasureRegion). So a reparented region stays exactly where it was on the image, which is what somebody dragging a row in a list expects, and no transform is applied or needed.

What legitimately changes: What legitimately changes What the region measures, if it is a tracked kind. A RegionKind::kHotSpot searches within its parent, so moving it to a different parent -- or to the top level, where it searches the whole frame -- changes its reading. That is the point of the operation rather than a side effect, but a caller should expect the numbers to move.

Parameters

Name Description
id The region to move.
new_parent_id Its new parent, or 0 for the top level.

Returns: kOk on success. Nothing is changed on any other result.

WouldCycle

auto WouldCycle(uint64_t id, uint64_t candidate_parent) const -> bool

Whether candidate_parent is id itself or sits underneath it.

Exposed because a UI wants to know before it offers the drop, rather than after the drag has been made.

Clear

void Clear()

Get

auto Get(uint64_t id) -> Region *

Get

auto Get(uint64_t id) const -> const Region *

GetByName

auto GetByName(const std::string &name) -> Region *

All

auto All() const -> const std::vector< Region > &

All

auto All() -> std::vector< Region > &

Count

auto Count() const -> size_t

SlotOf

auto SlotOf(uint64_t id) const -> std::optional< uint32_t >

The packed generational slot for a region, for building a SignalId. Returns nullopt if the id is unknown.

IdOfSlot

auto IdOfSlot(uint32_t packed) const -> uint64_t

The region a packed slot refers to, or 0 if it is stale.

Measure

void Measure(const int16_t *thermal, uint32_t width, uint32_t height, const EmissivityResolver *radiometry=nullptr, const FrameMetadata *frame=nullptr)

Compute statistics for every enabled region.

radiometry is what makes Region::emissivity mean anything. Given one, a region carrying its own emissivity has every pixel it samples re-resolved at that value before it is accumulated, so its minimum, maximum, mean, median and standard deviation are all reported at the region's emissivity rather than the camera's. Given nullptr (the default, and what a standalone RegionStore gets), a per-region emissivity is not applied and every region is measured at whatever the frame already carries.

Pass nullptr deliberately when the pipeline has already applied the per-region value itself, so it is not applied twice. frame names the capture being measured, so RegionState can report which frame its statistics belong to. It travels with the pass rather than being set beside it: an identity written by a separate call could get out of step with the statistics it names, which is the defect this closes rather than a new place to open it.

nullptr -- the default, and what a standalone RegionStore gets -- means there is no capture behind these pixels, and then RegionState::has_frame_metadata reads false rather than claiming frame 0. That is why there is a flag at all: sequence 0 is a real frame, the first of the stream, so no sequence value can mean "nobody said" (the rule stated at raw_frame.h:36).

Measure

void Measure(const float *celsius, uint32_t width, uint32_t height, const EmissivityResolver *radiometry=nullptr, const FrameMetadata *frame=nullptr)

Compute statistics from float Celsius data.

Measure

void Measure(const int16_t *thermal, uint32_t width, uint32_t height, const MeasureSpace &space, const EmissivityResolver *radiometry=nullptr, const FrameMetadata *frame=nullptr)

Measure regions that are authored in some other space (a Canvas) by mapping them into this frame first. See MeasureSpace. The sampled values are the frame's own pixels either way; only the geometry crosses the boundary.

Measure

void Measure(const float *celsius, uint32_t width, uint32_t height, const MeasureSpace &space, const EmissivityResolver *radiometry=nullptr, const FrameMetadata *frame=nullptr)

ReadStates

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

Copy the per-frame state of every region into out. Returns the number written, which is min(Count(), capacity).

ReadStates

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

SamplesOf

auto SamplesOf(uint64_t id) const -> const std::vector< RegionSample > *

This frame's samples for one region, or nullptr if the id is unknown. Empty when the region did not ask for samples.

A pointer into the store, valid until the next Measure() or any edit -- copy what you need before either. RegionEngine::Samples() is the form to use on a live camera, where the frame thread is writing through this same vector.

BlobsOf

auto BlobsOf(uint64_t id) const -> const std::vector< RegionBlob > *

This frame's detected blobs for one region, or nullptr if the id is unknown. Empty for anything but a RegionKind::kBlobGroup.

A pointer into the store, valid until the next Measure() or any edit -- copy what you need before either. RegionEngine::Blobs() is the form to use on a live camera, where the frame thread is writing through this same vector.