Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
omni::visual::Tuning Class Reference

Tuning visualizer. More...

#include <Tuning.h>

Collaboration diagram for omni::visual::Tuning:
Collaboration graph
[legend]

Public Member Functions

 Tuning (omni::proj::Tuning &)
 
 ~Tuning ()
 
omni::proj::Tuning const & tuning () const
 
void update ()
 Update shaders, warp grid and blend texture. More...
 
void updateBlendTexture ()
 Updates blend texture after it has changed by blend brush. More...
 
void updateWarpGrid ()
 Update warp grid mesh. More...
 
void setBlendTextureUpdateRect (QRect const &)
 Set portion of blend mask which is to be updated. More...
 
void drawTestCard (int _id, bool _grayscale=false)
 Draw Test card image for screen setup. More...
 
void drawWarpGrid () const
 Draws warp grid with lines and handles. More...
 
void drawWarpPatch () const
 Draw warp grip without lines and handles. More...
 
void drawOutput (float _inputOpacity=0.0, QColor const &_color=Qt::white, float _blendMaskOpacity=1.0, bool _grayscale=true) const
 Draws Blendmask with warp grid and brush stroke layer. More...
 
void drawCursor (QPointF const &_pos)
 Draw cursor for blend brush. More...
 
bool initialized () const
 
void updateWarpBuffer (visual::Session const *_vizSession)
 Update warp buffer which contains image of projector perspective. More...
 
void generateCalibrationData ()
 
void drawCalibratedInput (bool _flipped=false)
 

Private Member Functions

QRectF tuningRect () const
 Calculates rectangle of this tuning. More...
 
QVector4D channelCorrectionAsVec (Channel) const
 Return QVector4D of channel correction parameters. More...
 

Private Attributes

omni::proj::Tuningtuning_
 
ContextBoundPtr< visual::WarpGridwarpGrid_
 
ContextBoundPtr< QOpenGLTexture > blendTex_
 
ContextBoundPtr< Framebuffer32FcalibrationFramebuffer_
 
proj::Calibration calibration_
 
ContextBoundPtr
< QOpenGLFramebufferObject > 
warpGridBuffer_
 Frame buffer which holds a texture with current view image. More...
 
ContextBoundPtr
< QOpenGLFramebufferObject > 
testCardFrameBuffer_
 
QRect blendTextureUpdateRect_
 

Static Private Attributes

static ContextBoundPtr
< QOpenGLShaderProgram > 
calibrationShader_
 
static ContextBoundPtr
< QOpenGLShaderProgram > 
testCardShader_
 
static ContextBoundPtr
< QOpenGLShaderProgram > 
blendShader_
 
static ContextBoundPtr
< QOpenGLShaderProgram > 
blendBrushShader_
 
static ContextBoundPtr
< QOpenGLShaderProgram > 
blendBrushCursorShader_
 

Detailed Description

Tuning visualizer.

Constructor & Destructor Documentation

omni::visual::Tuning::Tuning ( omni::proj::Tuning _tuning)
39  :
40  tuning_(_tuning)
41  {}
omni::proj::Tuning & tuning_
Definition: Tuning.h:99
omni::visual::Tuning::~Tuning ( )
43 {}

Member Function Documentation

QVector4D omni::visual::Tuning::channelCorrectionAsVec ( Channel  _channel) const
private

Return QVector4D of channel correction parameters.

