[Paraview] Plugin with own thread
Stephan Rogge
Stephan.Rogge at tu-cottbus.de
Wed Mar 9 11:10:08 EST 2011
Hello,
after reading the tutorials and How-to's for writing ParaView Plugins I've
started with the Autostart-Example project. My goal was to create a plugin
which is executed in an external thread. It might happens that I need this
in the near future.
Well, it works quit well, I guess. But to avoid some errors and
miss-behaviors I need a confirmation that I am on the right way.
My approach is to use the signal-slot-pattern to communicate between the
main thread of ParaView and my own plugin-thread. The class
pqMyApplicationStarter represents the ParaView-plugin (which is running in
the main thread of ParaView?). There is an object in this class which
executes a loop within an external thread ( class Thread ), which extends
QThread.
As I read somewhere that vtk isn't implemented threaded-safe at all (at
least the rendering stuff) I decided to do all render calls in
pqMyApplicationStarter. When the UpdatedData()signal is fired the active
view needs to re-rendered.
The question I want to ask is very simple: Is this the right / best way to
create a thread and communicate with it via signals?
/////////////// Thread.h ////////////////////////////
class Thread : public QThread
{
Q_OBJECT
public:
Thread(QObject* parent = 0);
virtual ~Thread();
virtual void run();
signals:
void UpdatedData();
};
void Thread::run()
{
running = true;
while( running )
{
// Sleep awhile
msleep( 800 );
// Fire the signal
emit UpdatedData();
}
}
/////////////////////////////////////////////////////
/////////////// pqMyApplicationStarter //////////////
class pqMyApplicationStarter : public QObject
{
Q_OBJECT
typedef QObject Superclass;
public:
pqMyApplicationStarter(QObject* p=0);
~pqMyApplicationStarter();
// Callback for startup.
void onStartup();
public slots:
void Trigger();
};
void pqMyApplicationStarter::onStartup()
{
myThread = new Thread();
myThread->start();
pqActiveObjects::instance().connect( myThread, SIGNAL(UpdatedData()),
this, SLOT(Trigger()) );
}
void pqMyApplicationStarter::Trigger()
{
pqActiveObjects* object = &(pqActiveObjects::instance());
pqView* view = object->activeView();
if (view)
{
view->render();
}
view = NULL;
}
Thanks a lot.
Cheers,
Stephan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.paraview.org/pipermail/paraview/attachments/20110309/0baad825/attachment-0001.htm>
More information about the ParaView
mailing list