Subversion Repositories gelsvn

Rev

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

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