Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TuningGLView.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2015 "Omnidome" by cr8tr
2  * Dome Mapping Projection Software (http://omnido.me).
3  * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
4  *
5  * This file is part of Omnidome.
6  *
7  * Omnidome is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Affero General Public License for more details.
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef OMNI_UI_TUNINGGLVIEW_H_
21 #define OMNI_UI_TUNINGGLVIEW_H_
22 
23 #include <QOpenGLFramebufferObject>
24 
25 #include <omni/ui/GLView.h>
27 #include <omni/visual/Session.h>
28 #include <omni/visual/Tuning.h>
30 
31 namespace omni {
32  namespace ui {
33  /// A GLView for visualizing all modes of a projector view (tuning)
34  class TuningGLView :
35  public GLView,
36  public mixin::SharedDataModel<Session>,
37  public mixin::TuningFromIndex<TuningGLView>{
38  Q_OBJECT
40 
41  public:
42  TuningGLView(QWidget * = nullptr);
43  ~TuningGLView();
44 
45  /// If disabled, this widget accepts user inputs
46  bool viewOnly() const;
47 
48  /// If disabled, screen rect will be stretched over whole widget
49  bool keepAspectRatio() const;
50 
51  /// Flag for toggling drawing. Only black background is shown when false
52  bool isDrawingEnabled() const;
53 
54  /// Returns true if cursor is visible
55  bool showCursor() const;
56 
57  bool fullscreenMode() const;
58 
59  /// Return relative border value
60  float border() const;
61 
62  void setChildViews(std::set<TuningGLView *>const&);
63  std::set<TuningGLView *>childViews() const;
64 
65  public slots:
66  /// Set tuning index from session
67  void setTuningIndex(int);
68 
69  /// If disabled, screen rect will be stretched over whole widget
70  void setKeepAspectRatio(bool);
71 
72  /// If true, this widget does NOT accept user inputs
73  void setViewOnly(bool);
74 
75  void setShowCursor(bool);
76 
77  /**@brief Set flag which tells if projector view is actually drawn
78  * @detail Used for activate/deactivate fullscreen view
79  **/
80  void setDrawingEnabled(bool);
81 
82  /// Set relative border distance
83  void setBorder(float);
84 
85  /// Set fullscreen mode
86  void setFullScreenMode(bool);
87 
88  void updateWithChildViews();
89 
90  private slots:
91 
92  signals:
93  void dataModelChanged();
94 
95  protected:
96  void paintGL();
97  void mouseMoveEvent(QMouseEvent *event);
98  void mousePressEvent(QMouseEvent *event);
99  void mouseReleaseEvent(QMouseEvent *event);
100  void wheelEvent(QWheelEvent *event);
101  void keyPressEvent(QKeyEvent *event);
102  void showEvent(QShowEvent *event);
103 
104  private:
105  virtual void dataToFrontend();
106  inline virtual bool frontendToData() {
107  return false;
108  }
109 
110  bool flipped() const;
111 
112  void drawOutput(
113  float _blendMaskOpacity,
114  float _inputOpacity = 1.0,
115  QColor _color = Qt::white);
116 
117  /// Draw Canvas from Projector's perspective
118  void drawCanvas();
119 
120  /// Draw warp grid with handles while keeping aspect ratio
121  void drawWarpGrid();
122 
123  /// Draw blend mask with stroke buffer
124  void drawBlendMask();
125 
126  /// Draw test card image
127  void drawTestCard();
128 
129  /// Draw screen border (only if widget is not in view only mode)
130  void drawScreenBorder();
131 
132  /// Draw color corrected view (also used in export mode)
133  void drawColorCorrected();
134 
135  /// Draw fast live view
136  void drawLiveView();
137 
138  /// Update warp buffer which contains image of projector perspective
139  void updateWarpBuffer();
140 
141  /// Get rectangle of orthogonal view frustum
142  QRectF viewRect() const;
143 
144  /// Transform widget position to view position
145  QPointF screenPos(QPointF const& _pos) const;
146 
147  // Transform widget position to position in tuning image
148  QPointF pixelPos(QPointF const& _pos) const;
149 
150  /// Drawing function for drawing on orthogonal 2D surface within view
151  // rect
152  template<typename F>
153  void drawOnSurface(F f);
154 
155  /// Initialize OpenGL objects
156  bool initialize();
157 
158  /// Flags which determines if aspect ratio is used when drawing content
159  bool keepAspectRatio_ = false;
160 
161  /// Flag determines if user input is not accepted
162  bool viewOnly_ = false;
163 
164  /// Flag for toggling drawing. Only black background is shown when false
165  bool drawingEnabled_ = true;
166 
167  /// Flag which tells if mouse button is down
168  bool mouseDown_ = false;
169 
170  /// Cursor position (is not mouse position when widget is view only)
172 
173  /// Last stroke position
174  QPointF lastStrokePos_;
175 
176  /// Show cursor flag (cursor is also shown when widget is view only)
177  bool showCursor_ = true;
178 
179  /// Left over distance value for blend blush
180  float leftOverDistance_ = 0.0;
181 
182  /// Relative border
183  float border_ = 0.0;
184 
185  /// True if this widget is shown in fullscreen mode
186  bool fullscreenMode_ = false;
187 
188  std::set<TuningGLView *> childViews_;
189  };
190  }
191 }
192 
193 #endif /* OMNI_UI_TUNINGGLVIEW_H_ */
void drawScreenBorder()
Draw screen border (only if widget is not in view only mode)
Definition: TuningGLView.cpp:530
void wheelEvent(QWheelEvent *event)
Definition: TuningGLView.cpp:296
void drawTestCard()
Draw test card image.
Definition: TuningGLView.cpp:545
bool showCursor_
Show cursor flag (cursor is also shown when widget is view only)
Definition: TuningGLView.h:177
A session consists of a canvas, a mapping, a list of tunings and one or several inputs.
Definition: Session.h:41
#define OMNI_UI_SHARED_DATAMODEL(MODEL)
Definition: DataModel.h:216
void drawOnSurface(F f)
Drawing function for drawing on orthogonal 2D surface within view.
Definition: TuningGLView.cpp:434
void drawLiveView()
Draw fast live view.
Definition: TuningGLView.cpp:526
void updateWithChildViews()
Definition: TuningGLView.cpp:124
void keyPressEvent(QKeyEvent *event)
Definition: TuningGLView.cpp:310
QPointF cursorPosition_
Cursor position (is not mouse position when widget is view only)
Definition: TuningGLView.h:171
bool fullscreenMode() const
Definition: TuningGLView.cpp:95
std::set< TuningGLView * > childViews_
Definition: TuningGLView.h:188
void setChildViews(std::set< TuningGLView * >const &)
Definition: TuningGLView.cpp:114
void drawBlendMask()
Draw blend mask with stroke buffer.
Definition: TuningGLView.cpp:477
void showEvent(QShowEvent *event)
Definition: TuningGLView.cpp:555
bool showCursor() const
Returns true if cursor is visible.
Definition: TuningGLView.cpp:90
float border() const
Return relative border value.
Definition: TuningGLView.cpp:109
bool initialize()
Initialize OpenGL objects.
Definition: TuningGLView.cpp:349
void drawCanvas()
Draw Canvas from Projector's perspective.
Definition: TuningGLView.cpp:411
bool fullscreenMode_
True if this widget is shown in fullscreen mode.
Definition: TuningGLView.h:186
bool drawingEnabled_
Flag for toggling drawing. Only black background is shown when false.
Definition: TuningGLView.h:165
QPointF screenPos(QPointF const &_pos) const
Transform widget position to view position.
Definition: TuningGLView.cpp:392
float leftOverDistance_
Left over distance value for blend blush.
Definition: TuningGLView.h:180
TuningGLView(QWidget *=nullptr)
Definition: TuningGLView.cpp:30
void setTuningIndex(int)
Set tuning index from session.
Definition: TuningGLView.cpp:44
bool keepAspectRatio_
Flags which determines if aspect ratio is used when drawing content.
Definition: TuningGLView.h:159
void setKeepAspectRatio(bool)
If disabled, screen rect will be stretched over whole widget.
Definition: TuningGLView.cpp:62
bool viewOnly() const
If disabled, this widget accepts user inputs.
Definition: TuningGLView.cpp:68
QRectF viewRect() const
Get rectangle of orthogonal view frustum.
Definition: TuningGLView.cpp:363
float border_
Relative border.
Definition: TuningGLView.h:183
void mouseMoveEvent(QMouseEvent *event)
Definition: TuningGLView.cpp:140
void setFullScreenMode(bool)
Set fullscreen mode.
Definition: TuningGLView.cpp:85
virtual void dataToFrontend()
Pure virtual method which determines how data model is represented in frontend.
Definition: TuningGLView.cpp:626
void updateWarpBuffer()
Update warp buffer which contains image of projector perspective.
void paintGL()
Paint GL routine.
Definition: TuningGLView.cpp:570
void drawWarpGrid()
Draw warp grid with handles while keeping aspect ratio.
Definition: TuningGLView.cpp:454
void setBorder(float)
Set relative border distance.
Definition: TuningGLView.cpp:134
void setDrawingEnabled(bool)
Set flag which tells if projector view is actually drawn Used for activate/deactivate fullscreen vie...
Definition: TuningGLView.cpp:104
~TuningGLView()
Definition: TuningGLView.cpp:40
QPointF lastStrokePos_
Last stroke position.
Definition: TuningGLView.h:174
Holds a specific data model with frontend update mechanism.
Definition: DataModel.h:87
void mousePressEvent(QMouseEvent *event)
Mouse press event sets mouse position.
Definition: TuningGLView.cpp:208
bool isDrawingEnabled() const
Flag for toggling drawing. Only black background is shown when false.
Definition: TuningGLView.cpp:99
Definition: TuningFromIndex.h:30
std::set< TuningGLView * > childViews() const
Definition: TuningGLView.cpp:119
void drawColorCorrected()
Draw color corrected view (also used in export mode)
Definition: TuningGLView.cpp:519
bool flipped() const
Definition: TuningGLView.cpp:497
bool keepAspectRatio() const
If disabled, screen rect will be stretched over whole widget.
Definition: TuningGLView.cpp:57
bool mouseDown_
Flag which tells if mouse button is down.
Definition: TuningGLView.h:168
GLView for visualizing tunings or session Holds shared_ptr to session as data model.
Definition: GLView.h:35
void setShowCursor(bool)
Definition: TuningGLView.cpp:79
A GLView for visualizing all modes of a projector view (tuning)
Definition: TuningGLView.h:34
void mouseReleaseEvent(QMouseEvent *event)
Definition: TuningGLView.cpp:266
virtual bool frontendToData()
Return true if data has changed by front end.
Definition: TuningGLView.h:106
bool viewOnly_
Flag determines if user input is not accepted.
Definition: TuningGLView.h:162
void drawOutput(float _blendMaskOpacity, float _inputOpacity=1.0, QColor _color=Qt::white)
Definition: TuningGLView.cpp:502
QPointF pixelPos(QPointF const &_pos) const
Definition: TuningGLView.cpp:401
void setViewOnly(bool)
If true, this widget does NOT accept user inputs.
Definition: TuningGLView.cpp:73