[vtkusers] QVTKWidget

Moinier, Pierre (UK) Pierre.Moinier at baesystems.com
Wed Nov 25 09:32:33 EST 2009


Hi!
 
I am trying to get signal and slot work with QVTK. I have 2 threads, one
to compute and one to do the rendering. When the compute thread sends a
signal, I want this one to be picked up in order to update the scene. In
my visualisation widget I call initialView which creates a sphere. The
result is that as the compute threads is running, the sphere is being
rendered. However, When a signal is emited, this one is not picked up.
If I replace initialView with another member which does nothing, the
signal is being delivered. So my guess is that the vtkRenderWindow is
overwritting my original Widget, perhaps  with a different eventloop...
In fact, the window title is even reset to 'Visualisation toolkit -
openGL" when I use initialView, whereas I get the correct Window title
that I set in the constructor when I use the empty member... but with
nothing in the window.
 
Could anyone tell me what I am doing wrong? I guess the best thing is to
give some lines of codes...
 
Best Regards,
 
    -Pierre.
 
main.cpp:
 
#include <QApplication>
#include "MyWidget.h"
int main(int argc, char* argv[])
{
  QApplication app(argc, argv);
  MyWidget* widget;
  widget = new MyWidget(argc, argv);
  widget->show();
  return app.exec();
}
------------------------------------------------------------------------
-----
MyWidget.h
 
#include <QWidget>
#include <QVTKWidget.h>
#include "computethread.h"
 
class MyWidget : public QVTKWidget
{
  Q_OBJECT
 public:
  MyWidget(int argc, char **argv, QVTKWidget *parent = 0);
  QSize minimumSizeHint() const;
  QSize sizeHint() const;
private slots:
  void updateView();
private:
  ComputeThread* thread;
  void initialView();
  void initialView2();
  QVTKWidget *vtkwidget;
};
------------------------------------------------------------------------
-----
MyWidget.cpp
 
MyWidget::MyWidget(int argc, char **argv, QVTKWidget *parent) :
QVTKWidget(parent)
{
 
  // start compute thread
  thread = new ComputeThread(argc,argv);
  thread->start(); 
 
  initialView();
  setWindowTitle(tr("Visualization Window - v0.1"));
  resize(400, 300);
  connect(thread, SIGNAL(computeStuff()), this, SLOT(updateView()));
}
void MyWidget::initialView2()
{
}
void MyWidget::initialView()
{
  //create a rendering window and renderer
  vtkRenderer *ren = vtkRenderer::New();
  vtkRenderWindow *renderWindow = vtkRenderWindow::New();
  renderWindow->AddRenderer( ren );
  renderWindow->SetSize( 500, 500 );
 
  //Create a window interactor
  vtkRenderWindowInteractor *interactor =
vtkRenderWindowInteractor::New();
  interactor->SetRenderWindow( renderWindow );
 
  //create and actor and give it ball geometry
 
  vtkSphereSource* Sphere = vtkSphereSource::New();
  Sphere->SetCenter(0.0, 0.0, 0.0);
  Sphere->SetRadius(5.0);
 
  //create a mapper
  vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
  Mapper->SetInput(Sphere->GetOutput());
 
  // create an actor
  vtkActor *Actor = vtkActor::New();
  Actor->SetMapper(Mapper);
  // sphere color blue
  Actor->GetProperty()->SetColor(0,0,1);
 
  //assign our actor to the renderer
  ren->AddActor(Actor);
 
  renderWindow->AddRenderer(ren);
 
  //render the scene and start the interactor
  renderWindow->Render();
  interactor->Start();
 
  vtkwidget->SetRenderWindow(renderWindow);
  renderWindow->Delete();
}

 
 

********************************************************************
This email and any attachments are confidential to the intended
recipient and may also be privileged. If you are not the intended
recipient please delete it from your system and notify the sender.
You should not copy it or use it for any purpose nor disclose or
distribute its contents to any other person.
********************************************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091125/cedeef54/attachment.htm>


More information about the vtkusers mailing list