Subversion Repositories gelsvn

Rev

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

Rev 373 Rev 595
Line -... Line 1...
-
 
1
/* ----------------------------------------------------------------------- *
-
 
2
 * This file is part of GEL, http://www.imm.dtu.dk/GEL
-
 
3
 * Copyright (C) the authors and DTU Informatics
-
 
4
 * For license and list of authors, see ../../doc/intro.pdf
-
 
5
 * ----------------------------------------------------------------------- */
-
 
6
 
1
#include "CGLA/Vec4f.h"
7
#include "CGLA/Vec4f.h"
2
#include "Triangle.h"
8
#include "Triangle.h"
3
 
9
 
4
 
10
 
5
using namespace std;
11
using namespace std;
Line 24... Line 30...
24
{
30
{
25
	vert[0]  =_v0;
31
	vert[0]  =_v0;
26
	vert[1]  =_v1;
32
	vert[1]  =_v1;
27
	vert[2]  =_v2;
33
	vert[2]  =_v2;
28
 
34
 
29
#ifdef COMPUTE_SIGN
-
 
30
	vert_norm[0] = _vn0;
35
	vert_norm[0] = _vn0;
31
	vert_norm[1] = _vn1;
36
	vert_norm[1] = _vn1;
32
	vert_norm[2] = _vn2;
37
	vert_norm[2] = _vn2;
33
 
38
 
34
	edge_norm[0] = _en0;
39
	edge_norm[0] = _en0;
35
	edge_norm[1] = _en1;
40
	edge_norm[1] = _en1;
36
	edge_norm[2] = _en2;
41
	edge_norm[2] = _en2;
37
#endif
-
 
38
 
42
 
39
	face_norm = normalize(cross(vert[1]-vert[0], vert[2]-vert[0]));
43
	face_norm = normalize(cross(vert[1]-vert[0], vert[2]-vert[0]));
40
	for(int i=0;i<3;++i)
44
	for(int i=0;i<3;++i)
41
		{
45
		{
42
			int j= (i+1)%3;
46
			int j= (i+1)%3;
Line 106... Line 110...
106
				{
110
				{
107
					++vertex_scores[idx_0];
111
					++vertex_scores[idx_0];
108
					if(vertex_scores[idx_0] == 2)
112
					if(vertex_scores[idx_0] == 2)
109
						{
113
						{
110
							closest_pnt = vert[idx_0];
114
							closest_pnt = vert[idx_0];
111
#ifdef COMPUTE_SIGN
-
 
112
							normal = vert_norm[idx_0];
115
							normal = vert_norm[idx_0];
113
#endif
-
 
114
							break;
116
							break;
115
						}
117
						}
116
				}
118
				}
117
			else if(t >= edge_len[idx_0])
119
			else if(t >= edge_len[idx_0])
118
				{
120
				{
119
					++vertex_scores[idx_1];
121
					++vertex_scores[idx_1];
120
					if(vertex_scores[idx_1] == 2)
122
					if(vertex_scores[idx_1] == 2)
121
						{
123
						{
122
							closest_pnt = vert[idx_1];
124
							closest_pnt = vert[idx_1];
123
#ifdef COMPUTE_SIGN
-
 
124
							normal = vert_norm[idx_1];
125
							normal = vert_norm[idx_1];
125
#endif
-
 
126
							break;
126
							break;
127
						}
127
						}
128
				}
128
				}
129
			else if(dot(tri_plane_edge_norm[idx_0], p-vert[idx_0]) <=0)
129
			else if(dot(tri_plane_edge_norm[idx_0], p-vert[idx_0]) <=0)
130
				{
130
				{
131
					closest_pnt=vert[idx_0]+t*dir_3d;
131
					closest_pnt=vert[idx_0]+t*dir_3d;
132
#ifdef COMPUTE_SIGN
-
 
133
					normal = edge_norm[idx_0];
132
					normal = edge_norm[idx_0];
134
#endif
-
 
135
					break;
133
					break;
136
				}
134
				}
137
		}
135
		}
138
	if(idx_0 == 3)
136
	if(idx_0 == 3)
139
		{
137
		{
140
			closest_pnt = p - face_norm*(dot(p-vert[0],face_norm));
138
			closest_pnt = p - face_norm*(dot(p-vert[0],face_norm));
141
#ifdef COMPUTE_SIGN
-
 
142
			normal = face_norm;
139
			normal = face_norm;
143
#endif
-
 
144
		}
140
		}
145
	sq_dist = sqr_length(p-closest_pnt);
141
	sq_dist = sqr_length(p-closest_pnt);
146
	
142
	
147
#ifdef COMPUTE_SIGN
-
 
148
	// Compute dot product with angle weighted normal, and
143
	// Compute dot product with angle weighted normal, and
149
	// assign the sign based on the result.
144
	// assign the sign based on the result.
150
	if(dot(normal, p-closest_pnt) >=0)
145
	if(dot(normal, p-closest_pnt) >=0)
151
		sgn = 1.0f;
146
		sgn = 1.0f;
152
	else
147
	else
153
		sgn = -1.0f;
148
		sgn = -1.0f;
154
#else
-
 
155
	sgn = 1.0f;
-
 
156
#endif
-
 
157
 
149
 
158
	return true;
150
	return true;
159
}
151
}
160
 
152
 
161
}
153
}