397  {
398  QVector4D _vec(0.0, 0.0, 0.0, 0.0);
399  auto *_channelCorrection = calibration_.colorCorrection().correction(
400  _channel);
401 
402  if (!_channelCorrection) return _vec;
403 
404  _vec.setX(_channelCorrection->gamma());
405  _vec.setY(_channelCorrection->brightness());
406  _vec.setZ(_channelCorrection->contrast());
407  _vec.setW(_channelCorrection->multiplier());
408  return _vec;
409  }
ChannelCorrection * correction(Channel)
Return color correction for given channel.
Definition: ColorCorrection.cpp:95
proj::Calibration calibration_
Definition: Tuning.h:105
ColorCorrection const & colorCorrection() const
Return color correction.
Definition: Calibration.cpp:306
void omni::visual::Tuning::drawCalibratedInput ( bool  _flipped = false)
411  {
412  if (!calibrationShader_) return;
413 
414  auto *_currentInput = tuning().session().inputs().current();
415  if (!_currentInput) return;
416 
419  }
420 
421  withCurrentContext([&](QOpenGLFunctions& _) {
422  glMatrixMode(GL_PROJECTION);
423  glLoadIdentity();
424  QMatrix4x4 _m;
425  if (_flipped) {
426  _m.ortho(0.5, -0.5, 0.5, -0.5, -1.0, 1.0);
427  } else {
428  _m.ortho(-0.5, 0.5, -0.5, 0.5, -1.0, 1.0);
429 
430  }
431  glMultMatrixf(_m.constData());
432 
433  glMatrixMode(GL_MODELVIEW);
434  glLoadIdentity();
435 
436  useShader(*calibrationShader_, [&](UniformHandler& _h) {
437  _h.texUniform("image", _currentInput->textureId(),
438  GL_TEXTURE_RECTANGLE);
439  _h.texUniform("uv_map", calibrationFramebuffer_->texture());
440  _h.uniform("image_size",
441  QVector2D(_currentInput->width(),
442  _currentInput->height()));
443  _h.uniform("cc_red_vec",
445  Channel::RED));
446  _h.uniform("cc_green_vec",
448  GREEN));
449  _h.uniform("cc_blue_vec",
451  Channel::BLUE));
452  _h.uniform("cc_all_vec",
454  Channel::ALL));
455 
456  Rectangle::draw(-0.5, 0.5, 0.5, -0.5);
457  });
458  });
459  }
static ContextBoundPtr< QOpenGLShaderProgram > calibrationShader_
Definition: Tuning.h:114
Channel
Definition: Channel.h:24
void generateCalibrationData()
Definition: Tuning.cpp:391
omni::proj::Tuning const & tuning() const
Definition: Tuning.cpp:45
void withCurrentContext(ContextFunctor f)
Do OpenGL operations with current context, if it exists.
Definition: ContextSwitch.cpp:45
static void draw(float _left=-0.5, float _right=0.5, float _top=0.5, float _bottom=-0.5)
Draw rectangle from border coordinates.
Definition: Rectangle.cpp:28
QVector4D channelCorrectionAsVec(Channel) const
Return QVector4D of channel correction parameters.
Definition: Tuning.cpp:397
void useShader(QOpenGLShaderProgram &_s, std::function< void(UniformHandler &)>f)
Use shader with and do uniform assignment and drawing inside functor.
Definition: Shader.cpp:59
InputList & inputs()
Returns reference to list of inputs.
Definition: Session.cpp:84
Input * current()
Returns pointer to current input Returns nullptr if currentIdx_ == -1 or input list is empty...
Definition: List.cpp:78
Session const & session() const
Return const reference to owning session.
Definition: Tuning.cpp:282
ContextBoundPtr< Framebuffer32F > calibrationFramebuffer_
Definition: Tuning.h:103
void omni::visual::Tuning::drawCursor ( QPointF const &  _pos)

Draw cursor for blend brush.

