Subversion Repositories gelsvn

Rev

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

Rev 631 Rev 640
Line 4... Line 4...
4
//
4
//
5
//  Created by J. Andreas Bærentzen on 18/03/12.
5
//  Created by J. Andreas Bærentzen on 18/03/12.
6
//  Copyright 2012 __MyCompanyName__. All rights reserved.
6
//  Copyright 2012 __MyCompanyName__. All rights reserved.
7
//
7
//
8
#include <queue>
8
#include <queue>
-
 
9
#include <iomanip>
9
 
10
 
10
#include "polarize.h"
11
#include "polarize.h"
11
#include <CGLA/Vec2d.h>
12
#include <CGLA/Vec2d.h>
12
#include <LinAlg/LapackFunc.h>
13
#include <LinAlg/LapackFunc.h>
13
#include <HMesh/triangulate.h>
14
#include <HMesh/triangulate.h>
Line 23... Line 24...
23
using namespace std;
24
using namespace std;
24
using namespace HMesh;
25
using namespace HMesh;
25
 
26
 
26
 
27
 
27
 
28
 
28
inline bool same_level(float a, float b) {return abs(a-b) < 0.00001;}
29
inline bool same_level(double a, double b) {return abs(a-b) < 1e-10;}
29
 
30
 
30
 
31
 
31
struct LevelSetInfo
32
struct LevelSetInfo
32
{
33
{
33
    int id;
34
    int id;
Line 70... Line 71...
70
                edge_weights[h] += tan(ang/2) / l;
71
                edge_weights[h] += tan(ang/2) / l;
71
                edge_weights[wv.opp().halfedge()] += tan(ang_opp/2) / l;
72
                edge_weights[wv.opp().halfedge()] += tan(ang_opp/2) / l;
72
            }
73
            }
73
        }
74
        }
74
}
75
}
-
 
76
 
-
 
77
template<typename T>
75
void smooth_fun(Manifold& m,
78
void smooth_fun(Manifold& m,
76
                    VertexAttributeVector<int>& nailed,
79
                VertexAttributeVector<int>& nailed,
77
                    VertexAttributeVector<double>& fun)
80
                VertexAttributeVector<T>& fun, int iter=100)
78
{
81
{
79
    HalfEdgeAttributeVector<double> edge_weights;
82
    HalfEdgeAttributeVector<double> edge_weights;
80
    FaceAttributeVector<int> included(m.allocated_faces(),1);
83
    FaceAttributeVector<int> included(m.allocated_faces(),1);
81
    compute_edge_weights(m,edge_weights, included);
84
    compute_edge_weights(m,edge_weights, included);
82
    VertexAttributeVector<double> new_fun(m.no_vertices());
85
    VertexAttributeVector<T> new_fun(m.no_vertices());
83
    for(int i = 0; i < 1000; ++i)
86
    for(int i = 0; i < iter; ++i)
84
    {
87
    {
85
        for(VertexIDIterator v = m.vertices_begin(); v != m.vertices_end(); ++v)
88
        for(VertexIDIterator v = m.vertices_begin(); v != m.vertices_end(); ++v)
86
            if(!nailed[*v])
89
            if(!nailed[*v])
87
            {
90
            {
88
                double w_sum = 0;
91
                double w_sum = 0;
89
                new_fun[*v] = 0;
92
                new_fun[*v] = T(0);
90
                for(Walker wv = m.walker(*v); !wv.full_circle(); wv = wv.circulate_vertex_ccw())
93
                for(Walker wv = m.walker(*v); !wv.full_circle(); wv = wv.circulate_vertex_ccw())
91
                {
94
                {
92
                    double w = edge_weights[wv.halfedge()];
95
                    double w = edge_weights[wv.halfedge()];
93
                    new_fun[*v] += w * fun[wv.vertex()];
96
                    new_fun[*v] += w * fun[wv.vertex()];
94
                    w_sum += w;
97
                    w_sum += w;
95
                }
98
                }
96
                new_fun[*v] /= w_sum;
99
                new_fun[*v] /= w_sum;
97
            }
100
            }
98
            else
101
            else
99
                new_fun[*v] = fun[*v];
102
                new_fun[*v] = fun[*v];
100
            fun = new_fun;
103
        fun = new_fun;
101
    }
104
    }
102
}
105
}
103
 
106
 
