Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PostProcessorPoissonBlur.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 "PostProcessorPoissonBlur.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 <QLabel>
54 #include <QSlider>
55 #include <QVBoxLayout>
56 #include <QPushButton>
57 
58 
59 PostProcessorPoissonBlur::PostProcessorPoissonBlur()
60  : blur_(new ACG::PoissonBlurFilter(1.0f, 0.5f)), radius_(1.0f), minDist_(0.5f)
61 {
62 }
63 
64 
65 PostProcessorPoissonBlur::~PostProcessorPoissonBlur()
66 {
67  delete blur_;
68 }
69 
70 QString PostProcessorPoissonBlur::checkOpenGL()
71 {
72  if (!ACG::openGLVersion(3,0))
73  return QString("Poisson blur plugin requires OpenGL 3.0!");
74 
75  return QString("");
76 }
77 
78 
79 void PostProcessorPoissonBlur::postProcess( ACG::GLState* _glstate, const std::vector<const PostProcessorInput*>& _input, const PostProcessorOutput& _output )
80 {
81  glBindFramebuffer(GL_FRAMEBUFFER, _output.fbo_);
82  glDrawBuffer(_output.drawBuffer_);
83 
84  glDepthMask(1);
85  glColorMask(1,1,1,1);
86 
87 
88 
89  float scale = 1.0f / std::min(_input[0]->width, _input[0]->height);
90 
91  blur_->execute(_input[0]->colorTex_, scale);
92 }
93 
95 {
96  QAction * action = new QAction("Gaussian Blur Options" , this );
97 
98  connect(action,SIGNAL(triggered( bool )),this,SLOT(optionDialog( bool )));
99 
100  return action;
101 }
102 
103 void PostProcessorPoissonBlur::optionDialog( bool )
104 {
105  //generate widget
106  QDialog* optionsDlg = new QDialog();
107  QVBoxLayout* layout = new QVBoxLayout();
108  layout->setAlignment(Qt::AlignTop);
109 
110  QColor curColor;
111  curColor.setRgbF(0.3f, 0.2f, 0.7f);
112 
113  QLabel* label = new QLabel(tr("Radius [0, 32]:"));
114  layout->addWidget(label);
115 
116  QSlider* radiusSlider = new QSlider(Qt::Horizontal);
117  radiusSlider->setRange(1, 32);
118  radiusSlider->setValue(1);
119  radiusSlider->setTracking(true);
120  layout->addWidget(radiusSlider);
121 
122 
123  label = new QLabel(tr("MinDistance [0.1, 10.0]:"));
124  layout->addWidget(label);
125 
126  QSlider* minDistSlider = new QSlider(Qt::Horizontal);
127  minDistSlider->setRange(1, 100);
128  minDistSlider->setValue(5);
129  minDistSlider->setTracking(true);
130  layout->addWidget(minDistSlider);
131 
132 
133  QPushButton* btn = new QPushButton("Recompute");
134  layout->addWidget(btn);
135 
136  optionsDlg->setLayout(layout);
137 
138 
139  connect(btn, SIGNAL(clicked()), this, SLOT(recompute()));
140  connect(radiusSlider, SIGNAL(sliderMoved(int)), this, SLOT(radiusChanged(int)));
141  connect(minDistSlider, SIGNAL(sliderMoved(int)), this, SLOT(minDistChanged(int)));
142 
143 
144  optionsDlg->show();
145 }
146 
147 
148 void PostProcessorPoissonBlur::recompute( )
149 {
150  delete blur_;
151 
152  blur_ = new ACG::PoissonBlurFilter(radius_, minDist_);
153 }
154 
155 void PostProcessorPoissonBlur::radiusChanged(int r)
156 {
157  radius_ = float(r);
158 }
159 
160 void PostProcessorPoissonBlur::minDistChanged(int d)
161 {
162  minDist_ = float(d) * 0.1f;
163 }
164 
165 #if QT_VERSION < 0x050000
166 Q_EXPORT_PLUGIN2( postprocessorpoissonblurplugin , PostProcessorPoissonBlur );
167 #endif
168 
Namespace providing different geometric functions concerning angles.
Definition: DBSCANT.cc:51
bool openGLVersion(const int _major, const int _minor)
Definition: gl.cc:95
QAction * optionsAction()
Return options menu.