217  {
218  auto _rect = tuningRect();
219 
220  withCurrentContext([&](QOpenGLFunctions& _)
221  {
222  _.glEnable(GL_BLEND);
223 
224  useShader(*blendBrushCursorShader_, [&](UniformHandler& _h) {
225  float _rX = tuning_.blendMask().brushSize() * 0.5 / tuning_.width();
226  float _rY = _rX * (_rect.height() / _rect.width());
227  _h.uniform("width", GLfloat(0.002 / _rX));
228  _h.uniform("soft", GLfloat(0.0005 / _rX));
229  Rectangle::draw(_pos.x() - _rX, _pos.x() + _rX, _pos.y() + _rY,
230  _pos.y() - _rY);
231  });
232  });
233  }
omni::proj::Tuning & tuning_
Definition: Tuning.h:99
static ContextBoundPtr< QOpenGLShaderProgram > blendBrushCursorShader_
Definition: Tuning.h:118
void withCurrentContext(ContextFunctor f)
Do OpenGL operations with current context, if it exists.
Definition: ContextSwitch.cpp:45
BlendMask & blendMask()
Returns reference to blend mask.
Definition: Tuning.cpp:96
static void draw(float _left=-0.5, float _right=0.5, float _top=0.5, float _bottom=-0.5)
Draw rectangle from border coordinates.
Definition: Rectangle.cpp:28
void useShader(QOpenGLShaderProgram &_s, std::function< void(UniformHandler &)>f)
Use shader with and do uniform assignment and drawing inside functor.
Definition: Shader.cpp:59
QRectF tuningRect() const
Calculates rectangle of this tuning.
Definition: Tuning.cpp:461
int width() const
Returns width of screen.
Definition: Tuning.cpp:187
float brushSize() const
Brush size for tuning.
Definition: BlendMask.cpp:109
void omni::visual::Tuning::drawOutput ( float  _inputOpacity = 0.0,
QColor const &  _color = Qt::white,
float  _blendMaskOpacity = 1.0,
bool  _grayscale = true 
) const

Draws Blendmask with warp grid and brush stroke layer.

244  {
245  if (!blendShader_) return;
246 
247  withCurrentContext([&](QOpenGLFunctions& _) {
248  _.glEnable(GL_DEPTH_TEST);
249  _.glEnable(GL_BLEND);
250  _.glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
251 
252  if (!warpGridBuffer_) return;
253 
254  GLuint _inputTexId = warpGridBuffer_->texture();
255 
256  auto& _mask = tuning().blendMask();
257 
258  useShader(*blendShader_, [&](UniformHandler& _h) {
259  _h.uniform("top", _mask.topWidth());
260  _h.uniform("right", _mask.rightWidth());
261  _h.uniform("bottom", _mask.bottomWidth());
262  _h.uniform("left", _mask.leftWidth());
263  _h.uniform("edge_gamma", _mask.gamma());
264  _h.texUniform("input_tex", _inputTexId);
265  _h.uniform("input_opacity", _inputOpacity);
266  _h.uniform("color", _color.redF(),
267  _color.greenF(),
268  _color.blueF());
269  _h.uniform("gray_output", _grayscale);
270 
271  auto& _cC = tuning().colorCorrection();
272 
273  if (_cC.isUsed()) {
274  _h.uniform("cc_gamma", QVector4D(
275  _cC.red().gamma(),
276  _cC.green().gamma(),
277  _cC.blue().gamma(),
278  _cC.all().gamma()));
279  _h.uniform("cc_brightness", QVector4D(
280  _cC.red().brightness(),
281  _cC.green().brightness(),
282  _cC.blue().brightness(),
283  _cC.all().brightness()));
284  _h.uniform("cc_contrast", QVector4D(
285  _cC.red().contrast(),
286  _cC.green().contrast(),
287  _cC.blue().contrast(),
288  _cC.all().contrast()));
289  _h.uniform("cc_multiplier", QVector4D(
290  _cC.red().multiplier(),
291  _cC.green().multiplier(),
292  _cC.blue().multiplier(),
293  _cC.all().multiplier()));
294  } else {
295  QVector4D _null(0.0, 0.0, 0.0, 0.0);
296  _h.uniform("cc_multiplier", _null);
297  _h.uniform("cc_contrast", _null);
298  _h.uniform("cc_brightness", _null);
299  _h.uniform("cc_gamma", _null);
300  }
301 
302  _h.uniform("mask",
303  GLfloat(_blendMaskOpacity));
304  warpGrid_->draw();
305  });
306 
307  if (_blendMaskOpacity > 0.0) {
308  glColor4f(0.0, 0.0, 0.0, 1.0);
309  float _b = 4.0;
310 
311 
312  // Draw masks for borders
313  glBegin(GL_QUADS);
314  {
315  glVertex2f(-0.5, -0.5 - _b);
316  glVertex2f(0.5 - _b, -0.5);
317  glVertex2f(0.5 - _b, 0.5);
318  glVertex2f(-0.5, 0.5 + _b);
319  glVertex2f(-0.5 + _b, -0.5 - _b);
320  glVertex2f(0.5, -0.5);
321  glVertex2f(0.5, 0.5);
322  glVertex2f(-0.5 + _b, 0.5 + _b);
323  glVertex2f(-0.5 + _b, 0.5 + _b);
324  glVertex2f(0.5 - _b, 0.5 + _b);
325  glVertex2f(0.5 - _b, 0.5);
326  glVertex2f(-0.5 + _b, 0.5);
327  glVertex2f(-0.5 + _b, -0.5);
328  glVertex2f(0.5 - _b, -0.5);
329  glVertex2f(0.5 - _b, -0.5 - _b);
330  glVertex2f(-0.5 + _b, -0.5 - _b);
331  }
332  glEnd();
333 
334  useShader(*blendBrushShader_, [&](UniformHandler& _h) {
335  _h.texUniform("blend_tex", *blendTex_);
337  });
338  }
339  });
340  }
static void drawFlipped(float _left=-0.5, float _right=0.5, float _top=0.5, float _bottom=-0.5)
Draw rectangle from border coordinates, flipped on y axis version.
Definition: Rectangle.cpp:68
omni::proj::Tuning const & tuning() const
Definition: Tuning.cpp:45
ContextBoundPtr< QOpenGLFramebufferObject > warpGridBuffer_
Frame buffer which holds a texture with current view image.
Definition: Tuning.h:108
void withCurrentContext(ContextFunctor f)
Do OpenGL operations with current context, if it exists.
Definition: ContextSwitch.cpp:45
BlendMask & blendMask()
Returns reference to blend mask.
Definition: Tuning.cpp:96
void useShader(QOpenGLShaderProgram &_s, std::function< void(UniformHandler &)>f)
Use shader with and do uniform assignment and drawing inside functor.
Definition: Shader.cpp:59
ContextBoundPtr< QOpenGLTexture > blendTex_
Definition: Tuning.h:102
static ContextBoundPtr< QOpenGLShaderProgram > blendBrushShader_
Definition: Tuning.h:117
ColorCorrection & colorCorrection()
Color correction for projector.
Definition: Tuning.cpp:116
ContextBoundPtr< visual::WarpGrid > warpGrid_
Definition: Tuning.h:101
static ContextBoundPtr< QOpenGLShaderProgram > blendShader_
Definition: Tuning.h:116
void omni::visual::Tuning::drawTestCard ( int  _id,
bool  _grayscale = false 
)

