Subversion Repositories gelsvn

Rev

Rev 657 | Rev 663 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
647 janba 1
//
2
//  MeshEditor.cpp
3
//  GEL
4
//
5
//  Created by J. Andreas Bærentzen on 09/10/13.
6
//
7
//
662 janba 8
#include <thread>
9
#include <unistd.h>
647 janba 10
#include <GL/glew.h>
11
#include <functional>
12
#include "MeshEditor.h"
13
#include <string>
14
#include <iostream>
15
#include <vector>
16
#include <algorithm>
17
#include <queue>
18
 
19
#include <GLGraphics/Console.h>
20
 
21
#include <CGLA/eigensolution.h>
22
#include <CGLA/Vec2d.h>
23
#include <CGLA/Vec3d.h>
24
#include <CGLA/Mat3x3d.h>
25
#include <CGLA/Mat2x2d.h>
26
#include <CGLA/Mat2x3d.h>
27
#include <CGLA/Mat4x4d.h>
28
 
29
#include <LinAlg/Matrix.h>
30
#include <LinAlg/Vector.h>
31
#include <LinAlg/LapackFunc.h>
32
 
33
#include <HMesh/Manifold.h>
34
#include <HMesh/AttributeVector.h>
35
#include <HMesh/mesh_optimization.h>
36
#include <HMesh/curvature.h>
37
#include <HMesh/triangulate.h>
38
#include <HMesh/flatten.h>
39
#include <HMesh/dual.h>
40
#include <HMesh/load.h>
41
#include <HMesh/quadric_simplify.h>
42
#include <HMesh/smooth.h>
43
#include <HMesh/x3d_save.h>
44
#include <HMesh/obj_save.h>
45
#include <HMesh/off_save.h>
46
#include <HMesh/mesh_optimization.h>
47
#include <HMesh/triangulate.h>
48
#include <HMesh/cleanup.h>
49
#include <HMesh/cleanup.h>
50
#include <HMesh/refine_edges.h>
51
#include <HMesh/subdivision.h>
52
#include <HMesh/harmonics.h>
53
 
54
#include <Util/Timer.h>
55
 
56
#include "VisObj.h"
57
 
58
using namespace std;
59
using namespace CGLA;
60
using namespace HMesh;
61
using namespace Util;
62
 
