Subversion Repositories gelsvn

Rev

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

Rev 129 Rev 444
Line 8... Line 8...
8
using namespace CGLA;
8
using namespace CGLA;
9
using namespace std;
9
using namespace std;
10
 
10
 
11
namespace HMesh
11
namespace HMesh
12
{
12
{
-
 
13
	FaceIter get_null_face_iter()
-
 
14
	{
-
 
15
		static FaceList l;
-
 
16
		return l.end();
-
 
17
	}
-
 
18
	
13
		template<class R>
19
	template<class R>
14
		Face_template<R>::Face_template(): 
20
	Face_template<R>::Face_template(): 
15
				last(NULL_HALFEDGE_ITER),
21
	last(NULL_HALFEDGE_ITER),
16
				touched(0)
22
	touched(0)
17
		{}
23
	{}
18
 
24
	
19
		int no_edges(FaceIter f)
25
	int no_edges(FaceIter f)
-
 
26
	{
-
 
27
		FaceCirculator fc(f);
-
 
28
		while(!fc.end()) ++fc;
-
 
29
		return fc.no_steps();
-
 
30
	}
-
 
31
	
-
 
32
	Vec3f normal(FaceIter f)
-
 
33
	{
-
 
34
		vector<Vec3f> v;
-
 
35
		FaceCirculator fc(f);
-
 
36
		int k;
-
 
37
		for(k=0;!fc.end();++fc,++k)
20
		{
38
		{
21
				FaceCirculator fc(f);
-
 
22
				while(!fc.end()) ++fc;
39
			Vec3f p = fc.get_vertex()->pos;
23
				return fc.no_steps();
40
			v.push_back(p);
24
		}
41
		}
25
 
-
 
26
		Vec3f normal(FaceIter f)
42
		Vec3f norm(0);
-
 
43
		for(int i=0;i<k;++i)
27
		{
44
		{
28
				vector<Vec3f> v;
-
 
29
				FaceCirculator fc(f);
-
 
30
				int k;
-
 
31
				for(k=0;!fc.end();++fc,++k)
-
 
32
				{
-
 
33
						Vec3f p = fc.get_vertex()->pos;
-
 
34
						v.push_back(p);
-
 
35
				}
-
 
36
				Vec3f norm(0);
-
 
37
				for(int i=0;i<k;++i)
-
 
38
				{
-
 
39
						norm[0] += (v[i][1]-v[(i+1)%k][1])*(v[i][2]+v[(i+1)%k][2]);
45
			norm[0] += (v[i][1]-v[(i+1)%k][1])*(v[i][2]+v[(i+1)%k][2]);
40
						norm[1] += (v[i][2]-v[(i+1)%k][2])*(v[i][0]+v[(i+1)%k][0]);
46
			norm[1] += (v[i][2]-v[(i+1)%k][2])*(v[i][0]+v[(i+1)%k][0]);
41
						norm[2] += (v[i][0]-v[(i+1)%k][0])*(v[i][1]+v[(i+1)%k][1]);
47
			norm[2] += (v[i][0]-v[(i+1)%k][0])*(v[i][1]+v[(i+1)%k][1]);
42
				}
-
 
43
				float l = norm.length();
-
 
44
				if(l>0.0f)
-
 
45
						norm /= l;
-
 
46
				return norm;
-
 
47
		}
48
		}
-
 
49
		float l = norm.length();
-
 
50
		if(l>0.0f)
-
 
51
			norm /= l;
-
 
52
		return norm;
-
 
53
	}
48
 
54
	
49
		float area(FaceIter f)
55
	float area(FaceIter f)
-
 
56
	{
-
 
57
		FaceCirculator fc(f);
-
 
58
		int k;
-
 
59
		
-
 
60
		// M is a matrix that projects a vector onto the orthogonal
-
 
61
		// complement of the face normal
-
 
62
		Vec3f n = normal(f);
-
 
63
		Vec3f a,b;
-
 
64
		orthogonal(n, a, b);
-
 
65
		Mat3x3f M(a,b,n);
-
 
66
		
-
 
67
		// Get all projected vertices
-
 
68
		vector<Vec2f> v;		
-
 
69
		for(k=0;!fc.end();++fc,++k)
50
		{
70
		{
51
				FaceCirculator fc(f);
-
 
52
				int k;
-
 
53
 
-
 
54
				// M is a matrix that projects a vector onto the orthogonal
-
 
55
				// complement of the face normal
-
 
56
				Vec3f n = normal(f);
-
 
57
				Vec3f a,b;
-
 
58
				orthogonal(n, a, b);
-
 
59
				Mat3x3f M(a,b,n);
-
 
60
 
-
 
61
				// Get all projected vertices
-
 
62
				vector<Vec2f> v;		
-
 
63
				for(k=0;!fc.end();++fc,++k)
-
 
64
				{
-
 
65
						Vec3f p = M * fc.get_vertex()->pos;
71
			Vec3f p = M * fc.get_vertex()->pos;
66
						v.push_back(Vec2f(p[0], p[1]));
72
			v.push_back(Vec2f(p[0], p[1]));
67
				}
-
 
68
				float area = 0;
-
 
69
				for(int i=0;i<k;++i)
-
 
70
				{
-
 
71
						area += 0.5 * cross(v[i], v[(i+1)%k]);
-
 
72
				}
-
 
73
				return fabs(area);
-
 
74
		}
73
		}
75
 
-
 
-
 
74
		float area = 0;
76
		Vec3f centre(FaceIter f)
75
		for(int i=0;i<k;++i)
77
		{
76
		{
78
				Vec3f c(0);
-
 
79
				FaceCirculator fc(f);
-
 
80
				while(!fc.end())
-
 
81
				{
-
 
82
						c += fc.get_vertex()->pos;
77
			area += 0.5 * cross(v[i], v[(i+1)%k]);
83
						++fc;
-
 
84
				}
-
 
85
				c /= fc.no_steps();
-
 
86
				return c;
-
 
87
		}
78
		}
-
 
79
		return fabs(area);
-
 
80
	}
88
 
81
	
-
 
82
	Vec3f centre(FaceIter f)
-
 
83
	{
-
 
84
		Vec3f c(0);
-
 
85
		FaceCirculator fc(f);
-
 
86
		while(!fc.end())
-
 
87
		{
-
 
88
			c += fc.get_vertex()->pos;
-
 
89
			++fc;
-
 
90
		}
-
 
91
		c /= fc.no_steps();
-
 
92
		return c;
-
 
93
	}
-
 
94
	
89
		template struct Face_template<Iters>;	
95
	template struct Face_template<Iters>;	
90
 
96
	
91
}
97
}