Draw Test card image for screen setup.

51  {
52  if (!testCardFrameBuffer_) return;
53 
54  withCurrentContext([&](QOpenGLFunctions& _) {
55  _.glEnable(GL_TEXTURE_2D);
56  _.glDisable(GL_LIGHTING);
57  glColor4f(1.0,1.0,1.0,1.0);
58  _.glBindTexture(GL_TEXTURE_2D,testCardFrameBuffer_->texture());
60  _.glBindTexture(GL_TEXTURE_2D,0);
61  _.glDisable(GL_TEXTURE_2D);
62  });
63  }
void withCurrentContext(ContextFunctor f)
Do OpenGL operations with current context, if it exists.
Definition: ContextSwitch.cpp:45
static void draw(float _left=-0.5, float _right=0.5, float _top=0.5, float _bottom=-0.5)
Draw rectangle from border coordinates.
Definition: Rectangle.cpp:28
ContextBoundPtr< QOpenGLFramebufferObject > testCardFrameBuffer_
Definition: Tuning.h:110
void omni::visual::Tuning::drawWarpGrid ( ) const

Draws warp grid with lines and handles.

Parameters
_rectScreen Rectangle of input
66  {
67  if (!warpGrid_) return;
68  warpGrid_->drawLines();
69  warpGrid_->drawHandles(tuning_.color(), tuningRect());
70  }
omni::proj::Tuning & tuning_
Definition: Tuning.h:99
QColor color() const
Returns color for mapping.
Definition: Tuning.cpp:124
QRectF tuningRect() const
Calculates rectangle of this tuning.
Definition: Tuning.cpp:461
ContextBoundPtr< visual::WarpGrid > warpGrid_
Definition: Tuning.h:101
void omni::visual::Tuning::drawWarpPatch ( ) const

