Subversion Repositories gelsvn

Rev

Rev 630 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 630 Rev 641
Line 259... Line 259...
259
			Q[i][i] = -a_sum;
259
			Q[i][i] = -a_sum;
260
		}
260
		}
261
	EigenSolutionsSym(Q,V);
261
	EigenSolutionsSym(Q,V);
262
}
262
}
263
 
263
 
264
Harmonics::Harmonics(HMesh::Manifold& _mani, GLGraphics::Console& cs):mani(_mani), vtouched(_mani.allocated_vertices(), 0)
264
Harmonics::Harmonics(HMesh::Manifold& _mani):mani(_mani), vtouched(_mani.allocated_vertices(), 0)
265
{
265
{
266
    string shader_path = "/Users/jab/GEL/apps/MeshEdit/";
-
 
267
	GLuint vs = create_glsl_shader(GL_VERTEX_SHADER, vss);
-
 
268
	GLuint fs = create_glsl_shader(GL_FRAGMENT_SHADER, fss);
-
 
269
	
-
 
270
	// Create the program
-
 
271
	prog_P0 = glCreateProgram();
-
 
272
	
-
 
273
	// Attach all shaders
-
 
274
	if(vs) glAttachShader(prog_P0, vs);
-
 
275
	if(fs) glAttachShader(prog_P0, fs);
-
 
276
	
-
 
277
	// Link the program object and print out the info log
-
 
278
	glLinkProgram(prog_P0);
-
 
279
	print_glsl_program_log(prog_P0);
-
 
280
	
-
 
281
	// Install program object as part of current state
-
 
282
	glUseProgram(0);
-
 
283
	
-
 
284
    display_harmonics_diffuse.reg(cs, "display.harmonics.diffuse", "");
-
 
285
    display_harmonics_time.reg(cs, "display.harmonics.time", "");
-
 
286
    display_harmonics_highlight.reg(cs, "display.harmonics.highlight", "");
-
 
287
	
-
 
288
	triangulate_by_edge_face_split(mani);
-
 
289
 
266
  
290
    int i = 0;
267
    int i = 0;
291
    for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v, ++i)
268
    for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v, ++i)
292
        vtouched[*v] = i;
269
        vtouched[*v] = i;
293
	maximum_eigenvalue = mani.no_vertices()-1;
270
	maximum_eigenvalue = mani.no_vertices()-1;
Line 330... Line 307...
330
{
307
{
331
	for(int es=E0;es<=E1;++es)
308
	for(int es=E0;es<=E1;++es)
332
		add_frequency(es, scale);
309
		add_frequency(es, scale);
333
}
310
}
334
 
311
 
-
 
312
 
-
 
313
double Harmonics::compute_adf(HMesh::VertexAttributeVector<double>& F, double t)
-
 
314
{
-
 
315
	double F_max = 0;
-
 
316
	for(VertexID vid : mani.vertices()){
-
 
317
		for(int e = 1; e < V.Length(); ++e)
-
 
318
			F[vid] += sqr(Q[e][vtouched[vid]]) * exp(-t*V[e]/V[1]);
-
 
319
		F_max = max(F[vid], F_max);
-
 
320
	}
-
 
321
    return F_max;
-
 
322
}
-
 
323
 
-
 
324
 
-
 
325
GLuint HarmonicsRenderer::prog_P0 = 0;
-
 
326
GLGraphics::Console::variable<float> HarmonicsRenderer::display_harmonics_time;
-
 
327
GLGraphics::Console::variable<int> HarmonicsRenderer::display_harmonics_diffuse;
-
 
328
GLGraphics::Console::variable<int> HarmonicsRenderer::display_harmonics_highlight;
-
 
329
 
-
 
330
 
-
 
331
HarmonicsRenderer::HarmonicsRenderer(HMesh::Manifold& _m, Harmonics& _h, GLGraphics::Console& cs): m(&_m), h(&_h)
-
 
