Subversion Repositories gelsvn

Rev

Rev 149 | Rev 182 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include <algorithm>
#include "CGLA/Mat3x3f.h"
#include "smooth.h"
#include "HMesh/VertexCirculator.h"


namespace HMesh
{

        using namespace std;
        using namespace CGLA;
        using namespace HMesh;

        Vec3f laplacian(VertexIter vi)
        {
                Vec3f avg_pos(0);
                int n=0;
                
                VertexCirculator vc(vi);
                for(;!vc.end();++vc)
                        {
                                avg_pos += vc.get_vertex()->pos;
                                ++n;
                        }
                return avg_pos/n-vi->pos;
        }

        void laplacian_smooth(Manifold& m, float t)
        {
                vector<Vec3f> pos(m.no_vertices());
                int i=0;
                for(VertexIter vi = m.vertices_begin(); vi != m.vertices_end(); ++vi,++i)
                        if(!is_boundary(vi))
                                pos[i] =  t*laplacian(vi) + vi->pos;
                i=0;
                for(VertexIter vi = m.vertices_begin(); vi != m.vertices_end(); ++vi,++i)
                        if(!is_boundary(vi))
                                vi->pos = pos[i];
        }

        void taubin_smooth(Manifold& m, int max_iter)
        {
                for(int iter=0;iter<max_iter;++iter)
                        {
                                vector<Vec3f> lap(m.no_vertices());
                                int i=0;
                                for(VertexIter vi = m.vertices_begin(); 
                                                vi != m.vertices_end(); ++vi,++i)
                                        if(!is_boundary(vi))
                                                        lap[i] =  laplacian(vi);
                                i=0;
                                for(VertexIter vi = m.vertices_begin(); vi != m.vertices_end(); 
                                                ++vi,++i)
                                        if(!is_boundary(vi))
                                                vi->pos += (iter%2 == 0) ? 
                                                                 0.5  * lap[i] : 
                                                                -0.52 * lap[i];
                        }
        }


}