anatomist  5.0.5
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 #include <QtOpenGL/QGLWidget>
44 #if QT_VERSION >= 0x040600
45 class QGestureEvent;
46 #endif
47 
48 
49 namespace aims
50 {
51  class Quaternion;
52 }
53 
55 
56 
57 namespace anatomist
58 {
59  class AWindow;
60 
61  namespace internal
62  {
63  class AGraphicsView;
64  }
65 
66 
72  {
73  public:
74  virtual QSize sizeHint() const;
75  virtual QSize minimumSizeHint() const;
76 
77  virtual void updateGL();
78  void renderBackBuffer( ViewState::glSelectRenderMode selectmode );
79  void copyBackBuffer2Texture(void);
81  virtual void paintScene();
82 
83  protected:
84  virtual void initializeGL();
85  virtual void resizeGL( int w, int h );
86  virtual void paintGL();
87 #if QT_VERSION >= 0x040600
88  virtual void gestureEvent( QGestureEvent *event );
89 #endif
90  virtual void mousePressEvent( QMouseEvent* me );
91  virtual void mouseReleaseEvent( QMouseEvent* me );
92  virtual void mouseMoveEvent( QMouseEvent* me );
93  virtual void mouseDoubleClickEvent( QMouseEvent * );
94  virtual void keyPressEvent( QKeyEvent* ev );
95  virtual void keyReleaseEvent( QKeyEvent* ev );
96  virtual void focusInEvent( QFocusEvent * );
97  virtual void focusOutEvent( QFocusEvent * );
98  virtual void wheelEvent( QWheelEvent * );
99 
100  public:
101  // this private structure is public because it's used by internal functions
102  struct Private;
103  friend class ::GLWidgetManager_Private_QObject;
104 
105  GLWidgetManager( anatomist::AWindow* win, QGLWidget* widget );
106  virtual ~GLWidgetManager();
107 
108  QGLWidget* qglWidget();
111  QObject* qobject();
112 
113  void setPrimitives( const anatomist::GLPrimitives & li );
114  anatomist::GLPrimitives primitives() const;
115  void setSelectionPrimitives( const anatomist::GLPrimitives & li );
116  anatomist::GLPrimitives selectionPrimitives() const;
117  void clearLists();
120  void setExtrema( const Point3df & bmin, const Point3df & bmax );
122  void setWindowExtrema( const Point3df & bmin, const Point3df & bmax );
123  Point3df boundingMin() const;
124  Point3df boundingMax() const;
125  Point3df windowBoundingMin() const;
126  Point3df windowBoundingMax() const;
127  void setLightGLList( GLuint l );
128  GLuint lightGLList() const;
129  void setPreferredSize( int, int );
130  void setMinimumSizeHint( const QSize & );
131  virtual bool positionFromCursor( int x, int y, Point3df & position );
132  virtual bool cursorFromPosition( const Point3df & position, Point3df & cursor );
133  virtual Point3df objectPositionFromWindow( const Point3df & winpos );
134  virtual void readBackBuffer( int x, int y, GLubyte & red, GLubyte & green,
135  GLubyte & blue );
136  GLubyte* getTextureFromBackBuffer (void);
137  //GLubyte* getTextureFromBackBuffer (void);
138  virtual bool translateCursorPosition( float x, float y,
139  Point3df & position );
140 
141  virtual std::string name() const;
142  void setZoom( float z );
143  float zoom() const;
146  const aims::Quaternion & quaternion() const;
147  void setQuaternion( const Point4df & q );
148  void setQuaternion( const aims::Quaternion & q );
149  const float* rotation() const;
150  void setXDirection( bool invert );
151  void setYDirection( bool invert );
152  void setZDirection( bool invert );
153  bool invertedX() const;
154  bool invertedY() const;
155  bool invertedZ() const;
156  void setRotationCenter( const Point3df & );
157  Point3df rotationCenter() const;
158  bool perspectiveEnabled() const;
159  void enablePerspective( bool );
160  float perspectiveAngle() const;
161  void setPerspectiveAngle( float a );
162  bool perspectiveAutoFarPlane() const;
163  void setPerspectiveAutoFarPlane( bool x );
164  float perspectiveFarPlane() const;
165  void setPerspectiveFarPlane( float d );
166  float perspectiveNearPlane() const;
167  float perspectiveNearPlaneRatio() const;
168  void setPerspectiveNearPlaneRatio( float d );
169  void setAutoCentering( bool );
170  bool autoCentering() const;
171  virtual void recordStart( const QString & basename,
172  const QString & format = QString::null,
173  int width=0, int height=0 );
174  void saveContents( const QString & filename, const QString & format,
175  int width=0, int height=0 );
176  QImage snapshotImage( int bufmode, int width=0, int height=0 );
177  void saveOtherBuffer( const QString & filename,
178  const QString & format, int mode,
179  int width=0, int height=0 );
180  void setOtherBuffersSaveMode( int mode );
181  int otherBuffersSaveMode() const;
182 
183  bool hasTransparentObjects() const;
184  void setTransparentObjects( bool );
185  bool depthPeelingAllowed() const;
186  bool depthPeelingEnabled() const;
187  void enableDepthPeeling( bool );
188  unsigned depthPeelingPasses() const;
189  void setDepthPeelingPasses( unsigned n );
190  unsigned numTextureUnits() const;
191  bool recording() const;
192 
193  static QGLWidget* sharedWidget();
194  void setBackgroundAlpha( float a );
195 
196  GLWidgetManager* rightEye();
197  GLWidgetManager* leftEye();
198  void setRightEye( GLWidgetManager* );
199  void setLeftEye( GLWidgetManager* );
200 
201  AWindow * aWindow();
202  const AWindow * aWindow() const;
203 
204  virtual int width() = 0;
205  virtual int height() = 0;
206  // public slots:
207 
208  virtual void saveContents();
209  void saveContentsWithCustomSize();
210  virtual void recordStart();
211  void recordStartWithCustomSize();
212  virtual void recordStop();
213 
214  bool hasCameraChanged() const;
215 
218 
219  protected:
220  enum DrawMode
221  {
226  PolygonSelect
227  };
228 
229  virtual void project( int virtualWidth=0, int virtualHeight=0 );
230  virtual void setupView( int virtualWidth=0, int virtualHeight=0 );
231  void drawObjects( DrawMode m = Normal );
232  void depthPeelingRender( DrawMode m = Normal );
236  virtual void paintGL( DrawMode m, int virtualWidth=0, int virtualHeight=0 );
237  void record();
238 
241 
242  virtual void updateZBuffer();
243  bool isZBufferUpToDate() const;
244  void setZBufferUpdated( bool );
245  void stopZBufferTimer();
246  bool isRGBBufferUpToDate() const;
247  void setRGBBufferUpdated( bool );
248 
249  private:
250  Private *_pd;
251  };
252 
253 };
254 
255 
257 class GLWidgetManager_Private_QObject : public QObject
258 {
259  Q_OBJECT
260 
261 public:
262  GLWidgetManager_Private_QObject( QObject* parent,
265 
266 public slots:
267  void saveContents();
268  void saveContentsWithCustomSize();
269  void recordStart();
270  void recordStartWithCustomSize();
271  void recordStop();
272 
273 protected slots:
274  void updateZBuffer();
275 
276 private:
277  anatomist::GLWidgetManager *_manager;
278 };
279 
280 
281 #endif
anatomist::GLPrimitives _primitives
Base class for OpenGL-rendering widget.
Abstract base class Anatomist window.
Definition: Window.h:57
#define slots
see http://doc.qt.digia.com/qq/qq26-openglcanvas.html
anatomist::GLPrimitives _selectprimitives
std::list< RefGLItem > GLPrimitives
Definition: primitive.h:156
private internal class