iVS3D v2.0.9
Loading...
Searching...
No Matches
MaskCommand Class Reference

Generates masks asynchronously via PluginThread and writes them to disk. More...

#include <maskcommand.h>

Inheritance diagram for MaskCommand:
ImageCommand

Public Member Functions

 MaskCommand (const MaskRecord *record, Resolution exportResolution, ROI roi, QString folder, PluginThread *pluginThread, volatile bool *stopped=nullptr)
 Constructs a MaskCommand for async mask generation.
 
std::optional< QString > execute (ImageContext &ctx) override
 Requests mask generation and waits for result before writing to disk.
 
void onMaskFinished (const MaskGenerationResult &result)
 Receives completed mask from PluginThread (to be called by external connection).
 

Private Member Functions

tl::expected< cv::Mat, QString > waitForMask (uint imageIndex, int timeoutMs=30000)
 Waits for a specific mask to arrive from PluginThread.
 

Detailed Description

Generates masks asynchronously via PluginThread and writes them to disk.

Unlike TransformCommand which processes synchronously, MaskCommand:

  • Sends async mask generation requests to PluginThread
  • Blocks in execute() until the mask for the current image arrives
  • Tracks pending mask count to prevent overwhelming the plugin thread
  • Writes generated masks to disk
Author
Dominik Wüst
Date
February 2026

Constructor & Destructor Documentation

◆ MaskCommand()

MaskCommand::MaskCommand ( const MaskRecord record,
Resolution  exportResolution,
ROI  roi,
QString  folder,
PluginThread pluginThread,
volatile bool *  stopped = nullptr 
)

Constructs a MaskCommand for async mask generation.

Parameters
recordThe MaskRecord containing plugin name and settings
exportResolutionThe resolution for the export
roiThe region of interest
folderThe output folder for masks
pluginThreadThe PluginThread for async processing

Member Function Documentation

◆ execute()

std::optional< QString > MaskCommand::execute ( ImageContext ctx)
overridevirtual

Requests mask generation and waits for result before writing to disk.

Parameters
ctxThe image context
Returns
Error message if any, std::nullopt on success

Implements ImageCommand.

◆ onMaskFinished()

void MaskCommand::onMaskFinished ( const MaskGenerationResult result)

Receives completed mask from PluginThread (to be called by external connection).

Parameters
resultThe mask generation result

◆ waitForMask()

tl::expected< cv::Mat, QString > MaskCommand::waitForMask ( uint  imageIndex,
int  timeoutMs = 30000 
)
private

Waits for a specific mask to arrive from PluginThread.

Blocks the calling thread until the mask for the specified image arrives via onMaskFinished() callback, or until the timeout expires.

Parameters
imageIndexThe image index to wait for
timeoutMsTimeout in milliseconds (default 30000ms = 30 seconds). This provides a safety window to detect hung plugin operations. 30 seconds is sufficient for most GPU and CPU-based mask generation but will catch genuine failures (crashes, GPU errors).
Returns
Expected with the mask on success, or unexpected with error message on failure

The documentation for this class was generated from the following files: