Class TriggerBuffer

Captures incoming data windows into labelled segments, controlled by a trigger input. Stores both classification and regression labels uniformly as a per-frame MathNet.Numerics.LinearAlgebra.Matrix<T> of target values.

JSON configuration

Use these block entries inside a pipeline configuration. Input names must match other blocks in that pipeline; device addresses and file paths must match your setup.

Block entry for a larger pipeline. Params is not used. Capture must be a Trigger-compatible block that provides targets and start/stop events. Features supplies the matching observations. Completed segments can be used for batch training.

{
  "TriggerBuffer": {
    "Type": "triggerbuffer",
    "Inputs": ["Features", "Capture"]
  }
}

How Type, Inputs and Params work · Block catalogue and parameter reference

Inheritance
TriggerBuffer
Inherited Members
Namespace: MOSAIC.Models.FlowControl
Assembly: MOSAIC.dll
Syntax
public class TriggerBuffer : BaseBlock, INotifyPropertyChanged, INotifyPropertyChanging, ISubscriber, IPublisher, IBaseBlockProps, IJsonExportable, IDisposable, IAsyncDisposable
Remarks

Requires exactly two inputs in the pipeline JSON:

  1. A trigger block (first input). Sending a MathNet.Numerics.LinearAlgebra.Vector<T> starts / updates the active target; sending null stops the segment and finalises it. The sender is identified by class name containing "Trigger".
  2. A data provider (second input, e.g. SlidingWindow or MockUltrasoundSource). While capture is active, each published MathNet.Numerics.LinearAlgebra.Matrix<T> or MathNet.Numerics.LinearAlgebra.Vector<T> is accumulated as one data row in the segment.

Target shape — uniform across classification and regression. Each entry in dB has a MathNet.Numerics.LinearAlgebra.Matrix<T> Targets with one row per data row. For the classic click-driven Trigger block (which publishes the target Vector once on start), the buffer caches it as _currentTarget and queues an identical row for every data frame received during the segment — so classification consumers can read Targets.Row(0) and ignore the rest. For a streaming trigger (StreamTrigger, future DataGlove, etc.) that publishes a new target Vector each tick, the buffer queues whichever target is most recent at the moment each data row arrives — so regression consumers see a true per-frame target stream.

Constructors

TriggerBuffer(string)

Declaration
public TriggerBuffer(string name)
Parameters
Type Name Description
string name

Fields

_collecting

Active recording flag — toggled by trigger start / stop.

Declaration
private bool _collecting
Field Value
Type Description
bool

_currentLabel

Human-readable name attached to the segment, when known.

Declaration
private string _currentLabel
Field Value
Type Description
string

_currentTarget

Most recently received target vector. Held between trigger messages so that data frames arriving in between get labelled with the latest known target — this is what makes classic single-publish triggers and per-tick streaming triggers transparently interchangeable.

Declaration
private Vector<double>? _currentTarget
Field Value
Type Description
Vector<double>

_matrices

The data frames themselves; stacked vertically on stop.

Declaration
private readonly List<Matrix<double>> _matrices
Field Value
Type Description
List<Matrix<double>>

_targetRows

One row per captured data frame; finalised into a Matrix on stop.

Declaration
private readonly List<Vector<double>> _targetRows
Field Value
Type Description
List<Vector<double>>

Properties

JsonTypeName

Block type identifier for JSON serialization. Override for a custom name.

Declaration
protected override string JsonTypeName { get; }
Property Value
Type Description
string
Overrides
BaseBlock.JsonTypeName

MaxInputs

Needs exactly two inputs (e.g. a data stream + a Trigger/TriggerBuffer).

Declaration
public override int MaxInputs { get; }
Property Value
Type Description
int
Overrides
BaseBlock.MaxInputs

MinInputs

Needs exactly two inputs (e.g. a data stream + a Trigger/TriggerBuffer).

Declaration
public override int MinInputs { get; }
Property Value
Type Description
int
Overrides
BaseBlock.MinInputs

dB

All captured segments as (Label, Targets, Data) triples. Targets.RowCount equals the number of data frames received; the row at index k is the target that was active when data frame k arrived. For classification, every row is identical and consumers can use Targets.Row(0); for regression, rows vary across time.

