Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PostProcessorRadialBlur.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen *
5 * www.openflipper.org *
6 * *
7 *--------------------------------------------------------------------------- *
8 * This file is part of OpenFlipper. *
9 * *
10 * OpenFlipper is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU Lesser General Public License as *
12 * published by the Free Software Foundation, either version 3 of *
13 * the License, or (at your option) any later version with the *
14 * following exceptions: *
15 * *
16 * If other files instantiate templates or use macros *
17 * or inline functions from this file, or you compile this file and *
18 * link it with other files to produce an executable, this file does *
19 * not by itself cause the resulting executable to be covered by the *
20 * GNU Lesser General Public License. This exception does not however *
21 * invalidate any other reasons why the executable file might be *
22 * covered by the GNU Lesser General Public License. *
23 * *
24 * OpenFlipper is distributed in the hope that it will be useful, *
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
27 * GNU Lesser General Public License for more details. *
28 * *
29 * You should have received a copy of the GNU LesserGeneral Public *
30 * License along with OpenFlipper. If not, *
31 * see <http://www.gnu.org/licenses/>. *
32 * *
33 \*===========================================================================*/
34 
35 /*===========================================================================*\
36 * *
37 * $Revision: 17080 $ *
38 * $LastChangedBy: moeller $ *
39 * $Date: 2013-07-19 12:58:31 +0200 (Fri, 19 Jul 2013) $ *
40 * *
41 \*===========================================================================*/
42 
43 
44 #include <ACG/GL/acg_glew.hh>
45 
46 #include "PostProcessorRadialBlur.hh"
47 
48 #include <ACG/GL/ScreenQuad.hh>
49 #include <ACG/GL/ShaderCache.hh>
50 #include <ACG/GL/GLFormatInfo.hh>
51 
52 #include <QDialog>
53 #include <QColor>
54 #include <QLabel>
55 #include <QSlider>
56 #include <QVBoxLayout>
57 #include <ACG/QtWidgets/QtColorChooserButton.hh>
58 
59 
60 
61 PostProcessorRadialBlur::PostProcessorRadialBlur()
62  : blur_(16), radius_(1.0f), intensity_(0.0025f), center_(0.5f, 0.5f)
63 {
64 }
65 
66 
67 PostProcessorRadialBlur::~PostProcessorRadialBlur()
68 {
69 }
70 
71 QString PostProcessorRadialBlur::checkOpenGL()
72 {
73  if (!ACG::openGLVersion(3,0))
74  return QString("Radial Blur plugin requires OpenGL 3.0!");
75 
76  return QString("");
77 }
78 
79 
80 void PostProcessorRadialBlur::postProcess( ACG::GLState* _glstate, const std::vector<const PostProcessorInput*>& _input, const PostProcessorOutput& _output )
81 {
82  glBindFramebuffer(GL_FRAMEBUFFER, _output.fbo_);
83  glDrawBuffer(_output.drawBuffer_);
84 
85  glDepthMask(1);
86  glColorMask(1,1,1,1);
87 
88 
89  blur_.execute(_input[0]->colorTex_, radius_, intensity_, center_);
90 }
91 
93 {
94  QAction * action = new QAction("Radial Blur Options" , this );
95 
96  connect(action,SIGNAL(triggered( bool )),this,SLOT(optionDialog( bool )));
97 
98  return action;
99 }
100 
101 void PostProcessorRadialBlur::optionDialog( bool )
102 {
103  //generate widget
104  QDialog* optionsDlg = new QDialog();
105  QVBoxLayout* layout = new QVBoxLayout();
106  layout->setAlignment(Qt::AlignTop);
107 
108  QColor curColor;
109  curColor.setRgbF(0.3f, 0.2f, 0.7f);
110 
111  QLabel* label = new QLabel(tr("Samples [1, 32]:"));
112  layout->addWidget(label);
113 
114  QSlider* radiusSlider = new QSlider(Qt::Horizontal);
115  radiusSlider->setRange(1, 32);
116  radiusSlider->setValue(8);
117  radiusSlider->setTracking(true);
118  layout->addWidget(radiusSlider);
119 
120 
121  label = new QLabel(tr("Radius [0, 2]:"));
122  layout->addWidget(label);
123 
124  QSlider* sigmaSlider = new QSlider(Qt::Horizontal);
125  sigmaSlider->setRange(1, 100);
126  sigmaSlider->setValue(50);
127  sigmaSlider->setTracking(true);
128  layout->addWidget(sigmaSlider);
129 
130 
131  label = new QLabel(tr("Intensity [0.001, 0.01]:"));
132  layout->addWidget(label);
133 
134  QSlider* intensitySlider = new QSlider(Qt::Horizontal);
135  intensitySlider->setRange(0, 100);
136  intensitySlider->setValue(2);
137  intensitySlider->setTracking(true);
138  layout->addWidget(intensitySlider);
139 
140 
141  label = new QLabel(tr("CenterU [0, 1]:"));
142  layout->addWidget(label);
143 
144  QSlider* centerUSlider = new QSlider(Qt::Horizontal);
145  centerUSlider->setRange(0, 100);
146  centerUSlider->setValue(50);
147  centerUSlider->setTracking(true);
148  layout->addWidget(centerUSlider);
149 
150 
151  label = new QLabel(tr("CenterV [0, 1]:"));
152  layout->addWidget(label);
153 
154  QSlider* centerVSlider = new QSlider(Qt::Horizontal);
155  centerVSlider->setRange(0, 100);
156  centerVSlider->setValue(50);
157  centerVSlider->setTracking(true);
158  layout->addWidget(centerVSlider);
159 
160 
161 
162  optionsDlg->setLayout(layout);
163 
164 
165  connect(radiusSlider, SIGNAL(sliderMoved(int)), this, SLOT(samplesChanged(int)));
166  connect(sigmaSlider, SIGNAL(sliderMoved(int)), this, SLOT(radiusChanged(int)));
167  connect(intensitySlider, SIGNAL(sliderMoved(int)), this, SLOT(intensityChanged(int)));
168  connect(centerUSlider, SIGNAL(sliderMoved(int)), this, SLOT(centerXChanged(int)));
169  connect(centerVSlider, SIGNAL(sliderMoved(int)), this, SLOT(centerYChanged(int)));
170 
171 
172 
173  optionsDlg->show();
174 }
175 
176 
177 void PostProcessorRadialBlur::samplesChanged( int _n )
178 {
179  blur_.setKernel(_n);
180 }
181 
182 void PostProcessorRadialBlur::radiusChanged( int _r )
183 {
184  radius_ = float(_r) * 0.01f * 2.0f;
185 }
186 
187 void PostProcessorRadialBlur::intensityChanged( int _r )
188 {
189  float t = float(_r) * 0.01f;
190  intensity_ = 0.001f * (1.0f - t) + 0.01 * t;
191 }
192 
193 void PostProcessorRadialBlur::centerXChanged( int _r )
194 {
195  center_[0] = float(_r) * 0.01f;
196 }
197 
198 void PostProcessorRadialBlur::centerYChanged( int _r )
199 {
200  center_[1] = float(_r) * 0.01f;
201 }
202 
203 
204 #if QT_VERSION < 0x050000
205 Q_EXPORT_PLUGIN2( postprocessorradialblurplugin , PostProcessorRadialBlur );
206 #endif
207 
QAction * optionsAction()
Return options menu.
bool openGLVersion(const int _major, const int _minor)
Definition: gl.cc:95