QtBaseViewer.hh 33.6 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
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
*                                                                            *
*                              OpenFlipper                                   *
*      Copyright (C) 2001-2010 by Computer Graphics Group, RWTH Aachen       *
*                           www.openflipper.org                              *
*                                                                            *
*--------------------------------------------------------------------------- *
*  This file is part of OpenFlipper.                                         *
*                                                                            *
*  OpenFlipper is free software: you can redistribute it and/or modify       *
*  it under the terms of the GNU Lesser General Public License as            *
*  published by the Free Software Foundation, either version 3 of            *
*  the License, or (at your option) any later version with the               *
*  following exceptions:                                                     *
*                                                                            *
*  If other files instantiate templates or use macros                        *
*  or inline functions from this file, or you compile this file and          *
*  link it with other files to produce an executable, this file does         *
*  not by itself cause the resulting executable to be covered by the         *
*  GNU Lesser General Public License. This exception does not however        *
*  invalidate any other reasons why the executable file might be             *
*  covered by the GNU Lesser General Public License.                         *
*                                                                            *
*  OpenFlipper is distributed in the hope that it will be useful,            *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
*  GNU Lesser General Public License for more details.                       *
*                                                                            *
*  You should have received a copy of the GNU LesserGeneral Public           *
*  License along with OpenFlipper. If not,                                   *
*  see <http://www.gnu.org/licenses/>.                                       *
*                                                                            *
33
34
35
\*===========================================================================*/

/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
36
37
38
39
40
*                                                                            *
*   $Revision$                                                       *
*   $LastChangedBy$                                                *
*   $Date$                     *
*                                                                            *
41
\*===========================================================================*/
Jan Möbius's avatar
 
Jan Möbius committed
42
43
44
45
46
47




//=============================================================================
//
Jan Möbius's avatar
   
Jan Möbius committed
48
//  CLASS glViewer
Jan Möbius's avatar
 
Jan Möbius committed
49
50
51
//
//=============================================================================

Jan Möbius's avatar
Jan Möbius committed
52
53
#ifndef BASEVIEWER_HH
#define BASEVIEWER_HH
Jan Möbius's avatar
 
Jan Möbius committed
54
55
56

//== INCLUDES =================================================================

Jan Möbius's avatar
   
Jan Möbius committed
57
58
#include <OpenFlipper/common/Types.hh>
#include <OpenFlipper/common/ViewerProperties.hh>
Jan Möbius's avatar
 
Jan Möbius committed
59
60
61
62
63

#include <ACG/GL/GLState.hh>
#include <ACG/Scenegraph/SceneGraph.hh>
#include <ACG/QtWidgets/QtSceneGraphWidget.hh>

64
65
66
#include <ACG/ShaderUtils/GLSLShader.hh>
#include <ACG/GL/globjects.hh>

Jan Möbius's avatar
 
Jan Möbius committed
67
68
69
70
71
72
73
74
75
#include <QtOpenGL/QGLFormat>
#include <QBoxLayout>
#include <QtNetwork/QUdpSocket>
#include <QWheelEvent>
#include <QDropEvent>
#include <QContextMenuEvent>
#include <QDragEnterEvent>
#include <QMouseEvent>
#include <QAction>
76
#include <QKeyEvent>
Jan Möbius's avatar
 
Jan Möbius committed
77
78
79
80
81
82
#include <QSize>
#include <QMap>
#include <QString>
#include <QMenu>
#include <QToolBar>
#include <QTime>
83
#include <QTimer>
Jan Möbius's avatar
   
Jan Möbius committed
84
85
#include <QGraphicsWidget>
#include <QGraphicsSceneDragDropEvent>
Jan Möbius's avatar
 
Jan Möbius committed
86
87
88
89
90
91
92
93
94
95
96
97
98
99

#include <vector>
#include <string>


//== FORWARDDECLARATIONS ======================================================


class QPushButton;
class QToolButton;
class QSplitter;
class QTimer;
class QImage;
class QSocketNotifier;
Jan Möbius's avatar
Jan Möbius committed
100
class QGLFramebufferObject;
Jan Möbius's avatar
 
Jan Möbius committed
101
102
103
104
105
106
107
108
109
110
111


//== NAMESPACES ===============================================================

//== FORWARDDECLARATIONS ======================================================

namespace ACG {
  namespace QtWidgets {
    class QtWheel;
  }
}
112
class QGraphicsScene;
Jan Möbius's avatar
Jan Möbius committed
113
class QtGLViewerLayout;
Jan Möbius's avatar
 
Jan Möbius committed
114
class QtShiftPopupMenu;
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
115
class CursorPainter;
Jan Möbius's avatar
 
Jan Möbius committed
116
117
118
119
120


//== CLASS DEFINITION =========================================================


Jan Möbius's avatar
Jan Möbius committed
121
/** \class glViewer QtBaseViewer.hh <OpenFlipper/widgets/glWidget/QtBaseViewer.hh>
Jan Möbius's avatar
 
Jan Möbius committed
122

Jan Möbius's avatar
Jan Möbius committed
123
124
    Base Viewer Widget: All viewers are derived from this one. Implements
    Mouse & Keyboard Events.
Jan Möbius's avatar
 
Jan Möbius committed
125
126
 **/

