File: GraphicsView.hpp

package info (click to toggle)
vtk7 7.1.1%2Bdfsg2-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 127,396 kB
  • sloc: cpp: 1,539,584; ansic: 124,382; python: 78,038; tcl: 47,013; xml: 8,142; yacc: 5,040; java: 4,439; perl: 3,132; lex: 1,926; sh: 1,500; makefile: 126; objc: 83
file content (67 lines) | stat: -rw-r--r-- 1,983 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

#ifndef GraphicsView_hpp
#define GraphicsView_hpp

#include <QGraphicsView>
#include <QResizeEvent>
#include "QVTKWidget2.h"
#include "OpenGLScene.hpp"
#include "vtkGenericOpenGLRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkTextActor3D.h"

class GraphicsView : public QGraphicsView
{
  public:
    GraphicsView()
    {
      mCtx = new QGLContext(QGLFormat());
      mWidget = new QVTKWidget2(mCtx);
      this->setViewport(mWidget);
      this->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
      this->setScene(new OpenGLScene(mCtx, this));
      vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New();
      ren->SetBackground(0,0,0);
      ren->SetBackground2(1,1,1);
      ren->SetGradientBackground(1);
      vtkSmartPointer<vtkTextActor3D> textActor = vtkSmartPointer<vtkTextActor3D>::New();
      textActor->SetInput("Qt & VTK!!");
      ren->AddViewProp(textActor);
      ren->ResetCamera();
      mWidget->GetRenderWindow()->AddRenderer(ren);
      mWidget->GetRenderWindow()->SetSwapBuffers(0);  // don't let VTK swap buffers on us
      mWidget->setAutoBufferSwap(true);
    }
    ~GraphicsView()
    {
    }

  protected:

    void drawBackground(QPainter* p, const QRectF& vtkNotUsed(r))
      {
#if QT_VERSION >= 0x040600
      p->beginNativePainting();
#endif
      mWidget->GetRenderWindow()->PushState();
      mWidget->GetRenderWindow()->OpenGLInitState();
      mWidget->GetRenderWindow()->Render();
      mWidget->GetRenderWindow()->PopState();
#if QT_VERSION >= 0x040600
      p->endNativePainting();
#endif
      }

    void resizeEvent(QResizeEvent *event)
      {
        // give the same size to the scene that his widget has
        if (scene())
            scene()->setSceneRect(QRect(QPoint(0, 0), event->size()));
        QGraphicsView::resizeEvent(event);
        mWidget->GetRenderWindow()->SetSize(event->size().width(), event->size().height());
      }
    QGLContext* mCtx;
    QVTKWidget2* mWidget;
};

#endif