Subversion Repositories gelsvn

Rev

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

Rev 646 Rev 652
Line 487... Line 487...
487
                }
487
                }
488
            }
488
            }
489
        }
489
        }
490
    }
490
    }
491
    
491
    
-
 
492
    void TAL_smoothing(Manifold& m, float w, int max_iter)
-
 
493
    {
-
 
494
        for(int iter=0;iter<max_iter;++iter) {
-
 
495
            VertexAttributeVector<float> vertex_areas;
-
 
496
            VertexAttributeVector<Vec3d> laplacians;
-
 
497
            
-
 
498
            for(VertexIDIterator vid = m.vertices_begin(); vid != m.vertices_end(); ++vid)
-
 
499
            {
-
 
500
                vertex_areas[*vid] = 0;
-
 
501
                for(Walker w = m.walker(*vid); !w.full_circle(); w = w.circulate_vertex_ccw())
-
 
502
                    if(w.face() != InvalidFaceID)
-
 
503
                        vertex_areas[*vid] += area(m, w.face());
-
 
504
            }
-
 
505
            
-
 
506
            for(VertexIDIterator vid = m.vertices_begin(); vid != m.vertices_end(); ++vid)
-
 
507
            {
-
 
508
                laplacians[*vid] = Vec3d(0);
-
 
509
                double weight_sum = 0.0;
-
 
510
                if(boundary(m, *vid))
-
 
511
                {
-
 
512
                    double angle_sum = 0;
-
 
513
                    for(Walker w = m.walker(*vid); !w.full_circle(); w = w.circulate_vertex_ccw())
-
 
514
                    {
-
 
515
                        if (w.face() != InvalidFaceID)
-
 
516
                        {
-
 
517
                            Vec3d vec_a = normalize(m.pos(w.vertex()) - m.pos(*vid));
-
 
518
                            Vec3d vec_b = normalize(m.pos(w.circulate_vertex_ccw().vertex()) -
-
 
519
                                                    m.pos(*vid));
-
 
520
                            angle_sum += acos(max(-1.0,min(1.0,dot(vec_a,vec_b))));
-
 
521
                        }
-
 
522
                        if(boundary(m,w.vertex()))
-
 
523
                        {
-
 
524
                            laplacians[*vid] += m.pos(w.vertex()) - m.pos(*vid);
-
 
525
                            weight_sum += 1.0;
-
 
526
                        }
-
 
527
                    }
-
 
528
                    laplacians[*vid] /= weight_sum;
-
 
529
                    laplacians[*vid] *= exp(-3.0*sqr(max(0.0, M_PI-angle_sum)));
-
 
530
                }
-
 
531
                else
-
 
532
                {
-
 
533
                    for(Walker w = m.walker(*vid); !w.full_circle(); w = w.circulate_vertex_ccw())
-
 
534
                    {
-
 
535
                        float weight = vertex_areas[w.vertex()];
-
 
536
                        Vec3d l = m.pos(w.vertex()) - m.pos(*vid);
-
 
537
                        laplacians[*vid] +=  weight * l;
-
 
538
                        weight_sum += weight;
-
 
539
                    }
-
 
540
                    laplacians[*vid] /= weight_sum;
-
 
541
                    //                Vec3d n = normal(m, *vid);
-
 
542
                    //                if(sqr_length(n)>0.9)
-
 
543
                    //                    laplacians[*vid] -= n * dot(n, laplacians[*vid]);
-
 
544
                }
-
 
545
            }
-
 
546
            for(VertexIDIterator vid = m.vertices_begin(); vid != m.vertices_end(); ++vid)
-
 
547
                m.pos(*vid) += w*laplacians[*vid];
-
 
548
        }
-
 
549
    }
-
 
550
 
-
 
551
    
492
    
552
    
493
}
553
}