Jan Möbius's avatar
   
Jan Möbius committed
127
class DLLEXPORT glViewer : public QGraphicsWidget
Jan Möbius's avatar
 
Jan Möbius committed
128
129
130
131
132
133
134
135
{
Q_OBJECT

//-------------------------------------------------------------- public methods
public:

  //--------------------------------------------------- constructor / destructor

Jan Möbius's avatar
   
Jan Möbius committed
136
  /** Create a glViewer.
Jan Möbius's avatar
 
Jan Möbius committed
137
138
    \param _parent parent widget
    \param _name name (qt internal, qt debugging)
Dirk Wilden's avatar
Dirk Wilden committed
139
    \param _properties viewerOptions controlled by PluginFunctions
Jan Möbius's avatar
 
Jan Möbius committed
140
141
142
143
    \param _statusBar pointer to an existing status bar for this widget,
     if \c statusBar==0 then a \a private status bar will be created
    \param _format OpenGL context settings, will be passed to glarea()
  */
144
  glViewer( QGraphicsScene* _scene,
145
146
            QGLWidget* _glWidget,
            Viewer::ViewerProperties& _properties,
147
            QGraphicsWidget* _parent=0);
Jan Möbius's avatar
 
Jan Möbius committed
148
149

  /// Destructor.
Jan Möbius's avatar
   
Jan Möbius committed
150
  virtual ~glViewer();
Jan Möbius's avatar
 
Jan Möbius committed
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170





  //------------------------------------------------------------- public methods

  virtual QSize sizeHint () const;

  /// Makes this widget the current widget for OpenGL operations.
  virtual void makeCurrent();
  /// Swaps the screen contents with the off-screen buffer.
  virtual void swapBuffers();

  /// Lock update of projection matrix.
  void lockProjectionUpdate( void ) { projectionUpdateLocked_ = true; }

  /// Unlock update of projection matrix.
  void unlockProjectionUpdate( void ) { projectionUpdateLocked_ = false; }

171
172
  signals :
    void functionMenuUpdate();
Jan Möbius's avatar
 
Jan Möbius committed
173

174
175
    void statusMessage (const QString & message, int timeout = 0);

176
  public:
Jan Möbius's avatar
 
Jan Möbius committed
177

178
179
  /// Enable/disable mouse tracking (move events with no button press)
  void trackMouse(bool _track);
Jan Möbius's avatar
 
Jan Möbius committed
180
181
182

  /** Set scene graph.
      Sets the scene graph to the the graph rooted at \c _root.
183
      Recomputes Scene center and resets the trackball center if specified.
Jan Möbius's avatar
 
Jan Möbius committed
184
185
186
      The \c sceneGraphToched() signal will be emitted (even if
      \c _root does not actually change).
  */
187
  void sceneGraph(ACG::SceneGraph::BaseNode* _root, const bool _resetTrackBall = false);
Jan Möbius's avatar
 
Jan Möbius committed
188
189
190
191
192
193
194
195


   /// projection mode
  enum ProjectionMode {
    ORTHOGRAPHIC_PROJECTION, //!< orthographic
    PERSPECTIVE_PROJECTION   //!< perspective
  };

196
197
198
  /// Navigation mode
  enum NavigationMode {
	  NORMAL_NAVIGATION, 	 //!< Normal mode
Mike Kremer's avatar
Mike Kremer committed
199
	  FIRSTPERSON_NAVIGATION  //!< First person mode
200
201
  };

Jan Möbius's avatar
 
Jan Möbius committed
202
203
204
205
206
  /// Changes the projection mode and updates the projection matrix.
  void projectionMode(ProjectionMode _p);
  /// get current projection mode
  ProjectionMode projectionMode() const { return projectionMode_; }

207
208
209
210
  /// Changes the navigation mode
  void navigationMode(NavigationMode _n);
  /// get current navigation mode
  NavigationMode navigationMode() const { return navigationMode_; }
Jan Möbius's avatar
 
Jan Möbius committed
211

212
213
  /** Sets the center and dimension of the whole scene.  This point is
      used as fixpoint for rotations and to set the eye point far
Jan Möbius's avatar
 
Jan Möbius committed
214
215
      enough from the scene so that the whole scene is visible.
    */
216
  void setScenePos( const ACG::Vec3d& _center, double _radius, const bool _resetTrackBall = false );
217

Jan Möbius's avatar
 
Jan Möbius committed
218
219
  /// set the viewing direction
  void viewingDirection( const ACG::Vec3d& _dir, const ACG::Vec3d& _up );
220
221
222
  
  /// Set look at transformation directly
  void lookAt(const ACG::Vec3d& _eye, const ACG::Vec3d& _center, const ACG::Vec3d& _up);
223
  
Jan Möbius's avatar
 
Jan Möbius committed
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
  /// Automatically normalize normals?
  enum NormalsMode {
    /// use provided normals as is
    DONT_TOUCH_NORMALS,
    /** Automatically normalize normals.
        Input normals are not normalized \a or the transformation matrix
	does scaling or shearing.
     */
    NORMALIZE_NORMALS
  };

  /// set treatment of normals
  void normalsMode(NormalsMode _mode);
  /// get treatment of normals
  NormalsMode normalsMode() const { return normalsMode_; }

  /// copy current framebuffer to an QImage
  void copyToImage( QImage& _image, GLenum _buffer=GL_BACK) {
    copyToImage(_image, 0, 0, glWidth(), glHeight(), _buffer);
  }

  /// copy current framebuffer to an QImage
  void copyToImage( QImage& _image,
		    unsigned int _left,  unsigned int _top,
		    unsigned int _width, unsigned int _height,
		    GLenum _buffer );


  /// get width of QGLWidget
  unsigned int glWidth() const;
  /// get height of QGLWidget
  unsigned int glHeight() const;
  /// get size of QGLWIdget
  QSize glSize() const;
  /// map global to glarea coords
  QPoint glMapFromGlobal( const QPoint& _pos ) const;
  /// map glarea coords to global coords
  QPoint glMapToGlobal( const QPoint& _pos ) const;

  /// convert current view to text representation
  void encodeView(QString& _view);
  /** Decode and apply text representation of view encoded by encodeView().
      If \c _view was successfully decoded it will immediately be applied
      and \c true is returned, \c false is returned else.
   */
  bool decodeView(const QString& _view);

  /// initialize modelview matrix to identity
  void initModelviewMatrix();

  // get all Mouse & Key Events for GlWidget
  void grabGLArea();

  // undo grabbing GLArea
  void releaseGLArea();

  /// One or two pass Drawing
  void drawBlendedObjects(bool _status) { blending_ = _status; }

  /// translate the scene and update modelview matrix
  void translate(const ACG::Vec3d& trans);

  /// rotate the scene (around its center) and update modelview matrix
  void rotate(const ACG::Vec3d& axis, double angle)
288
  { rotate(axis, angle, properties_.trackballCenter()); }
Jan Möbius's avatar
 
Jan Möbius committed
289
290
291
292

  /// rotate the scene and update modelview matrix
  void rotate(const ACG::Vec3d& axis, double angle, const ACG::Vec3d& _center);

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
293
294
295
296
297
298
  /// sets the current cursor painter
  void setCursorPainter (CursorPainter *_cursorPainter);

  /// will be called from CursorPainter to inform the viewer that the cursor position changed
  void updateCursorPosition (QPointF _scenePos);

Mike Kremer's avatar
Mike Kremer committed
299
300
301
302
303
304
305
306
307
308
309
310
  /// First person navigation: Move forward
  void moveForward();

  /// First person navigation: Move back
  void moveBack();

  /// First person navigation: Strafe left
  void strafeLeft();

  /// First person navigation: Strafe Right
  void strafeRight();

Jan Möbius's avatar
 
Jan Möbius committed
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
//---------------------------------------------------------------- public slots
public slots:

  /// Redraw scene. Triggers paint event for updating the view (cf. drawNow()).
  virtual void updateGL();

  /// set home position
  virtual void setHome();
  /// go to home pos
  virtual void home();
  /// view the whole scene
  virtual void viewAll();
  /// Fly to. Get closer if \c _move_back=\c false, get more distant else.
  virtual void flyTo(const QPoint& _pos, bool _move_back);
  /// Fly to, get closer.
  virtual void flyTo(const QPoint& _pos) { flyTo(_pos,false); }
  /// Fly to, get more distant.
  virtual void flyFrom(const QPoint& _pos) { flyTo(_pos,true); }

  /**  Fly to point and set new viewing direction (animated).
   * @param _position New viewer position ( the new eye point of the viewer )
   * @param _center   The new scene center ( the point we are looking at )
   * @param _time     Animation time in ms
   */
  virtual void flyTo(const ACG::Vec3d& _position,
		               const ACG::Vec3d& _center,
		               double       _time = 1000.0);

  /// set perspective view (projectionMode(PERSPECTIVE_PROJECTION))
  virtual void perspectiveProjection();
  /// set orthographic view (projectionMode(ORTHOGRAPHIC_PROJECTION))
  virtual void orthographicProjection();
  /// toggle projection mode
  virtual void toggleProjectionMode();
345
346
  /// toggle navigation mode
  virtual void toggleNavigationMode();
347
348
349
  
  /// Set fovy
  virtual void setFOVY(double _fovy);
Jan Möbius's avatar
 
Jan Möbius committed
350

351
352
353
  signals:

    void projectionModeChanged( bool _ortho );
354
    void navigationModeChanged( bool _normal );
355
356

  public slots:
Jan Möbius's avatar
 
Jan Möbius committed
357
358
359
360
361

  /// set view, used for synchronizing
  virtual void setView( const ACG::GLMatrixd& _modelview,
			               const ACG::GLMatrixd& _inverse_modelview );

362
363
364
  void actionPasteView();
  void actionCopyView();

Jan Möbius's avatar
 
Jan Möbius committed
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
//-------------------------------------------------------------- public signals
signals:

  /** A signal for giving mouse events to the application.
      This is done if the Pick-Button (top-most button of the toolbar)
      is activated. Connect to this signal to implement application
      specific handling of mouse events.<br>
      \a Notes:
      \arg You have to test for the QMouseEvent::type() of the
      event yourself (press/release/move)!
      \arg signalMouseEventIdentify() is emitted on button press if
      actionMode()==Question.
  */
  void signalMouseEvent(QMouseEvent*, const std::string&);

  /// This signal does not send the pick mode and is kept for compatibility
  void signalMouseEvent(QMouseEvent*);

  /// Emitted in Pick mode. Uses pick mode.
  void signalWheelEvent(QWheelEvent*, const std::string&);

Jan Möbius's avatar
Mike:    
Jan Möbius committed
386
  /** Emitted instead of signalMouseEvent() if actionMode()==Question
Jan Möbius's avatar
 
Jan Möbius committed
387
388
389
      and \c _event is a mouse press event.
   */
  void signalMouseEventIdentify( QMouseEvent* );
Jan Möbius's avatar
Mike:    
Jan Möbius committed
390
391
392
393
394
  
  /** Emitted instead of signalMouseEvent() if actionMode()==Light
      and \c _event is a mouse press event.
   */
  void signalMouseEventLight( QMouseEvent* );
Jan Möbius's avatar
 
Jan Möbius committed
395
396
397

  /// scene graph has changed
  void signalSceneGraphChanged(ACG::SceneGraph::BaseNode* _root);
398

399
400
401
402
  /** Emitted if a (double) mouse click is performed in actionMode()==ExamineMode
   */
  void signalMouseEventClick ( QMouseEvent*, bool _double );

Jan Möbius's avatar
 
Jan Möbius committed
403
404
405
406
407
408
409
410
411

  signals:

  /** If popups are disabled context menu mode is set to custom Menu and the signal is passed
   * from the QGLWidget to this signal. You can use mapToGlobal for mapping this point to
   * global coords.
   */
  void signalCustomContextMenuRequested ( const QPoint & );

412
413
414
415
416
  private slots:

  /// Handle click timeout
  void slotClickTimeout ();

Jan Möbius's avatar
 
Jan Möbius committed
417
418
419
420
421

//----------------------------------------------------------- protected methods
protected:

  friend class QtGLGraphicsScene;
Jan Möbius's avatar
Jan Möbius committed
422
  friend class SimpleGLGraphicsScene;
Jan Möbius's avatar
 
Jan Möbius committed
423
424
425
426
427
428
429
  friend class QtGLGraphicsView;

  /// initialize OpenGL states
  virtual void initializeGL();
  /// draw the scene. Triggered by updateGL().
  virtual void paintGL();
  /// handle resize events
Jan Möbius's avatar
   
Jan Möbius committed
430
431
432
  virtual void resizeEvent(QGraphicsSceneResizeEvent * _e);
  /// handle move events
  virtual void moveEvent (QGraphicsSceneMoveEvent * _e);
Jan Möbius's avatar
 
Jan Möbius committed
433
434

  /// handle mouse press events
435
  virtual void mousePressEvent(QGraphicsSceneMouseEvent* _event);
Jan Möbius's avatar
 
Jan Möbius committed
436
  /// handle mouse double click events
437
  virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* _event);
