2
* Interface independent application class
4
* Author : Ricardo Marroquim
6
* Date created : 20-12-2007
15
#include "splat_pyramid.h"
18
#include <QTextStream>
19
#include <wrap/gl/trimesh.h>
21
//#include <QGLFramebufferObject>
23
//#include "GL/glut.h"
28
void PyramidPointRendererPlugin::Init(QAction *, MeshDocument &md, RenderMode &, QGLWidget *gla)
33
canvas_width = gla->width();
34
canvas_height = gla->height();
36
//canvas_width = canvas_height = 1024.0;
40
bool color_per_vertex = false;
42
foreach(MeshModel * mp, md.meshList) {
43
// Create a new primitive from given file
44
objects.push_back( Object( objects.size() ) );
46
vector<Surfeld> *surfels = (objects.back()).getSurfels();
48
if (mp->hasDataMask( MeshModel::MM_VERTCOLOR ) )
49
color_per_vertex = true;
51
Color4b c (180, 180, 180, 255);
52
float quality = 0.0001;
56
CMeshO::VertexIterator vi;
58
for(vi=mp->cm.vert.begin(); vi!=mp->cm.vert.end(); ++vi)
61
Point3f p = (*vi).P();
62
Point3f n = (*vi).N();
67
surfels->push_back ( Surfeld (p, n, c, quality, radius, pos) );
73
render_mode = PYRAMID_POINTS_COLOR;
75
render_mode = PYRAMID_POINTS;
77
// Sets the default rendering algorithm and loads vertex arrays
78
for (unsigned int i = 0; i < objects.size(); ++i)
79
objects[i].setRendererType( render_mode );
82
QDir shadersDir = QDir(qApp->applicationDirPath());
84
if (shadersDir.dirName() == "debug" || shadersDir.dirName() == "release" || shadersDir.dirName() == "plugins" )
86
#elif defined(Q_OS_MAC)
87
if (shadersDir.dirName() == "MacOS") {
89
if(shadersDir.exists("shaders")) break;
95
QDir::setCurrent(shadersDir.absolutePath());
98
createPointRenderer( );
106
sDialog = new Dialog(point_based_render, gla);
107
sDialog->move(10,100);
113
* Initialize opengl and application state variables.
114
* @param default_mode Defines the initial rendering mode.
116
PyramidPointRendererPlugin::PyramidPointRendererPlugin() {
118
render_mode = PYRAMID_POINTS;
119
point_based_render = NULL;
130
//check_for_ogl_error("Init");
133
void PyramidPointRendererPlugin::initActionList()
135
actionList << new QAction("SplatPyramid", this);
138
PyramidPointRendererPlugin::~PyramidPointRendererPlugin( ) {
140
delete point_based_render;
143
/// Render all points with OpenGL
144
void PyramidPointRendererPlugin::drawPoints(void) {
146
glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
150
for (surfelVectorIter it = objects[0].getSurfels()->begin(); it != objects[0].getSurfels()->end(); ++it) {
151
// Color4b c = it->Color();
152
// glColor4f(c[0], c[1], c[2], 1.0f);
153
Point3f p = it->Center();
154
//glVertex3f(p[0], p[1], p[2]);
160
* Display method to render the models.
162
//void PyramidPointRendererPlugin::draw( void ) {
163
void PyramidPointRendererPlugin::Render(QAction *, MeshDocument &, RenderMode &, QGLWidget* gla )
165
if (objects.size() == 0)
168
point_based_render->clearBuffers();
173
glGetv(GL_MODELVIEW_MATRIX,mv);
175
scale_factor = (mv.GetColumn3(0)).Norm();
177
float fov_scale = ((GLArea*)gla)->getFov();
181
fov_scale = 1.0 / (tanf(vcg::math::ToRad(fov_scale*.5f)) * 1.0);
183
// Set factor for scaling projected radii of samples in projection phase
184
scale_factor = fov_scale;
185
point_based_render->setScaleFactor( scale_factor );
188
Point3f eye = mv * Point3f(0, 0, 0);
190
// Set eye for back face culling in vertex shader of projection phase
191
point_based_render->setEye( Point3f(eye[0], eye[1], eye[2]) );
193
for (unsigned int i = 0; i < objects.size(); ++i)
194
point_based_render->projectSamples( &objects[i] );
196
point_based_render->interpolate();
198
point_based_render->draw();
209
/// @param w New window width
210
/// @param h New window height
211
void PyramidPointRendererPlugin::reshape(int, int) {
212
// camera->reshape(w, h);
216
* Changes the rendering algorithm.
217
* @param type Rendering mode.
219
void PyramidPointRendererPlugin::changeRendererType( int type ) {
220
for (unsigned int i = 0; i < objects.size(); ++i)
221
objects[i].setRendererType((point_render_type_enum) type);
223
createPointRenderer( );
227
* Defines the rendering algorithm.
228
* point_based_render is of generic type, depending on
229
* the choice one of the inherited classes is instanced.
231
void PyramidPointRendererPlugin::createPointRenderer( void ) {
233
if (point_based_render)
234
delete point_based_render;
236
if (render_mode == PYRAMID_POINTS)
237
point_based_render = new PyramidPointRenderer(canvas_width, canvas_height);
238
else if (render_mode == PYRAMID_POINTS_COLOR)
239
point_based_render = new PyramidPointRendererColor(canvas_width, canvas_height);
241
assert (point_based_render);
243
((PyramidPointRendererBase*)point_based_render)->setShadersDir(QDir::currentPath());
244
((PyramidPointRendererBase*)point_based_render)->createShaders();
249
* Returns the model's number of points.
250
* @return Number of points.
252
int PyramidPointRendererPlugin::getNumberPoints ( void ) {
255
for (unsigned int i = 0; i < objects.size(); ++i)
256
num_pts += objects[i].numberPoints();
262
* Sets the reconstruction filter size.
263
* Multiplicator of the radius size.
264
* @param s Reconstruction filter size.
266
void PyramidPointRendererPlugin::setReconstructionFilter ( double s ) {
267
if (point_based_render)
268
point_based_render->setReconstructionFilterSize(s);
272
* Sets the quality threshold for interpolating samples.
273
* @param q Quality threshold.
275
void PyramidPointRendererPlugin::setQualityThreshold ( double q ) {
276
if (point_based_render)
277
point_based_render->setQualityThreshold(q);
281
* Sets the prefilter size.
282
* @param s Prefilter size.
284
void PyramidPointRendererPlugin::setPrefilter ( double s ) {
285
if (point_based_render)
286
point_based_render->setPrefilterSize(s);
290
* Sets the kernel size for the template rendering algorithm only.
291
* @param m Kernel size mxm.
293
void PyramidPointRendererPlugin::setGpuMask ( int m ) {
294
point_based_render->setGpuMaskSize( m );
298
* Sets per-vertex color on/off if the model has
299
* color information per point.
300
* @param c Per-vertex color state.
302
void PyramidPointRendererPlugin::setPerVertexColor ( bool ) {
303
//point_based_render->setVertexPerColor( c );
304
for (unsigned int i = 0; i < objects.size(); ++i) {
305
// Reset renderer type to load per vertex color or default color in vertex array
306
objects[i].setRendererType( objects[i].getRendererType() );
311
* Turns auto-rotate on/off.
312
* Auto-rotate turns the model continuously.
313
* @param r Auto-rotate state.
315
void PyramidPointRendererPlugin::setAutoRotate ( bool r ) {
320
* Turns depth test on/off.
321
* @param d Depth test state.
323
void PyramidPointRendererPlugin::setDepthTest ( bool d ) {
324
if (point_based_render)
325
point_based_render->setDepthTest(d);
329
* Change model material properties.
330
* @param mat Id of material (see materials.h for list)
332
void PyramidPointRendererPlugin::changeMaterial( int mat ) {
333
point_based_render->setMaterial( mat );
337
* Turns backface culling on/off.
338
* @param b Backface culling state.
340
void PyramidPointRendererPlugin::setBackFaceCulling ( bool c ) {
341
if (point_based_render)
342
point_based_render->setBackFaceCulling(c);
346
* Turns elliptical weights on/off.
347
* @param b Elliptical weight state.
349
void PyramidPointRendererPlugin::setEllipticalWeight ( bool b ) {
350
point_based_render->setEllipticalWeight(b);
354
* Turns quality per vertex on/off.
355
* @param c Quality per vertex state.
357
void PyramidPointRendererPlugin::setQualityPerVertex ( bool c ) {
358
point_based_render->setQualityPerVertex(c);
361
/// Cycles through objects list for displaying individual parts of the model.
362
/// When selected = 0 displays all files
363
void PyramidPointRendererPlugin::increaseSelected ( void ) {
365
if (selected > (int)objects.size())
367
cout << "selected : " << selected << endl;
371
/// Cycles through objects list for displaying individual parts of the model.
372
/// When selected = 0 displays all files
373
void PyramidPointRendererPlugin::decreaseSelected ( void ) {
376
selected = objects.size();
377
cout << "selected : " << selected << endl;
380
Q_EXPORT_PLUGIN(PyramidPointRendererPlugin)