332
{
-
 
333
    if (prog_P0 == 0) {
-
 
334
        string shader_path = "/Users/jab/GEL/apps/MeshEdit/";
-
 
335
        GLuint vs = create_glsl_shader(GL_VERTEX_SHADER, vss);
-
 
336
        GLuint fs = create_glsl_shader(GL_FRAGMENT_SHADER, fss);
-
 
337
        
-
 
338
        // Create the program
-
 
339
        prog_P0 = glCreateProgram();
-
 
340
        
-
 
341
        // Attach all shaders
-
 
342
        if(vs) glAttachShader(prog_P0, vs);
-
 
343
        if(fs) glAttachShader(prog_P0, fs);
-
 
344
        
-
 
345
        // Link the program object and print out the info log
-
 
346
        glLinkProgram(prog_P0);
-
 
347
        print_glsl_program_log(prog_P0);
-
 
348
        
-
 
349
        // Install program object as part of current state
-
 
350
        glUseProgram(0);
-
 
351
        
-
 
352
        
-
 
353
        display_harmonics_diffuse.reg(cs, "display.harmonics.diffuse", "");
-
 
354
        display_harmonics_time.reg(cs, "display.harmonics.time", "");
-
 
355
        display_harmonics_highlight.reg(cs, "display.harmonics.highlight", "");
-
 
356
    }
-
 
357
    draw_adf();
-
 
358
}
-
 
359
 
-
 
360
 
335
void Harmonics::parse_key(unsigned char key)
361
void HarmonicsRenderer::parse_key(unsigned char key)
336
{
362
{
337
	switch(key) {
363
	switch(key) {
338
		case '+': 
364
		case '+':
339
			display_harmonics_time = display_harmonics_time+0.001; 
365
			display_harmonics_time = display_harmonics_time+0.001;
340
			break;
366
			break;
Line 350... Line 376...
350
	}
376
	}
351
	
377
	
352
}
378
}
353
 
379
 
354
 
380
 
-
 
381
 
-
 
382
 
355
void Harmonics::draw_adf()
383
void HarmonicsRenderer::draw_adf()
356
{
384
{
357
	vector<double> F(mani.no_vertices(),0);
385
    VertexAttributeVector<double> F;
358
	double F_max = 0;
-
 
359
	for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v){
-
 
360
		int v_idx = vtouched[*v];
-
 
361
		for(int e = 1; e < V.Length(); ++e)
-
 
362
			F[v_idx] += sqr(Q[e][v_idx]) * exp(-(display_harmonics_time)*V[e]/V[1]);
386
    double F_max = h->compute_adf(F, display_harmonics_time);
363
		F_max = max(F[v_idx], F_max);
-
 
364
	}
-
 
365
	cout << "F max" <<  F_max << endl;
387
	cout << "F max" <<  F_max << endl;
-
 
388
    
-
 
389
    glNewList(display_list, GL_COMPILE);
366
	glUseProgram(prog_P0);
390
	glUseProgram(prog_P0);
367
	glUniform1f(glGetUniformLocation(prog_P0,"eig_max"),F_max);//2*M_PI);
391
	glUniform1f(glGetUniformLocation(prog_P0,"eig_max"),F_max);//2*M_PI);
368
	glUniform1i(glGetUniformLocation(prog_P0,"do_diffuse"),display_harmonics_diffuse);
392
	glUniform1i(glGetUniformLocation(prog_P0,"do_diffuse"),display_harmonics_diffuse);
369
   	glUniform1i(glGetUniformLocation(prog_P0,"do_highlight"),display_harmonics_highlight);
393
   	glUniform1i(glGetUniformLocation(prog_P0,"do_highlight"),display_harmonics_highlight);
370
	GLuint attrib = glGetAttribLocationARB(prog_P0, "eigenvalue");
394
	GLuint attrib = glGetAttribLocationARB(prog_P0, "eigenvalue");
371
	
395
	
372
	glFrontFace(GL_CW);
396
	glFrontFace(GL_CW);
373
	for(FaceIDIterator f = mani.faces_begin(); f != mani.faces_end(); ++f){
397
	for(FaceIDIterator f = m->faces_begin(); f != m->faces_end(); ++f){
374
		glBegin(GL_TRIANGLES);
398
		glBegin(GL_TRIANGLES);
375
        for(Walker w = mani.walker(*f); !w.full_circle(); w = w.circulate_face_cw()){
399
        for(Walker w = m->walker(*f); !w.full_circle(); w = w.circulate_face_cw()){
376
			int i = vtouched[w.vertex()];
-
 
377
			glVertexAttrib1f(attrib,F[i]);
400
			glVertexAttrib1f(attrib,F[w.vertex()]);
378
			glNormal3dv(normal(mani, w.vertex()).get());
401
			glNormal3dv(normal(*m, w.vertex()).get());
379
			glVertex3dv(mani.pos(w.vertex()).get());
402
			glVertex3dv(m->pos(w.vertex()).get());
380
		}
403
		}
381
		glEnd();
404
		glEnd();
382
	}
405
	}
383
	glFrontFace(GL_CCW);
406
	glFrontFace(GL_CCW);
384
	glUseProgram(0);
407
	glUseProgram(0);
-
 
408
    glEndList();
385
}
409
}
386
 
410