Jan Möbius's avatar
 
Jan Möbius committed
438
  /// handle mouse move events
439
  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* _event);
Jan Möbius's avatar
 
Jan Möbius committed
440
  /// handle mouse release events
441
  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* _event);
Jan Möbius's avatar
 
Jan Möbius committed
442
  /// handle mouse wheel events
443
  virtual void wheelEvent(QGraphicsSceneWheelEvent* _event);
Jan Möbius's avatar
 
Jan Möbius committed
444
  /// handle mouse press events
Jan Möbius's avatar
   
Jan Möbius committed
445
  virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent* _e);
Jan Möbius's avatar
 
Jan Möbius committed
446
447
448


  /// specialized viewer: hande mouse events
449
  void viewMouseEvent( QMouseEvent* _event);
Jan Möbius's avatar
 
Jan Möbius committed
450
  /// specialized viewer: handle wheel events
451
  void viewWheelEvent(QWheelEvent* _event);
452
453
  /// specialized viewer: hande key events
  void viewKeyEvent( QKeyEvent* _event);
Jan Möbius's avatar
 
Jan Möbius committed
454

Jan Möbius's avatar
Mike:    
Jan Möbius committed
455
  
Jan Möbius's avatar
 
Jan Möbius committed
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
  protected:


  /// updates projection matrix
  void updateProjectionMatrix();