104
void segment_manifold(Manifold& m, HalfEdgeAttributeVector<int>& ls_id,
107
void segment_manifold(Manifold& m, HalfEdgeAttributeVector<int>& ls_id,
105
                      FaceAttributeVector<int>& segmentation,
108
                      FaceAttributeVector<int>& segmentation,
Line 141... Line 144...
141
            for(auto be:boundaries[SEG_NO])
144
            for(auto be:boundaries[SEG_NO])
142
                cout << be << " ";
145
                cout << be << " ";
143
            cout << endl;
146
            cout << endl;
144
            SEG_NO += 1;
147
            SEG_NO += 1;
145
        }
148
        }
146
    
149
        
147
    }
150
    }
148
}
151
}
149
 
152
 
150
 
153
 
151
void shortest_edge_triangulate_face(Manifold& m, FaceID f0, VertexAttributeVector<int>& level_set_id_vertex)
154
void shortest_edge_triangulate_face(Manifold& m, FaceID f0, VertexAttributeVector<int>& level_set_id_vertex)
Line 176... Line 179...
176
        const int N = verts.size();
179
        const int N = verts.size();
177
        for(int i = 0; i < N - 2; ++i){
180
        for(int i = 0; i < N - 2; ++i){
178
            for(int j = i + 2; j < N; ++j){
181
            for(int j = i + 2; j < N; ++j){
179
                if(verts[i] != verts[j] &&
182
                if(verts[i] != verts[j] &&
180
                   !connected(m, verts[i], verts[j]) &&
183
                   !connected(m, verts[i], verts[j]) &&
181
                   (level_set_id_vertex[verts[i]] == 0 || level_set_id_vertex[verts[i]] != level_set_id_vertex[verts[j]])
184
                   (level_set_id_vertex[verts[i]] == 0 || level_set_id_vertex[verts[i]] != level_set_id_vertex[verts[j]]) &&
-
 
185
                   valency(m, verts[i])<5 && valency(m,verts[j])<5
182
                   )
186
                   )
183
                    vpairs.push_back(pair<int,int>(i, j));
187
                    vpairs.push_back(pair<int,int>(i, j));
184
            }
188
            }
185
        }
189
        }
186
        if(vpairs.empty()){
190
        if(vpairs.empty()){
Line 400... Line 404...
400
        gsum += gdir;
404
        gsum += gdir;
401
    }
405
    }
402
    return gsum;
406
    return gsum;
403
}
407
}
404
 
408
 
-
 
409
Vec2d extend_fun2(HMesh::Manifold& m, HMesh::HalfEdgeID h,
-
 
410
                  HMesh::VertexAttributeVector<double>& fun,
-
 
411
                  HMesh::VertexAttributeVector<Vec2d>& fun2)
-
 
412
{
-
 
413
    Walker w = m.walker(h);
-
 
414
    FaceID f = w.face();
-
 
415
    Vec3d a = m.pos(w.opp().vertex());
-
 
416
    Vec3d b = m.pos(w.vertex());
-
 
417
    Vec3d c = m.pos(w.next().vertex());
-
 
418
    Vec3d g = grad(m, fun, f);
-
 
419
    Vec3d n = normal(m, f);
-
 
420
    Vec3d N = normalize(cross(g, n));
-
 
421
    float dot_nba = dot(N,b-a);
-
 
422
    Vec2d cval;
-
 
423
    if(dot_nba > 1e-5)
-
 
424
    {
-
 
425
        float t = dot(N, c-a)/dot_nba;
-
 
426
        if(t>0 && t < 1) {
-
 
427
            Vec2d aval = fun2[w.opp().vertex()];
-
 
428
            Vec2d bval = fun2[w.vertex()];
-
 
429
            return (1-t)*aval + t*bval;
-
 
430
        }
-
 
431
    }
-
 
432
    return Vec2d(0);
-
 
433
}
-
 
434
 
-
 
435
 
405
double solve_for_orthogonal_gradients(HMesh::Manifold& m, HMesh::VertexAttributeVector<double>& fun,
436
double solve_for_orthogonal_gradients(HMesh::Manifold& m, HMesh::VertexAttributeVector<double>& fun,
406
                                     HalfEdgeID h, double beta, double gamma)
437
                                      HalfEdgeID h, double beta, double gamma)
