Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
QmitkDataGeneratorBase Class Referenceabstract

Base class that orchestrates asynchronous data generation for image/ROI pairs. More...

#include <QmitkDataGeneratorBase.h>

Inheritance diagram for QmitkDataGeneratorBase:
Collaboration diagram for QmitkDataGeneratorBase:

Public Types

using JobResultMapType = QmitkDataGenerationJobBase::ResultMapType
 Alias for the result map type produced by generation jobs. More...
 

Public Slots

void SetDataStorage (mitk::DataStorage *storage)
 Sets the data storage for monitoring, storing WIP placeholders, and final results. More...
 
void SetAutoUpdate (bool autoUpdate)
 Enables or disables automatic update on data changes. More...
 

Signals

void DataGenerationStarted (const mitk::DataNode *imageNode, const mitk::DataNode *roiNode, const QmitkDataGenerationJobBase *job) const
 Emitted when a data generation job is started for outdated or missing data. More...
 
void NewDataAvailable (mitk::DataStorage::SetOfObjects::ConstPointer data) const
 Emitted when new final result data has been produced and added to the data storage. More...
 
void GenerationFinished () const
 Emitted when all generation jobs have finished and all results are up to date. More...
 
void JobError (QString error, const QmitkDataGenerationJobBase *failedJob) const
 Emitted when a generation job encounters an error. More...
 

Public Member Functions

 QmitkDataGeneratorBase (const QmitkDataGeneratorBase &other)=delete
 
QmitkDataGeneratorBase & operator= (const QmitkDataGeneratorBase &other)=delete
 
virtual ~QmitkDataGeneratorBase ()
 
mitk::DataStorage::Pointer GetDataStorage () const
 Returns the data storage used by this generator. More...
 
bool GetAutoUpdate () const
 Returns whether automatic updates are enabled. More...
 
bool IsGenerating () const
 Returns whether data generation jobs are currently running or pending. More...
 
bool Generate () const
 Checks data validity and triggers generation of missing or outdated data. More...
 
virtual bool IsValidResultAvailable (const mitk::DataNode *imageNode, const mitk::DataNode *roiNode) const =0
 Checks whether a valid final result exists for the given image and ROI. More...
 

Protected Types

using InputPairVectorType = std::vector< std::pair< mitk::DataNode::ConstPointer, mitk::DataNode::ConstPointer > >
 Vector of image/ROI node pairs used as input for generation. More...
 

Protected Slots

void OnJobError (QString error, const QmitkDataGenerationJobBase *failedJob) const
 Handles error signals from generation jobs and re-emits JobError. More...
 
void OnFinalResultsAvailable (JobResultMapType results, const QmitkDataGenerationJobBase *job) const
 Handles completed job results, adds them to the data storage, and emits NewDataAvailable. More...
 

Protected Member Functions

 QmitkDataGeneratorBase (mitk::DataStorage::Pointer storage, QObject *parent=nullptr)
 Constructs a generator with the given data storage. More...
 
 QmitkDataGeneratorBase (QObject *parent=nullptr)
 Constructs a generator without an initial data storage. More...
 
virtual bool ChangedNodeIsRelevant (const mitk::DataNode *changedNode) const =0
 Determines whether a changed data node is relevant and should trigger a regeneration. More...
 
virtual InputPairVectorType GetAllImageROICombinations () const =0
 Returns all image/ROI pairs for which data generation is needed. More...
 
virtual void IndicateFutureResults (const mitk::DataNode *imageNode, const mitk::DataNode *roiNode) const =0
 Adds placeholder nodes and WIP dummy data to the data storage for missing or outdated results. More...
 
virtual std::pair< QmitkDataGenerationJobBase *, mitk::DataNode::Pointer > GetNextMissingGenerationJob (const mitk::DataNode *imageNode, const mitk::DataNode *roiNode) const =0
 Returns the next generation job and its associated placeholder node. More...
 
virtual void RemoveObsoleteDataNodes (const mitk::DataNode *imageNode, const mitk::DataNode *roiNode) const =0
 Removes obsolete result nodes for the given image/ROI pair from the data storage. More...
 
virtual mitk::DataNode::Pointer PrepareResultForStorage (const std::string &label, mitk::BaseData *result, const QmitkDataGenerationJobBase *job) const =0
 Wraps a generation result in a data node suitable for storage. More...
 
InputPairVectorType FilterImageROICombinations (InputPairVectorType &&imageROICombinations) const
 Filters image/ROI pairs to only include those whose nodes exist in the data storage. More...
 