//------------------------------------------------------------- protected slots
protected slots:

  /// process signals from wheelX_
  virtual void slotWheelX(double _dAngle);
  /// process signals from wheelX_
  virtual void slotWheelY(double _dAngle);
  /// process signals from wheelZ_
  virtual void slotWheelZ(double _dist);

  /// correct ??? (same function as in qt src)
  virtual void cleanupEventFilter()
  { removeEventFilter( sender());}

//----------------------------------------------------------- private functions
private:

  /// Copy constructor. Never used!
Jan Möbius's avatar
   
Jan Möbius committed
481
  glViewer(const glViewer&);
Jan Möbius's avatar
 
Jan Möbius committed
482
  /// Assignment operator. Never used!
Jan Möbius's avatar
   
Jan Möbius committed
483
  glViewer& operator=(const glViewer&);
Jan Möbius's avatar
 
Jan Möbius committed
484
485

  // create widgets
486
  void createWidgets();
Jan Möbius's avatar
 
Jan Möbius committed
487
488
489
490
491
492
493
494
495

  /* Recursively draws each node in the scene graph.
      Called by paintGL(). */
  void drawScene();
  // helper called by drawScene().
  void drawScene_mono();
  // helper called by drawScene() when stereo viewing is active.
  void drawScene_stereo();

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
496
497
498
499
500
501
502
503
504
505
506
507
508
509
  // helper called by drawScene_stereo() when opengl stereo viewing is active.
  void drawScene_glStereo();

  // helper called by drawScene_stereo() when anaglyph stereo viewing is active.
  void drawScene_anaglyphStereo();

  // helper called by drawScene_stereo() when custom anaglyph stereo viewing is active.
  void drawScene_customAnaglyphStereo();

  // helper called to initialize/update custom anaglyph stereo
  void updateCustomAnaglyphStereo();

  // helper called to cleanup custom anaglyph stereo
  void finiCustomAnaglyphStereo();