Declaration
public List<(string Label, Matrix<double> Targets, Matrix<double> Data)> dB { get; }
Property Value
Type Description
List<(string Label, Matrix<double> Targets, Matrix<double> Data)>

Methods

Clear()

Clears all captured segments and resets state.

Declaration
public void Clear()

ConfigureInput(IServiceProvider, JsonModel)

Declaration
public static TriggerBuffer ConfigureInput(IServiceProvider sp, JsonModel m)
Parameters
Type Name Description
IServiceProvider sp
JsonModel m
Returns
Type Description
TriggerBuffer

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Declaration
public override void Dispose()
Overrides
BaseBlock.Dispose()

FormatVector(Vector<double>)

Declaration
private static string FormatVector(Vector<double> v)
Parameters
Type Name Description
Vector<double> v
Returns
Type Description
string

GetJsonParams()

Block-specific parameters for JSON. Override to provide custom parameters.

Declaration
protected override IReadOnlyList<object>? GetJsonParams()
Returns
Type Description
IReadOnlyList<object>

The values for Params, in the order this block's ConfigureInput reads them, or null when the block takes no parameters.

Overrides
BaseBlock.GetJsonParams()

HandleTrigger(object?, object?, string)

Declaration
private void HandleTrigger(object? sender, object? data, string senderName)
Parameters
Type Name Description
object sender
object data
string senderName

OnReceive(object, object?)

Processes incoming data from an upstream block. Must be implemented by derived classes.

Declaration
protected override void OnReceive(object sender, object? data)
Parameters
Type Name Description
object sender

The publishing block, or whatever else delivered the value.

object data
Overrides
BaseBlock.OnReceive(object, object)
Remarks

Called on the dispatching thread, not the UI thread.

RemoveSegment(int)

Removes a single segment from dB by index. Bounds-checked; silently no-ops if the index is out of range (e.g. the UI raced with a concurrent Clear()). Does NOT republish dB's count — downstream consumers only react to additions, and a deletion shouldn't force them to retrain mid-session.

Declaration
public bool RemoveSegment(int index)
Parameters
Type Name Description
int index

Zero-based index in dB.

Returns
Type Description
bool

true if a segment was removed.

ResetSegmentState()

Declaration
private void ResetSegmentState()

ResolveSegmentLabel(object?, string)

Pick a human-readable label for the segment from whichever trigger-like block sent the start message. The classic Trigger block exposes CurrentActionName (e.g. "THUMB"); a future StreamTrigger exposes SessionName instead. Try both via reflection so the buffer doesn't need a compile-time reference to either type; fall back to the sender's class name only if neither property exists or is empty.

Declaration
private static string ResolveSegmentLabel(object? sender, string fallbackTypeName)
Parameters
Type Name Description
object sender
string fallbackTypeName
Returns
Type Description
string

SaveToCsv(string)

Save all segments to CSV. Each row of output is one data frame with the corresponding target vector prepended: label, t0, t1, …, tD-1, d0, d1, …, dC-1.

Declaration
public void SaveToCsv(string filePath)
Parameters
Type Name Description
string filePath

StackVectorsAsRows(List<Vector<double>>)

Stack a list of equal-length vectors into a single matrix with one row per vector. Handles the case where vectors have differing lengths by padding shorter rows with zeros up to the widest vector seen.

Declaration
private static Matrix<double> StackVectorsAsRows(List<Vector<double>> rows)
Parameters
Type Name Description
List<Vector<double>> rows
Returns
Type Description
Matrix<double>

StartCapture(Vector<double>, string, object?)

Declaration
private void StartCapture(Vector<double> firstLabel, string senderName, object? sender)
Parameters
Type Name Description
Vector<double> firstLabel
string senderName
object sender

StopCapture()

Declaration
private void StopCapture()

Implements

INotifyPropertyChanged
INotifyPropertyChanging
ISubscriber
IPublisher
IBaseBlockProps
IJsonExportable
IDisposable
IAsyncDisposable

Search documentation

Start typing to search the documentation.