Subversion Repositories gelsvn

Rev

Rev 630 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 630 Rev 641
Line 61... Line 61...
61
	"		normal = normalize(gl_NormalMatrix * gl_Normal);\n"
61
	"		normal = normalize(gl_NormalMatrix * gl_Normal);\n"
62
	"		eig = eigenvalue;\n"
62
	"		eig = eigenvalue;\n"
63
	"		eig2 = eigenvalue2;\n"
63
	"		eig2 = eigenvalue2;\n"
64
	"	}\n";
64
	"	}\n";
65
	
65
	
66
	string fss = 	
66
	string fss =
67
	"#version 120\n"
67
	"#version 120\n"
68
	"#extension GL_EXT_gpu_shader4 : enable\n"
68
	"#extension GL_EXT_gpu_shader4 : enable\n"
69
	"	\n"
69
	"	\n"
70
	"	varying vec3 normal;\n"
70
	"	varying vec3 normal;\n"
71
	"	varying float eig;\n"
71
	"	varying float eig;\n"
Line 74... Line 74...
74
	"	uniform float eig_max2;\n"
74
	"	uniform float eig_max2;\n"
75
	"	uniform bool do_highlight;\n"
75
	"	uniform bool do_highlight;\n"
76
	"	uniform bool do_diffuse;\n"
76
	"	uniform bool do_diffuse;\n"
77
	"	const vec3 light_dir = vec3(0,0,1);\n"
77
	"	const vec3 light_dir = vec3(0,0,1);\n"
78
	"	\n"
78
	"	\n"
79
	" float basef(float x) {return max(0.0,min(1.0,2.0-4.0*abs(x)));\n}" 
79
	" float basef(float x) {return max(0.0,min(1.0,2.0-4.0*abs(x)));\n}"
80
	"	void main()\n"
80
	"	void main()\n"
81
	"	{\n"
81
	"	{\n"
82
	"		float dot_ln = max(0.0,dot(light_dir, normal));\n"
82
	"		float dot_ln = max(0.0,dot(light_dir, normal));\n"
83
	"		\n"
83
	"		\n"
84
	"		float eig_norm = eig/eig_max;\n"
84
	"		float eig_norm = eig/eig_max;\n"
Line 152... Line 152...
152
			if(!is_generalized)
152
			if(!is_generalized)
153
				area_i = 1; // if standard S is an identity matrix;
153
				area_i = 1; // if standard S is an identity matrix;
154
			mb_S.insert_entry(i,area_i);
154
			mb_S.insert_entry(i,area_i);
155
			mb_S.next_column_nonsort();
155
			mb_S.next_column_nonsort();
156
			S[i] = area_i;
156
			S[i] = area_i;
157
		}     
157
		}
158
	
158
	
159
	cout << "solving generalized problem... i = " << mani.no_vertices()<< endl;
159
	cout << "solving generalized problem... i = " << mani.no_vertices()<< endl;
160
	
160
	
161
	
161
	
162
	//+STANDARD
162
	//+STANDARD
Line 214... Line 214...
214
	{
214
	{
215
		proj[es] = Vec3d(0.0);
215
		proj[es] = Vec3d(0.0);
216
		for(VertexIter v=mani.vhandles_begin(); v != mani.vhandles_end(); ++v)
216
		for(VertexIter v=mani.vhandles_begin(); v != mani.vhandles_end(); ++v)
217
		{
217
		{
218
			proj[es] +=  Vec3d(v->pos) * Q[es][v->touched] * S[v->touched];
218
			proj[es] +=  Vec3d(v->pos) * Q[es][v->touched] * S[v->touched];
219
			max_eig_values[es] = max(max_eig_values[es], static_cast<float>(abs(Q[es][v->touched])));     
219
			max_eig_values[es] = max(max_eig_values[es], static_cast<float>(abs(Q[es][v->touched])));
220
		}     
220
		}
221
	}
221
	}
222
	cout << endl;
222
	cout << endl;
223
}
223
}
224
 
224
 
225
#else
225
#else
Line 250... Line 250...
250
				double a_left  = acos(min(1.0, max(-1.0, d_left)));
250
				double a_left  = acos(min(1.0, max(-1.0, d_left)));
251
				double a_right = acos(min(1.0, max(-1.0, d_right)));
251
				double a_right = acos(min(1.0, max(-1.0, d_right)));
252
				
252
				
253
				double w = 1.0/tan(a_left) + 1.0/tan(a_right);
253
				double w = 1.0/tan(a_left) + 1.0/tan(a_right);
254
				
254
				
255
				Q[i][j] = -w/sqrt(area_i*area_j);						
255
				Q[i][j] = -w/sqrt(area_i*area_j);
256
				//Q[i][j] = -1;						
256
				//Q[i][j] = -1;
257
				a_sum += Q[i][j];
257
				a_sum += Q[i][j];
258
			}
258
			}
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
	
266
  
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
 
-
 
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;
294
	make_laplace_operator();
271
	make_laplace_operator();
Line 315... Line 292...
315
	if(es<maximum_eigenvalue)
292
	if(es<maximum_eigenvalue)
316
		for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v){
293
		for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v){
317
			Vec3d p = Vec3d(proj[es]);
294
			Vec3d p = Vec3d(proj[es]);
318
			double Qval = Q[es][vtouched[*v]];
295
			double Qval = Q[es][vtouched[*v]];
319
			
296
			
320
			mani.pos(*v) += p * Qval * scale; 	
297
			mani.pos(*v) += p * Qval * scale;
321
		}
298
		}
322
}
299
}
323
 
300
 
324
void Harmonics::reset_shape()
301
void Harmonics::reset_shape()
325
{
302
{
326
	for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
303
	for(VertexIDIterator v = mani.vertices_begin(); v != mani.vertices_end(); ++v)
327
		mani.pos(*v) = Vec3d(0);	
304
		mani.pos(*v) = Vec3d(0);
328
}
305
}
329
void Harmonics::partial_reconstruct(int E0, int E1, float scale)
306
void Harmonics::partial_reconstruct(int E0, int E1, float scale)
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;
341
		case '-': 
367
		case '-':
342
			display_harmonics_time = display_harmonics_time-0.001; 
368
			display_harmonics_time = display_harmonics_time-0.001;
343
			break;
369
			break;
344
		case 'd':	
370
		case 'd':
345
			display_harmonics_diffuse = !display_harmonics_diffuse; 
371
			display_harmonics_diffuse = !display_harmonics_diffuse;
346
			break;
372
			break;
347
		case 'h':
373
		case 'h':
348
			display_harmonics_highlight = !display_harmonics_highlight;
374
			display_harmonics_highlight = !display_harmonics_highlight;
349
			break;			
375
			break;
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