510

511
512
  // Draws the scene for a philips stereo display ( Header, left color image, right depth map )
  void drawScenePhilipsStereo();
Jan Möbius's avatar
Dennis:    
Jan Möbius committed
513

514
515
516
  // Updates the scene for a philips stereo display
  void updateScenePhilipsStereo();

Jan Möbius's avatar
 
Jan Möbius committed
517
518
519
520
521
//-------------------------------------------------------------- protected data
protected:

  // helper
  bool                         isRotating_;
Mike Kremer's avatar
Mike Kremer committed
522
  bool                         lookAround_;
Jan Möbius's avatar
 
Jan Möbius committed
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539


//---------------------------------------------------------------- private data
private:


  // data stored for home view
  ACG::Vec3d                   home_center_;
  double                       home_radius_;
  ACG::GLMatrixd               home_modelview_,
                               home_inverse_modelview_;
  double                       homeOrthoWidth_;


  // modi
  NormalsMode                  normalsMode_;
  ProjectionMode               projectionMode_;
Jan Möbius's avatar
Jan Möbius committed
540
  NavigationMode               navigationMode_;
541

Jan Möbius's avatar
 
Jan Möbius committed
542
543
544
545
546
547
548
549
550
551
552
553
554
555

  // helper
  bool                         trackMouse_;
  bool                         glareaGrabbed_;
  double                       frame_time_;


  // scenegraph stuff
  ACG::SceneGraph::BaseNode*   sceneGraphRoot_;

  bool                         projectionUpdateLocked_;
  bool                         blending_;

  // graphics scene used to paint gl context and widgets
556
  QGraphicsScene* glScene_;
Jan Möbius's avatar
 
Jan Möbius committed
557

Jan Möbius's avatar
   
Jan Möbius committed
558
559
560
  // gl widget used as drawing area to paint the graphics scene
  QGLWidget* glWidget_;

Jan Möbius's avatar
 
Jan Möbius committed
561
  // Base graphics widget layout
Jan Möbius's avatar
Jan Möbius committed
562
  QtGLViewerLayout* glBaseLayout_;
Jan Möbius's avatar
 
Jan Möbius committed
563
564
565
566
567
568
569

  // vector of current draw mode actions
  std::vector< QAction * > drawMenuActions_;

  // Used to calculate the time passed between redraws
  QTime redrawTime_;

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
570
571
572
573
574
575
576
577
578
  // Used to draw the current cursor in the scene
  CursorPainter *cursorPainter_;

  // position of the cursor picked into the scenegraph
  ACG::Vec3d cursorPoint3D_;

  // indicates that we successfully mapped the cursor into the scene
  bool cursorPositionValid_;

Jan Möbius's avatar
Jan Möbius committed
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
  //===========================================================================
  /** @name Wheels
   * @{ */
  //===========================================================================

  public:
    bool wheelsVisible();

  public slots:
    void slotShowWheels();
    void slotHideWheels();

  private:
    // rotate around x-axis
    ACG::QtWidgets::QtWheel* wheelX_;
    // rotate around y-axis
    ACG::QtWidgets::QtWheel* wheelY_;
    // translate along z-axis
    ACG::QtWidgets::QtWheel* wheelZ_;


  /** @} */

602
603
604
605
606
  //===========================================================================
  /** @name view handling
   * @{ */
  //===========================================================================
  signals:
607
    /// This signal is emitted when the scene is repainted due to any event.
608
    void viewUpdated();
609

610
611
    /// This signal is emitted whenever the view is changed by the user
    void viewChanged();
612

613
614
615
    /// make this widget active
    void signalMakeActive ();

Jan Möbius's avatar
Jan Möbius committed
616
  /** @} */