Draw warp grip without lines and handles.

73  {
74  warpGrid_->draw();
75  }
ContextBoundPtr< visual::WarpGrid > warpGrid_
Definition: Tuning.h:101
void omni::visual::Tuning::generateCalibrationData ( )
391  {
393  tuning_.height()));
395  }
void render(Tuning const &)
Render calibration from tuning.
Definition: Calibration.cpp:168
omni::proj::Tuning & tuning_
Definition: Tuning.h:99
void setRenderSize(QSize const &)
Set new size for renderer output. Resets calibration.
Definition: Calibration.cpp:302
proj::Calibration calibration_
Definition: Tuning.h:105
int height() const
Returns height of screen.
Definition: Tuning.cpp:192
int width() const
Returns width of screen.
Definition: Tuning.cpp:187
ContextBoundPtr< Framebuffer32F > calibrationFramebuffer_
Definition: Tuning.h:103
bool omni::visual::Tuning::initialized ( ) const
236  {
237  return !!blendTex_ && !!blendShader_ && !!testCardShader_;
238  }
ContextBoundPtr< QOpenGLTexture > blendTex_
Definition: Tuning.h:102
static ContextBoundPtr< QOpenGLShaderProgram > testCardShader_
Definition: Tuning.h:115
static ContextBoundPtr< QOpenGLShaderProgram > blendShader_
Definition: Tuning.h:116
void omni::visual::Tuning::setBlendTextureUpdateRect ( QRect const &  _rect)

Set portion of blend mask which is to be updated.

131  {
132  int _radius = tuning_.blendMask().brushSize() / 2 + 1;
133 
134  blendTextureUpdateRect_ = _rect.normalized().adjusted(-_radius,
135  -_radius,
136  _radius,
137  _radius)
138  & QRect(0, 0,
139  tuning_.width(), tuning_.height());
140  }
QRect blendTextureUpdateRect_
Definition: Tuning.h:112
omni::proj::Tuning & tuning_
Definition: Tuning.h:99
BlendMask & blendMask()
Returns reference to blend mask.
Definition: Tuning.cpp:96
int height() const
Returns height of screen.
Definition: Tuning.cpp:192
int width() const
Returns width of screen.
Definition: Tuning.cpp:187
float brushSize() const
Brush size for tuning.
Definition: BlendMask.cpp:109
omni::proj::Tuning const & omni::visual::Tuning::tuning ( ) const
46  {
47  return tuning_;
48  }
omni::proj::Tuning & tuning_
Definition: Tuning.h:99
QRectF omni::visual::Tuning::tuningRect ( ) const
private

Calculates rectangle of this tuning.

462  {
463  float _projAspect = float(tuning_.width()) / tuning_.height();
464  float _left = -0.5, _right = 0.5, _bottom = -0.5, _top = 0.5;
465 
466  if (_projAspect > 1.0)
467  {
468  _top *= _projAspect;
469  _bottom *= _projAspect;
470  }
471  else
472  {
473  _left /= _projAspect;
474  _right /= _projAspect;
475  }
476  return QRectF(QPointF(_left, _top), QPointF(_right, _bottom));
477  }
omni::proj::Tuning & tuning_
Definition: Tuning.h:99
int height() const
Returns height of screen.
Definition: Tuning.cpp:192
int width() const
Returns width of screen.
Definition: Tuning.cpp:187
void omni::visual::Tuning::update ( )

Update shaders, warp grid and blend texture.