63
namespace GLGraphics {
64
 
65
    namespace {
66
 
67
        bool wantshelp(const std::vector<std::string> & args)
68
        {
69
            if(args.size() == 0)
70
                return false;
71
 
72
            string str = args[0];
73
 
74
            if(str=="help" || str=="HELP" || str=="Help" || str=="?")
75
                return true;
76
 
77
            return false;
78
        }
79
 
80
 
81
        bool wantshelp(MeshEditor* me, const std::vector<std::string> & args)
82
        {
83
            if(args.size() == 0)
84
                return false;
85
 
86
            string str = args[0];
87
 
88
            if(str=="help" || str=="HELP" || str=="Help" || str=="?")
89
                return true;
90
 
91
            return false;
92
        }
93
 
94
        /// Function that aligns two meshes.
95
        void console_align(MeshEditor* me, const std::vector<std::string> & args)
96
        {
97
            if(wantshelp(args)) {
98
                me->printf("usage: align <dest> <src>");
99
                me->printf("This function aligns dest mesh with src");
100
                me->printf("In practice the GLViewController of src is copied to dst.");
101
                me->printf("both arguments are mandatory and must be numbers between 1 and 9.");
102
                me->printf("Note that results might be unexpexted if the meshes are not on the same scale");
103
            }
104
 
105
            int dest = 0;
106
 
107
            if(args.size()>0){
108
                istringstream a0(args[0]);
109
                a0 >> dest;
110
                --dest;
111
 
112
                if(dest <0 || dest>8)
113
                {
114
                    me->printf("dest mesh out of range (1-9)");
115
                    return;
116
                }
117
            }
118
            else
119
            {
120
                me->printf("neither source nor destination mesh?!");
121
                return;
122
            }
123
 
124
            int src = 0;
125
            if(args.size()>1){
126
                istringstream a1(args[1]);
127
                a1 >> src;
128
                --src;
129
 
130
                if(src <0 || src>8)
131
                {
132
                    me->printf("src mesh out of range (1-9)");
133
                    return;
134
                }
135
            }
136
            else
137
            {
138
                me->printf("no src mesh?");
139
                return;
140
            }
141
            me->align(src,dest);
142
        }
143
 
144
 
145
 
146
 
147
        void console_ridge_lines(MeshEditor* me, const std::vector<std::string> & args)
148
        {
149
            if(wantshelp(args)) {
150
                me->printf("usage: ridge_lines");
151
                return;
152
            }
153
 
154
            me->save_active_mesh();
155
 
156
            Manifold& mani = me->active_mesh();
157
 
158
            VertexAttributeVector<Mat3x3d> curvature_tensors(mani.allocated_vertices());
159
            VertexAttributeVector<Vec3d> min_curv_direction(mani.allocated_vertices());
160
            VertexAttributeVector<Vec3d> max_curv_direction(mani.allocated_vertices());
161
            VertexAttributeVector<Vec2d> curvature(mani.allocated_vertices());
162
 
163
 
164
 
165
            curvature_paraboloids(mani,
166
                                  min_curv_direction,
167
                                  max_curv_direction,
168
                                  curvature);
169
 
170
            for(auto vid : mani.vertices())
171
            {
172
                Vec3d max_curv_dir = normalize(max_curv_direction[vid]);
173
                Vec3d min_curv_dir = normalize(min_curv_direction[vid]);
174
                double vid_min_pc = curvature[vid][0];
175
                double vid_max_pc = curvature[vid][1];
176
                bool ridge = true;
177
                bool ravine = true;
178
                Walker w = mani.walker(vid);
179
                Vec3d r(0);
180
                for(; !w.full_circle();w = w.circulate_vertex_ccw())
181
                {
182
                    Vec3d e = (mani.pos(w.vertex()) - mani.pos(vid));
183
 
184
                    if(abs(dot(min_curv_dir,e)) > abs(dot(max_curv_dir,e)))
185
                    {
186
                        if(curvature[w.vertex()][0]<vid_min_pc+20)
187
                            ravine = false;
188
 
189
                    }
190
                    else
191
                    {
192
                        if(curvature[w.vertex()][1]>vid_max_pc-20)
193
                            ridge = false;
194
                    }
195
                }
196
                DebugRenderer::vertex_colors[vid] = Vec3f(ridge,ravine,0.0);
197
            }
198
            for(auto fid : mani.faces())
199
                DebugRenderer::face_colors[fid] = Vec3f(.3,.3,.6);
200
            for(auto hid : mani.halfedges()) {
201
 
202
                Walker w = mani.walker(hid);
203
                Vec3f c0 = DebugRenderer::vertex_colors[w.opp().vertex()];
204
                Vec3f c1 = DebugRenderer::vertex_colors[w.vertex()];
205
 
206
                DebugRenderer::edge_colors[hid] = (c0==c1) ? c0 : Vec3f(0.1,0.1,0.3);
207
 
208
            }
209
        }
210
 
211
        void transform_mesh(Manifold& mani, const Mat4x4d& m)
212
        {
213
            for(VertexIDIterator vid = mani.vertices_begin(); vid != mani.vertices_end(); ++vid)
214
                mani.pos(*vid) = m.mul_3D_point(mani.pos(*vid));
215
        }
216
 
217
        void console_scale(MeshEditor* me, const std::vector<std::string> & args)
218
        {
219
            if(wantshelp(args)) {
220
                me->printf("usage: scale sx sy sz");
221
                return;
222
            }
223
 
224
            Vec3d s;
225
 
226
            if(args.size() > 0){
227
                istringstream a0(args[0]);
228
                a0 >> s[0];
229
            }
230
            if(args.size() > 1){
231
                istringstream a0(args[0]);
232
                a0 >> s[1];
233
            }
234
            if(args.size() > 2){
235
                istringstream a0(args[0]);
236
                a0 >> s[2];
237
            }
238
 
239
            me->save_active_mesh();
240
            transform_mesh(me->active_mesh(),scaling_Mat4x4d(s));
241
            me->refit();
242
        }
243
 
657 janba 244
        void console_test(MeshEditor* me, const std::vector<std::string> & args)
245
        {
246
            if(wantshelp(args)) {
247
                me->printf("usage: test");
248
                return;
249
            }
250
 
251
            me->save_active_mesh();
252
            me->active_mesh().slit_edges(me->get_vertex_selection());
253
        }
254
 
647 janba 255
 
256
        void console_flatten(MeshEditor* me, const std::vector<std::string> & args)
257
        {
258
            if(wantshelp(args)) {
259
                me->printf("usage: flatten <floater|harmonic|barycentric>");
260
                me->printf("This function flattens a meshs with a simple boundary. It is mostly for showing mesh");
261
                me->printf("parametrization methods. The current mesh MUST have a SINGLE boundary loop");
262
                me->printf("This loop is mapped to the unit circle in a regular fashion (equal angle intervals).");
263
                me->printf("All non boundary vertices are placed at the origin. Then the system is relaxed iteratively");
264
                me->printf("using the weight scheme given as argument.");
265
                return;
266
            }
267
 
268
            me->save_active_mesh();
269
 
270
            WeightScheme ws = BARYCENTRIC_W;
271
            if(args.size()>0){
272
                if(args[0] == "floater")
273
                    ws = FLOATER_W;
274
                else if(args[0] == "harmonic")
275
                    ws = HARMONIC_W;
276
                else if(args[0] == "lscm")
277
                    ws = LSCM_W;
278
            }
279
            else
280
                return;
281
 
282
            flatten(me->active_mesh(), ws);
283
 
284
            return;
285
        }
286
 
287
        void console_save(MeshEditor* me, const std::vector<std::string> & args)
288
        {
289
            if(wantshelp(args)) {
290
                me->printf("usage: save <name->x3d|name->obj> ");
291
 
292
                return;
293
            }
294
            const string& file_name = args[0];
295
            if(args.size() == 1){
296
                if(file_name.substr(file_name.length()-4,file_name.length())==".obj"){
297
                    obj_save(file_name, me->active_mesh());
298
 
299
                    return;
300
                }
301
                else if(file_name.substr(file_name.length()-4,file_name.length())==".off"){
302
                    off_save(file_name, me->active_mesh());
303
 
304
                    return;
305
                }
306
                else if(file_name.substr(file_name.length()-4,file_name.length())==".x3d"){
307
                    x3d_save(file_name, me->active_mesh());
308
 
309
                    return;
310
                }
311
                me->printf("unknown format");
312
                return;
313
            }
314
            me->printf("usage: save <name->x3d|name->obj> ");
315
        }
316
 
317
 
318
        void console_refine_edges(MeshEditor* me, const std::vector<std::string> & args)
319
        {
320
            if(wantshelp(args)) {
321
                me->printf("usage: refine.split_edges <length>");
322
                me->printf("splits edges longer than <length>; default is 0.5 times average length");
323
                return;
324
            }
325
 
326
            me->save_active_mesh();
327
 
328
            float thresh = 0.5f;
329
 
330
            if(args.size() > 0){
331
                istringstream a0(args[0]);
332
                a0 >> thresh;
333
            }
334
 
335
            float avg_length = average_edge_length(me->active_mesh());
336
 
337
            refine_edges(me->active_mesh(), thresh * avg_length);
338
 
339
            return;
340
 
341
        }
342
 
343
        void console_refine_faces(MeshEditor* me, const std::vector<std::string> & args)
344
        {
345
            if(wantshelp(args)) {
346
                me->printf("usage: refine.split_faces ");
347
                me->printf("usage:  Takes no arguments. Inserts a vertex at the centre of each face.");
348
 
349
                return;
350
            }
351
            me->save_active_mesh();
352
 
353
            triangulate_by_vertex_face_split(me->active_mesh());
354
 
355
            return;
356
 
357
        }
358
 
359
        void console_cc_subdivide(MeshEditor* me, const std::vector<std::string> & args)
360
        {
361
            if(wantshelp(args)) {
362
                me->printf("usage: subdivide.catmull_clark ");
363
                me->printf("Does one step of Catmull-Clark subdivision");
364
 
365
                return;
366
            }
367
            me->save_active_mesh();
368
 
369
            cc_split(me->active_mesh(),me->active_mesh());
370
            cc_smooth(me->active_mesh());
371
 
372
            return;
373
        }
374
 
375
        void console_loop_subdivide(MeshEditor* me, const std::vector<std::string> & args)
376
        {
377
            if(wantshelp(args)) {
378
                me->printf("usage: subdivide.loop");
379
                me->printf("Does one step of Loop subdivision");
380
 
381
                return;
382
            }
383
            me->save_active_mesh();
384
 
385
            loop_split(me->active_mesh(),me->active_mesh());
386
            loop_smooth(me->active_mesh());
387
 
388
            return;
389
        }
390
 
391
        void console_root3_subdivide(MeshEditor* me, const std::vector<std::string> & args)
392
        {
393
            if(wantshelp(args)) {
394
                me->printf("usage: subdivide.root3");
395
                me->printf("Does one step of sqrt(3) subdivision");
396
 
397
                return;
398
            }
399
            me->save_active_mesh();
400
 
401
            root3_subdivide(me->active_mesh(),me->active_mesh());
402
 
403
            return;
404
        }
405
 
406
 
407
        void console_doosabin_subdivide(MeshEditor* me, const std::vector<std::string> & args)
408
        {
409
            if(wantshelp(args)) {
410
                me->printf("usage: subdivide.doo_sabin ");
411
                me->printf("Does one step of Doo-Sabin Subdivision");
412
 
413
                return;
414
            }
415
            me->save_active_mesh();
416
 
417
            cc_split(me->active_mesh(),me->active_mesh());
418
            dual(me->active_mesh());
419
 
420
            return;
421
        }
422
 
423
        void console_butterfly_subdivide(MeshEditor* me, const std::vector<std::string> & args)
424
        {
425
            if(wantshelp(args)) {
426
                me->printf("usage: subdivide.butterfly ");
427
                me->printf("Does one step of Modified Butterfly Subdivision");
428
 
429
                return;
430
            }
431
            me->save_active_mesh();
432
 
433
            butterfly_subdivide(me->active_mesh(),me->active_mesh());
434
 
435
            return;
436
        }
437
 
438
        void console_dual(MeshEditor* me, const std::vector<std::string> & args)
439
        {
440
            if(wantshelp(args))
441
            {
442
                me->printf("usage: dual ");
443
                me->printf("Produces the dual by converting each face to a vertex placed at the barycenter.");
444
                return;
445
            }
446
            me->save_active_mesh();
447
 
448
            dual(me->active_mesh());
449
 
450
            return;
451
        }
452
 
453
 
454
        void console_minimize_curvature(MeshEditor* me, const std::vector<std::string> & args)
455
        {
456
            if(wantshelp(args))
457
            {
458
                me->printf("usage: optimize.minimize_curvature <anneal>");
459
                me->printf("Flip edges to minimize mean curvature.");
460
                me->printf("If anneal is true, simulated annealing (slow) is used rather than a greedy scheme");
461
                return;
462
            }
463
            me->save_active_mesh();
464
 
465
            bool anneal=false;
466
            if(args.size() > 0)
467
            {
468
                istringstream a0(args[0]);
469
                a0 >> anneal;
470
            }
471
 
472
            minimize_curvature(me->active_mesh(), anneal);
473
            me->post_create_display_list();
474
            return;
475
        }
476
 
477
        void console_minimize_dihedral(MeshEditor* me, const std::vector<std::string> & args)
478
        {
479
            if(wantshelp(args))
480
            {
481
                me->printf("usage: optimize.minimize_dihedral <iter> <anneal> <use_alpha> <gamma> ");
482
                me->printf("Flip edges to minimize dihedral angles.");
483
                me->printf("Iter is the max number of iterations. anneal tells us whether to use ");
484
                me->printf("simulated annealing and not greedy optimization. use_alpha (default=true) ");
485
                me->printf("means to use angle and not cosine of anglegamma (default=4) is the power ");
486
                me->printf("to which we raise the dihedral angle");
487
                return;
488
            }
489
            me->save_active_mesh();
490
 
491
            int iter = 1000;
492
            if(args.size() > 0)
493
            {
494
                istringstream a0(args[0]);
495
                a0 >> iter;
496
            }
497
 
498
            bool anneal = false;
499
            if(args.size() > 1)
500
            {
501
                istringstream a0(args[1]);
502
                a0 >> anneal;
503
            }
504
 
505
            bool use_alpha = true;
506
            if(args.size() > 2)
507
            {
508
                istringstream a0(args[2]);
509
                a0 >> use_alpha;
510
            }
511
 
512
            float gamma = 4.0f;
513
            if(args.size() > 3)
514
            {
515
                istringstream a0(args[3]);
516
                a0 >> gamma;
517
            }
518
 
519
 
520
            minimize_dihedral_angle(me->active_mesh(), iter, anneal, use_alpha, gamma);
521
            return;
522
        }
523
 
524
        void console_maximize_min_angle(MeshEditor* me, const std::vector<std::string> & args)
525
        {
526
            if(wantshelp(args))
527
            {
528
                me->printf("usage: optimize.maximize_min_angle <thresh> <anneal>");
529
                me->printf("Flip edges to maximize min angle - to make mesh more Delaunay.");
530
                me->printf("If the dot product of the normals between adjacent faces < thresh");
531
                me->printf("no flip will be made. anneal selects simulated annealing rather ");
532
                me->printf("nthan greedy optimization.");
533
                return;
534
            }
535
            me->save_active_mesh();
536
 
537
            float thresh = 0.0f;
538
            if(args.size() > 0)
539
            {
540
                istringstream a0(args[0]);
541
                a0 >> thresh;
542
            }
543
            bool anneal = false;
544
            if(args.size() > 1)
545
            {
546
                istringstream a0(args[1]);
547
                a0 >> anneal;
548
            }
549
            maximize_min_angle(me->active_mesh(),thresh,anneal);
550
            return;
551
        }
552
 
553
 
554
        void console_optimize_valency(MeshEditor* me, const std::vector<std::string> & args)
555
        {
556
            if(wantshelp(args))
557
            {
558
                me->printf("usage: optimize.valency <anneal> ");
559
                me->printf("Optimizes valency for triangle meshes. Anneal selects simulated annealing rather than greedy optim.");
560
                return;
561
            }
562
            me->save_active_mesh();
563
 
564
            bool anneal = false;
565
            if(args.size() > 0)
566
            {
567
                istringstream a0(args[0]);
568
                a0 >> anneal;
569
            }
570
            optimize_valency(me->active_mesh(), anneal);
571
            return;
572
        }
573
 
574
            void console_analyze(MeshEditor* me, const std::vector<std::string> & args)
575
            {
576
                if(wantshelp(args))
577
                {
578
                    me->printf("usage:  harmonics.analyze");
579
                    me->printf("Creates the Laplace Beltrami operator for the mesh and finds all eigensolutions.");
580
                    me->printf("It also projects the vertices onto the eigenvectors - thus transforming the mesh");
581
                    me->printf("to this basis.");
582
                    me->printf("Note that this will stall the computer for a large mesh - as long as we use Lapack.");
583
                    return;
584
                }
585
                me->harmonics_analyze_mesh();
586
                return;
587
            }
588
 
589
 
590
        //    void console_partial_reconstruct(MeshEditor* me, const std::vector<std::string> & args)
591
        //    {
592
        //        if(args.size() != 3)
593
        //            me->printf("usage: haramonics.partial_reconstruct <e0> <e1> <s>");
594
        //
595
        //        if(wantshelp(args)) {
596
        //            me->printf("Reconstruct from projections onto eigenvectors. The two first arguments indicate");
597
        //            me->printf("the eigenvector interval that we reconstruct from. The last argument is the ");
598
        //            me->printf("scaling factor. Thus, for a vertex, v, the formula for computing the position, p, is:");
599
        //            me->printf("for (i=e0; i<=e1;++i) p += proj[i] * Q[i][v] * s;");
600
        //            me->printf("where proj[i] is the 3D vector containing the x, y, and z projections of the mesh onto");
601
        //            me->printf("eigenvector i. Q[i][v] is the v'th coordinate of the i'th eigenvector.");
602
        //            me->printf("Note that if vertex coordinates are not first reset, the result is probably unexpected.");
603
        //        }
604
        //        me->save_active_mesh();
605
        //
606
        //        if(args.size() != 3)
607
        //            return;
608
        //
609
        //        int E0,E1;
610
        //        float scale;
611
        //        istringstream a0(args[0]);
612
        //        a0 >> E0;
613
        //        istringstream a1(args[1]);
614
        //        a1 >> E1;
615
        //        istringstream a2(args[2]);
616
        //        a2 >> scale;
617
        //        me->harmonics_partial_reconstruct(E0,E1,scale);
618
        //        return;
619
        //    }
620
        //
621
        //    void console_reset_shape(MeshEditor* me, const std::vector<std::string> & args)
622
        //    {
623
        //        if(wantshelp(args))
624
        //        {
625
        //            me->printf("usage: harmonics.reset_shape ");
626
        //            me->printf("Simply sets all vertices to 0,0,0. Call this before doing partial_reconstruct");
627
        //            me->printf("unless you know what you are doing.");
628
        //            return;
629
        //        }
630
        //        me->save_active_mesh();
631
        //        me->harmonics_reset_shape();
632
        //        return;
633
        //    }
634
 
635
 
636
        void console_close_holes(MeshEditor* me, const std::vector<std::string> & args)
637
        {
638
            if(wantshelp(args))
639
            {
640
                me->printf("usage: cleanup.close_holes");
641
                me->printf("This function closes holes. It simply follows the loop of halfvectors which");
642
                me->printf("enclose the hole and add a face to which they all point.");
643
                return;
644
            }
645
            me->save_active_mesh();
646
 
647
            close_holes(me->active_mesh());
648
            return;
649
        }
650
 
651
        void console_reload(MeshEditor* me, const std::vector<std::string> & args)
652
        {
653
            if(wantshelp(args))
654
            {
655
                me->printf("usage:  load <file>");
656
                me->printf("(Re)loads the current file if no argument is given, but");
657
                me->printf("if an argument is given, then that becomes the current file");
658
                return;
659
            }
660
            me->save_active_mesh();
661
 
662
            if(!me->reload_active_from_file(args.size() > 0 ? args[0]:""))
663
                me->printf("failed to load");
664
 
665
            return;
666
        }
667
 
668
 
669
        void console_add_mesh(MeshEditor* me, const std::vector<std::string> & args)
670
        {
671
            if(wantshelp(args))
672
            {
673
                me->printf("usage:  add_mesh <file>");
674
                me->printf("Loads the file but without clearing the mesh. Thus, the loaded mesh is added to the");
675
                me->printf("current model.");
676
                return;
677
            }
678
            me->save_active_mesh();
679
 
680
            if(!me->add_to_active_from_file(args.size() > 0 ? args[0]:""))
681
                me->printf("failed to load");
682
 
683
            return;
684
        }
685
 
686
        void console_valid(MeshEditor* me, const std::vector<std::string> & args)
687
        {
688
            if(wantshelp(args))
689
            {
690
                me->printf("usage:  validity");
691
                me->printf("Tests validity of Manifold");
692
                return;
693
            }
694
            if(valid(me->active_mesh()))
695
                me->printf("Mesh is valid");
696
            else
697
                me->printf("Mesh is invalid - check console output");
698
            return;
699
        }
700
 
701
        void console_Dijkstra(MeshEditor* me, const std::vector<std::string> & args)
702
        {
703
            if(wantshelp(args))
704
            {
705
                me->printf("usage:  Dijkstra");
706
                return;
707
            }
708
 
709
            Manifold& m = me->active_mesh();
710
 
711
 
712
            VertexAttributeVector<double> dist(m.allocated_vertices(), DBL_MAX);
713
            VertexAttributeVector<int> visited(m.allocated_vertices(), 0);
714
            VertexID v = *m.vertices_begin();
715
            dist[v]=0;
716
            priority_queue<pair<double,VertexID>> pq;
717
            pq.push(make_pair(-dist[v], v));
718
            double max_dist;
719
            while(!pq.empty())
720
            {
721
                VertexID v = pq.top().second;
722
                max_dist = dist[v];
723
                pq.pop();
724
 
725
                if(!visited[v]){
726
                    visited[v]=1;
727
 
728
                    for(Walker w = m.walker(v); !w.full_circle(); w = w.circulate_vertex_ccw())
729
                        if(!visited[w.vertex()])
730
                        {
731
                            double d = dist[v] + length(m, w.halfedge());
732
                            if(d<dist[w.vertex()]) {
733
                                dist[w.vertex()] = d;
734
                                pq.push(make_pair(-d, w.vertex()));
735
                            }
736
                        }
737
                }
738
            }
739
 
740
            for(auto vid : m.vertices()) {
741
                DebugRenderer::vertex_colors[vid] = Vec3f(1-dist[vid]/max_dist,0,0);
742
                cout << dist[vid] << endl;
743
            }
744
            for(auto fid : m.faces())
745
                DebugRenderer::face_colors[fid] = Vec3f(0.3);
746
 
747
            for(auto hid : m.halfedges()) {
748
                Walker w = m.walker(hid);
749
                DebugRenderer::edge_colors[hid] = Vec3f(1.0-max(dist[w.vertex()],dist[w.opp().vertex()])/max_dist,0,0);
750
            }
751
            return;
752
        }
753
 
754
        void console_info(MeshEditor* me, const std::vector<std::string> & args)
755
        {
756
            if(wantshelp(args))
757
            {
758
                me->printf("usage:  info");
759
                me->printf("Provides information about mesh.");
760
                return;
761
            }
762
            Vec3d p0, p7;
763
            bbox(me->active_mesh(), p0, p7);
764
            stringstream bbox_corners;
765
            bbox_corners << p0 << " - " << p7 << endl;
766
            me->printf("Bounding box corners : %s", bbox_corners.str().c_str());
767
            map<int,int> val_hist;
768
 
769
            for(VertexIDIterator vi = me->active_mesh().vertices_begin(); vi != me->active_mesh().vertices_end(); ++vi)
770
            {
771
                int val = valency(me->active_mesh(), *vi);
772
                if(val_hist.find(val) == val_hist.end())
773
                    val_hist[val] = 0;
774
                ++val_hist[val];
775
            }
776
 
777
            me->printf("Valency histogam");
778
            for(map<int,int>::iterator iter = val_hist.begin(); iter != val_hist.end(); ++iter)
779
            {
780
                stringstream vhl;
781
                vhl << iter->first << ", " << iter->second;
782
                me->printf("%d, %d", iter->first, iter->second);
783
            }
784
 
785
            me->printf("Mesh contains %d faces", me->active_mesh().no_faces());
786
            me->printf("Mesh contains %d halfedges", me->active_mesh().no_halfedges());
787
            me->printf("Mesh contains %d vertices", me->active_mesh().no_vertices());
788
            return;
789
        }
790
 
791
 
792
        void console_simplify(MeshEditor* me, const std::vector<std::string> & args)
793
        {
794
            if(wantshelp(args))
795
            {
796
                me->printf("usage: simplify <fraction> ");
797
                me->printf("Performs Garland Heckbert (quadric based) mesh simplification.");
798
                me->printf("The only argument is the fraction of vertices to keep.");
799
                return;
800
            }
801
            me->save_active_mesh();
802
 
803
            float keep_fraction;
804
            if(args.size() == 0)
805
            {
806
                me->printf("you must specify fraction of vertices to keep");
807
                return;
808
            }
809
            istringstream a0(args[0]);
810
            a0 >> keep_fraction;
811
 
812
            Vec3d p0, p7;
813
            bbox(me->active_mesh(), p0, p7);
814
            Vec3d d = p7-p0;
815
            float s = 1.0/d.max_coord();
816
            Vec3d pcentre = (p7+p0)/2.0;
817
            for(VertexIDIterator vi = me->active_mesh().vertices_begin(); vi != me->active_mesh().vertices_end(); ++vi){
818
                me->active_mesh().pos(*vi) = (me->active_mesh().pos(*vi) - pcentre) * s;
819
            }
820
            cout << "Timing the Garland Heckbert (quadric based) mesh simplication..." << endl;
821
            Timer timer;
822
            timer.start();
823
 
824
            //simplify
825
            quadric_simplify(me->active_mesh(),keep_fraction,0.0001f,true);
826
 
827
            cout << "Simplification complete, process time: " << timer.get_secs() << " seconds" << endl;
828
 
829
            //clean up the mesh, a lot of edges were just collapsed
830
            me->active_mesh().cleanup();
831
 
832
            for(VertexIDIterator vi = me->active_mesh().vertices_begin(); vi != me->active_mesh().vertices_end(); ++vi)
833
                me->active_mesh().pos(*vi) = me->active_mesh().pos(*vi)*d.max_coord() + pcentre;
834
            return;
835
        }
836
 
837
        void console_vertex_noise(MeshEditor* me, const std::vector<std::string> & args)
838
        {
839
            if(wantshelp(args))
840
            {
841
                me->printf("usage: noise.perturb_vertices <amplitude>");
842
                me->printf("adds a random vector to each vertex. A random vector in the unit cube is generated and");
843
                me->printf("to ensure an isotropic distribution, vectors outside the unit ball are discarded.");
844
                me->printf("The vector is multiplied by the average edge length and then by the amplitude specified.");
845
                me->printf("If no amplitude is specified, the default (0.5) is used.");
846
                return;
847
            }
848
            me->save_active_mesh();
849
 
850
            float avg_length = average_edge_length(me->active_mesh());
851
 
852
            float noise_amplitude = 0.5f;
853
            if(args.size() > 0) {
854
                istringstream a0(args[0]);
855
                a0 >> noise_amplitude;
856
            }
857
 
858
            gel_srand(0);
859
            for(VertexIDIterator vi = me->active_mesh().vertices_begin(); vi != me->active_mesh().vertices_end(); ++vi){
860
                Vec3d v;
861
                do{
862
                    v = Vec3d(gel_rand(),gel_rand(),gel_rand());
863
                    v /= (float)(GEL_RAND_MAX);
864
                    v -= Vec3d(0.5);
865
                    v *= 2.0;
866
                }
867
                while(sqr_length(v) > 1.0);
868
 
869
                v *= noise_amplitude;
870
                v *= avg_length;
871
                me->active_mesh().pos(*vi) += v;
872
            }
873
            return;
874
        }
875
 
876
        void console_perpendicular_vertex_noise(MeshEditor* me, const std::vector<std::string> & args)
877
        {
878
            if(wantshelp(args)) {
879
                me->printf("usage: noise.perturb_vertices_perpendicular <amplitude>");
880
                me->printf("adds the normal times a random scalar times amplitude times");
881
                me->printf("times average edge length to the vertex. (default amplitude=0.5)");
882
                return;
883
            }
884
            me->save_active_mesh();
885
 
886
            float avg_length = average_edge_length(me->active_mesh());
887
 
888
            float noise_amplitude = 0.5;
889
            if(args.size() > 0)
890
            {
891
                istringstream a0(args[0]);
892
                a0 >> noise_amplitude;
893
            }
894
 
895
            VertexAttributeVector<Vec3d> normals(me->active_mesh().allocated_vertices());
896
            for(VertexIDIterator vi = me->active_mesh().vertices_begin(); vi != me->active_mesh().vertices_end(); ++vi)
897
                normals[*vi] = normal(me->active_mesh(), *vi);
898
 
899
            gel_srand(0);
900
            for(VertexIDIterator vi = me->active_mesh().vertices_begin(); vi != me->active_mesh().vertices_end(); ++vi)
901
            {
902
                float rval = 0.5-gel_rand() / float(GEL_RAND_MAX);
903
                me->active_mesh().pos(*vi) += normals[*vi]*rval*noise_amplitude*avg_length*2.0;
904
            }
905
            return;
906
        }
907
 
908
        void console_noisy_flips(MeshEditor* me, const std::vector<std::string> & args)
909
        {
910
            if(wantshelp(args)){
911
                me->printf("usage:  noise.perturb_topology <iter>");
912
                me->printf("Perform random flips. iter (default=1) is the number of iterations.");
913
                me->printf("mostly for making nasty synthetic test cases.");
914
                return;
915
            }
916
            me->save_active_mesh();
917
 
918
            int iter = 1;
919
            if(args.size() > 0){
920
                istringstream a0(args[0]);
921
                a0 >> iter;
922
            }
923
 
924
            randomize_mesh(me->active_mesh(),  iter);
925
            return;
926
        }
927
 
928
        void console_laplacian_smooth(MeshEditor* me, const std::vector<std::string> & args)
929
        {
930
            if(wantshelp(args)) {
931
                me->printf("usage:  smooth.laplacian <weight> <iter>");
932
                me->printf("Perform Laplacian smoothing. weight is the scaling factor for the Laplacian.");
933
                me->printf("default weight = 1.0. Default number of iterations = 1");
934
                return;
935
            }
936
            me->save_active_mesh();
937
 
938
            float t=1.0;
939
            if(args.size() > 0){
940
                istringstream a0(args[0]);
941
                a0 >> t;
942
            }
943
            int iter = 1;
944
            if(args.size()>1){
945
                istringstream a0(args[1]);
946
                a0 >> iter;
947
            }
948
            Util::Timer tim;
949
            tim.start();
950
            /// Simple laplacian smoothing with an optional weight.
951
            laplacian_smooth(me->active_mesh(), t, iter);
952
            cout << "It took "<< tim.get_secs();
953
            return;
954
        }
955
 
956
 
957
        void console_mean_curvature_smooth(MeshEditor* me, const std::vector<std::string> & args){
958
            if(wantshelp(args)) {
959
                me->printf("usage:  smooth.mean_curvature <weight> <iter>");
960
                me->printf("Perform mean curvature smoothing. weight is the scaling factor for the");
961
                me->printf("mean curvature vector which has been normalized by dividing by edge lengths");
962
                me->printf("this allows for larger steps as suggested by Desbrun et al.");
963
                me->printf("default weight = 1.0. Default number of iterations = 1");
964
                return;
965
            }
966
            me->save_active_mesh();
967
 
968
            double t=1.0;
969
            if(args.size() > 0){
970
                istringstream a0(args[0]);
971
                a0 >> t;
972
            }
973
            int iter=1;
974
            if(args.size() > 1){
975
                istringstream a0(args[1]);
976
                a0 >> iter;
977
            }
978
            VertexAttributeVector<Vec3d> new_pos(me->active_mesh().allocated_vertices());
979
            for(int j = 0; j < iter; ++j){
980
                for(VertexIDIterator v = me->active_mesh().vertices_begin(); v != me->active_mesh().vertices_end(); ++v) {
981
                    Vec3d m;
982
                    double w_sum;
983
                    unnormalized_mean_curvature_normal(me->active_mesh(), *v, m, w_sum);
984
                    new_pos[*v] = Vec3d(me->active_mesh().pos(*v))  + (t * m/w_sum);
985
                }
986
                for(VertexIDIterator v = me->active_mesh().vertices_begin(); v != me->active_mesh().vertices_end(); ++v)
987
                    me->active_mesh().pos(*v) = new_pos[*v];
988
            }
989
            return;
990
        }
991
 
992
        void console_taubin_smooth(MeshEditor* me, const std::vector<std::string> & args)
993
        {
994
            if(wantshelp(args)){
995
                me->printf("usage:  smooth.taubin <iter>");
996
                me->printf("Perform Taubin smoothing. iter (default=1) is the number of iterations.");
997
                return;
998
            }
999
            me->save_active_mesh();
1000
 
1001
            int iter = 1;
1002
            if(args.size() > 0){
1003
                istringstream a0(args[0]);
1004
                a0 >> iter;
1005
            }
1006
            /// Taubin smoothing is similar to laplacian smoothing but reduces shrinkage
1007
            taubin_smooth(me->active_mesh(),  iter);
1008
 
1009
            return;
1010
        }
1011
 
1012
        void console_fvm_anisotropic_smooth(MeshEditor* me, const std::vector<std::string> & args)
1013
        {
1014
            if(wantshelp(args)){
1015
                me->printf("usage: smooth.fuzzy_vector_median <iter>");
1016
                me->printf("Smooth normals using fuzzy vector median smoothing. iter (default=1) is the number of iterations");
1017
                me->printf("This function does a very good job of preserving sharp edges.");
1018
                return;
1019
            }
1020
            me->save_active_mesh();
1021
 
1022
            int iter=1;
1023
            if(args.size() > 0){
1024
                istringstream a0(args[0]);
1025
                a0 >> iter;
1026
            }
1027
            // Fuzzy vector median smoothing is effective when it comes to preserving sharp edges.
1028
            anisotropic_smooth(me->active_mesh(),  iter, FVM_NORMAL_SMOOTH);
1029
 
1030
            return;
1031
        }
1032
 
1033
        void console_bilateral_anisotropic_smooth(MeshEditor* me, const std::vector<std::string> & args)
1034
        {
1035
            if(wantshelp(args)){
1036
                me->printf("usage: smooth.fuzzy_vector_median <iter>");
1037
                me->printf("Smooth normals using fuzzy vector median smoothing. iter (default=1) is the number of iterations");
1038
                me->printf("This function does a very good job of preserving sharp edges.");
1039
                return;
1040
            }
1041
            me->save_active_mesh();
1042
 
1043
            int iter=1;
1044
            if(args.size() > 0){
1045
                istringstream a0(args[0]);
1046
                a0 >> iter;
1047
            }
1048
 
1049
            anisotropic_smooth(me->active_mesh(),  iter, BILATERAL_NORMAL_SMOOTH);
1050
 
1051
            return;
1052
        }
1053
 
1054
        void console_triangulate(MeshEditor* me, const std::vector<std::string> & args)
1055
        {
1056
            if(wantshelp(args)) {
1057
                me->printf("usage:  triangulate");
1058
                me->printf("This function triangulates all non triangular faces of the mesh.");
1059
                me->printf("you may want to call it after hole closing. For a polygon it simply connects");
1060
                me->printf("the two closest vertices in a recursive manner until only triangles remain");
1061
                return;
1062
            }
1063
            me->save_active_mesh();
1064
 
1065
            shortest_edge_triangulate(me->active_mesh());
1066
            me->active_mesh().cleanup();
1067
            valid(me->active_mesh());
1068
            return;
1069
        }
1070
 
1071
 
1072
        void console_remove_caps(MeshEditor* me, const std::vector<std::string> & args)
1073
        {
1074
            if(wantshelp(args)) {
1075
                me->printf("usage:  cleanup.remove_caps thresh");
1076
                me->printf("Remove caps (triangles with one very big angle). The thresh argument is the fraction of PI to");
1077
                me->printf("use as threshold for big angle. Default is 0.85. Caps are removed by flipping.");
1078
                return;
1079
            }
1080
            me->save_active_mesh();
1081
 
1082
            float t = 0.85f;
1083
            if(args.size() > 0){
1084
                istringstream a0(args[0]);
1085
                a0 >> t;
1086
            }
1087
            remove_caps(me->active_mesh(), static_cast<float>(M_PI) *t);
1088
            me->active_mesh().cleanup();
1089
 
1090
            return;
1091
        }
1092
 
1093
        void console_remove_needles(MeshEditor* me, const std::vector<std::string> & args)
1094
        {
1095
            if(wantshelp(args)){
1096
                me->printf("usage: cleanup.remove_needles <thresh>");
1097
                me->printf("Removes very short edges by collapse. thresh is multiplied by the average edge length");
1098
                me->printf("to get the length shorter than which we collapse. Default = 0.1");
1099
                return;
1100
            }
1101
            me->save_active_mesh();
1102
 
1103
            float thresh = 0.1f;
1104
            if(args.size() > 0){
1105
                istringstream a0(args[0]);
1106
                a0 >> thresh;
1107
            }
1108
            float avg_length = average_edge_length(me->active_mesh());
1109
            remove_needles(me->active_mesh(), thresh * avg_length);
1110
            me->active_mesh().cleanup();
1111
 
1112
            return;
1113
        }
1114
 
1115
        void console_undo(MeshEditor* me, const std::vector<std::string> & args)
1116
        {
1117
            if(wantshelp(args)) {
1118
                me->printf("usage:  undo");
1119
                me->printf("This function undoes one operation. Repeated undo does nothing");
1120
                return;
1121
            }
1122
            me->restore_active_mesh();
1123
            return;
1124
        }
1125
 
662 janba 1126
        void console_save_trackball(MeshEditor* me, const std::vector<std::string> & args)
1127
        {
1128
            if(wantshelp(args)) {
1129
                me->printf("usage:  display.save_trackball");
1130
                me->printf("This function saves the trackball to disk");
1131
                return;
1132
            }
1133
            me->save_ball();
1134
            return;
1135
        }
1136
 
1137
        void console_load_trackball(MeshEditor* me, const std::vector<std::string> & args)
1138
        {
1139
            if(wantshelp(args)) {
1140
                me->printf("usage:  display.load_trackball");
1141
                me->printf("This function loads the trackball from disk");
1142
                return;
1143
            }
1144
            me->load_ball();
1145
            return;
1146
        }
1147
 
647 janba 1148
 
1149
    }
1150
 
1151
 
1152
    void MeshEditor::register_console_function(const std::string& name,
1153
                                               const std::function<void(MeshEditor*, const std::vector<std::string>&)>& con_fun,
1154
                                               const std::string& help_txt)
1155
    {
1156
        std::function<void (const std::vector<std::string>&)> f = bind(con_fun, this, placeholders::_1);
1157
        theConsole.reg_cmdN(name, f, help_txt);
1158
    }
1159
 
1160
    void MeshEditor::keyparse(unsigned short key){
1161
        //toggle console with ESC
1162
        if (key == 27)
1163
        {
1164
            console_visible = !console_visible;
1165
            return;
1166
        }
1167
 
1168
        if (console_visible)
1169
        {
662 janba 1170
            static Timer tim;
1171
            if(key==13)
1172
                tim.start();
647 janba 1173
            theConsole.keyboard(key);
1174
            if(key == 13)
1175
            {
1176
                active_visobj().post_create_display_list();
662 janba 1177
                double t = tim.get_secs();
1178
                printf("%f seconds",t);
647 janba 1179
            }
1180
            return;
1181
        }
1182
        else {
1183
 
1184
            switch(key) {
1185
                case 'q': exit(0);
1186
                case '\033':
1187
                    console_visible = false;
1188
                    break;
1189
                case '1':
1190
                case '2':
1191
                case '3':
1192
                case '4':
1193
                case '5':
1194
                case '6':
1195
                case '7':
1196
                case '8':
1197
                case '9':
1198
                {
1199
                    int w[4];
1200
                    glGetIntegerv(GL_VIEWPORT, w);
1201
                    active = key - '1';
1202
                    active_view_control().reshape(w[2],w[3]);
1203
                }
1204
                    break;
1205
                case 'f': display_smooth_shading = !display_smooth_shading; break;
1206
                case 'w':
1207
                    display_render_mode = "wire"; break;
1208
                case 'n':
1209
                    display_render_mode = "normal"; break;
1210
                case 'i':
1211
                    display_render_mode = "isophotes"; break;
1212
                case 'r':
1213
                    display_render_mode = "reflection"; break;
1214
                case 'h':
1215
                    display_render_mode = "harmonics"; break;
1216
                case 't':
1217
                    display_render_mode = "toon"; break;
1218
                case 'g':
1219
                    display_render_mode = "glazed"; break;
1220
                case 'a':
1221
                    display_render_mode = "ambient_occlusion"; break;
1222
                case 'c':
1223
                    display_render_mode = "copper"; break;
1224
                case 'C':
1225
                    display_render_mode = "curvature_lines"; break;
1226
                case 'M':
1227
                    display_render_mode = "mean_curvature"; break;
1228
                case 'G':
1229
                    display_render_mode = "gaussian_curvature"; break;
657 janba 1230
                case ' ':
1231
                    active_visobj().clear_selection();
1232
                    break;
1233
 
647 janba 1234
            }
1235
 
1236
            if(key != '\033') post_create_display_list();
1237
        }
1238
 
1239
    }
1240
 
1241
    void MeshEditor::printf(const char* format, ...)
1242
    {
1243
        //format text
1244
        char buffer[1024];
1245
        va_list args;
1246
        va_start(args, format);
1247
        vsprintf(buffer, format, args);
1248
        va_end(args);
1249
        theConsole.print(buffer);
1250
    }
1251
 
1252
    void MeshEditor::key_up(){theConsole.key_up();}
1253
    void MeshEditor::key_down(){theConsole.key_down();}
1254
    void MeshEditor::key_left(){theConsole.key_left();}
1255
    void MeshEditor::key_right(){theConsole.key_right();}
1256
    void MeshEditor::key_home(){theConsole.key_home();}
1257
    void MeshEditor::key_end(){theConsole.key_end();}
1258
 
662 janba 1259
 
1260
 
647 janba 1261
    void MeshEditor::grab_ball(TrackBallAction action, const CGLA::Vec2i& pos){
1262
        active_view_control().grab_ball(action, pos);
1263
    }
1264
    void MeshEditor::roll_ball(const CGLA::Vec2i& pos){
1265
        active_view_control().roll_ball(pos);
1266
    }
1267
    void MeshEditor::release_ball(){
1268
        active_view_control().release_ball();
1269
    }
1270
    bool MeshEditor::try_spinning_ball(){
1271
        return active_view_control().try_spin();
1272
    }
1273
 
662 janba 1274
    void MeshEditor::save_ball() {
1275
        ofstream ofs("trackball.bin", ios_base::binary);
1276
        active_view_control().save(ofs);
1277
 
1278
    }
1279
    void MeshEditor::load_ball() {
1280
        ifstream ifs("trackball.bin", ios_base::binary);
1281
        active_view_control().load(ifs);
1282
 
1283
    }
1284
 
1285
 
656 janba 1286
    bool MeshEditor::grab_mesh(const CGLA::Vec2i& pos)
1287
    {
1288
        if(depth_pick(pos[0], pos[1], depth))
1289
        {
1290
            dragging = true;
1291
            mouse_x = pos[0];
1292
            mouse_y = pos[1];
1293
            Vec3d p0 = screen2world(mouse_x, mouse_y, depth);
1294
            Manifold& m = active_mesh();
1295
            active_visobj().save_old();
1296
            Vec3d c;
1297
            float r;
1298
            bsphere(m, c, r);
1299
            for(auto vid : m.vertices())
1300
            {
1301
                double l = sqr_length(p0-m.pos(vid));
657 janba 1302
                weight_vector[vid] = exp(-l/(brush_size*r*r));
656 janba 1303
            }
1304
            return true;
1305
        }
1306
        return false;
1307
    }
1308
 
1309
    bool MeshEditor::drag_mesh(const CGLA::Vec2i& pos)
1310
    {
1311
        if(dragging)
1312
        {
1313
            Vec3d p0 = screen2world(mouse_x, mouse_y, depth);
1314
            Vec3d p1 = screen2world(pos[0], pos[1], depth);
1315
            Vec3d v = p1-p0;
1316
            Manifold& m = active_mesh();
1317
            for(auto vid : m.vertices())
1318
                m.pos(vid) = active_visobj().mesh_old().pos(vid) + weight_vector[vid] * v;
1319
            post_create_display_list();
1320
            return true;
1321
        }
1322
        return false;
1323
    }
1324
 
1325
    void MeshEditor::release_mesh()
1326
    {
1327
        dragging = false;
1328
    }
647 janba 1329
 
656 janba 1330
 
662 janba 1331
    mutex parallel_work;
647 janba 1332
    void MeshEditor::display(int scale){
1333
        glClearColor(1, 1, 1, 0);
1334
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
662 janba 1335
 
1336
//        parallel_work.lock();
1337
//        active_visobj().post_create_display_list();
647 janba 1338
        active_visobj().display(display_render_mode, theConsole, display_smooth_shading, display_gamma);
1339
        if(console_visible)
1340
        {
1341
            glUseProgram(0);
1342
            theConsole.display(scale);
1343
        }
662 janba 1344
//        parallel_work.unlock();
1345
//        std::this_thread::sleep_for(std::chrono::milliseconds(10));
647 janba 1346
    }
1347
 
1348
    void MeshEditor::reshape(int w, int h) {
1349
        for(VisObj& v : vo)
1350
            v.view_control().reshape(w, h);
1351
    }
1352
 
1353
    void MeshEditor::init() {
1354
        glewInit();
1355
 
1356
        GLint vp[4];
1357
        glGetIntegerv(GL_VIEWPORT, vp);
1358
        for(VisObj& vis_obj : vo)
1359
            vis_obj.view_control().reshape(vp[2], vp[3]);
1360
 
1361
        glEnable(GL_CULL_FACE);
1362
        glCullFace(GL_BACK);
1363
        glEnable(GL_LIGHTING);
1364
        glEnable(GL_LIGHT0);
1365
        glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);
1366
 
1367
        glMatrixMode(GL_MODELVIEW);
1368
        glLoadIdentity();
1369
        glClearColor(1,1,0, 0.f);
1370
        glColor4f(1.0f, 1.0f, 1.0f, 0.f);
1371
        float material[4] = {1,1,1,1};
1372
        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material);
