Subversion Repositories gelsvn

Rev

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

Rev 630 Rev 631
Line 213... Line 213...
213
 
213
 
214
    avo().save_old();
214
    avo().save_old();
215
 
215
 
216
	double vmin, vmax;
216
	double vmin, vmax;
217
    VertexAttributeVector<double> fun;
217
    VertexAttributeVector<double> fun;
218
    VertexAttributeVector<double> par;
218
    VertexAttributeVector<Vec2d> par;
219
    make_height_fun(active_mesh(), fun, vmin, vmax);
219
    make_height_fun(active_mesh(), fun, vmin, vmax);
220
    polarize_mesh(active_mesh(), fun, vmin, vmax, divisions, par);
220
    polarize_mesh(active_mesh(), fun, vmin, vmax, divisions, par);
221
}
221
}
222
 
222
 
223
void transform_mesh(Manifold& mani, const Mat4x4d& m)
223
void transform_mesh(Manifold& mani, const Mat4x4d& m)
Line 358... Line 358...
358
}
358
}
359
 
359
 
360
void console_cc_subdivide(const std::vector<std::string> & args)
360
void console_cc_subdivide(const std::vector<std::string> & args)
361
{
361
{
362
    if(wantshelp(args)) {
362
    if(wantshelp(args)) {
363
        theConsole.printf("usage: refine.catmull_clark ");
363
        theConsole.printf("usage: subdivide.catmull_clark ");
364
        theConsole.printf("Does one step of Catmull-Clark subdivision");
364
        theConsole.printf("Does one step of Catmull-Clark subdivision");
365
		
365
		
366
        return;
366
        return;
367
    }
367
    }
368
    avo().save_old();
368
    avo().save_old();
Line 371... Line 371...
371
    cc_smooth(active_mesh());
371
    cc_smooth(active_mesh());
372
	
372
	
373
    return;
373
    return;
374
}
374
}
375
 
375
 
-
 
376
void console_loop_subdivide(const std::vector<std::string> & args)
-
 
377
{
-
 
378
    if(wantshelp(args)) {
-
 
379
        theConsole.printf("usage: subdivide.loop");
-
 
380
        theConsole.printf("Does one step of Loop subdivision");
-
 
381
		
-
 
382
        return;
-
 
383
    }
-
 
384
    avo().save_old();
-
 
385
	
-
 
386
    loop_split(active_mesh(),active_mesh());
-
 
387
    loop_smooth(active_mesh());
-
 
388
	
-
 
389
    return;
-
 
390
}
-
 
391
 
-
 
392
void console_root3_subdivide(const std::vector<std::string> & args)
-
 
393
{
-
 
394
    if(wantshelp(args)) {
-
 
395
        theConsole.printf("usage: subdivide.root3");
-
 
396
        theConsole.printf("Does one step of sqrt(3) subdivision");
-
 
397
		
-
 
398
        return;
-
 
399
    }
-
 
400
    avo().save_old();
-
 
401
	
-
 
402
    root3_subdivide(active_mesh(),active_mesh());
-
 
403
	
-
 
404
    return;
-
 
405
}
-
 
406
 
-
 
407
 
376
void console_doosabin_subdivide(const std::vector<std::string> & args)
408
void console_doosabin_subdivide(const std::vector<std::string> & args)
377
{
409
{
378
    if(wantshelp(args)) {
410
    if(wantshelp(args)) {
379
        theConsole.printf("usage: refine.doo_sabin ");
411
        theConsole.printf("usage: subdivide.doo_sabin ");
380
        theConsole.printf("Does one step of Doo-Sabin Subdivision");
412
        theConsole.printf("Does one step of Doo-Sabin Subdivision");
381
		
413
		
382
        return;
414
        return;
383
    }
415
    }
384
    avo().save_old();
416
    avo().save_old();
Line 387... Line 419...
387
    dual(active_mesh());
419
    dual(active_mesh());
388
    
420
    
389
    return;
421
    return;
390
}
422
}
391
 
423
 
-
 
424
void console_butterfly_subdivide(const std::vector<std::string> & args)
-
 