78  {
80 
81  primaryContextSwitch([&](QOpenGLFunctions& _) {
82  initShader(testCardShader_, "testcard");
83  initShader(blendShader_, "blend");
84  initShader(blendBrushShader_, "blendbrush");
85  initShader(blendBrushCursorShader_, "blendBrushCursor");
86  initShader(calibrationShader_, "calibration");
87 
88  if (!testCardFrameBuffer_ ||
89  testCardFrameBuffer_->width() != tuning_.width() ||
90  testCardFrameBuffer_->height() != tuning_.height()) {
91  QOpenGLFramebufferObjectFormat _format;
92  _format.setMipmap(true);
93  _format.setSamples(0);
94  _format.setAttachment(QOpenGLFramebufferObject::NoAttachment);
95  testCardFrameBuffer_.reset(new QOpenGLFramebufferObject(
96  tuning_.width(),
97  tuning_.height(),
98  _format));
99  }
100  });
101 
102  updateWarpGrid();
104 
105  draw_on_framebuffer(testCardFrameBuffer_.get(),[&](QOpenGLFunctions& _) {
106  QMatrix4x4 _m;
107  _m.ortho(-0.5,0.5,0.5,-0.5,-1.0,1.0);
108  glMultMatrixf(_m.constData());
109  }, [&](QOpenGLFunctions& _) {
110  glColor4f(1.0,1.0,1.0,1.0);
111  _.glDisable(GL_LIGHTING);
112  auto _color = tuning_.color();
113  GLfloat _red = _color.redF();
114  GLfloat _green = _color.greenF();
115  GLfloat _blue = _color.blueF();
116  testCardShader_->bind();
117  testCardShader_->setUniformValue("resolution",
118  GLfloat(tuning_.width()),
119  GLfloat(tuning_.height()));
120  testCardShader_->setUniformValue("test_color", _red,
121  _green,
122  _blue);
123  testCardShader_->setUniformValue("projector_id", GLint(tuning_.id() + 1));
124  testCardShader_->setUniformValue("gray_output", false);
125  Rectangle::draw();
126  testCardShader_->release();
127  });
128  }
void draw_on_framebuffer(FRAMEBUFFER *_f, PROJECTION _p, MODELVIEW _m)
Draw into QOpenGLFramebufferObject with given projection and model.
Definition: util.h:103
void reset()
Delete held object and internal state.
Definition: ContextBoundPtr.h:99
T * get() const
Definition: ContextBoundPtr.h:123
QString fileToStr(const QString &_filename)
Return content of file from a file name.
Definition: util.cpp:29
static ContextBoundPtr< QOpenGLShaderProgram > calibrationShader_
Definition: Tuning.h:114
void initShader(QOpenGLShaderProgram &_s, const char *_filename)
Initialize shader: load from file and compile.
Definition: Shader.cpp:27
int id() const
Return id of tuning.
Definition: Tuning.cpp:286
omni::proj::Tuning & tuning_
Definition: Tuning.h:99
static ContextBoundPtr< QOpenGLShaderProgram > blendBrushCursorShader_
Definition: Tuning.h:118
QColor color() const
Returns color for mapping.
Definition: Tuning.cpp:124
static void draw(float _left=-0.5, float _right=0.5, float _top=0.5, float _bottom=-0.5)
Draw rectangle from border coordinates.
Definition: Rectangle.cpp:28
void updateBlendTexture()
Updates blend texture after it has changed by blend brush.
Definition: Tuning.cpp:142
ContextBoundPtr< QOpenGLFramebufferObject > testCardFrameBuffer_
Definition: Tuning.h:110
void primaryContextSwitch(ContextFunctor f)
Switch to primary context to create OpenGL objects like textures etc.
Definition: ContextSwitch.cpp:40
static ContextBoundPtr< QOpenGLShaderProgram > blendBrushShader_
Definition: Tuning.h:117
int height() const
Returns height of screen.
Definition: Tuning.cpp:192
int width() const
Returns width of screen.
Definition: Tuning.cpp:187
static ContextBoundPtr< QOpenGLShaderProgram > testCardShader_
Definition: Tuning.h:115
void updateWarpGrid()
Update warp grid mesh.
Definition: Tuning.cpp:342
static ContextBoundPtr< QOpenGLShaderProgram > blendShader_
Definition: Tuning.h:116
void omni::visual::Tuning::updateBlendTexture ( )

Updates blend texture after it has changed by blend brush.

Transform tuning sized rect to stroke buffer sized rect

Optimization for uploading only a portion of the blend

