Into

Modules

Documentation

classPiiDefaultOperation

#include <PiiDefaultOperation.h>

A functional implementation of the PiiOperation interface.

Inherits PiiBasicOperation, PiiFlowController::SyncListener

Inherited by PiiAbsoluteOperation, PiiArithmeticOperation, PiiAverageOperation, PiiBackgroundExtractor, PiiBoundaryFinderOperation, PiiCacheOperation, PiiClassifierOperation, PiiClassIndexMapper, PiiClassInfoMapper, PiiClock, PiiColorChannelSetter, PiiColorChannelSplitter, PiiColorConverter, PiiColorCorrelogramOperation, PiiColorModelMatcher, PiiColorPercentiles, PiiComparisonOperation, PiiConfusionMatrixBuilder, PiiContrastOperation, PiiCornerDetector, PiiDatabaseOperation, PiiDebugOperation, PiiDefectGeometryOperation, PiiDemuxOperation, PiiDiffOperation, PiiDistributionNormalizer, PiiEdgeDetector, PiiFeatureCombiner, PiiFeatureRangeLimiter, PiiFileSystemScanner, PiiFileSystemWatcher, PiiFireWireOperation, PiiFlowLevelChanger, PiiFourierTransform, PiiFrequencyCounter, PiiGradientFeatureOperation, PiiGrayFeatureOperation, PiiHistogramBackProjector, PiiHistogramCollector, PiiHistogramEqualizer, PiiHistogramOperation, PiiHoughTransformOperation, PiiIdGenerator, PiiImageAnnotator, PiiImageConversionSwitch, PiiImageCropper, PiiImageFileWriter, PiiImageFilterOperation, PiiImageGeometryOperation, PiiImagePieceJoiner, PiiImageReaderOperation, PiiImageRotationOperation, PiiImageScaleOperation, PiiImageSplitter, PiiImageUnwarpOperation, PiiIoOutputOperation, PiiLabelingOperation, PiiLbpOperation, PiiLogOperation, PiiLookupTable, PiiMaskGenerator, PiiMathematicalFunction, PiiMatrixCombiner, PiiMatrixComposer, PiiMatrixDecomposer, PiiMatrixFlipper, PiiMatrixNormalizer, PiiMinMaxOperation, PiiMorphologyOperation, PiiMovingAverageOperation, PiiMultiPointTracker, PiiMultiVariableHistogram, PiiNetworkOperation, PiiObjectCapturer, PiiObjectCounter, PiiObjectPropertyExtractor, PiiObjectRateChanger, PiiObjectReplicator, PiiOrientationEstimator, PiiPeakDetector, PiiPisoOperation, PiiQuantizerOperation, PiiRegExpMatcher, PiiRgbNormalizer, PiiSampleBalancer, PiiSampleRandomizer, PiiSequenceGenerator, PiiShapeContextOperation, PiiSpectralPeakDetector, PiiStringConverter, PiiStringFormatter, PiiStringizer, PiiSwitch, PiiTableLabelerOperation, PiiTemplateMatcher, PiiThresholdingOperation, PiiTypeCastingOperation, PiiUndistortOperation, PiiVideoFileWriter, PiiVisualTrainer, PiiWaveletTextureOperation, PiiWaveletTransform

Description

This class provides facilities for synchronizing and processing incoming objects adding and an execution mechanism for serial and parallel processing.

PiiDefaultOperation delegates the task of handling synchronization issues to PiiFlowController. It uses different flow controllers for different operations to optimize the performance of passing objects. The processing of accepted objects is controlled by PiiOperationProcessor, which uses the flow controller to check processing preconditions and invokes the process() function of PiiDefaultOperation whenever needed. PiiOperationProcessor subclasses determine the actual execution mechanism (threaded or not).

It is possible to change the execution mechanism at run time, but only if the operation is in Stopped state.

Properties

int

The priority of the operation in Threaded processing mode.

Processing mode.

Public types

enum
{ NonThreaded, Threaded }

Processing modes.

Constructors and destructor

Creates a new PiiDefaultOperation with the given default processing mode.

Public member functions

virtual void
(
  • bool reset
)

Checks the operation for execution.

virtual void

Interrupts the processor.

virtual void
( )