std::string GetPairDescription (const InputPairVectorType::value_type &imageAndSeg) const
 Returns a human-readable description of an image/ROI pair for debug logging. More...
 
bool DoGenerate () const
 Core generation loop that checks validity and launches jobs for all image/ROI pairs. More...
 
void EnsureRecheckingAndGeneration () const
 Ensures generation is (re)started, either immediately or by flagging a restart if already running. More...
 

Static Protected Member Functions

static mitk::DataNode::Pointer CreateWIPDataNode (mitk::BaseData *dataDummy, const std::string &nodeName)
 Creates a WIP placeholder data node for future results. More...
 

Protected Attributes

mitk::WeakPointer< mitk::DataStorage > m_Storage
 
bool m_AutoUpdate
 
std::mutex m_DataMutex
 
itk::TimeStamp m_GenerationTime
 

Detailed Description

Base class that orchestrates asynchronous data generation for image/ROI pairs.

This class manages the lifecycle of background data generation jobs for pairs of images and ROIs. It ensures that for each image/ROI combination (defined by derived classes), a result instance (e.g., mitk::ImageStatisticsContainer) is calculated when needed (missing or outdated) and stored in the associated data storage. Derived classes define how to produce image/ROI pairs, how to detect existing results, what constitutes the next generation step, and how to clean up obsolete data. The base class observes the data storage for changes and orchestrates the checking and generation workflow.

The data storage serves two roles: (1) it stores and retrieves final results, and (2) it tracks the generation state via work-in-progress (WIP) placeholder nodes for pending or in-progress jobs.

See also
QmitkDataGenerationJobBase
QmitkImageAndRoiDataGeneratorBase
QmitkImageStatisticsDataGenerator

Definition at line 45 of file QmitkDataGeneratorBase.h.

Member Typedef Documentation

◆ InputPairVectorType

using QmitkDataGeneratorBase::InputPairVectorType = std::vector<std::pair<mitk::DataNode::ConstPointer, mitk::DataNode::ConstPointer> >
protected

Vector of image/ROI node pairs used as input for generation.

Definition at line 171 of file QmitkDataGeneratorBase.h.

◆ JobResultMapType

Alias for the result map type produced by generation jobs.

Definition at line 55 of file QmitkDataGeneratorBase.h.

Constructor & Destructor Documentation

◆ QmitkDataGeneratorBase() [1/3]

QmitkDataGeneratorBase::QmitkDataGeneratorBase ( const QmitkDataGeneratorBase &  other)
delete

◆ ~QmitkDataGeneratorBase()

virtual QmitkDataGeneratorBase::~QmitkDataGeneratorBase ( )
virtual

◆ QmitkDataGeneratorBase() [2/3]

QmitkDataGeneratorBase::QmitkDataGeneratorBase ( mitk::DataStorage::Pointer  storage,
QObject *  parent = nullptr 
)
protected

Constructs a generator with the given data storage.

Parameters
[in]storageThe data storage where all produced data should be stored.
[in]parentOptional parent QObject for Qt ownership.

◆ QmitkDataGeneratorBase() [3/3]

QmitkDataGeneratorBase::QmitkDataGeneratorBase ( QObject *  parent = nullptr)
protected

Constructs a generator without an initial data storage.

Parameters
[in]parentOptional parent QObject for Qt ownership.

Member Function Documentation

◆ ChangedNodeIsRelevant()

virtual bool QmitkDataGeneratorBase::ChangedNodeIsRelevant ( const mitk::DataNode *  changedNode) const
protectedpure virtual

Determines whether a changed data node is relevant and should trigger a regeneration.

Parameters
[in]changedNodeThe node that was changed in the data storage.
Returns
True if the change is relevant and an update should be triggered.

Implemented in QmitkImageAndRoiDataGeneratorBase, and QmitkImageStatisticsDataGenerator.

◆ CreateWIPDataNode()

static mitk::DataNode::Pointer QmitkDataGeneratorBase::CreateWIPDataNode ( mitk::BaseData *  dataDummy,
const std::string &  nodeName 
)
staticprotected

Creates a WIP placeholder data node for future results.

The created node is marked as a hidden helper object with a "pending" generation status. Can be used by IndicateFutureResults() implementations.

Parameters
[in]dataDummyThe dummy data object to attach to the node. Must not be nullptr.
[in]nodeNameThe name to assign to the node.
Returns
A newly created placeholder data node.
Exceptions
mitk::Exceptionif dataDummy is nullptr.

◆ DataGenerationStarted

void QmitkDataGeneratorBase::DataGenerationStarted ( const mitk::DataNode *  imageNode,
const mitk::DataNode *  roiNode,
const QmitkDataGenerationJobBase *  job 
) const
signal