Jan Möbius's avatar
Jan Möbius committed
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
  
  
  //===========================================================================
  /** @name Projection settings
  * @{ */
    //===========================================================================
    
    public:
    /**
    * Set new center point of scene
    */
    void setSceneCenter( const ACG::Vec3d& _center ) { properties_.sceneCenter(_center); };
    
    /** \brief Set Trackball Center point of scene
    *
    * The scene is rotated around the trackball center when using the mouse
    */
    void setTrackBallCenter( const ACG::Vec3d& _center ) { properties_.trackballCenter(_center); }
    
    /** \brief Get Trackball Center point of scene
    *
    * The scene is rotated around the trackball center when using the mouse
    */
    const ACG::Vec3d trackBallCenter( ) { return properties_.trackballCenter(); };
    
    /** Get scene's center
    \see setScenePos()
    */
    const ACG::Vec3d scene_center() const { return properties_.sceneCenter(); }
    /** Get scene's radius
    \see setScenePos()
    */
    double scene_radius() const { return properties_.sceneRadius(); }
  
  /** @} */
Jan Möbius's avatar
Jan Möbius committed
652

Jan Möbius's avatar
 
Jan Möbius committed
653
654
655
656
657
658
659
660
661
662
663
664
665
666
  //===========================================================================
  /** @name Stereo
   * @{ */
  //===========================================================================

  public slots:

    /// enable/disable stereo mode
    virtual void setStereoMode(bool _b);

  private:
    // stereo stuff
    bool                         stereo_;

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
667
668
669
670
671
672
673
    // custom anaglyph stuff
    int    agTexWidth_;
    int    agTexHeight_;
    GLuint agTexture_[2];
    GLuint agProgram_;
    bool   customAnaglyphSupported_;

674
675
676
677
678
679
680
    // Philips stereo mode stuff
    int     pTexWidth_;
    int     pTexHeight_;
    ACG::Texture2D pColorTexture_;
    ACG::Texture2D pDepthStencilTexture_;
    GLSL::PtrProgram pProgram_;
    bool philipsStereoInitialized_;
Jan Möbius's avatar
 
Jan Möbius committed
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704

  /** @} */


  //===========================================================================
  /** @name Key handling
   * @{ */
  //===========================================================================

  signals:
    /** \brief Key Event received
     *
     * This signal is emitted if a Key press event is received which is not handled by
     * the widget itself. If internal key handling is disabled the events are passed to
     * the parent of this widget.
     */
    void signalKeyPressEvent(QKeyEvent*);

  protected:

    /** \brief Get keyPress events from the glArea
     *
     * This function is called by the internal gl widget when receiving a key press event.
     */
705
    virtual void keyPressEvent(QKeyEvent* _event) { _event->ignore(); };
Jan Möbius's avatar
 
Jan Möbius committed
706
707
708
709
710
711
712

    /** \brief Get keyRelease events from the glArea
     *
     * This function is called by the internal gl widget when receiving a key release event.
     * Here these events are simply passed to the parent widget.
     *
     */
Jan Möbius's avatar
   
Jan Möbius committed
713
    virtual void keyReleaseEvent(QKeyEvent* _event) { _event->ignore(); };
Jan Möbius's avatar
 
Jan Möbius committed
714
715
716
717
718
719
720
721

    /** \brief Handle key events in view mode
     *
     * This funtion is called by the BaseViewer if a key press event occured in view mode.
     * This function has to be implemented by every viewer!
     *
     * @return If the derived class handled the event it has to return true otherwise false
     */
722
    virtual bool viewKeyPressEvent(QKeyEvent* /* _event */ ) { return false; }
Jan Möbius's avatar
 
Jan Möbius committed
723
724
725
726
727
728
729
730

  /** @} */

  //===========================================================================
  /** @name Drag and Drop
   * @{ */
  //===========================================================================

731
  public:
Jan Möbius's avatar
 
Jan Möbius committed
732
733

    /// drag & drop for modelview copying
Jan Möbius's avatar
   
Jan Möbius committed
734
735
    virtual void dragEnterEvent(QGraphicsSceneDragDropEvent* _e);

Jan Möbius's avatar
 
Jan Möbius committed
736
    /// drag & drop for modelview copying
Jan Möbius's avatar
   
Jan Möbius committed
737
    virtual void dropEvent(QGraphicsSceneDragDropEvent* _e);
Jan Möbius's avatar
 
Jan Möbius committed
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769

  signals:
    /** Signal is emitted when Control modifier is pressed and mouse moded.
     * It will only be emitted if in externalDragMode ( see setExternalDrag )
     */
    void startDragEvent( QMouseEvent* _event );

    /** Signal is emitted only if in externalDragMode ( see setExternalDrag )
     * It will be send if a drag enters the gl widget.
     */
    void dragEnterEvent(QDragEnterEvent* _event);

    /** Signal is emitted only if in externalDragMode ( see setExternalDrag )
     * It will be send if a drop occurs in the gl widget.
     */
    void dropEvent( QDropEvent* _event );


  /** @} */

  //===========================================================================
  /** @name Snapshots
   * @{ */
  //===========================================================================

  public slots:


    /** Trigger a snapshot and increase the snapshot counter.
        Save snapshot to file determined by snapshotBaseFileName() and
        the current snapshot counter. The \a back buffer will be saved.
    */
