[vtkusers] QVTKWidget2 and vtkImageViewer2

Clinton Stimpson clinton at elemtech.com
Wed Feb 8 16:37:01 EST 2012


Instead of doing a cast, you need a #include "vtkGenericOpenGLRenderWindow.h"

On Wednesday, February 08, 2012 02:12:30 pm Jonathan Morra wrote:
> When I try this I get
> 'vtkImageViewer2::SetRenderWindow' : cannot convert parameter 1 from
> 'vtkGenericOpenGLRenderWindow *' to 'vtkRenderWindow *'
> Types pointed to are unrelated; conversion requires reinterpret_cast,
> C-style cast or function-style cast
> 
> Can I just do a static cast?
> 
> On Wed, Feb 8, 2012 at 12:21 PM, Clinton Stimpson 
<clinton at elemtech.com>wrote:
> > On Wednesday, February 08, 2012 12:05:35 pm Jonathan Morra wrote:
> > > I am trying to paint on top of a QVTKWidget and am having trouble doing
> > 
> > so.
> > 
> > >  I have tried to follow the instructions at
> > > 
> > > http://vtk.1045678.n5.nabble.com/QVTKWidget-paintEvent-td2852642.html.
> >  
> >  But
> >  
> > > have since had no luck with QVTKWidget.  I tried to swap QVTKWidget
> > > with QVTKWidget2, but was also unsuccessful there.  I was hoping
> > > 1.  If someone could provide a very small example of using QPainter
> > > with QVTKWidget and vtkImageViewer2.
> > > 2.  A small example of using QVTKWidget2 with vtkImageViewer2.
> > > 3.  A description of what's different between QVTKWidget and
> > > QVTKWidget2?
> > 
> > The main difference is that QVTKWidget2 derives from QGLWidget and comes
> > with
> > the functionality of QGLWidget.  For general usage, there probably isn't
> > much
> > different between the two.
> > 
> > Here's a way to use QPainter with QVTKWidget2:
> > 
> > class MyQVTKWidget2 : public QVTKWidget2
> > {
> > 
> > public:
> >  MyQVTKWidget2(QWidget* p = NULL) : QVTKWidget2(p)
> >  {
> >  
> >    // don't clear the scene when QPainter is constructed, since it will
> >    be
> > 
> > used to add
> > 
> >    // to the scene
> >    setAutoFillBackground(false);
> >  
> >  }
> >  
> >  // overload Frame() to add our painting on top of VTK's completed
> > 
> > rendering
> > 
> >  void Frame()
> >  {
> >  
> >    QPainter p(this);
> >    p.drawLine(0,0,100,100);
> >    p.end();
> >    
> >    QVTKWidget2::Frame();
> >  
> >  }
> > 
> > };
> > 
> > 
> > To use that with vtkImageViewer2:
> > 
> > int main(int argc, char** argv)
> > {
> > 
> >  QApplication app(argc, argv);
> >  
> >  MyQVTKWidget2 widget;
> >  widget.resize(256,256);
> >  
> >  vtkPNGReader* reader = vtkPNGReader::New();
> >  char* fname = vtkTestUtilities::ExpandDataFileName(argc, argv,
> > 
> > "Data/vtk.png");
> > 
> >  reader->SetFileName(fname);
> >  delete [] fname;
> >  
> >  vtkImageViewer2* image_view = vtkImageViewer2::New();
> >  image_view->SetInputConnection(reader->GetOutputPort());
> >  
> >  image_view->SetupInteractor(widget.GetRenderWindow()->GetInteractor());
> >  image_view->SetRenderWindow(widget.GetRenderWindow());
> >  
> >  image_view->SetColorLevel(138.5);
> >  image_view->SetColorWindow(233);
> >  
> >  widget.show();
> >  
> >  app.exec();
> >  
> >  image_view->Delete();
> >  reader->Delete();
> >  
> >  return 0;
> > 
> > }
> > 
> > 
> > --
> > Clinton Stimpson
> > Elemental Technologies, Inc
> > Computational Simulation Software, LLC
> > www.csimsoft.com

-- 
Clinton Stimpson
Elemental Technologies, Inc
Computational Simulation Software, LLC
www.csimsoft.com



More information about the vtkusers mailing list