Prepares the operation for pausing.

virtual QVariant
(
  • const char * name
)

Acquires processLock() for reading and returns the property.

virtual bool
(
  • const char * name
  • const QVariant & value
)

Ensures that no property will be set while process() or syncEvent() is being called by acquiring processLock() for writing.

virtual void
( )

Starts the processor.

virtual void
( )

Prepares the operation for stopping.

virtual bool
(
  • unsigned long time = ULONG_MAX
)

Waits until the processor is finished.

Protected member functions

int

Returns the id of the synchronized socket group being processed.

virtual PiiFlowController *

Creates a flow controller for this operation.

bool

Returns true if the operation has been checked for execution (check()) but not started (start()) yet.

Creates a new PiiDefaultOperation with the given default processing mode.

int
virtual void
( )  = 0

Executes one round of processing.

Returns a pointer to a lock that PiiDefaultOperation uses to synchronize calls to property(), setProperty(), process(), and syncEvent().

void
(
  • int priority
)
void
virtual void
( )

Informs the operation about synchronization events.

Property details

  • int priority

    [read, write]

    The priority of the operation in Threaded processing mode.

    Threaded operations with a high priority are more likely to be scheduled for execution than those with a low priority. Use QThread::Priority as the value for this property. The default value is QThread::NormalPriority. Note that this value has no effect on non-threaded operations.

    Within a single processing pipeline, priority is meaningful only for asynchronous operations that may discard some of their input objects. Setting priority to a lower value increases the probability of discarding an input object. Priority is useful for synchronous operations if a configuration contains multiple independent processing pipelines.

    Thread priority cannot be changed on Linux.

  • ProcessingMode processingMode

    [read, write]

    Processing mode.

    PiiDefaultOperation can be run in either its own thread (Threaded) or in the thread of the operation that sends data to its inputs (NonThreaded). Note that the processing mode can only be changed when the operation is either stopped or paused, and only before check(). Setting the value in other situations has no effect. Furthermore, some derived operations may disable processing mode changes altogether.

Enumeration details

  • enum ProcessingMode

    Processing modes.

    • NonThreaded - objects are processed immediately when received in the context of the sending thread.

    • Threaded - processing happens in a separate thread that is awakened when new objects appear.

