Subversion Repositories gelsvn

Rev

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

Rev 182 Rev 595
Line -... Line 1...
-
 
1
/* ----------------------------------------------------------------------- *
-
 
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
1
#include <queue>
3
 * Copyright (C) the authors and DTU Informatics
-
 
4
 * For license and list of authors, see ../../doc/intro.pdf
-
 
5
 * ----------------------------------------------------------------------- */
2
 
6
 
3
#include "HMesh/FaceCirculator.h"
-
 
4
#include "HMesh/VertexCirculator.h"
-
 
5
#include "refine_edges.h"
7
#include "refine_edges.h"
6
 
8
 
7
using namespace std;
9
#include <vector>
8
using namespace CGLA;
10
#include <iterator>
-
 
11
 
9
using namespace HMesh;
12
#include "Manifold.h"
-
 
13
#include "AttributeVector.h"
10
 
14
 
11
namespace HMesh
15
namespace HMesh
12
{
16
{
-
 
17
    using namespace std;
-
 
18
 
13
	float average_edge_length(Manifold& mani)
19
    float average_edge_length(const Manifold& m)
14
	{
20
    {
15
		float lsum = 0;
21
        float lsum = 0;
16
		for(HalfEdgeIter he = mani.halfedges_begin(); 
22
        for(HalfEdgeIDIterator h = m.halfedges_begin(); h != m.halfedges_end(); ++h)
17
				he != mani.halfedges_end(); ++he)
-
 
18
			lsum += length(he);
23
            lsum += length(m, *h);
19
		return lsum / mani.no_halfedges();
24
        return lsum / m.no_halfedges();
20
	}
25
    }
21
 
26
 
22
	int refine_edges(Manifold& mani, float t)
27
    int refine_edges(Manifold& m, float t)
23
	{
28
    {
24
		int work = 0;
29
        int work = 0;
-
 
30
       
-
 
31
        vector<HalfEdgeID> hedges;
-
 
32
        hedges.reserve(m.no_halfedges());
-
 
33
        copy(m.halfedges_begin(), m.halfedges_end(), back_inserter(hedges));
25
 
34
 
26
		for(HalfEdgeIter he = mani.halfedges_begin(); 
35
        HalfEdgeAttributeVector<int> touched(m.allocated_halfedges(), 0);
-
 
36
 
27
				he != mani.halfedges_end(); ++he)
37
        cout << "Refining edges";
-
 
38
        for(vector<HalfEdgeID>::iterator h = hedges.begin(); h != hedges.end(); ++h){
28
			he->touched = 1;
39
            Walker w = m.walker(*h);
29
 
40
 
30
		for(HalfEdgeIter he = mani.halfedges_begin();
41
            if(!m.in_use(*h) || w.face() == InvalidFaceID || length(m, *h) < t || touched[*h])
31
				he != mani.halfedges_end(); ++he)
42
                continue;
32
			if(he->face!=NULL_FACE_ITER && length(he)>t && he->touched==1)
-
 
33
				{
43
 
34
					++work;
44
            ++work;
35
					he->opp->touched = 0;
45
            if( work % 10000 == 0)
36
					VertexIter vi = mani.split_edge(he);
46
                cout << ".";
37
 
47
 
38
					HalfEdgeIter h1 = vi->he->opp;
48
            touched[w.opp().halfedge()] = 1;
39
					HalfEdgeIter h2 = vi->he->prev;
49
//            VertexID v = m.split_edge(*h);
40
 
50
 
41
					FaceIter f1 = h1->face;
51
//            Walker wv = m.walker(v);
-
 
52
 
42
					if(f1 != NULL_FACE_ITER)
53
//            FaceID f1 = wv.opp().face();
43
						{
-
 
44
							f1->last = h1;
54
           // if(f1 != InvalidFaceID)
45
							mani.triangulate(f1);
55
             //   m.split_face_by_vertex(f1);
46
						}
-
 
47
 
56
 
48
					FaceIter f2 = h2->face;
57
//            FaceID f2 =  wv.prev().face();
49
					if(f2 != NULL_FACE_ITER)
58
           // if(f2 != InvalidFaceID)
50
						{
-
 
51
							f2->last = h2;
-
 
52
							mani.triangulate(f2);
59
            //    m.split_face_by_vertex(f2);
53
						}
60
 
54
				}
61
        }
-
 
62
        cout << endl;
55
		return work;
63
        return work;
56
	}
64
    }
57
 
65
 
58
}
66
}