1373
        glEnable(GL_DEPTH_TEST);
1374
 
1375
        register_console_function("simplify", console_simplify,"");
1376
 
1377
        register_console_function("ridge_lines", console_ridge_lines,"");
1378
 
1379
        register_console_function("smooth.mean_curvature", console_mean_curvature_smooth,"");
1380
        register_console_function("smooth.laplacian", console_laplacian_smooth,"");
1381
        register_console_function("smooth.taubin", console_taubin_smooth,"");
1382
        register_console_function("smooth.fuzzy_vector_median_anisotropic", console_fvm_anisotropic_smooth ,"");
1383
        register_console_function("smooth.bilateral_anisotropic", console_bilateral_anisotropic_smooth ,"");
1384
 
1385
        register_console_function("optimize.valency", console_optimize_valency,"");
1386
        register_console_function("optimize.minimize_dihedral_angles", console_minimize_dihedral,"");
1387
        register_console_function("optimize.minimize_curvature", console_minimize_curvature,"");
1388
        register_console_function("optimize.maximize_min_angle", console_maximize_min_angle,"");
1389
        register_console_function("cleanup.close_holes", console_close_holes,"");
1390
        register_console_function("load_mesh", console_reload,"");
1391
        register_console_function("add_mesh", console_add_mesh,"");