Function details

  • PiiDefaultOperation

    ( )
    [protected]

    Creates a new PiiDefaultOperation with the given default processing mode.

  • ~PiiDefaultOperation

    ()
  • virtual void check

    (
    • bool reset
    )
    [virtual]

    Checks the operation for execution.

    This function creates a suitable flow controller by calling createFlowController(). It then sets the flow controller to the active processor and sets the processor as the input controller for all inputs.

    If you change socket groupings in your overridden implementation, please call PiiDefaultOperation::check() after that. Otherwise, your new groupings will not be in effect.

    Reimplemented from PiiBasicOperation.

  • virtual void interrupt

    ()
    [virtual]

    Interrupts the processor.

    Does not alter the state of the operation unless the processor does so.

    Reimplemented from PiiOperation.

  • virtual void pause

    ()
    [virtual]

    Prepares the operation for pausing.

    The functioning is dependent on the type of the processor. In threaded mode, the operation will be turned into Pausing state, and processing will pause once the thread has finished its current processing round. In simple mode, the processor will check if the operation has connected inputs. If it does, the operation will turn into Pausing state and wait until it receives pause signals from previous operations in the pipeline. If there are no connected inputs, the operation will immediately turn into Paused state.

    Reimplemented from PiiOperation.

  • virtual QVariant property

    (
    • const char * name
    )
    [virtual]

    Acquires processLock() for reading and returns the property.

    Reimplemented from PiiOperation.

  • virtual bool setProperty

    (
    • const char * name
    • const QVariant & value
    )
    [virtual]

    Ensures that no property will be set while process() or syncEvent() is being called by acquiring processLock() for writing.

    Then sets the property.

    Reimplemented from PiiOperation.

  • virtual void start

    ()
    [virtual]

    Starts the processor.

    If check() has not been called, this function writes out a warning and returns.

    Reimplemented from PiiOperation.

  • virtual void stop

    ()
    [virtual]

    Prepares the operation for stopping.

    Works analogously to pause().

    Reimplemented from PiiOperation.

  • virtual bool wait

    (
    • unsigned long time = ULONG_MAX
    )
    [virtual]

    Waits until the processor is finished.

    Reimplemented from PiiBasicOperation.

  • int activeInputGroup

    ()
    [protected]

    Returns the id of the synchronized socket group being processed.

    If all input sockets work in parallel, or there are no input sockets, this value can be safely ignored. Otherwise, one can use the value to decide which sockets need to be read and processed in process().

  • virtual PiiFlowController * createFlowController

    ()
    [protected, virtual]

    Creates a flow controller for this operation.

    This function is called by the default implementation of check(). A new flow controller will be always be created when the check() function is called. The old controller will be deleted.

    The default implementation tries to find an optimal flow controller for the active input configuration:

    • If there are no connected inputs, a null pointer will be returned.

    • If the operation has only one connected input, PiiOneInputFlowController will be used.

    • If there are many inputs, but all are in the same group, PiiOneGroupFlowController will be used.

    • Otherwise, PiiDefaultFlowController will be used. The flow controller will be configured with loose parent-child relationships between groups with a non-negative group id and at least one connected socket. The relationships will be assigned in the order of increasing magnitude. For example, if there are sockets in groups 0, 1, and -1, 0 will be set as the (loose) parent of 1. Group -1 will be independent of the others.

    Subclasses may override the default behavior by installing a custom flow controller. You need to do this if your operation has, for example, sibling groups that share a common parent group, or if you need to assign strict relationships between input groups. If you override this function, make sure the flow controller takes the control of all connected inputs.
    Returns

    a pointer to a flow controller. PiiDefaultOperation will take the ownership of the pointer. If you don't want inputs to be controlled, return 0.

    See also
  • bool isChecked

    ()
    [protected]

    Returns true if the operation has been checked for execution (check()) but not started (start()) yet.

  • int priority

    ()
    [protected]
  • virtual void process

    ()
    [protected, pure virtual]

    Executes one round of processing.

    This function is invoked by the processor if the necessary preconditions for a new processing round are met. This function does all the necessary calculations to create output objects and sends them to output sockets.

    Calls to process(), syncEvent(), and setProperty() are synchronized and cannot occur simultaneously. PiiDefaultOperation ensures this by locking processLock() for reading before calling process().

    Note: With time-consuming operations, one should occasionally check that the operation hasn't been interrupted, i.e. that state() returns Running.

    Exceptions
    PiiExecutionException

    whenever an unrecoverable error occurs during a processing round, the operation is interrupted, or finishes execution due to end of input data.

  • ProcessingMode processingMode

    ()
    [protected]
  • PiiReadWriteLock * processLock

    ()
    [protected]

    Returns a pointer to a lock that PiiDefaultOperation uses to synchronize calls to property(), setProperty(), process(), and syncEvent().

    This lock can be used if a subclass needs to protect stuff from being accessed concurrently. Acquiring the lock for writing blocks concurrent calls to all of the mentioned functions. Acquiring the lock for reading blocks only setProperty() and allows simultaneous execution of the other (read-locked) functions.

  • void setPriority

    (
    • int priority
    )
    [protected]
  • void setProcessingMode

    ( )
    [protected]
  • virtual void syncEvent

    ( )
    [protected, virtual]

    Informs the operation about synchronization events.

    The most typical use of this function is to see when all objects in an input group and all of its child groups have been received. For example, if the operation reads large images from one input and a number of sub-images for each large image from another input, a sync event is sent whenever all the small images that correspond to one large image have been processed. Your implementation may then either just record the synchronized state or to send any buffered data. The default implementation does nothing.

    Calls to process(), syncEvent(), and setProperty() are synchronized and cannot occur simultaneously. PiiDefaultOperation ensures this by locking processLock() for reading before calling syncEvent().

     void MyOperation::syncEvent(SyncEvent* event)
     {
       if (event->type() == SyncEvent::EndInput &&
           event->groupId() == _pLargeImageInput->groupId())
         doWhateverNeededNow();
     }
    

    Reimplemented from PiiFlowController::SyncListener.

Notes (0)

Add a note

Not a single note added yet. Be the first, add yours.