![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Stream/StreamRecorderAlgorithm.h>
Records multiple ImageStream and TrackingStream instances and optionally merges their results into one or more TrackedSharedImageSet objects. More...
Inheritance diagram for StreamRecorderAlgorithm:Records multiple ImageStream and TrackingStream instances and optionally merges their results into one or more TrackedSharedImageSet objects.
There are three modes for the recorded data to be saved to disk:
setSaveToFile(false)setSaveToFile(true) and setLiveStreamRecording(false)setSaveToFile(true) and setLiveStreamRecording(true)Modes 2 and 3 support both synchronous/blocking (takeOutput) and asynchronous/non-blocking (takeOutputAsync) saving of recorded data to disk once recording has finished.
In live saving mode (3), you can limit memory use by retaining only the last N frames in memory via setSaveStreamingFramesKeptInMemory(N).
takeOutput or takeOutputAsync will not contain the actual image data for those frames as their content was replaced with a placeholder.Example usage:
Classes | |
| struct | OwningDataListAsync |
| Helper class for managing recorded data together with a future to ensure that background saving tasks are complete before the data is deleted. More... | |
Public Types | |
| enum class | DataCombinationMode { Individual = 0 , All = 1 , FirstTracking = 2 , OneOnOne = 3 } |
| Specifies how image and tracking data should be combined when both types are recorded. More... | |
Public Types inherited from Algorithm | |
| enum | Status { Unknown = -1 , Success = 0 , Error = 1 , InvalidInput , IncompleteInput , OutOfMemoryHost , OutOfMemoryGPU , UnsupportedGPU , UnknownAction , AbortedByUser , User = 1000 } |
| Status codes. More... | |
Public Member Functions | |
| StreamRecorderAlgorithm (std::vector< Stream * > inputStreams) | |
| Constructs the recorder for multiple Stream objects. | |
| void | compute () override |
| Performs basic consistency checks, method itself is not involved in recording. | |
| OwningDataList | takeOutput () override |
| Returns all recorded data based on the configured combination mode. | |
| OwningDataListAsync | takeOutputAsync () |
| Returns recorded data along with a future for any pending background save tasks. | |
| virtual void | start () |
| Initializes individual StreamRecorder instances for each input stream and starts recording. | |
| virtual void | stop () |
| Stops all StreamRecorders and combines recorded output based on the selected combination mode. | |
| void | restart () |
| Restarts recording without clearing internal data. | |
| bool | isRestarting () const |
| Returns true if the algorithm is currently restarting. | |
| bool | isRecording () const |
| Returns true if any StreamRecorder is recording. | |
| void | configure (const Properties *p) override |
| Configure this object instance by de-serializing the given Properties. | |
| void | configuration (Properties *p) const override |
| Serialize the current object configuration into the given Properties object. | |
| int | recordedFrames () const |
| Returns total number of recorded image frames across all ImageStreamRecorders. | |
| int | recordedTrackingData () const |
| Returns total number of recorded tracking samples across all TrackingStreamRecorders. | |
| virtual size_t | recordedBytes () |
| Returns total memory usage for all recorded images and tracking data. | |
| double | passedTime () const |
| Returns the elapsed recording time of the current recording session, in seconds. | |
| bool | limitReached () const |
| Returns true if any recording limit (e.g. time, memory, sample count) has been reached in any of the StreamRecorders. | |
| StreamRecorder * | recorder (int which=0) const |
| Returns a specific StreamRecorder instance by index. | |
| int | numRecorders () const |
| Returns the number of StreamRecorder instances. | |
| TrackingStreamRecorder * | trackingRecorder (int which=0) const |
| Returns a TrackingStreamRecorder by index (only considers tracking recorders). | |
| ImageStreamRecorder * | imageRecorder (int which=0) const |
| Returns an ImageStreamRecorder by index (only considers image recorders). | |
| std::vector< Stream * > | recordedStreams () const |
| Returns all recorded Stream instances. | |
| TrackingStream & | trackingStream (int which=0) const |
| Returns a TrackingStream by index (only considers tracking streams). | |
| ImageStream & | imageStream (int which=0) const |
| Returns an ImageStream by index (only considers image streams). | |
| void | setTimestampSource (bool deviceImage=false, bool deviceTracking=false) |
| Configures which timestamp source to use for image and tracking streams. | |
| bool | trackingTimeUseDevice () const |
| Returns whether device timestamps are used for tracking streams. | |
| bool | imageTimeUseDevice () const |
| Returns whether device timestamps are used for image streams. | |
| std::vector< TrackingInstrument > | allTrackingDevices () |
| Returns a copy of all tracking instruments. | |
| std::vector< TrackingInstrument > | allTrackingInstruments () const |
| Returns all TrackingInstruments from all recorded TrackingStreams. | |
| void | setSaveToFile (bool save) |
Enables automatic saving of recorded data to m_savePath after recording ends. | |
| bool | saveToFile () const |
Returns true if automatic saving to m_savePath is enabled. | |
| bool | isDataBeingSaved (const Data *data) const |
| Returns true if the given data is currently being saved to disk. | |
| void | setSaveAsDicom (bool flag) |
| Enables saving of recorded data as DICOM. Disabled by default; ImFusion format is used otherwise. | |
| bool | saveAsDicom () const |
| Returns whether recorded data will be saved in DICOM format. | |
| void | setSavePath (std::string savePath) |
| Sets the base directory for saving recorded data. Data is saved to subfolders within this path. | |
| std::string | savePath () const |
| Returns the base save directory. | |
| void | setPatientName (std::string patientName) |
| Sets the patient name for data saving. Used in subfolder and filename generation. | |
| std::string | patientName () const |
| Returns the configured patient name. | |
| void | setPatientNameSuffix (std::string suffix) |
| Sets a suffix for the patient name (e.g., name-X-suffix). | |
| std::string | patientNameSuffix () const |
| Returns the patient name suffix. | |
| void | setNumberOfDataToKeep (int n) |
| Sets how many recent recordings to keep in the data widget. Use 0 to keep all. | |
| int | numberOfDataToKeep () const |
| Returns the number of recordings retained in the data widget. 0 means all are kept. | |
| void | setCompression (bool compress) |
| Deprecated: Enables compression before saving. Default is off. | |
| void | setCompressSave (bool save) |
| Enables compression for saved data. Ignored if saveStreamingFramesKeptInMemory is not Zero. | |
| bool | compressSave () const |
| Returns whether compression is enabled for saved data. Ignored if saveStreamingFramesKeptInMemory is not Zero. | |
| DataCombinationMode | dataCombinationMode () const |
| Returns the current data combination mode. | |
| void | setDataCombinationMode (DataCombinationMode m) |
| Sets how recorded data should be combined. See DataCombinationMode for available modes. | |
| void | setLimits (double timeLimitInSeconds, double systemMemLimit, int imageSamplesLimit, int trackingSamplesLimit, size_t recordedBytesLimit) |
| Sets recording constraints. Use zero to disable any given limit. | |
| double | timeLimit () const |
| Returns the time limit for recording in seconds. Zero indicates no limit. | |
| double | systemMemLimit () const |
| Returns the allowed ratio of RAM usage during recording (between 0 and 1). Zero indicates no limit. | |
| int | imageSamplesLimit () const |
| Returns the maximum number of image samples to record per ImageStreamRecorder. Zero disables the limit. | |
| int | trackingSamplesLimit () const |
| Returns the maximum number of tracking samples to record per TrackingStreamRecorder. Zero disables the limit. | |
| size_t | recordedBytesLimit () const |
| Returns the maximum number of bytes allowed for recording per StreamRecorder. Zero disables the limit. | |
| void | setTrackingQualityThreshold (double t) |
| Sets a quality threshold for tracking samples. Values below this threshold or NaN are excluded. | |
| double | trackingQualityThreshold () const |
| Returns the configured tracking quality threshold. | |
| void | setStopOnImageSizeChanged (bool flag) |
| Enables or disables stopping when the image size changes. | |
| bool | isStopOnImageSizeChanged () const |
| Returns true if recording stops when the image size changes. | |
| void | setStopOnDeviceListChanged (bool flag) |
| Specify whether to stop when the device list of a tracking stream changes. | |
| bool | isStopOnDeviceListChanged () const |
| Returns if the recording stops when the device list of a tracking stream changes. | |
| void | setStopOnInstrumentsChanged (bool flag) |
| Sets whether recording stops when currently recorded instrument is removed in a TrackingStream. | |
| bool | stopOnInsturmentsChanged () const |
| Returns true if recording stops when an instruments is removed in a TrackingStream. | |
| void | setRecordBothTimestamps (bool x) |
| Sets whether both arrival and device timestamps are recorded. | |
| bool | recordBothTimestamps () const |
| Returns true if both timestamps are recorded. | |
| void | setCaptureMode (StreamRecorder::CaptureMode captureMode) |
| Sets the capture mode. | |
| StreamRecorder::CaptureMode | captureMode () const |
| Returns the current capture mode. | |
| void | setCaptureNextSample () |
| Enables capturing the next sample. | |
| void | setLiveStreamRecording (bool x) |
Enables saving images during live recording. Requires saveToFile to be true. | |
| bool | liveStreamRecording () const |
| Returns true if images are saved during live recording. | |
| void | setSaveStreamingFramesKeptInMemory (int val) |
| Specifies how many frames to retain in memory during recording. Use -1 for no limit. | |
| int | saveStreamingFramesKeptInMemory () const |
| Returns the number of frames retained in memory. -1 means unlimited. | |
| void | setSaveRecordingsAsync (bool flag) |
| Enables asynchronous saving after recording ends. | |
| bool | saveRecordingsAsync () const |
| Returns true if asynchronous saving is enabled. | |
| void | setAutomaticLimitRestart (bool flag) |
| Enables automatic restart of the recording into new containers if recording stops due to a limit being exceeded. | |
| bool | automaticLimitRestart () const |
| Returns true if automatic restart is enabled after a limit being exceeded. | |
| void | setAutomaticImageChangeRestart (bool flag) |
| Enables automatic restart of the recording into new containers when images in ImageStream change (e.g., size, type, channels, number of images). | |
| bool | automaticImageChangeRestart () const |
| Returns true if restart on image stream changes is enabled. | |
Public Member Functions inherited from Algorithm | |
| Algorithm () | |
| Default constructor will registers a single "compute" action that calls compute() and returns status(). | |
| virtual void | setProgress (Progress *progress) |
| Sets a Progress interface the algorithm can use to notify observers about its computing progress. | |
| Progress * | progress () const |
| Returns the progress interface if set. | |
| virtual int | status () const |
| Indicates the status of the last call to compute(). | |
| virtual bool | survivesDataDeletion (const Data *) const |
| Indicates whether the algorithm can handle (partial) deletion of the specified data, by default this checks whether the data is in the input list. | |
| const FactoryInfo & | factoryInfo () const |
| Returns the record describing how this Algorithm was instantiated by the AlgorithmFactory. | |
| void | setFactoryInfo (const FactoryInfo &value) |
| Sets the record describing how this Algorithm was instantiated by the AlgorithmFactory. | |
| Status | runAction (const std::string &id) |
Run the action with name id if it exists. | |
| const std::vector< Action > & | actions () |
| Get a mapping from Action id to Action as registered in this algorithm. | |
Public Member Functions inherited from Configurable | |
| virtual void | configureDefaults () |
| Retrieve the properties of this object, replaces values with their defaults and sets it again. | |
| void | registerParameter (ParameterBase *param) |
| Register the given Parameter or SubProperty, so that it will be configured during configure()/configuration(). | |
| void | unregisterParameter (const ParameterBase *param) |
| Remove the given Parameter or SubProperty from the list of registered parameters. | |
| Configurable (const Configurable &rhs) | |
| Configurable (Configurable &&rhs) noexcept | |
| Configurable & | operator= (const Configurable &) |
| Configurable & | operator= (Configurable &&) noexcept |
Public Member Functions inherited from SignalReceiver | |
| SignalReceiver ()=default | |
| Default constructor. | |
| SignalReceiver (const SignalReceiver &other) | |
| Copy constructor, does not copy any existing signal connections from other. | |
| SignalReceiver & | operator= (SignalReceiver rhs) |
| Assignment operator, disconnects all existing connections, does not copy any existing signal connections from rhs. | |
| virtual | ~SignalReceiver () |
| Virtual destructor disconnects from all connected signals. | |
Static Public Member Functions | |
| static bool | createCompatible (const DataList &data, Algorithm **a=nullptr) |
Static Public Member Functions inherited from Algorithm | |
| static bool | createCompatible (const DataList &data, Algorithm **a=nullptr) |
| Factory function to check algorithm compatibility with input data and optionally instantiate it. | |
Protected Member Functions | |
| std::unique_ptr< StreamRecorder > | createRecorderForStream (Stream *stream) |
| Creates a suitable recorder for the given stream and attaches listeners for byte count and limit events. | |
| void | addEventListenersToRecorder (StreamRecorder *rec) |
| Connects signals from created StreamRecorder instances so that statistics are reflected in the UI. | |
| virtual OwningDataList | outputInternal (std::function< std::unique_ptr< TrackedSharedImageSet >()> containerFactory) |
| Combines recorded data based on the configured combination mode using a container factory. | |
| void | saveRecordedData (const OwningDataList &odl) |
Saves recorded data. Uses blocking or asynchronous saving depending on m_saveRecordingsAsync. | |
| virtual std::future< void > | saveRecordedDataAsync (const DataList &dataList, const std::vector< std::string > &paths) |
| Asynchronously saves data. Override in derived classes for custom saving behavior. | |
| virtual void | saveRecordedDataBlocking (const DataList &dataList, const std::vector< std::string > &paths) |
| Synchronously saves data. Override in derived classes for custom saving behavior. | |
| virtual void | extractRecordedData () |
Collects recorded data from internal recorders and stores it in m_lastRecordedData. | |
Protected Member Functions inherited from Algorithm | |
| void | loadDefaults () |
| void | registerAction (const std::string &id, const std::string &guiName, const std::function< Algorithm::Status(void)> &action) |
| Register an action to be run via runAction. | |
| template<typename D> | |
| void | registerAction (const std::string &id, const std::string &guiName, Algorithm::Status(D::*action)(void)) |
| Template version of runAction that can be used with a pointer to a member function. | |
| void | registerAction (const Action &action) |
| Register an action. | |
Protected Member Functions inherited from SignalReceiver | |
| void | disconnectAll () |
| Disconnects all existing connections. | |
Protected Attributes | |
| std::vector< Stream * > | m_inputStreams |
| Input streams (mapped 1:1 to m_streamRecorders) | |
| std::vector< std::unique_ptr< StreamRecorder > > | m_streamRecorders |
| Recorders for input streams. | |
| std::recursive_mutex | m_mutexRecorders |
| Mutex to protect recorder manipulation. | |
| std::mutex | m_mutexCtrlUpdate |
| Mutex to protect signal emission to controllers. | |
| DataCombinationMode | m_combinationMode = DataCombinationMode::Individual |
| How recorded data is combined. | |
| std::string | m_savePath |
| Directory for saving recorded data. | |
| std::string | m_patientName = "Patient-01" |
| Subfolder and filename for saved data. | |
| std::string | m_patientNameSuffix = "" |
| Optional suffix added to filenames. | |
| bool | m_saveToFile = true |
| If true, saved automatically to file in background thread. | |
| bool | m_saveAsDicom = false |
| If true, data saved in DICOM format; otherwise in ImFusion format. | |
| int | m_numberOfDataToKeep = 1 |
| Number of recent recordings retained in data widget (default: 1) | |
| bool | m_compressSave = false |
| If true, data compressed before saving. | |
| bool | m_useDeviceTracking = false |
| If true, use device timestamps for tracking, otherwise arrival timestamps. | |
| bool | m_useDeviceImages = false |
| If true, use device timestamps for images, otherwise arrival timestamps. | |
| double | m_timeLimit = 0 |
| Time-based recording limit (seconds) | |
| double | m_systemMemLimit = 0 |
| Max ratio of used physical RAM (0 = unlimited) | |
| int | m_imageSamplesLimit = 0 |
| Max number of image frames to record (per recorder) | |
| int | m_trackingSamplesLimit = 0 |
| Max number of tracking samples to record (per recorder) | |
| size_t | m_recordedBytesLimit = 0 |
| Max number of bytes to record. | |
| double | m_trackingQualityThreshold = 0.2 |
| Quality threshold for tracking samples, samples below threshold (or NaN) are not recorded. | |
| bool | m_stopOnImageSizeChanged = true |
| Stops recording when image dimensions change in the stream. | |
| bool | m_restartRecordingOnImageDescriptorsChanged = false |
| If true, restarts recording automatically when the image structure (size, number of channels, frame count) changes. | |
| bool | m_stopOnInstrumentsChanged = true |
| If true, stops recording when instruments change in a TrackingStream. | |
| bool | m_limitRestartRecording = false |
| If true, automatically restarts recording when any limit criterion is exceeded. | |
| bool | m_recordBothTimestamps = false |
| If true, saves both arrival and device timestamps in data components. | |
| StreamRecorder::CaptureMode | m_captureMode = StreamRecorder::CaptureMode::CaptureAll |
| Selected mode for sample capturing. | |
| bool | m_saveRecordingsAsync = true |
| If true, recorded data is saved asynchronously, otherwise block (both in a background thread) | |
| bool | m_liveStreamRecording = false |
| If true, enables live recording of image streams during acquisition. Requires m_saveToFile = true. | |
| int | m_saveStreamingFramesKeptInMemory |
| Number of image frames retained in memory during live recording. -1 indicates unlimited retention. | |
| std::unique_ptr< BackgroundExporter > | m_exporter |
| Exporter for the saving task after recording. | |
Protected Attributes inherited from Algorithm | |
| std::string | m_name |
| Algorithm name. | |
| Progress * | m_progress = nullptr |
| Non-owing pointer to a progress interface. May be a nullptr. | |
| FactoryInfo | m_factoryInfo = {} |
| Record describing how this algorithm was instantiated by the AlgorithmFactory. | |
| int | m_status = Status::Unknown |
| Algorithm status after last call to compute() | |
| std::vector< Action > | m_actions |
| Map of key given by the id of the action, of the available actions of this algorithm. | |
Protected Attributes inherited from Configurable | |
| std::vector< Param > | m_params |
| List of all registered Parameter and SubProperty instances. | |
Additional Inherited Members | |
Public Attributes inherited from Algorithm | |
| Signal | signalOutputChanged |
| Signal should be emitted by Algorithms when their output/result has changed. | |
| Signal | signalParametersChanged |
| Signal should be emitted by Algorithms when their parameter configuration has changed. | |
Public Attributes inherited from Configurable | |
| Signal | signalParametersChanged |
Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted. | |
|
strong |
Specifies how image and tracking data should be combined when both types are recorded.
| Enumerator | |
|---|---|
| Individual | Default: No merging. One SharedImageSet is created per image in each ImageStream, and one TrackingSequence per TrackingInstrument in each TrackingStream. |
| All | All recorded images are returned in the form of TrackedSharedImageSets, each containing a copy of all TrackingSequences. |
| FirstTracking | Each recorded SharedImageSet receives a copy of the first TrackingSequence (first instrument of the first TrackingStream) and is returned as TrackedSharedImageSet. Remaining instruemnts are recorded separately as TrackingSequences.
|
| OneOnOne | Combines SharedImageSet and TrackingSequence pairwise into a TrackedSharedImageSets, originating from the first image from the first ImageStream and first TrackingInstrument from the first TrackingStream, the same with the second image and tracking instrument, etc. Remaining image or tracking data is recorded individually.
|
| StreamRecorderAlgorithm | ( | std::vector< Stream * > | inputStreams | ) |
Constructs the recorder for multiple Stream objects.
Only ImageStream and TrackingStream types are considered; others are ignored.
|
overridevirtual |
Performs basic consistency checks, method itself is not involved in recording.
Implements Algorithm.
|
overridevirtual |
Returns all recorded data based on the configured combination mode.
Blocks if data is still being saved in the background. Use takeOutputAsync() for non-blocking retrieval. Returned data is sorted by time, newest first, if recording has been performed more than once.
Reimplemented from Algorithm.
| OwningDataListAsync takeOutputAsync | ( | ) |
Returns recorded data along with a future for any pending background save tasks.
If no save tasks exist or saving is synchronous, the future will be empty. Check future.valid() and call future.wait() before deleting the data. Data is sorted by time, newest first.
|
virtual |
Initializes individual StreamRecorder instances for each input stream and starts recording.
Clears internal buffers prior to starting.
|
virtual |
Stops all StreamRecorders and combines recorded output based on the selected combination mode.
If setSaveToFile(true) is used, data is saved synchronously or asynchronously depending on m_saveRecordingsAsync.
|
overridevirtual |
Configure this object instance by de-serializing the given Properties.
The default implementation will do so automatically for all registered Parameter and SubProperty instances.
Reimplemented from Configurable.
Reimplemented in SweepRecorderAlgorithm.
|
overridevirtual |
Serialize the current object configuration into the given Properties object.
The default implementation will do so automatically for all registered Parameter and SubProperty instances.
Reimplemented from Configurable.
Reimplemented in SweepRecorderAlgorithm.
| TrackingStream & trackingStream | ( | int | which = 0 | ) | const |
Returns a TrackingStream by index (only considers tracking streams).
| std::range_error | if the specified index which is negative or exceeds the number of available tracking streams. |
| ImageStream & imageStream | ( | int | which = 0 | ) | const |
Returns an ImageStream by index (only considers image streams).
| std::range_error | if the specified index which is negative or exceeds the number of available image streams. |
| void setTimestampSource | ( | bool | deviceImage = false, |
| bool | deviceTracking = false ) |
Configures which timestamp source to use for image and tracking streams.
| deviceImage | Use device timestamp in ImageStreamRecorder if true, arrival time otherwise. |
| deviceTracking | Use device timestamp in TrackingStreamRecorder if true, arrival time otherwise. |
| std::vector< TrackingInstrument > allTrackingDevices | ( | ) |
Returns a copy of all tracking instruments.
| void setSaveToFile | ( | bool | save | ) |
Enables automatic saving of recorded data to m_savePath after recording ends.
Saving occurs in a background thread.
| void setCompression | ( | bool | compress | ) |
Deprecated: Enables compression before saving. Default is off.
| void setStopOnImageSizeChanged | ( | bool | flag | ) |
Enables or disables stopping when the image size changes.
| bool isStopOnImageSizeChanged | ( | ) | const |
Returns true if recording stops when the image size changes.
| void setStopOnDeviceListChanged | ( | bool | flag | ) |
Specify whether to stop when the device list of a tracking stream changes.
| bool isStopOnDeviceListChanged | ( | ) | const |
Returns if the recording stops when the device list of a tracking stream changes.
| void setStopOnInstrumentsChanged | ( | bool | flag | ) |
Sets whether recording stops when currently recorded instrument is removed in a TrackingStream.
If false, the resulting TrackingSequences may vary in length and recording duration.
| void setRecordBothTimestamps | ( | bool | x | ) |
Sets whether both arrival and device timestamps are recorded.
If true, the recorded data contains elementwise TimestampDataComponents.
| void setCaptureMode | ( | StreamRecorder::CaptureMode | captureMode | ) |
Sets the capture mode.
| void setCaptureNextSample | ( | ) |
Enables capturing the next sample.
|
protectedvirtual |
Combines recorded data based on the configured combination mode using a container factory.
| containerFactory | Factory function for creating TrackedSharedImageSet instances. Override output() to use this method with custom data container types (e.g., ultrasound sweeps). |
Reimplemented in SweepRecorderAlgorithm.
|
protectedvirtual |
Asynchronously saves data. Override in derived classes for custom saving behavior.
Reimplemented in SweepRecorderAlgorithm.
|
protectedvirtual |
Synchronously saves data. Override in derived classes for custom saving behavior.
Reimplemented in SweepRecorderAlgorithm.
|
protected |
Stops recording when image dimensions change in the stream.
|
protected |
Number of image frames retained in memory during live recording. -1 indicates unlimited retention.