425
{
-
 
426
    if(wantshelp(args)) {
-
 
427
        theConsole.printf("usage: subdivide.butterfly ");
-
 
428
        theConsole.printf("Does one step of Modified Butterfly Subdivision");
-
 
429
		
-
 
430
        return;
-
 
431
    }
-
 
432
    avo().save_old();
-
 
433
	
-
 
434
    butterfly_subdivide(active_mesh(),active_mesh());
-
 
435
    
-
 
436
    return;
-
 
437
}
-
 
438
 
392
void console_dual(const std::vector<std::string> & args)
439
void console_dual(const std::vector<std::string> & args)
393
{
440
{
394
    if(wantshelp(args)) 
441
    if(wantshelp(args)) 
395
    {
442
    {
396
        theConsole.printf("usage: dual ");
443
        theConsole.printf("usage: dual ");
Line 759... Line 806...
759
    for(VertexIDIterator vi = active_mesh().vertices_begin(); vi != active_mesh().vertices_end(); ++vi){
806
    for(VertexIDIterator vi = active_mesh().vertices_begin(); vi != active_mesh().vertices_end(); ++vi){
760
        Vec3d v;
807
        Vec3d v;
761
        do{
808
        do{
762
            v = Vec3d(gel_rand(),gel_rand(),gel_rand());
809
            v = Vec3d(gel_rand(),gel_rand(),gel_rand());
763
            v /= (float)(GEL_RAND_MAX);
810
            v /= (float)(GEL_RAND_MAX);
-
 
811
            v -= Vec3d(0.5);
-
 
812
            v *= 2.0;
764
        } 
813
        }
765
        while(sqr_length(v) > 1.0);
814
        while(sqr_length(v) > 1.0);
766
		
815
		
767
        v -= Vec3d(0.5);
-
 
768
        v *= 2.0;
-
 
769
        v *= noise_amplitude;
816
        v *= noise_amplitude;
770
        v *= avg_length;
817
        v *= avg_length;
771
        active_mesh().pos(*vi) += v;
818
        active_mesh().pos(*vi) += v;
772
    }		
819
    }		
773
    return;
820
    return;
Line 843... Line 890...
843
    int iter = 1;
890
    int iter = 1;
844
    if(args.size()>1){
891
    if(args.size()>1){
845
        istringstream a0(args[1]);
892
        istringstream a0(args[1]);
846
        a0 >> iter;
893
        a0 >> iter;
847
    }
894
    }
-
 
895
    Util::Timer tim;
-
 
896
    tim.start();
848
    /// Simple laplacian smoothing with an optional weight.
897
    /// Simple laplacian smoothing with an optional weight.
849
    for(int i=0;i<iter;++i) 
898
    laplacian_smooth(active_mesh(), t, iter);
850
        laplacian_smooth(active_mesh(), t);
899
    cout << "It took "<< tim.get_secs();
851
    return;
900
    return;
852
}
901
}
853
 
902
 
854
 
903
 
855
void console_mean_curvature_smooth(const std::vector<std::string> & args){
904
void console_mean_curvature_smooth(const std::vector<std::string> & args){
Line 905... Line 954...
905
    taubin_smooth(active_mesh(),  iter);
954
    taubin_smooth(active_mesh(),  iter);
906
	
955
	
907
    return;
956
    return;
908
}
957
}
909
 
958
 
910
void console_fvm_smooth(const std::vector<std::string> & args)
959
void console_fvm_anisotropic_smooth(const std::vector<std::string> & args)
-
 
960
{
-
 
961
    if(wantshelp(args)){
-
 
962
        theConsole.printf("usage: smooth.fuzzy_vector_median <iter>");
-
 
963
        theConsole.printf("Smooth normals using fuzzy vector median smoothing. iter (default=1) is the number of iterations");
-
 
964
        theConsole.printf("This function does a very good job of preserving sharp edges.");
-
 
965
        return;
-
 
966
    }
-
 
967
    avo().save_old();
-
 
968
	
-
 
969
    int iter=1;
-
 
970
    if(args.size() > 0){
-
 
971
        istringstream a0(args[0]);
-
 
972
        a0 >> iter;
-
 
973
    }
-
 
974
    // Fuzzy vector median smoothing is effective when it comes to preserving sharp edges.
-
 
975
    anisotropic_smooth(active_mesh(),  iter, FVM_NORMAL_SMOOTH);
-
 
976
	
-
 
977
    return;
-
 
978
}
-
 
979
 
-
 
980
void console_bilateral_anisotropic_smooth(const std::vector<std::string> & args)
911
{	
981
{
912
    if(wantshelp(args)){
982
    if(wantshelp(args)){
913
        theConsole.printf("usage: smooth.fuzzy_vector_median <iter>");
983
        theConsole.printf("usage: smooth.fuzzy_vector_median <iter>");
914
        theConsole.printf("Smooth normals using fuzzy vector median smoothing. iter (default=1) is the number of iterations");
984
        theConsole.printf("Smooth normals using fuzzy vector median smoothing. iter (default=1) is the number of iterations");
915
        theConsole.printf("This function does a very good job of preserving sharp edges.");
985
        theConsole.printf("This function does a very good job of preserving sharp edges.");
916
        return;
986
        return;
Line 920... Line 990...
920
    int iter=1;
990
    int iter=1;
921
    if(args.size() > 0){
991
    if(args.size() > 0){
922
        istringstream a0(args[0]);
992
        istringstream a0(args[0]);
923
        a0 >> iter;
993
        a0 >> iter;
924
    }
994
    }
925
    // Fuzzy vector median smoothing is effective when it comes to preserving sharp edges. 
-
 
-
 
995
    
926
    fvm_smooth(active_mesh(),  iter);
996
    anisotropic_smooth(active_mesh(),  iter, BILATERAL_NORMAL_SMOOTH);
927
	
997
	
928
    return;
998
    return;
929
}
999
}
930
 
1000
 
931
void console_triangulate(const std::vector<std::string> & args)
1001
void console_triangulate(const std::vector<std::string> & args)
Line 1069... Line 1139...
1069
    active_view_control().try_spin();
1139
    active_view_control().try_spin();
1070
    glutPostRedisplay();
1140
    glutPostRedisplay();
1071
}
1141
}
1072
 
1142
 
1073
 
1143
 
1074
void mouse(int button, int state, int x, int y) 
1144
void mouse(int button, int state, int x, int y)     
1075
{
1145
{
1076
    Vec2i pos(x,y);
1146
    Vec2i pos(x,y);
1077
    if (state==GLUT_DOWN) 
1147
    if (state==GLUT_DOWN) 
1078
    {
1148
    {
1079
        if (button==GLUT_LEFT_BUTTON && glutGetModifiers() == 0)
1149
        if (button==GLUT_LEFT_BUTTON && glutGetModifiers() == 0)
Line 1189... Line 1259...
1189
    glutIdleFunc(animate);
1259
    glutIdleFunc(animate);
1190
}
1260
}
1191
void init_gl()
1261
void init_gl()
1192
{
1262
{
1193
    glewInit();
1263
    glewInit();
-
 
1264
    glEnable(GL_CULL_FACE);
-
 
1265
    glCullFace(GL_BACK);
1194
    glEnable(GL_LIGHTING);
1266
    glEnable(GL_LIGHTING);
1195
    glEnable(GL_LIGHT0);
1267
    glEnable(GL_LIGHT0);
1196
    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
1268
    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
1197
	
1269
	
1198
    // Set the value of a uniform
1270
    // Set the value of a uniform
Line 1211... Line 1283...
1211
    theConsole.reg_cmdN("harmonics.partial_reconstruct", console_partial_reconstruct,"");
1283
    theConsole.reg_cmdN("harmonics.partial_reconstruct", console_partial_reconstruct,"");
1212
    theConsole.reg_cmdN("simplify", console_simplify,"");
1284
    theConsole.reg_cmdN("simplify", console_simplify,"");
1213
    theConsole.reg_cmdN("smooth.mean_curvature", console_mean_curvature_smooth,"");
1285
    theConsole.reg_cmdN("smooth.mean_curvature", console_mean_curvature_smooth,"");
1214
    theConsole.reg_cmdN("smooth.laplacian", console_laplacian_smooth,"");
1286
    theConsole.reg_cmdN("smooth.laplacian", console_laplacian_smooth,"");
1215
    theConsole.reg_cmdN("smooth.taubin", console_taubin_smooth,"");
1287
    theConsole.reg_cmdN("smooth.taubin", console_taubin_smooth,"");
1216
    theConsole.reg_cmdN("smooth.fuzzy_vector_median", console_fvm_smooth,"");
1288
    theConsole.reg_cmdN("smooth.fuzzy_vector_median_anisotropic", console_fvm_anisotropic_smooth ,"");
-
 
1289
    theConsole.reg_cmdN("smooth.bilateral_anisotropic", console_bilateral_anisotropic_smooth ,"");
1217
	
1290
	
1218
    theConsole.reg_cmdN("optimize.valency", console_optimize_valency,"");
1291
    theConsole.reg_cmdN("optimize.valency", console_optimize_valency,"");
1219
    theConsole.reg_cmdN("optimize.minimize_dihedral_angles", console_minimize_dihedral,"");
1292
    theConsole.reg_cmdN("optimize.minimize_dihedral_angles", console_minimize_dihedral,"");
1220
    theConsole.reg_cmdN("optimize.minimize_curvature", console_minimize_curvature,"");
1293
    theConsole.reg_cmdN("optimize.minimize_curvature", console_minimize_curvature,"");
1221
    theConsole.reg_cmdN("optimize.maximize_min_angle", console_maximize_min_angle,"");
1294
    theConsole.reg_cmdN("optimize.maximize_min_angle", console_maximize_min_angle,"");
Line 1226... Line 1299...
1226
    theConsole.reg_cmdN("cleanup.remove_caps", console_remove_caps,"");
1299
    theConsole.reg_cmdN("cleanup.remove_caps", console_remove_caps,"");
1227
    theConsole.reg_cmdN("cleanup.remove_needles", console_remove_needles,"");
1300
    theConsole.reg_cmdN("cleanup.remove_needles", console_remove_needles,"");
1228
    theConsole.reg_cmdN("triangulate", console_triangulate,"");
1301
    theConsole.reg_cmdN("triangulate", console_triangulate,"");
1229
    theConsole.reg_cmdN("refine.split_edges", console_refine_edges,"");
1302
    theConsole.reg_cmdN("refine.split_edges", console_refine_edges,"");
1230
    theConsole.reg_cmdN("refine.split_faces", console_refine_faces,"");
1303
    theConsole.reg_cmdN("refine.split_faces", console_refine_faces,"");
1231
    theConsole.reg_cmdN("refine.catmull_clark", console_cc_subdivide,"");
1304
    theConsole.reg_cmdN("subdivide.catmull_clark", console_cc_subdivide,"");
-
 
1305
    theConsole.reg_cmdN("subdivide.loop", console_loop_subdivide,"");
-
 
1306
    theConsole.reg_cmdN("subdivide.root3", console_root3_subdivide,"");
1232
    theConsole.reg_cmdN("refine.doo_sabin", console_doosabin_subdivide,"");
1307
    theConsole.reg_cmdN("subdivide.doo_sabin", console_doosabin_subdivide,"");
-
 
1308
    theConsole.reg_cmdN("subdivide.butterfly", console_butterfly_subdivide,"");
1233
    theConsole.reg_cmdN("save_mesh", console_save,"");
1309
    theConsole.reg_cmdN("save_mesh", console_save,"");
1234
    theConsole.reg_cmdN("noise.perturb_vertices", console_vertex_noise,"");
1310
    theConsole.reg_cmdN("noise.perturb_vertices", console_vertex_noise,"");
1235
    theConsole.reg_cmdN("noise.perturb_vertices_perpendicular", console_perpendicular_vertex_noise,"");
1311
    theConsole.reg_cmdN("noise.perturb_vertices_perpendicular", console_perpendicular_vertex_noise,"");
1236
    theConsole.reg_cmdN("noise.perturb_topology", console_noisy_flips,"");
1312
    theConsole.reg_cmdN("noise.perturb_topology", console_noisy_flips,"");
1237
 
1313