407
{
438
{
408
    Vec3d n = normal(m, m.walker(h).face());
439
    Vec3d n = normal(m, m.walker(h).face());
409
    
440
    
410
    Vec3d uvw[3];
441
    Vec3d uvw[3];
411
    Vec3d abc;
442
    Vec3d abc;
412
    Walker w = m.walker(h);
443
    Walker w = m.walker(h);
413
    VertexID vid[] = {w.next().vertex(), w.opp().vertex(),w.vertex()};
444
    VertexID vid[] = {w.next().vertex(), w.opp().vertex(),w.vertex()};
414
 
445
    
415
    for(int i=0; !w.full_circle(); w = w.next(),++  i)
446
    for(int i=0; !w.full_circle(); w = w.next(),++  i)
416
    {
447
    {
417
        uvw[i] = normalize(cross(n, m.pos(vid[(i+1)%3]) - m.pos(vid[(i+2)%3])));
448
        uvw[i] = normalize(cross(n, m.pos(vid[(i+1)%3]) - m.pos(vid[(i+2)%3])));
418
        uvw[i] /= dot(m.pos(vid[i])-m.pos(vid[(i+1)%3]), uvw[i]);
449
        uvw[i] /= dot(m.pos(vid[i])-m.pos(vid[(i+1)%3]), uvw[i]);
419
        abc[i] = fun[vid[i]];
450
        abc[i] = fun[vid[i]];
Line 442... Line 473...
442
        c_new += cos(new_angle)*X + sin(new_angle)*Y;
473
        c_new += cos(new_angle)*X + sin(new_angle)*Y;
443
    }
474
    }
444
    circle_pos[v] = normalize(c_new);
475
    circle_pos[v] = normalize(c_new);
445
}
476
}
446
 
477
 
-
 
478
template<typename T>
-
 
479
void orthogonal_trajectories(Manifold& m, VertexID v, VertexAttributeVector<double>& f, double min_length_fun,
-
 
480
                             VertexAttributeVector<T>& h_in, VertexAttributeVector<T>& h_out)
-
 
481
{
-
 
482
    h_out[v] = T(0);
-
 
483
 
-
 
484
    T num(0);
-
 
485
    double denom = 0.0001;
-
 
486
    for(Walker w = m.walker(v); !w.full_circle(); w = w.circulate_vertex_ccw())
-
 
487
    {
-
 
488
        double weight = area(m, w.face());
-
 
489
 
-
 
490
        Vec3d a = m.pos(v);
-
 
491
        Vec3d b = m.pos(w.vertex());
-
 
492
        Vec3d c = m.pos(w.next().vertex());
-
 
493
        
-
 
494
        
-
 
495
        Vec3d fvec(f[v],f[w.vertex()], f[w.next().vertex()]);
-
 
496
        if(sqr_length(fvec)>0)
-
 
497
            fvec.normalize();
-
 
498
        double f_a = fvec[0];
-
 
499
        double f_b = fvec[1];
-
 
500
        double f_c = fvec[2];
-
 
501
        
-
 
502
        T h_b = h_in[w.vertex()];
-
 
503
        T h_c = h_in[w.next().vertex()];
-
 
504
        
-
 
505
        Vec3d e_a = c-b;
-
 
506
        Vec3d e_b = a-c;
-
 
507
        Vec3d e_c = b-a;
-
 
508
        
-
 
509
        Vec3d N = normalize(cross(e_b,e_c)+cross(e_c,e_a)+cross(e_a,e_b));
-
 
510
        Vec3d g_a = cross(N, normalize(e_a));
-
 
511
        g_a /= dot(g_a, e_b);
-
 
512
 
-
 
513
        Vec3d g_b = cross(N, normalize(e_b));
-
 
514
        g_b /= dot(g_b, e_c);
-
 
515
 
-
 
516
        Vec3d g_c = cross(N, normalize(e_c));
-
 
517
        g_c /= dot(g_c, e_a);
-
 
518
        
-
 
519
        num -= weight * (h_b * (f_a*dot(g_a, g_b) + f_b*dot(g_b,g_b) + f_c*dot(g_b,g_c)) +
-
 
520
                         h_c * (f_a*dot(g_a, g_c) + f_b*dot(g_b,g_c) + f_c*dot(g_c, g_c)));
-
 
521
        denom += weight * (f_a * dot(g_a,g_a)+ f_b*dot(g_a,g_b) +f_c*dot(g_a, g_c));
-
 
522
 
-
 
523
    }
-
 
524
    h_out[v] = num / denom;
-
 
525
}
-
 