770
    virtual void snapshot(int _width = 0, int _height = 0, bool _alpha = false);
Jan Möbius's avatar
 
Jan Möbius committed
771

Dirk Wilden's avatar
Dirk Wilden committed
772
    /// Take a snapshot and store it in the given image
773
    virtual void snapshot(QImage& _image, int _width = 0, int _height = 0, bool _alpha = false, bool _hideCoordsys = false, int samples = 1);
Dirk Wilden's avatar
Dirk Wilden committed
774

Jan Möbius's avatar
 
Jan Möbius committed
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
  /** @} */

  //===========================================================================
  /** @name Picking
   * @{ */
  //===========================================================================
  public:
    /** Apply pick action. <br>
     *   Information about the picked primitive is stored in the
     *   provided pointers. No information is stored if 0-pointers
     *   are given. Resulting values are defined only if \c true
     *   has been returned!<br>
     *
     * @param _pickTarget Select what should be picked: Faces/Vertices/...
     * @param _mousePos   The position to be used for picking
     * @param _nodeIdx    If picking is successfull this will contain the id of the scenegraph node picked.
     * @param _targetIdx  Special index defined by the picked Node. E.g. Facehandle/VertexHandle/.. for MeshNodes
     * @param _hitPointPtr Pointer to 3D point from picking
     * @return Successfull?
     */
    bool pick( ACG::SceneGraph::PickTarget _pickTarget,
               const QPoint& _mousePos,
               unsigned int& _nodeIdx,
               unsigned int& _targetIdx,
               ACG::Vec3d*   _hitPointPtr=0 );

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
    /** Apply pick action. <br>
     *   Picks all objects in the given Region. Information about the picked primitives is stored in the
     *   provided list. Resulting values are defined only if \c true
     *   has been returned!
     *  <br>
     *
     * @param _pickTarget Select what should be picked: Faces/Vertices/...
     * @param _region     Area for picking
     * @param _list       List of found scenegraph objects (node/target pairs)
     * @return Successfull?
     */
    bool pick_region( ACG::SceneGraph::PickTarget                _pickTarget,
                      const QRegion&                             _region,
                      QList<QPair<unsigned int, unsigned int> >& _list);

Henrik Zimmer's avatar
Henrik Zimmer committed
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870

    /** Apply pick action. <br>
     *   Picks all objects in the given Region. Information about the picked primitives is stored in the
     *   provided list. Resulting values are defined only if \c true
     *   has been returned!
     *  <br>
     *
     * @param _pickTarget Select what should be picked: Faces/Vertices/...
     * @param _region     Area for picking
     * @param _list       List of found scenegraph objects (node/target pairs)
     * @param _points     back projected 3d points
     * @return Successful?
     */
    bool pick_region( ACG::SceneGraph::PickTarget                _pickTarget,
                      const QRegion&                             _region,
                      QList<QPair<unsigned int, unsigned int> >& _list,
                      QVector<ACG::Vec3d>&                       _points);

    /** Apply pick action. <br>
     *   Picks all objects in the given Region. Information about the picked primitives is stored in the
     *   provided list. Resulting values are defined only if \c true
     *   has been returned!
     *  <br>
     *
     * @param _pickTarget Select what should be picked: Faces/Vertices/...
     * @param _region     Area for picking
     * @param _list       List of found scenegraph objects (node/target pairs)
     * @param _depths     depths [0,1]
     * @return Successful?
     */
    bool pick_region( ACG::SceneGraph::PickTarget                _pickTarget,
                      const QRegion&                             _region,
                      QList<QPair<unsigned int, unsigned int> >& _list,
                      QVector<float>&                            _depths);

  /** Apply pick action. <br>
     *   Picks all objects in the given Region. Information about the picked primitives is stored in the
     *   provided list. Resulting values are defined only if \c true
     *   has been returned!
     *  <br>
     *
     * @param _pickTarget Select what should be picked: Faces/Vertices/...
     * @param _region     Area for picking
     * @param _list       List of found scenegraph objects (node/target pairs)
     * @param _depths     depths [0,1]
     * @param _points     back projected 3d points
     * @return Successful?
     */
    bool pick_region( ACG::SceneGraph::PickTarget                _pickTarget,
                      const QRegion&                             _region,
                      QList<QPair<unsigned int, unsigned int> >& _list,
                      QVector<float>&                            _depths,
                      QVector<ACG::Vec3d>&                       _points);


Jan Möbius's avatar
 
Jan Möbius committed
871
872
873
874
875
876
877
878
879
880
    /** get the coordinates of the picked point by z-buffer re-projection
     * @param _mousePos The position to pick
     * @param _hitPoint The point returned by the reprojection
     * @return Successfull?
     */
    bool fast_pick( const QPoint&  _mousePos,
                    ACG::Vec3d&    _hitPoint );

  private:

