Subversion Repositories gelsvn

Rev

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

#include "refine_edges.h"

#include <queue>

#include "Manifold.h"
#include "HalfEdgeHandle.h"
#include "VertexHandle.h"
#include "FaceHandle.h"
#include "FaceCirculator.h"
#include "VertexCirculator.h"

namespace HMesh
{
    //using namespace std;
    //using namespace CGLA;


    float average_edge_length(Manifold& mani)
    {
        float lsum = 0;
        for(HalfEdgeHandle he = mani.halfedges_begin(); he != mani.halfedges_end(); ++he)
            lsum += length(he);
        return lsum / mani.no_halfedges();
    }

    int refine_edges(Manifold& mani, float t)
    {
        int work = 0;

        for(HalfEdgeHandle he = mani.halfedges_begin(); he != mani.halfedges_end(); ++he)
            he.get().touched = 1;

        for(HalfEdgeHandle he = mani.halfedges_begin(); he != mani.halfedges_end(); ++he){
            if(he.face() != NULL_FACE_HANDLE && length(he) > t && he.get().touched == 1){
                ++work;
                he.opp().get().touched = 0;
                VertexHandle vi = mani.split_edge(he);

                HalfEdgeHandle h1 = vi.out().opp();
                HalfEdgeHandle h2 = vi.out().prev();

                FaceHandle f1 = h1.face();
                if(f1 != NULL_FACE_HANDLE){
                    f1.get().last_idx = h1.get_idx();
                    mani.split_face_by_vertex(f1);
                }

                FaceHandle f2 = h2.face();
                if(f2 != NULL_FACE_HANDLE){
                    f2.get().last_idx = h2.get_idx();
                    mani.split_face_by_vertex(f2);
                }
            }
        }
        return work;
    }

}