526
 
447
void polarize_mesh(Manifold& m, VertexAttributeVector<double>& fun, double vmin, double vmax, const int divisions, VertexAttributeVector<Vec2d>& parametrization)
527
void polarize_mesh(Manifold& m, VertexAttributeVector<double>& fun, double vmin, double vmax, const int divisions, VertexAttributeVector<Vec2d>& parametrization)
448
{
528
{
449
    vmax -= 0.01 * (vmax-vmin);
-
 
450
    float interval = (vmax-vmin)/divisions;
529
    double interval = (vmax-vmin)/(divisions+1);
451
    
530
    
452
    VertexAttributeVector<int> status(m.allocated_vertices(), 0);
531
    VertexAttributeVector<int> status(m.allocated_vertices(), 0);
453
    
532
    
454
    
533
    
455
    // ----------------------------------------
534
    // ----------------------------------------
456
    cout << "Tracing level set curves" << endl;
535
    cout << "Tracing level set curves" << endl;
457
    
536
    
458
    vector<HalfEdgeID> hidvec;
-
 
459
    for(HalfEdgeIDIterator hid = m.halfedges_begin(); hid != m.halfedges_end(); ++hid)
-
 
460
    {
-
 
461
        Walker w = m.walker(*hid);
-
 
462
        if(fun[w.vertex()] > fun[w.opp().vertex()])
-
 
463
            hidvec.push_back(*hid);
-
 
464
    }
-
 
465
    
537
    
466
    for(size_t i = 0; i<hidvec.size(); ++i)
538
    for(int cut_no=1; cut_no<divisions+1;++cut_no)
467
    {
539
    {
468
        Walker w = m.walker(hidvec[i]);
-
 
469
        
-
 
470
        float b = (fun[w.vertex()]- vmin)/interval;
540
        double cut_val = vmin + cut_no * interval;
471
        float a = (fun[w.opp().vertex()] - vmin)/interval;
-
 
472
        float floor_b = floor(b);
-
 
473
        float floor_a = floor(a);
-
 
474
        
541
        
475
        Vec3d pb = m.pos(w.vertex());
542
        vector<HalfEdgeID> hidvec;
476
        for(int j=floor_b; j>floor_a; --j)
543
        for(HalfEdgeID hid : m.halfedges())
477
        {
544
        {
478
            float t = (j-a) / (b-a);
545
            Walker w = m.walker(hid);
-
 
546
            double bval = fun[w.vertex()];
-
 
547
            double aval = fun[w.opp().vertex()];
-
 
548
            if(aval<bval && aval <= cut_val && cut_val < bval)
-
 
549
            {
-
 
550
                double t = (cut_val-aval)/(bval-aval);
479
            Vec3d p = t * pb + (1.0-t) * m.pos(w.opp().vertex());
551
                Vec3d p = t*m.pos(w.vertex()) + (1.0-t)*m.pos(w.opp().vertex());
480
            VertexID v_new = m.split_edge(w.halfedge());
552
                VertexID vnew = m.split_edge(hid);
481
            w = w.prev();
553
                m.pos(vnew) = p;
482
            status[v_new] = 1;
554
                status[vnew] = 1;
483
            fun[v_new] = j * interval + vmin;
555
                fun[vnew] = cut_val;
484
            m.pos(v_new) = p;
556
            }
485
        }
557
        }
486
    }
-
 
487
    
-
 
488
    bool did_work;
-
 
489
    do
-
 
490
    {
-
 
491
        did_work = false;
-
 
492
        
558
        
493
        for(FaceIDIterator fid = m.faces_begin(); fid != m.faces_end(); ++fid)
559
        for(FaceID fid : m.faces())
494
            for(Walker w = m.walker(*fid);!w.full_circle(); w = w.next())
560
                for(Walker w = m.walker(fid);!w.full_circle(); w = w.next())
495
                if(status[w.vertex()] == 1 && !(status[w.next().vertex()]==1 && same_level(fun[w.vertex()],fun[w.next().vertex()]))
-
 
496
                   && !(status[w.prev().vertex()]==1 && same_level(fun[w.vertex()],fun[w.prev().vertex()])))
561
                    if(status[w.vertex()] == 1 && same_level(fun[w.vertex()],cut_val))
497
                {
-
 
498
                    Walker w0 = w;
-
 
499
                    w = w.next().next();
-
 
500
                    do
-
 
501
                    {
562
                    {
502
                        if(status[w.vertex()] == 1 && w.next().halfedge() != w0.halfedge() &&
563
                        Walker w0 = w;
503
                           same_level(fun[w0.vertex()],fun[w.vertex()]))
564
                        w = w.next().next();
-
 
565
                        do
504
                        {
566
                        {
-
 
567
                            if(status[w.vertex()] == 1 &&
-
 
568
                               w.next().halfedge() != w0.halfedge() &&
-
 
569
                               same_level(fun[w0.vertex()],cut_val))
-
 
570
                            {
505
                            m.split_face_by_edge(*fid, w0.vertex(), w.vertex());
571
                                m.split_face_by_edge(fid, w0.vertex(), w.vertex());
506
                            did_work = true;
572
                                break;
507
                            break;
573
                            }
-
 
574
                            w = w.next();
508
                        }
575
                        }
-
 
576
                        while(!w.full_circle());
509
                        w = w.next();
577
                        break;
510
                    }
578
                    }
511
                    while(!w.full_circle());
-
 
512
                    break;
-
 
513
                }
-
 
514
    }
579
    }
515
    while(did_work);
-
 
516
    
580
 
517
    shortest_edge_triangulate(m);
581
    shortest_edge_triangulate(m);
518
    
582
    
-
 
583
 
-
 
584
    
519
    // ----------------------------
585
    // ----------------------------
520
    cout << "Numbering the level sets" << endl;
586
    cout << "Numbering the level sets" << endl;
521
    VertexAttributeVector<int> nailed(m.no_vertices(),0);
-
 
522
    vector<LevelSetInfo> level_set_info;
587
    vector<LevelSetInfo> level_set_info;
523
    HalfEdgeAttributeVector<int> level_set_id(m.allocated_halfedges(), -1);
588
    HalfEdgeAttributeVector<int> level_set_id(m.allocated_halfedges(), -1);
524
    VertexAttributeVector<int> level_set_id_vertex(m.allocated_vertices(), -1);
589
    VertexAttributeVector<int> level_set_id_vertex(m.allocated_vertices(), -1);
525
    VertexAttributeVector<Vec2d> circle_pos;
-
 
526
    for(auto vid = m.vertices_begin(); vid != m.vertices_end(); ++vid)
-
 
527
        circle_pos[*vid] = Vec2d(0,0);
-
 
528
    int no_id=0;
590
    int no_id=0;
529
    for(HalfEdgeIDIterator hid = m.halfedges_begin(); hid != m.halfedges_end(); ++hid)
591
    for(HalfEdgeID hid : m.halfedges())
530
    {
592
    {
531
        Walker w = m.walker(*hid);
593
        Walker w = m.walker(hid);
532
        if(status[w.vertex()] == 1 && status[w.opp().vertex()] == 1 &&
594
        if(status[w.vertex()] == 1 && status[w.opp().vertex()] == 1 &&
533
           same_level(fun[w.vertex()], fun[w.opp().vertex()]) &&
595
           same_level(fun[w.vertex()], fun[w.opp().vertex()]) &&
534
           level_set_id[w.halfedge()] == -1)
596
           level_set_id[w.halfedge()] == -1)
535
        {
597
        {
536
            LevelSetInfo lsi;
598
            LevelSetInfo lsi;
537
            lsi.id = no_id;
599
            lsi.id = no_id;
538
            lsi.fun_value = fun[w.vertex()];
600
            lsi.fun_value = fun[w.vertex()];
539
            lsi.components = 1;
601
            lsi.components = 1;
540
            lsi.no_vertices = 0;
602
            lsi.no_vertices = 0;
541
            float level_set_length = 0;
603
            double level_set_length = 0;
542
            while(level_set_id[w.halfedge()] != no_id)
604
            while(level_set_id[w.halfedge()] != no_id)
543
            {
605
            {
544
                level_set_length += length(m,w.halfedge());
606
                level_set_length += length(m,w.halfedge());
545
                level_set_id[w.halfedge()] = no_id;
607
                level_set_id[w.halfedge()] = no_id;
546
                level_set_id[w.opp().halfedge()] = no_id;
608
                level_set_id[w.opp().halfedge()] = no_id;
547
                level_set_id_vertex[w.vertex()] = no_id;
609
                level_set_id_vertex[w.vertex()] = no_id;
548
                w = w.next();
610
                w = w.next();
549
                while(status[w.vertex()] != 1 || !same_level(fun[w.vertex()], fun[w.opp().vertex()]))
611
                while(!(status[w.vertex()] == 1 && same_level(fun[w.vertex()], fun[w.opp().vertex()])))
550
                    w = w.circulate_vertex_cw();
612
                    w = w.circulate_vertex_cw();
551
                lsi.no_vertices += 1;
613
                lsi.no_vertices += 1;
552
                
-
 
553
            }
614
            }
554
            lsi.h = w.halfedge();
615
            lsi.h = w.halfedge();
555
            lsi.length = level_set_length;
616
            lsi.length = level_set_length;
556
            double param = 0;
-
 
557
 
-
 
558
            do
-
 
559
            {
-
 
560
                double angle = 2.0 * M_PI * param / lsi.length;
-
 
561
                circle_pos[w.opp().vertex()] = Vec2d(cos(angle), sin(angle));
-
 
562
                nailed[w.opp().vertex()] = 1;
-
 
563
                param += length(m, w.halfedge());
-
 
564
                w = w.next();
-
 
565
                while(status[w.vertex()] != 1 || !same_level(fun[w.vertex()], fun[w.opp().vertex()]))
-
 
566
                    w = w.circulate_vertex_cw();
-
 
567
            }
-
 
568
            while(w.halfedge() != lsi.h);
-
 
569
            level_set_info.push_back(lsi);
617
            level_set_info.push_back(lsi);
570
            level_set_info.back().print();
618
            level_set_info.back().print();
571
            ++no_id;
619
            ++no_id;
572
            assert(level_set_info.size()==no_id);
620
            assert(level_set_info.size()==no_id);
573
        }
621
        }
Line 590... Line 638...
590
        {
638
        {
591
            min_length_h = lsi.h;
639
            min_length_h = lsi.h;
592
            min_length_fun = lsi.fun_value;
640
            min_length_fun = lsi.fun_value;
593
            min_length = lsi.length;
641
            min_length = lsi.length;
594
            min_length_id = lsi.id;
642
            min_length_id = lsi.id;
-
 
643
            
595
        }
644
        }
596
    }
645
    }
597
    
646
    
598
    smooth_fun(m, nailed, fun);
-
 
599
    
-
 
600
    FaceAttributeVector<int> segmentation;
-
 
601
    vector<vector<int>> boundaries;
-
 
602
    segment_manifold(m, level_set_id, segmentation, boundaries);
-
 
603
    
-
 
604
    VertexAttributeVector<Vec3d> cylinder_pos;
-
 
605
    for(auto vid = m.vertices_begin();vid != m.vertices_end(); ++vid)
-
 
606
        if (nailed[*vid])//level_set_id_vertex[*vid] == min_length_id)
-
 
607
            cylinder_pos[*vid] = Vec3d(circle_pos[*vid][0], circle_pos[*vid][1],min_length_fun);    
-
 
608
        else
-
 
609
            cylinder_pos[*vid] = Vec3d(0,0,fun[*vid]);
-
 
610
    
-
 
611
    HalfEdgeAttributeVector<double> edge_weights(m.allocated_halfedges(), 0);
-
 
612
    FaceAttributeVector<int> included(m.allocated_faces(), 1);
-
 
613
    for(auto fid = m.faces_begin(); fid != m.faces_end(); ++fid)
-
 
614
    {
-
 
615
        if(boundaries[segmentation[*fid]].size() == 1)
-
 
616
            included[*fid] = 0;
-
 
617
    }
-
 
618
    compute_edge_weights(m,edge_weights,included);
-
 
619
    VertexAttributeVector<Vec3d> new_cylinder_pos(m.no_vertices());
-
 
620
    for(int i = 0; i < 1500; ++i)
-
 
621
    {
-
 
622
        for(VertexIDIterator v = m.vertices_begin(); v != m.vertices_end(); ++v)
-
 
623
            if(!nailed[*v])//level_set_id_vertex[*v] != min_length_id)
-
 
624
            {
-
 
625
//                recompute_circle_param(m, *v, fun, circle_pos, min_length_fun);
-
 
626
                double w_sum = 0;
-
 
627
                new_cylinder_pos[*v] = Vec3d(0);
-
 
628
                for(Walker wv = m.walker(*v); !wv.full_circle(); wv = wv.circulate_vertex_ccw())
-
 
629
                {
-
 
630
                    double w = edge_weights[wv.halfedge()];
-
 
631
                    new_cylinder_pos[*v] += w * cylinder_pos[wv.vertex()];
-
 
632
                    w_sum += w;
-
 
633
                }
-
 
634
                if(w_sum> 0.0)
-
 
635
                    new_cylinder_pos[*v] /= w_sum;
-
 
636
                Vec2d v2d(new_cylinder_pos[*v][0], new_cylinder_pos[*v][1]);
-
 
637
                double l =length(v2d);
-
 
638
                if(l>0.1) {
-
 
639
                    new_cylinder_pos[*v][0] /= l;
-
 
640
                    new_cylinder_pos[*v][1] /= l;
-
 
641
                }
-
 
642
                if(level_set_id_vertex[*v] != -1)
-
 
643
                    new_cylinder_pos[*v][2] = fun[*v];
-
 
644
            }
-
 
645
            else
-
 
646
                new_cylinder_pos[*v] = cylinder_pos[*v];
-
 
647
        for(auto v = m.vertices_begin();v != m.vertices_end(); ++v)
-
 
648
            cylinder_pos[*v] = 0.9*cylinder_pos[*v]+ 0.1*new_cylinder_pos[*v];
-
 
649
    }
-
 
650
  for(auto vid = m.vertices_begin();vid != m.vertices_end(); ++vid)
-
 
651
        parametrization[*vid] = Vec2d(cylinder_pos[*vid][0],cylinder_pos[*vid][1]);
-
 
652
    return;
-
 
653
 
-
 
654
//    for(auto vid = m.vertices_begin();vid != m.vertices_end(); ++vid)
-
 
655
//        m.pos(*vid) = cylinder_pos[*vid];// Vec2d(cylinder_pos[*vid][0],cylinder_pos[*vid][1]);
-
 
656
 
-
 
657
    
-
 
658
//    vector<pair<double,VertexID>> verts;
-
 
659
//    for(auto vid = m.vertices_begin();vid != m.vertices_end(); ++vid)
-
 
660
//        if(!same_level(min_length_fun, fun[*vid]))
-
 
661
//            verts.push_back(pair<double,VertexID>(abs(fun[*vid]-min_length_fun),*vid));
-
 
662
//    sort(verts.begin(), verts.end());
-
 
663
//    
-
 
664
//    for(auto p:verts)
-
 
665
//    {
-
 
666
//        VertexID vid = p.second;
-
 
667
//        recompute_circle_param(m, vid, fun, circle_pos, min_length_fun);
-
 
668
//    }
-
 
669
//    parametrization = circle_pos;
-
 
670
//    return;
-
 
671
    
-
 
672
    
-
 
673
//    // nail max length level set to circle.
-
 
674
//    Walker w = m.walker(min_length_h);
-
 
675
//    priority_queue<pair<double, HalfEdgeID>> hq;
-
 
676
//    float param = 0;
-
 
677
//    do
-
 
678
//    {
-
 
679
//        hq.push(pair<double,HalfEdgeID>(-abs(fun[w.next().vertex()]-min_length_fun),w.halfedge()));
-
 
680
//        hq.push(pair<double,HalfEdgeID>(-abs(fun[w.opp().next().vertex()]-min_length_fun),w.opp().halfedge()));
-
 
681
//        
-
 
682
//        nailed[w.opp().vertex()] = 1;
-
 
683
//        w = w.next();
-
 
684
//        while(level_set_id[w.halfedge()] != min_length_id)
-
 
685
//            w = w.circulate_vertex_cw();
-
 
686
//    }
-
 
687
//    while(w.halfedge() != min_length_h);
-
 
688
    
-
 
689
//    parametrize(m, nailed, circle_pos, parametrization, fun, min_length_fun);
-
 
690
//    propagate_values(m, nailed, circle_pos, parametrization, level_set_id_vertex, level_set_info, fun, min_length_fun);
-
 
691
    
-
 
692
////    for(int i=0;i<level_set_info.size(); ++i)
-
 
693
////        level_set_info[i].print();
-
 
694
//    
-
 
695
//    VertexAttributeVector<Vec3d> circle_center_attrib(m.no_vertices(),Vec3d(0,0,0));
-
 
696
//    for(auto vid = m.vertices_begin(); vid != m.vertices_end(); ++vid)
-
 
697
//    {
-
 
698
//        if(level_set_id_vertex[*vid]>-1)
-
 
699
//        {
-
 
700
//            LevelSetInfo& lsi = level_set_info[level_set_id_vertex[*vid]];
-
 
701
//            circle_center_attrib[*vid] = lsi.avg_pos;
-
 
702
//            nailed[*vid] = 1;
-
 
703
//        }
-
 
704
//    }
-
 
705
////    propagate(m, nailed, circle_center_attrib);
-
 
706
//    Manifold m2 = m;
-
 
707
//    for(auto vid = m2.vertices_begin(); vid != m2.vertices_end(); ++vid)
-
 
708
//    {
-
 
709
//        m2.pos(*vid) = circle_pos[*vid];
-
 
710
//        m2.pos(*vid)[2] = 0.01 * fun[*vid];
-
 
711
//    }
-
 
712
//    obj_save("blob.obj", m2);
-
 
713
    
-
 
714
//    for(auto vid = m.vertices_begin(); vid != m.vertices_end(); ++vid)
-
 
715
//    {
-
 
716
//        Vec3d p =circle_pos[*vid];//-circle_center_attrib[*vid];
-
 
717
//        parametrization[*vid] = Vec2d(p[0],p[1]);
-
 
718
//    }
-
 
719
    
-
 
720
    
-
 
721
    // ----------------------------
647
    // ----------------------------
722
    cout << "Remove vertices not on level set curves" << endl;
648
    cout << "Remove vertices not on level set curves" << endl;
723
    
649
    
724
    vector<VertexID> vid_vec;
-
 
725
    for(VertexIDIterator vid = m.vertices_begin(); vid != m.vertices_end(); ++vid)
-
 
726
        if(status[*vid]==0)
-
 
727
            vid_vec.push_back(*vid);
-
 
728
    
-
 
729
    random_shuffle(vid_vec.begin(), vid_vec.end());
-
 
730
    for (size_t i=0; i<vid_vec.size(); ++i) {
-
 
731
        FaceID f = m.merge_one_ring(vid_vec[i]);
-
 
732
        if(f != InvalidFaceID)
-
 
733
            shortest_edge_triangulate_face(m, f, level_set_id_vertex);
-
 
734
        else
-
 
735
            cout << "vertex not removed " << valency(m, vid_vec[i]) << endl;
-
 
736
    }
-
 
737
    
-
 
738
    for(FaceIDIterator fid = m.faces_begin(); fid != m.faces_end(); ++fid)
-
 
739
        if(no_edges(m, *fid) > 3)
-
 
740
            shortest_edge_triangulate_face(m, *fid, level_set_id_vertex);
-
 
741
    
-
 
742
    
-
 
743
//    VertexAttributeVector<Vec3d> recalled_positions;
-
 
744
//    for(VertexIDIterator vid = m.vertices_begin(); vid != m.vertices_end(); ++vid)
-
 
745
//        recalled_positions[*vid] = m.pos(*vid);
-
 
746
//    
-
 
747
//    
-
 
748
    TriangleQuality tq_energy(level_set_id_vertex);
-
 
749
    priority_queue_optimization(m, tq_energy);
-
 
750
    
-
 
751
    
-
 
752
    
650
    
753
}
651
}
754
 
652
 
755
void make_height_fun(const HMesh::Manifold& m, HMesh::VertexAttributeVector<double>& fun,
653
void make_height_fun(const HMesh::Manifold& m, HMesh::VertexAttributeVector<double>& fun,
756
                     double& vmin, double& vmax)
654
                     double& vmin, double& vmax)
757
{
655
{
758
    VertexIDIterator vid = m.vertices_begin();
656
    VertexIDIterator vid = m.vertices_begin();
759
    vmin = vmax = m.pos(*vid)[2];
657
    vmin = vmax = m.pos(*vid)[1];
760
    for(; vid != m.vertices_end(); ++vid)
658
    for(; vid != m.vertices_end(); ++vid)
761
    {
659
    {
762
        double v = dot(m.pos(*vid),Vec3d(0.0,1,0.00));
660
        double v = dot(m.pos(*vid),Vec3d(0.0,1,0.00));
763
        fun[*vid] = v;
661
        fun[*vid] = v;
764
        vmin = min(v, vmin);
662
        vmin = min(v, vmin);
765
        vmax = max(v, vmax);
663
        vmax = max(v, vmax);
766
    }
664
    }
767
}
665
}
-
 
666