Emitted when a data generation job is started for outdated or missing data.

Parameters
[in]imageNodeThe image data node being processed.
[in]roiNodeThe ROI data node being processed (may be nullptr).
[in]jobPointer to the started generation job.

◆ DoGenerate()

bool QmitkDataGeneratorBase::DoGenerate ( ) const
protected

Core generation loop that checks validity and launches jobs for all image/ROI pairs.

Returns
True if all results are valid; false if new jobs were triggered.

◆ EnsureRecheckingAndGeneration()

void QmitkDataGeneratorBase::EnsureRecheckingAndGeneration ( ) const
protected

Ensures generation is (re)started, either immediately or by flagging a restart if already running.

◆ FilterImageROICombinations()

InputPairVectorType QmitkDataGeneratorBase::FilterImageROICombinations ( InputPairVectorType &&  imageROICombinations) const
protected

Filters image/ROI pairs to only include those whose nodes exist in the data storage.

Parameters
[in]imageROICombinationsThe pairs to filter (moved into the method).
Returns
A filtered vector containing only pairs with nodes present in the data storage.

◆ Generate()

bool QmitkDataGeneratorBase::Generate ( ) const

Checks data validity and triggers generation of missing or outdated data.

The generation is performed asynchronously using a thread pool. To detect when all jobs have completed, connect to the GenerationFinished signal.

Returns
True if all results are already valid; false if new generation was triggered.

◆ GenerationFinished

void QmitkDataGeneratorBase::GenerationFinished ( ) const
signal

Emitted when all generation jobs have finished and all results are up to date.

◆ GetAllImageROICombinations()

virtual InputPairVectorType QmitkDataGeneratorBase::GetAllImageROICombinations ( ) const
protectedpure virtual

Returns all image/ROI pairs for which data generation is needed.

The ROI element of a pair may be nullptr if no ROI is required.

Returns
A vector of image/ROI node pairs.

Implemented in QmitkImageAndRoiDataGeneratorBase.

◆ GetAutoUpdate()

bool QmitkDataGeneratorBase::GetAutoUpdate ( ) const

Returns whether automatic updates are enabled.

When enabled, the generator automatically triggers regeneration when:

  • Input data nodes have been changed or modified
  • Generation-relevant settings in derived classes have changed
Returns
True if auto-update is enabled; false otherwise.

◆ GetDataStorage()

mitk::DataStorage::Pointer QmitkDataGeneratorBase::GetDataStorage ( ) const

Returns the data storage used by this generator.

Returns
The data storage, or nullptr if none is set.

◆ GetNextMissingGenerationJob()

virtual std::pair<QmitkDataGenerationJobBase*,mitk::DataNode::Pointer> QmitkDataGeneratorBase::GetNextMissingGenerationJob ( const mitk::DataNode *  imageNode,
const mitk::DataNode *  roiNode 
) const
protectedpure virtual

Returns the next generation job and its associated placeholder node.

Note
The caller takes ownership of the returned job instance.
Parameters
[in]imageNodeThe image data node.
[in]roiNodeThe ROI data node (may be nullptr).
Returns
A pair of (job, placeholder node) with three possible outcomes:
  • Both null: nothing to do.
  • Both set: a pending placeholder needs computation; trigger the job.
  • Job null, node set: a job for this node is already in progress; wait for completion.

Implemented in QmitkImageStatisticsDataGenerator.

◆ GetPairDescription()

std::string QmitkDataGeneratorBase::GetPairDescription ( const InputPairVectorType::value_type &  imageAndSeg) const
protected

Returns a human-readable description of an image/ROI pair for debug logging.

Parameters
[in]imageAndSegThe image/ROI pair to describe.
Returns
A descriptive string.

◆ IndicateFutureResults()

virtual void QmitkDataGeneratorBase::IndicateFutureResults ( const mitk::DataNode *  imageNode,
const mitk::DataNode *  roiNode 
) const
protectedpure virtual

Adds placeholder nodes and WIP dummy data to the data storage for missing or outdated results.

The placeholder nodes will be replaced by real results once generation completes. Derived classes define the detection strategy and dummy data format.

Parameters
[in]imageNodeThe image data node.
[in]roiNodeThe ROI data node (may be nullptr).

Implemented in QmitkImageStatisticsDataGenerator.

◆ IsGenerating()

bool QmitkDataGeneratorBase::IsGenerating ( ) const

Returns whether data generation jobs are currently running or pending.

