iVS3D v2.0.0
Loading...
Searching...
No Matches
ITransform Interface Referenceabstract

The ITransform interface is used for algorithms to create additional image files from the source images. Plugins for this interface are dynamically loaded from the plugins folder. Each ITransform needs to provide an QWidget for user interaction and a display name. Using the transform method, the plugin can create additional images such as semantic maps for the given source image. More...

#include <itransform.h>

Inheritance diagram for ITransform:
ITransformRequestDequeue SemanticSegmentation

Signals

void sendToGui (uint idx, const cv::Mat &img)
 [signal] sendToGui is emitted if the ITransform instance has an image to display to the user.
 

Public Member Functions

virtual QWidget * getSettingsWidget (QWidget *parent)=0
 getSettingsWidget is provides an QWidget to display plugin specific settings to the user. Keep in mind that the widget will run in gui thread while this ITransform instance is moved to a worker thread! Use DirectConnection for signals between the widget and this instance or ensure thread safety for interaction.
 
virtual QString getName () const =0
 getName returns the display name for the plugin.
 
virtual ITransformcopy ()=0
 copy creates a new ITransform instance which is a deep copy.
 
virtual TransformResult transform (uint idx, const cv::Mat &img, const Resolution &resolution, const ROI &roi)=0
 transform generates additional images from the given image. The signal sendToGui can be used to update the preview for the user.
 
virtual void enableCuda (bool enabled)=0
 enableCuda enables use of the CUDA api to accelerate computations.
 
virtual void setSettings (QMap< QString, QVariant > settings)=0
 setter for plugin's settings
 
virtual QMap< QString, QVariant > getSettings ()=0
 getter for plugin's settings
 
virtual void activate ()
 activate will be called before the plugin is used, i.e. when the user selects it in the seampling window or when exporting.
 
virtual void deactivate ()
 deactivate will be called when the plugin is no longer used, i.e. when the user deselects it in the sampling window or when exporting finishes. This should be used to free resources such as gpu memory.
 

Detailed Description

The ITransform interface is used for algorithms to create additional image files from the source images. Plugins for this interface are dynamically loaded from the plugins folder. Each ITransform needs to provide an QWidget for user interaction and a display name. Using the transform method, the plugin can create additional images such as semantic maps for the given source image.

Since calculation on images can be computationally expensive, the ITransform instance is moved to a worker thread. Previews for the gui can be sent to the gui thread using the sendToGui signal.

Keep in mind that the QWidget provided by getSettingsWidget will run in the gui thread while the ITransform instance itself is moved to a worker thread. Intraction between the QWidget and ITransform has to be threadsafe!

See also
SemanticSegmentation
Date
2021/03/30
Author
Dominik Wüst

This example shows how to create a ITransform plugin and a settings widget with a button:

class Plugin : public ITransform {
Q_OBJECT
Q_PLUGIN_METADATA(IID "pse.iVS3D.ITransform")
Q_INTERFACES(ITransform)
QWidget *settingsWidget = nullptr;
cv::Mat image;
uint imageIdx;
private slots:
void onButtonPressed(){
// this code runs in worker thread
// compute some preview...
cv::Mat preview = cv::convert(image, RGB2GREY);
// ... and update gui
emit sendToGui(imageIdx, preview);
}
public:
QWidget* getSettingsWidget(QWidget* parent){
if(settingsWidget) return settingWidget;
// create a widget with a button
auto *button = new QPushButton(parent, "Press me");
settingsWidget = new QWidget(parent);
settingsWidget->layout()->addWidget(button);
// connect button to Plugin using Qt DirectConnection
connect(button, &QPushButton::pressed, this, &Plugin::onButtonPressed, Qt::DirectConnection);
}
ImageList transform(uint idx, const cv::Mat &img){
image = img;
imageIdx = idx;
// perform transformation and show result on gui
auto res = doWork();
emit sendToGui(imageIdx,res[0]);
return res;
}
// other methods here...
};
The ITransform interface is used for algorithms to create additional image files from the source imag...
Definition itransform.h:88

The Button on the settingsWidget is connected to the plugin using the threadsafe DirectConnection. This allows to calculate computationally expensive previews in the worker thread and update the gui after calculation has finished.

Member Function Documentation

◆ copy()

virtual ITransform * ITransform::copy ( )
pure virtual

copy creates a new ITransform instance which is a deep copy.

Returns
The copy

Implemented in ITransformRequestDequeue, and SemanticSegmentation.

◆ enableCuda()

virtual void ITransform::enableCuda ( bool  enabled)
pure virtual

enableCuda enables use of the CUDA api to accelerate computations.

Parameters
enabledThe CUDA api is used if true

Implemented in ITransformRequestDequeue, and SemanticSegmentation.

◆ getName()

virtual QString ITransform::getName ( ) const
pure virtual

getName returns the display name for the plugin.

Returns
The name to display.

Implemented in ITransformRequestDequeue, and SemanticSegmentation.

◆ getSettings()

virtual QMap< QString, QVariant > ITransform::getSettings ( )
pure virtual

getter for plugin's settings

Returns
QMap with the settings

Implemented in ITransformRequestDequeue, and SemanticSegmentation.

◆ getSettingsWidget()

virtual QWidget * ITransform::getSettingsWidget ( QWidget *  parent)
pure virtual

getSettingsWidget is provides an QWidget to display plugin specific settings to the user. Keep in mind that the widget will run in gui thread while this ITransform instance is moved to a worker thread! Use DirectConnection for signals between the widget and this instance or ensure thread safety for interaction.

Parameters
parentThe parent for the QWidget
Returns
The QWidget with the plugin settings

Implemented in ITransformRequestDequeue, and SemanticSegmentation.

◆ sendToGui

void ITransform::sendToGui ( uint  idx,
const cv::Mat &  img 
)
signal

[signal] sendToGui is emitted if the ITransform instance has an image to display to the user.

Parameters
idxThe index of the image in transformation
imgThe image to display to the user

◆ setSettings()

virtual void ITransform::setSettings ( QMap< QString, QVariant >  settings)
pure virtual

setter for plugin's settings

Parameters
QMapwith the settings

Implemented in ITransformRequestDequeue, and SemanticSegmentation.

◆ transform()

virtual TransformResult ITransform::transform ( uint  idx,
const cv::Mat &  img,
const Resolution resolution,
const ROI roi 
)
pure virtual

transform generates additional images from the given image. The signal sendToGui can be used to update the preview for the user.

Parameters
idxThe index of the image to transform
imgThe image to transform
Returns
Pointers to the transformed images

Implemented in ITransformRequestDequeue, and SemanticSegmentation.


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