Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PostProcessorBilateralBlur.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 "PostProcessorBilateralBlur.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 PostProcessorBilateralBlur::PostProcessorBilateralBlur()
62  : blur_(32, 32, 4, 2.0f, 2.0f, GL_RGBA)
63 {
64 }
65 
66 
67 PostProcessorBilateralBlur::~PostProcessorBilateralBlur()
68 {
69 }
70 
71 QString PostProcessorBilateralBlur::checkOpenGL()
72 {
73  if (!ACG::openGLVersion(3,0))
74  return QString("Bilateral blur plugin requires OpenGL 3.0!");
75 
76  return QString("");
77 }
78 
79 
80 void PostProcessorBilateralBlur::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 
90  blur_.resizeInput(_input[0]->width, _input[0]->height);
91 
92 
93  blur_.setParams(_glstate->projection(), _input[0]->depthTex_);
94 
95 
96  blur_.execute(_input[0]->colorTex_, 0, 0, 0);
97 }
98 
100 {
101  QAction * action = new QAction("Gaussian Blur Options" , this );
102 
103  connect(action,SIGNAL(triggered( bool )),this,SLOT(optionDialog( bool )));
104 
105  return action;
106 }
107 
108 void PostProcessorBilateralBlur::optionDialog( bool )
109 {
110  //generate widget
111  QDialog* optionsDlg = new QDialog();
112  QVBoxLayout* layout = new QVBoxLayout();
113  layout->setAlignment(Qt::AlignTop);
114 
115  QColor curColor;
116  curColor.setRgbF(0.3f, 0.2f, 0.7f);
117 
118  QLabel* label = new QLabel(tr("Radius [1, 32]:"));
119  layout->addWidget(label);
120 
121  QSlider* radiusSlider = new QSlider(Qt::Horizontal);
122  radiusSlider->setRange(1, 32);
123  radiusSlider->setValue(8);
124  radiusSlider->setTracking(true);
125  layout->addWidget(radiusSlider);
126 
127 
128  label = new QLabel(tr("spatial sigma [0.1, 20.0]:"));
129  layout->addWidget(label);
130 
131  QSlider* sigmaSlider = new QSlider(Qt::Horizontal);
132  sigmaSlider->setRange(1, 200);
133  sigmaSlider->setValue(10);
134  sigmaSlider->setTracking(true);
135  layout->addWidget(sigmaSlider);
136 
137 
138  label = new QLabel(tr("linear depth sigma [0.1, 20.0]:"));
139  layout->addWidget(label);
140 
141  QSlider* sigmaRSlider = new QSlider(Qt::Horizontal);
142  sigmaRSlider->setRange(1, 200);
143  sigmaRSlider->setValue(10);
144  sigmaRSlider->setTracking(true);
145  layout->addWidget(sigmaRSlider);
146 
147 
148  optionsDlg->setLayout(layout);
149 
150 
151  connect(radiusSlider, SIGNAL(sliderMoved(int)), this, SLOT(radiusChanged(int)));
152  connect(sigmaSlider, SIGNAL(sliderMoved(int)), this, SLOT(sigmaSChanged(int)));
153  connect(sigmaRSlider, SIGNAL(sliderMoved(int)), this, SLOT(sigmaRChanged(int)));
154 
155 
156  optionsDlg->show();
157 }
158 
159 
160 void PostProcessorBilateralBlur::radiusChanged( int _radius )
161 {
162  ACG::Vec2f sigma = blur_.sigma();
163  blur_.setKernel(_radius, sigma[0], sigma[1]);
164 }
165 
166 void PostProcessorBilateralBlur::sigmaSChanged( int _val )
167 {
168  ACG::Vec2f sigma = blur_.sigma();
169  sigma[0] = float(_val) * 0.1f;
170  blur_.setKernel(blur_.radius(), sigma[0], sigma[1]);
171 }
172 
173 
174 void PostProcessorBilateralBlur::sigmaRChanged( int _val )
175 {
176  ACG::Vec2f sigma = blur_.sigma();
177  sigma[1] = float(_val) * 0.1f;
178  blur_.setKernel(blur_.radius(), sigma[0], sigma[1]);
179 }
180 
181 
182 #if QT_VERSION < 0x050000
183 Q_EXPORT_PLUGIN2( postprocessorbilateralblurplugin , PostProcessorBilateralBlur );
184 #endif
185 
int radius() const
radius
const GLMatrixd & projection() const
get projection matrix
Definition: GLState.hh:789
QAction * optionsAction()
Return options menu.
const ACG::Vec2f & sigma() const
blur (sigmaS, sigmaR)
bool openGLVersion(const int _major, const int _minor)
Definition: gl.cc:95