Jan Möbius's avatar
Dennis:    
Jan Möbius committed
881
882
883
884
885
886
887
888
889
890
891
892
893
894
    /// pick using colors
    int pickColor( ACG::SceneGraph::PickTarget _pickTarget,
                   const QPoint& _mousePos,
                   unsigned int& _nodeIdx,
                   unsigned int& _targetIdx,
                   ACG::Vec3d*   _hitPointPtr=0 );

    /// pick using selection buffer
    bool pickGL( ACG::SceneGraph::PickTarget _pickTarget,
                 const QPoint& _mousePos,
                 unsigned int& _nodeIdx,
                 unsigned int& _targetIdx,
                 ACG::Vec3d*   _hitPointPtr=0 );

Jan Möbius's avatar
Jan Möbius committed
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
    /// pick from cache
    int pickFromCache( ACG::SceneGraph::PickTarget _pickTarget,
                       const QPoint& _mousePos,
                       unsigned int& _nodeIdx,
                       unsigned int& _targetIdx,
                       ACG::Vec3d*   _hitPointPtr=0 );

  private:

    /// Framebuffer object that holds the pick cache
    QGLFramebufferObject *pickCache_;

    /// Should the pick cache be updated
    bool updatePickCache_;

910
911
912
    /// Pick target stored in pick cache
    ACG::SceneGraph::PickTarget pickCacheTarget_;

Jan Möbius's avatar
Jan Möbius committed
913
914
915
    /// Is pick caching supported
    bool pickCacheSupported_;

Jan Möbius's avatar
 
Jan Möbius committed
916
  /** @} */
917
918
919
920
921
922
923
924
925
926

  //===========================================================================
  /** @name Merge from examiner
   * @{ */
  //===========================================================================

  public:

  /// Lock scene rotation
  void allowRotation( bool _mode ) { allowRotation_ = _mode; };
927
  bool allowRotation() { return allowRotation_; };
928
929
930
931
932
933
934

  private slots:

    void slotAnimation();

  protected:

935
936
937
938
    /** \brief mouse interaction position
    *
    * This variable stores the last mouse position during mouse interaction.
    */
939
    QPoint   lastPoint2D_;
940
941
942
943
944
945
    
    /** \brief mouse interaction depth
    *
    * This variable stores the depth when the user started a mouse interaction.
    */
    float startDepth_;
946
947
948
949
950
951

  private:

    /// virtual trackball: map 2D screen point to unit sphere
    bool mapToSphere(const QPoint& _p, ACG::Vec3d& _result) const;

Mike Kremer's avatar
Mike Kremer committed
952
    /// Navigate through scene if first person mode has been selected
Jan Möbius's avatar
Jan Möbius committed
953
    void handleFirstPersonNavigation( QMouseEvent* _event);
954
955

    /// Navigate through scene if normal mode has been selected
Jan Möbius's avatar
Jan Möbius committed
956
    void handleNormalNavigation( QMouseEvent* _event);
957

958
959
960
961
962
963
964
965
966
967
968
969

    // mouse interaction
    ACG::Vec3d    lastPoint3D_;
    bool          lastPoint_hitSphere_;
    bool          allowRotation_;

    // animation stuff
    ACG::Vec3d                   lastRotationAxis_;
    double                       lastRotationAngle_;
    QTime                        lastMoveTime_;
    QTimer*                      timer_;

970
971
972
973
    QTimer                       clickTimer_;
    QTime                        clickTime_;
    QMouseEvent                  clickEvent_;

974
    /** @} */
Jan Möbius's avatar
   
Jan Möbius committed
975
976
977
978
979
980
981
982
983
984
985

  //===========================================================================
  /** @name Viewer State
   * @{ */
  //===========================================================================

  public:
    /// Returns a pointer to the Viewer Status
    Viewer::ViewerProperties* properties(){ return &properties_; };

  private:
986
    /// All properties for this viewer
Dirk Wilden's avatar
Dirk Wilden committed
987
    Viewer::ViewerProperties& properties_;
Jan Möbius's avatar
   
Jan Möbius committed
988

989
990
991
    /// Gl State
    ACG::GLState                 *glstate_;

992
993
994
    /// Have the viewer gl properties been initalized
    bool initialized_;

Jan Möbius's avatar
   
Jan Möbius committed
995
  private slots:
996
997
998
    /** Called when properties for the viewer require a redraw
     * The slot will trigger the redraw after setting the right properties.
     */
Jan Möbius's avatar
   
Jan Möbius committed
999
1000
    void slotPropertiesUpdated();

1001
1002
1003
1004
1005
1006
  private:
    /** This will apply all properties without redrawing
     *  You have to set the context yourself!
     */
    void applyProperties();

Jan Möbius's avatar
   
Jan Möbius committed
1007
  /** @} */
Jan Möbius's avatar
 
Jan Möbius committed
1008
1009
1010
1011
1012
};


//=============================================================================
//=============================================================================
Jan Möbius's avatar
Jan Möbius committed
1013
#endif // BASEVIEWER_HH defined
Jan Möbius's avatar
 
Jan Möbius committed
1014
//=============================================================================