143  {
144  const int _resolution = BlendMask::resolution();
145  auto _fullRect = QRect(0, 0, _resolution, _resolution);
146 
147  if (!blendTex_)
148  {
149  primaryContextSwitch([&](QOpenGLFunctions& _) {
150 
151  // Reset blend texture
152  blendTextureUpdateRect_ = _fullRect;
153 
154  if (!blendTex_.reset(new QOpenGLTexture(tuning_.blendMask().
155  strokeBuffer().toQImage()))) {
156  return;
157  }
158  blendTex_->bind();
159  _.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
160  GL_CLAMP_TO_EDGE);
161  _.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
162  GL_CLAMP_TO_EDGE);
163  _.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
164  GL_LINEAR);
165  _.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
166  GL_LINEAR);
167  blendTex_->release();
168  });
169  }
170 
171 
172  withCurrentContext([&](QOpenGLFunctions& _)
173  {
174  auto& _blendMask = tuning().blendMask();
175  auto _ptr = _blendMask.strokeBufferData();
176 
177  /// Transform tuning sized rect to stroke buffer sized rect
178  auto _transformRect = [&](QRect const& _rect) -> QRect {
179  auto _res = BlendMask::resolution();
180  return QRect(
181  _res * _rect.x() / tuning_.width(),
182  _res * _rect.y() / tuning_.height(),
183  _res * _rect.width() / tuning_.width(),
184  _res * _rect.height() / tuning_.height());
185  };
186 
187  /// Optimization for uploading only a portion of the blend
188  // buffer to texture
189  if (blendTextureUpdateRect_ != _fullRect)
190  {
191  auto _r = _transformRect(blendTextureUpdateRect_) & _fullRect;
192  auto _data = _blendMask.strokeBuffer().cropRect(_r);
193  _ptr = (void *)(_data.data().data());
194  _.glBindTexture(GL_TEXTURE_2D, blendTex_->textureId());
195  _.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
196  _.glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
197  _.glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
198  _.glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
199  _.glTexSubImage2D(GL_TEXTURE_2D, 0, _r.x(), _r.y(),
200  _r.width(), _r.height(), GL_RED,
201  GL_UNSIGNED_BYTE, _ptr);
202  _.glBindTexture(GL_TEXTURE_2D, 0);
203  blendTextureUpdateRect_ = _fullRect;
204  } else
205  {
206  auto _r = _fullRect;
207  _.glBindTexture(GL_TEXTURE_2D, blendTex_->textureId());
208  _.glTexSubImage2D(GL_TEXTURE_2D, 0, _r.x(), _r.y(),
209  _r.width(), _r.height(), GL_RED,
210  GL_UNSIGNED_BYTE, _ptr);
211  _.glBindTexture(GL_TEXTURE_2D, 0);
212  }
213  });
214  }
void reset()
Delete held object and internal state.
Definition: ContextBoundPtr.h:99
QRect blendTextureUpdateRect_
Definition: Tuning.h:112
omni::proj::Tuning & tuning_
Definition: Tuning.h:99
omni::proj::Tuning const & tuning() const
Definition: Tuning.cpp:45
void withCurrentContext(ContextFunctor f)
Do OpenGL operations with current context, if it exists.
Definition: ContextSwitch.cpp:45
BlendMask & blendMask()
Returns reference to blend mask.
Definition: Tuning.cpp:96
void primaryContextSwitch(ContextFunctor f)
Switch to primary context to create OpenGL objects like textures etc.
Definition: ContextSwitch.cpp:40
ContextBoundPtr< QOpenGLTexture > blendTex_
Definition: Tuning.h:102
int height() const
Returns height of screen.
Definition: Tuning.cpp:192
int width() const
Returns width of screen.
Definition: Tuning.cpp:187
void * strokeBufferData() const
Return void* pointer to strokebuffer data, used for OpenGL Texture.
Definition: BlendMask.cpp:137
static constexpr int resolution()
Resolution of blend mask.
Definition: BlendMask.h:38
void omni::visual::Tuning::updateWarpBuffer ( visual::Session const *  _vizSession)

Update warp buffer which contains image of projector perspective.

