File: radianceScalingRenderer.h

package info (click to toggle)
meshlab 1.3.2+dfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 21,096 kB
  • ctags: 33,630
  • sloc: cpp: 224,813; ansic: 8,170; xml: 119; makefile: 80
file content (193 lines) | stat: -rw-r--r-- 6,023 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/****************************************************************************
* Render Radiance Scaling                                                   *
* Meshlab's plugin                                                          *
*                                                                           *
* Copyright(C) 2010                                                         *
* Vergne Romain, Dumas Olivier                                              *
* INRIA - Institut Nationnal de Recherche en Informatique et Automatique    *
*                                                                           *
* All rights reserved.                                                      *
*                                                                           *
* This program is free software; you can redistribute it and/or modify      *
* it under the terms of the GNU General Public License as published by      *
* the Free Software Foundation; either version 2 of the License, or         *
* (at your option) any later version.                                       *
*                                                                           *
* This program is distributed in the hope that it will be useful,           *
* but WITHOUT ANY WARRANTY; without even the implied warranty of            *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
* for more details.                                                         *
*                                                                           *
****************************************************************************/
#ifndef RADIANCESCALINGRENDERER_H
#define RADIANCESCALINGRENDERER_H

#include <GL/glew.h>
#include <common/interfaces.h>

#include <QObject>
#include <QAction>
#include <QString>
#include <map>

#include "shaderDialog.h"
#include "gpuProgram.h"
#include "framebufferObject.h"
#include "texture2D.h"

class RadianceScalingRendererPlugin : public QObject, public MeshRenderInterface {
    Q_OBJECT
    Q_INTERFACES(MeshRenderInterface)

    bool             _supported;
    QList<QAction *> _actionList;
    ShaderDialog    *_sDialog;

 public:
    RadianceScalingRendererPlugin();
    
    QList<QAction *> actions() {
      if(_actionList.isEmpty()) initActionList();
      return _actionList;
    }
    
    void initActionList();
    
    virtual bool isSupported() {return _supported;}
    virtual void Init(QAction *a, MeshDocument &m, RenderMode &rm, QGLWidget *gla);
    virtual void Finalize(QAction *a, MeshDocument *m, GLArea * gla);
    virtual void Render(QAction *a, MeshDocument &m, RenderMode &rm, QGLWidget *gla);  

    inline void setEnable(bool enabled);
    inline void setLit(bool lit);
    inline void setInvert(int invert);
    inline void setDisplay(int index);
    inline void setEnhancement(float enhancement);
    inline void setTransition(float transition);
    inline void setConvexLit(const QString &filename);
    inline void setConcavLit(const QString &filename);

 private:
    FramebufferObject *_fbo;
    GPUProgram        *_buffPass;
    GPUProgram        *_rsPass;
    FloatTexture2D    *_depthTex;
    FloatTexture2D    *_gradTex;
    FloatTexture2D    *_normTex;
    UbyteTexture2D    *_colorTex;
    UbyteTexture2D    *_convexLS;
    UbyteTexture2D    *_concavLS;
    int                _w,_h;
    
    void initShaders(bool reload=false);
    void initFBOs();
    void cleanShaders();
    void cleanFBOs();

    void createLit(const QString &filename,int type);

    inline void drawQuad();
    inline void swapToScreenMode();
    inline void swapToWorldMode();
    inline void checkViewport();
};

inline void RadianceScalingRendererPlugin::swapToScreenMode() {
  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
  glLoadIdentity();
  //glDepthMask(GL_FALSE);
}

inline void RadianceScalingRendererPlugin::swapToWorldMode() {
  glMatrixMode(GL_PROJECTION);
  glPopMatrix();
  glMatrixMode(GL_MODELVIEW);
  glPopMatrix();
  glDepthMask(GL_TRUE);
  glEnable(GL_DEPTH_TEST);
}

inline void RadianceScalingRendererPlugin::drawQuad() {
  glBegin(GL_QUADS);

  glTexCoord2f(0.0,0.0); glVertex2f(-1.0,-1.0);
  glTexCoord2f(1.0,0.0); glVertex2f( 1.0,-1.0);
  glTexCoord2f(1.0,1.0); glVertex2f( 1.0, 1.0);
  glTexCoord2f(0.0,1.0); glVertex2f(-1.0, 1.0);

  glEnd();
}

inline void RadianceScalingRendererPlugin::checkViewport() {
  int v[4];
  glGetIntegerv(GL_VIEWPORT,v);
  
  if(v[2]!=_w || v[3]!=_h) {
    _w = v[2];
    _h = v[3];
    
    cleanFBOs();
    initFBOs();
    initShaders(true);
  }
}

inline void RadianceScalingRendererPlugin::setEnable(bool enabled) {
  _rsPass->enable();
  _rsPass->setUniform1i("enabled",enabled);
  _rsPass->disable();
}

inline void RadianceScalingRendererPlugin::setLit(bool lit) 
{
	  initShaders(false);
		_rsPass->enable();
	  _rsPass->setUniform1i("lit",lit);
	  _rsPass->disable();
}

inline void RadianceScalingRendererPlugin::setInvert(int invert) {
  _rsPass->enable();
  _rsPass->setUniform1i("invert",invert);
  _rsPass->disable();
}

inline void RadianceScalingRendererPlugin::setDisplay(int index) {
	if(index==1) {
		initShaders(false);
	}
  _rsPass->enable();
  _rsPass->setUniform1i("display",index);
  _rsPass->disable();
}

inline void RadianceScalingRendererPlugin::setEnhancement(float enhancement) {
  _rsPass->enable();
  _rsPass->setUniform1f("enhancement",enhancement);
  _rsPass->disable();
}

inline void RadianceScalingRendererPlugin::setTransition(float transition) {
  _rsPass->enable();
  _rsPass->setUniform1f("transition",transition);
  _rsPass->disable();
}

inline void RadianceScalingRendererPlugin::setConvexLit(const QString &filename) {
  initShaders(false);
	createLit(filename,0);
  
}

inline void RadianceScalingRendererPlugin::setConcavLit(const QString &filename) {
 initShaders(false);
  createLit(filename,1);
}

#endif