1392
 
1393
        register_console_function("cleanup.remove_caps", console_remove_caps,"");
1394
        register_console_function("cleanup.remove_needles", console_remove_needles,"");
1395
        register_console_function("triangulate", console_triangulate,"");
1396
        register_console_function("refine.split_edges", console_refine_edges,"");
1397
        register_console_function("refine.split_faces", console_refine_faces,"");
1398
        register_console_function("subdivide.catmull_clark", console_cc_subdivide,"");
1399
        register_console_function("subdivide.loop", console_loop_subdivide,"");
1400
        register_console_function("subdivide.root3", console_root3_subdivide,"");
1401
        register_console_function("subdivide.doo_sabin", console_doosabin_subdivide,"");
1402
        register_console_function("subdivide.butterfly", console_butterfly_subdivide,"");
1403
        register_console_function("save_mesh", console_save,"");
1404
        register_console_function("noise.perturb_vertices", console_vertex_noise,"");
1405
        register_console_function("noise.perturb_vertices_perpendicular", console_perpendicular_vertex_noise,"");
1406
        register_console_function("noise.perturb_topology", console_noisy_flips,"");
1407
 
1408
        register_console_function("dual", console_dual,"");
1409
        register_console_function("flatten", console_flatten,"");
1410
 
1411
        register_console_function("align", console_align,"");