352  {
353  primaryContextSwitch([&](QOpenGLFunctions& _) {
354  // If tuning size has changed, reset warpGrid framebuffer
355  if (warpGridBuffer_)
356  {
357  if ((warpGridBuffer_->width() != tuning().width()) ||
358  (warpGridBuffer_->height() !=
360  }
361 
362  // If warp grid framebuffer is empty, make a new one
363  if (!warpGridBuffer_)
364  {
365  if (!warpGridBuffer_.reset(new QOpenGLFramebufferObject(
366  tuning().width(),
367  tuning().height()))) return;
368 
369  warpGridBuffer_->setAttachment(QOpenGLFramebufferObject::Depth);
370  }
371  });
372 
373  // Draw projector's perspective on framebuffer texture
375  [&](QOpenGLFunctions& _) // Projection
376  // Operation
377  {
378  glMultMatrixf(tuning().projector().projectionMatrix().constData());
379  },
380  [&](QOpenGLFunctions& _) // Model View
381  // Operation
382  {
383  _.glClear(
384  GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
385  _.glEnable(GL_DEPTH_TEST);
386  _vizSession->drawCanvas();
387  _vizSession->drawCanvasWireframe();
388  });
389  }
void draw_on_framebuffer(FRAMEBUFFER *_f, PROJECTION _p, MODELVIEW _m)
Draw into QOpenGLFramebufferObject with given projection and model.
Definition: util.h:103
void reset()
Delete held object and internal state.
Definition: ContextBoundPtr.h:99
T * get() const
Definition: ContextBoundPtr.h:123
omni::proj::Tuning const & tuning() const
Definition: Tuning.cpp:45
ContextBoundPtr< QOpenGLFramebufferObject > warpGridBuffer_
Frame buffer which holds a texture with current view image.
Definition: Tuning.h:108
void primaryContextSwitch(ContextFunctor f)
Switch to primary context to create OpenGL objects like textures etc.
Definition: ContextSwitch.cpp:40
int height() const
Returns height of screen.
Definition: Tuning.cpp:192
int width() const
Returns width of screen.
Definition: Tuning.cpp:187
void omni::visual::Tuning::updateWarpGrid ( )

Update warp grid mesh.

342  {
343  if (!warpGrid_) {
344  if (!warpGrid_.reset(new visual::WarpGrid(tuning_.warpGrid()))) return;
345  }
346 
347  warpGrid_->update();
348  }
omni::proj::Tuning & tuning_
Definition: Tuning.h:99
WarpGrid & warpGrid()
Returns reference to warp grid.
Definition: Tuning.cpp:86
ContextBoundPtr< visual::WarpGrid > warpGrid_
Definition: Tuning.h:101

Field Documentation

ContextBoundPtr< QOpenGLShaderProgram > omni::visual::Tuning::blendBrushCursorShader_
staticprivate
ContextBoundPtr< QOpenGLShaderProgram > omni::visual::Tuning::blendBrushShader_
staticprivate
ContextBoundPtr< QOpenGLShaderProgram > omni::visual::Tuning::blendShader_
staticprivate
ContextBoundPtr<QOpenGLTexture> omni::visual::Tuning::blendTex_
private
QRect omni::visual::Tuning::blendTextureUpdateRect_
private
proj::Calibration omni::visual::Tuning::calibration_
private
ContextBoundPtr<Framebuffer32F> omni::visual::Tuning::calibrationFramebuffer_
private
ContextBoundPtr< QOpenGLShaderProgram > omni::visual::Tuning::calibrationShader_
staticprivate
ContextBoundPtr<QOpenGLFramebufferObject> omni::visual::Tuning::testCardFrameBuffer_
private
ContextBoundPtr< QOpenGLShaderProgram > omni::visual::Tuning::testCardShader_
staticprivate
omni::proj::Tuning& omni::visual::Tuning::tuning_
private
ContextBoundPtr<visual::WarpGrid> omni::visual::Tuning::warpGrid_
private
ContextBoundPtr<QOpenGLFramebufferObject> omni::visual::Tuning::warpGridBuffer_
private

Frame buffer which holds a texture with current view image.


The documentation for this class was generated from the following files: