anatomist  5.1.2
3D neuroimaging data viewer
glwidgetmanager.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 
35 #ifndef ANATOMIST_WINDOW_GLWIDGETMANAGER_H
36 #define ANATOMIST_WINDOW_GLWIDGETMANAGER_H
37 
41 
42 #include <qglobal.h>
43 #if QT_VERSION >= 0x060000
44 #include <QOpenGLWidget>
45 #define ANA_USE_QOPENGLWIDGET 1
46 #else
47 #include <QtOpenGL/QGLWidget>
48 #endif
49 #if QT_VERSION >= 0x040600
50 class QGestureEvent;
51 #endif
52 
53 
54 namespace aims
55 {
56  class Quaternion;
57 }
58 
60 
61 
62 namespace anatomist
63 {
64  class AWindow;
65 
66  namespace internal
67  {
68  class AGraphicsView;
69  }
70 
71 
77  {
78  public:
79  enum DrawMode
80  {
86  };
87 
88  virtual QSize sizeHint() const;
89  virtual QSize minimumSizeHint() const;
90 
91  virtual void updateGL();
95  virtual void paintScene();
96 
97  virtual void initializeGL();
98  virtual void resizeGL( int w, int h );
99  virtual void paintGL();
100 #if QT_VERSION >= 0x040600
101  virtual void gestureEvent( QGestureEvent *event );
102 #endif
103  virtual void mousePressEvent( QMouseEvent* me );
104  virtual void mouseReleaseEvent( QMouseEvent* me );
105  virtual void mouseMoveEvent( QMouseEvent* me );
106  virtual void mouseDoubleClickEvent( QMouseEvent * );
107  virtual void keyPressEvent( QKeyEvent* ev );
108  virtual void keyReleaseEvent( QKeyEvent* ev );
109  virtual void focusInEvent( QFocusEvent * );
110  virtual void focusOutEvent( QFocusEvent * );
111  virtual void wheelEvent( QWheelEvent * );
112 
113  public:
114  // this private structure is public because it's used by internal functions
115  struct Private;
116  friend class ::GLWidgetManager_Private_QObject;
117 
118 #ifdef ANA_USE_QOPENGLWIDGET
119  GLWidgetManager( anatomist::AWindow* win, QOpenGLWidget* widget );
120 #else
121  GLWidgetManager( anatomist::AWindow* win, QGLWidget* widget );
122 #endif
123  virtual ~GLWidgetManager();
124 
125 #ifdef ANA_USE_QOPENGLWIDGET
126  QOpenGLWidget* qglWidget();
127 #else
128  QGLWidget* qglWidget();
129 #endif
132  QObject* qobject();
133 
138  void clearLists();
141  void setExtrema( const Point3df & bmin, const Point3df & bmax );
143  void setWindowExtrema( const Point3df & bmin, const Point3df & bmax );
148  void setLightGLList( GLuint l );
149  GLuint lightGLList() const;
150  void setPreferredSize( int, int );
151  void setMinimumSizeHint( const QSize & );
152  virtual bool positionFromCursor( int x, int y, Point3df & position );
153  virtual bool cursorFromPosition( const Point3df & position, Point3df & cursor );
154  virtual Point3df objectPositionFromWindow( const Point3df & winpos );
155  virtual void readBackBuffer( int x, int y, GLubyte & red, GLubyte & green,
156  GLubyte & blue );
158  virtual bool translateCursorPosition( float x, float y,
159  Point3df & position );
160 
161  virtual std::string name() const;
162  void setZoom( float z );
163  float zoom() const;
166  const aims::Quaternion & quaternion() const;
167  void setQuaternion( const Point4df & q );
168  void setQuaternion( const aims::Quaternion & q );
169  const float* rotation() const;
170  void setXDirection( bool invert );
171  void setYDirection( bool invert );
172  void setZDirection( bool invert );
173  bool invertedX() const;
174  bool invertedY() const;
175  bool invertedZ() const;
176  void setRotationCenter( const Point3df & );
178  bool perspectiveEnabled() const;
179  void enablePerspective( bool );
180  float perspectiveAngle() const;
181  void setPerspectiveAngle( float a );
184  float perspectiveFarPlane() const;
185  void setPerspectiveFarPlane( float d );
186  float perspectiveNearPlane() const;
189  void setAutoCentering( bool );
190  bool autoCentering() const;
191  virtual void recordStart( const QString & basename,
192  const QString & format = QString(),
193  int width=0, int height=0 );
194  void saveContents( const QString & filename, const QString & format,
195  int width=0, int height=0 );
196  QImage snapshotImage( int bufmode, int width=0, int height=0 );
197  void saveOtherBuffer( const QString & filename,
198  const QString & format, int mode,
199  int width=0, int height=0 );
200  void setOtherBuffersSaveMode( int mode );
201  int otherBuffersSaveMode() const;
202 
203  bool hasTransparentObjects() const;
204  void setTransparentObjects( bool );
205  bool depthPeelingAllowed() const;
206  bool depthPeelingEnabled() const;
207  void enableDepthPeeling( bool );
208  unsigned depthPeelingPasses() const;
209  void setDepthPeelingPasses( unsigned n );
210  unsigned numTextureUnits() const;
211  bool recording() const;
212 
213 #ifdef ANA_USE_QOPENGLWIDGET
214  static QOpenGLWidget* sharedWidget();
215 #else
216  static QGLWidget* sharedWidget();
217 #endif
218  void setBackgroundAlpha( float a );
219 
224 
226  const AWindow * aWindow() const;
227 
228  virtual int width() = 0;
229  virtual int height() = 0;
230  // public slots:
231 
232  virtual void saveContents();
234  virtual void recordStart();
236  virtual void recordStop();
237 
238  bool hasCameraChanged() const;
241  void resizeOtherFramebuffers( int w, int h );
242 
245 
246  protected:
247  virtual void project( int virtualWidth=0, int virtualHeight=0 );
248  virtual void setupView( int virtualWidth=0, int virtualHeight=0 );
254  virtual void paintGL( DrawMode m, int virtualWidth=0, int virtualHeight=0 );
255  void record();
256 
259 
260  virtual void updateZBuffer();
261  bool isZBufferUpToDate() const;
262  void setZBufferUpdated( bool );
264  bool isRGBBufferUpToDate() const;
265  void setRGBBufferUpdated( bool );
266 
267  private:
268  Private *_pd;
269  };
270 
271 };
272 
273 
275 class GLWidgetManager_Private_QObject : public QObject
276 {
277  Q_OBJECT
278 
279 public:
283 
284 public slots:
285  void saveContents();
287  void recordStart();
289  void recordStop();
290 
291 protected slots:
293 
294 private:
295  anatomist::GLWidgetManager *_manager;
296 };
297 
298 
299 #endif
#define slots
GLWidgetManager_Private_QObject(QObject *parent, anatomist::GLWidgetManager *man)
Abstract base class Anatomist window.
Definition: Window.h:58
Base class for OpenGL-rendering widget.
GLubyte * getTextureFromBackBuffer()
bool perspectiveEnabled() const
void setOtherBuffersSaveMode(int mode)
bool depthPeelingEnabled() const
bool depthPeelingAllowed() const
void setYDirection(bool invert)
virtual void resizeGL(int w, int h)
void setMinimumSizeHint(const QSize &)
void saveOtherBuffer(const QString &filename, const QString &format, int mode, int width=0, int height=0)
virtual bool positionFromCursor(int x, int y, Point3df &position)
void setLightGLList(GLuint l)
virtual void focusInEvent(QFocusEvent *)
void setRightEye(GLWidgetManager *)
bool perspectiveAutoFarPlane() const
void setWindowExtrema(const Point3df &bmin, const Point3df &bmax)
set window extrema (in the local orientation)
bool isZBufferUpToDate() const
float perspectiveNearPlane() const
void drawObjects(DrawMode m=Normal)
void resizeOtherFramebuffers(int w, int h)
void setPerspectiveAngle(float a)
virtual bool cursorFromPosition(const Point3df &position, Point3df &cursor)
virtual void keyPressEvent(QKeyEvent *ev)
Point3df rotationCenter() const
virtual void recordStart()
void setLeftEye(GLWidgetManager *)
virtual void mouseReleaseEvent(QMouseEvent *me)
virtual void paintScene()
basically calls paintGL()
virtual void mousePressEvent(QMouseEvent *me)
GLWidgetManager(anatomist::AWindow *win, QGLWidget *widget)
virtual void keyReleaseEvent(QKeyEvent *ev)
Point3df windowBoundingMin() const
virtual void focusOutEvent(QFocusEvent *)
Point3df boundingMin() const
GLuint lightGLList() const
QObject * qobject()
this QObject is used for slots: updateZBuffer, saveContents, recordStart, recordStop
virtual void readBackBuffer(int x, int y, GLubyte &red, GLubyte &green, GLubyte &blue)
void setPerspectiveAutoFarPlane(bool x)
virtual void paintGL(DrawMode m, int virtualWidth=0, int virtualHeight=0)
Virtual width and height are used to perform off-screen rendering.
virtual void recordStart(const QString &basename, const QString &format=QString(), int width=0, int height=0)
QImage snapshotImage(int bufmode, int width=0, int height=0)
virtual void setupView(int virtualWidth=0, int virtualHeight=0)
static QGLWidget * sharedWidget()
const float * rotation() const
virtual void initializeGL()
void setRotationCenter(const Point3df &)
anatomist::GLPrimitives primitives() const
float perspectiveFarPlane() const
bool isRGBBufferUpToDate() const
virtual void updateZBuffer()
virtual void saveContents()
unsigned depthPeelingPasses() const
unsigned numTextureUnits() const
void setSelectionPrimitives(const anatomist::GLPrimitives &li)
virtual std::string name() const
bool hasTransparentObjects() const
void bindOtherFramebuffer(DrawMode m)
virtual void mouseMoveEvent(QMouseEvent *me)
float perspectiveNearPlaneRatio() const
void depthPeelingRender(DrawMode m=Normal)
void saveContents(const QString &filename, const QString &format, int width=0, int height=0)
void setQuaternion(const Point4df &q)
int otherBuffersSaveMode() const
anatomist::GLPrimitives _selectprimitives
anatomist::GLPrimitives selectionPrimitives() const
void setPerspectiveNearPlaneRatio(float d)
void setPreferredSize(int, int)
GLWidgetManager * leftEye()
virtual void project(int virtualWidth=0, int virtualHeight=0)
virtual bool translateCursorPosition(float x, float y, Point3df &position)
void setExtrema(const Point3df &bmin, const Point3df &bmax)
set objects extrema, this also automatically sets the window bounding box
virtual QSize minimumSizeHint() const
void setDepthPeelingPasses(unsigned n)
void renderBackBuffer(ViewState::glSelectRenderMode selectmode)
void setXDirection(bool invert)
virtual Point3df objectPositionFromWindow(const Point3df &winpos)
virtual QSize sizeHint() const
void setBackgroundAlpha(float a)
GLWidgetManager * rightEye()
const AWindow * aWindow() const
const aims::Quaternion & quaternion() const
The quaternion rotates the initial eye direction (0, 0, 1) into the view coordinates,...
void setPrimitives(const anatomist::GLPrimitives &li)
virtual void mouseDoubleClickEvent(QMouseEvent *)
Point3df boundingMax() const
float perspectiveAngle() const
void setPerspectiveFarPlane(float d)
void setZDirection(bool invert)
virtual void wheelEvent(QWheelEvent *)
Point3df windowBoundingMax() const
void setQuaternion(const aims::Quaternion &q)
anatomist::GLPrimitives _primitives
see http://doc.qt.digia.com/qq/qq26-openglcanvas.html
std::list< RefGLItem > GLPrimitives
Definition: primitive.h:156