1412
        register_console_function("undo", console_undo,"");
1413
 
1414
        register_console_function("validity", console_valid,"");
1415
        register_console_function("info", console_info,"");
1416
 
1417
        //        register_console_function("harmonics.reset_shape", console_reset_shape, "");
1418
        register_console_function("harmonics.analyze", console_analyze, "");
1419
        //        register_console_function("harmonics.partial_reconstruct", console_partial_reconstruct,"");
1420
 
1421
        register_console_function("Dijkstra", console_Dijkstra,"");
1422
 
662 janba 1423
        register_console_function("display.save_trackball", console_save_trackball, "Saves trackball to disk");
1424
        register_console_function("display.load_trackball", console_load_trackball, "Load trackball to disk");
1425
 
647 janba 1426
        register_console_function("transform.scale", console_scale, "Scale mesh");
657 janba 1427
        register_console_function("test", console_test, "Test some shit");
647 janba 1428
        active.reg(theConsole, "active_mesh", "The active mesh");
1429
        display_render_mode.reg(theConsole, "display.render_mode", "Display render mode");
657 janba 1430
        brush_size.reg(theConsole, "brush_size", "Size of brush used for editing");
647 janba 1431
        display_smooth_shading.reg(theConsole, "display.smooth_shading", "1 for smooth shading 0 for flat");
1432
        display_gamma.reg(theConsole, "display.gamma", "The gamma setting for the display");
1433
 
1434
        theConsole.print("Welcome to MeshEdit");
1435
        theConsole.newline();
1436
    }
1437
 
1438
    bool MeshEditor::add_file(const std::string& str)
1439
    {
1440
        while (active_mesh().no_vertices()>0 && active<NO_MESHES)
1441
            active  = active + 1;
1442
        if(active == NO_MESHES)
1443
            active = 0;
1444
        if(active_visobj().reload(str)) {
1445
            active_visobj().post_create_display_list();
1446
            return true;
1447
        }
1448
        return false;
1449
    }
1450
 
1451
    bool MeshEditor::reload_active_from_file(const std::string& str)
1452
    {
1453
        if(active_visobj().reload(str)) {
1454
            active_visobj().post_create_display_list();
1455
            return true;
1456
        }
1457
        return false;
1458
    }
1459
 
1460
    bool MeshEditor::add_to_active_from_file(const std::string& str)
1461
    {
1462
        if(active_visobj().add_mesh(str)) {
1463
            active_visobj().post_create_display_list();
1464
            return  true;
1465
        }
1466
        return false;
1467
    }
1468
 
1469
 
1470
}