File: GraphicsView.hpp

package info (click to toggle)
vtk6 6.3.0%2Bdfsg2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 118,880 kB
  • sloc: cpp: 1,442,792; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,119; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 154; makefile: 103; objc: 17
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