Subversion Repositories gelsvn

Rev

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

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