Set to true when DataGenerationStarted is emitted and becomes false when GenerationFinished is emitted.

Returns
True if generation is in progress; false otherwise.

◆ IsValidResultAvailable()

virtual bool QmitkDataGeneratorBase::IsValidResultAvailable ( const mitk::DataNode *  imageNode,
const mitk::DataNode *  roiNode 
) const
pure virtual

Checks whether a valid final result exists for the given image and ROI.

Parameters
[in]imageNodeThe image data node to check.
[in]roiNodeThe ROI data node to check (may be nullptr if no ROI is used).
Returns
True if a valid, up-to-date result is available; false otherwise.

Implemented in QmitkImageStatisticsDataGenerator.

◆ JobError

void QmitkDataGeneratorBase::JobError ( QString  error,
const QmitkDataGenerationJobBase *  failedJob 
) const
signal

Emitted when a generation job encounters an error.

Parameters
[in]errorThe error description.
[in]failedJobPointer to the job that failed.

◆ NewDataAvailable

void QmitkDataGeneratorBase::NewDataAvailable ( mitk::DataStorage::SetOfObjects::ConstPointer  data) const
signal

Emitted when new final result data has been produced and added to the data storage.

Parameters
[in]dataThe set of newly added result data nodes.

◆ OnFinalResultsAvailable

void QmitkDataGeneratorBase::OnFinalResultsAvailable ( JobResultMapType  results,
const QmitkDataGenerationJobBase *  job 
) const
protectedslot

Handles completed job results, adds them to the data storage, and emits NewDataAvailable.

Parameters
[in]resultsThe result map from the completed job.
[in]jobPointer to the job that produced the results.

◆ OnJobError

void QmitkDataGeneratorBase::OnJobError ( QString  error,
const QmitkDataGenerationJobBase *  failedJob 
) const
protectedslot

Handles error signals from generation jobs and re-emits JobError.

Parameters
[in]errorThe error message.
[in]failedJobPointer to the job that failed.

◆ operator=()

QmitkDataGeneratorBase& QmitkDataGeneratorBase::operator= ( const QmitkDataGeneratorBase &  other)
delete

◆ PrepareResultForStorage()

virtual mitk::DataNode::Pointer QmitkDataGeneratorBase::PrepareResultForStorage ( const std::string &  label,
mitk::BaseData *  result,
const QmitkDataGenerationJobBase *  job 
) const
protectedpure virtual

Wraps a generation result in a data node suitable for storage.

Parameters
[in]labelThe result label from the job's result map.
[in]resultThe generated data to store.
[in]jobThe job that produced the result.
Returns
A data node ready to be added to the data storage.

Implemented in QmitkImageStatisticsDataGenerator.

◆ RemoveObsoleteDataNodes()

virtual void QmitkDataGeneratorBase::RemoveObsoleteDataNodes ( const mitk::DataNode *  imageNode,
const mitk::DataNode *  roiNode 
) const
protectedpure virtual

Removes obsolete result nodes for the given image/ROI pair from the data storage.

Obsolete nodes are interim result nodes that have been superseded by newer results.

Parameters
[in]imageNodeThe image data node.
[in]roiNodeThe ROI data node (may be nullptr).

Implemented in QmitkImageStatisticsDataGenerator.

◆ SetAutoUpdate

void QmitkDataGeneratorBase::SetAutoUpdate ( bool  autoUpdate)
slot

Enables or disables automatic update on data changes.

Parameters
[in]autoUpdateTrue to enable; false to disable.

◆ SetDataStorage

void QmitkDataGeneratorBase::SetDataStorage ( mitk::DataStorage *  storage)
slot

Sets the data storage for monitoring, storing WIP placeholders, and final results.

Parameters
[in]storagePointer to the data storage to use. May be nullptr to disconnect.

Member Data Documentation

◆ m_AutoUpdate

bool QmitkDataGeneratorBase::m_AutoUpdate
protected

Definition at line 268 of file QmitkDataGeneratorBase.h.

◆ m_DataMutex

std::mutex QmitkDataGeneratorBase::m_DataMutex
mutableprotected

Definition at line 270 of file QmitkDataGeneratorBase.h.

◆ m_GenerationTime

itk::TimeStamp QmitkDataGeneratorBase::m_GenerationTime
mutableprotected

Time stamp for the last successful run through with the current image roi pairs.

Definition at line 273 of file QmitkDataGeneratorBase.h.

◆ m_Storage

mitk::WeakPointer<mitk::DataStorage> QmitkDataGeneratorBase::m_Storage
protected

Definition at line 266 of file QmitkDataGeneratorBase.h.


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