File: intersection_numbers.c

package info (click to toggle)
snappea 3.0d3-20.1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 5,896 kB
  • ctags: 3,582
  • sloc: ansic: 33,469; sh: 8,293; python: 7,623; makefile: 240
file content (287 lines) | stat: -rw-r--r-- 8,167 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
 *	intersection_numbers.c
 *
 *	This file provides the kernel function
 *
 *		void compute_intersection_numbers(Triangulation *manifold);
 *
 *	which computes the intersection numbers of the curves stored
 *	in the scratch_curve[][][][][] fields of the Tetrahedra, and
 *	writes the results to the intersection_number[][] fields of
 *	the Cusps.  That is,
 *
 *		intersection_number[M][M] will be the intersection number of
 *					scratch_curve[0][M] with scratch_curve[1][M],
 *
 *		intersection_number[M][L] will be the intersection number of
 *					scratch_curve[0][M] with scratch_curve[1][L],
 *
 *		intersection_number[L][M] will be the intersection number of
 *					scratch_curve[0][L] with scratch_curve[1][M],
 *
 *		intersection_number[L][L] will be the intersection number of
 *					scratch_curve[0][L] with scratch_curve[1][L].
 *
 *	Each intersection number is the algebraic sum of the crossing
 *	numbers.  As viewed from infinity (looking toward the fat
 *	part of the manifold), each crossing of the form
 *
 *	  scratch_curve[1]
 *			^
 *			|							contributes +1,
 *		----|---> scratch_curve[0]
 *			|
 *			|
 *
 *	while each crossing of the form
 *
 *
 *	  scratch_curve[0]
 *			^
 *			|							contributes -1,
 *		----|---> scratch_curve[1]
 *			|
 *			|
 *
 *	This file also provides the utility
 *
 *		void copy_curves_to_scratch(	Triangulation	*manifold,
 *										int				which_set,
 *										Boolean			double_copy_on_tori);
 *
 *	which copies the current peripheral curves to the scratch_curves[which_set]
 *	fields of the manifold's Tetrahedra.  If double_copy_on_tori is TRUE,
 *	it copies peripheral curves on orientable cusps to both sheets of
 *	the Cusps' orientation double covers.
 *
 *
 *	Overview of Intersection Number Algorithm.
 *
 *	Consider the triangulation of the boundary components by the
 *	triangles at the (truncated) ideal vertices.  As explained
 *	in peripheral_curves.c, we work in the orientation double cover,
 *	so in fact each ideal vertex contributes two triangles, one
 *	left_handed and the other right_handed.  Relative to the
 *	orientation on the cusp (and even nonorientable cusps are
 *	effectively oriented, since we work in the orientation double
 *	cover) we imagine each scratch_curve[0] entering a given triangle
 *	on the right side of a given edge, and each scratch_curve[1]
 *	entering on the left:
 *
 *				           /\
 *				          /  \
 *				         /    \
 *				        /      \
 *				       /        \
 *				      /          \
 *				     /            \
 *				    /              \
 *				   /                \
 *				  /                  \
 *				 /      1 \  / 0      \
 *				/__________\/__________\
 *				\          /\          /
 *				 \      0 /  \ 1      /
 *				  \                  /
 *				   \                /
 *				    \              /
 *				     \            /
 *				      \          /
 *				       \        /
 *				        \      /
 *				         \    /
 *				          \  /
 *				           \/
 *
 *	Of necessity, the curves must cross on the edge (if both are
 *	nonzero).  There may be additional crossings in the interior of
 *	the triangle, depending on where the various curves are entering
 *	and exiting.  To avoid counting the intersections on the edges
 *	twice (once for each of the two incident triangles) we make the
 *	convention to count edge crossings only where scratch_curve[0] is
 *	entering (not exiting) the triangle.
 */

#include "kernel.h"

void compute_intersection_numbers(
	Triangulation	*manifold)
{
	Cusp		*cusp;
	Tetrahedron	*tet;
	int			f,
				g,
				h,
				i,
				j,
				face_on_the_left,
				face_on_the_right;

	/*
	 *	Initialize all the intersection numbers to zero.
	 */

	for (cusp = manifold->cusp_list_begin.next;
		 cusp != &manifold->cusp_list_end;
		 cusp = cusp->next)

		for (i = 0; i < 2; i++)		/* i = M, L */

			for (j = 0; j < 2; j++)	/* j = M, L */

				cusp->intersection_number[i][j] = 0;


	/*
	 *	Count the intersections on the edges.
	 */

	/* which Tetrahedron */
	for (tet = manifold->tet_list_begin.next;
		 tet != &manifold->tet_list_end;
		 tet = tet->next)

		/* which ideal vertex */
		for (i = 0; i < 4; i++)

			/* which side of the vertex */
			for (j = 0; j < 4; j++)
			{
				if (i == j)
					continue;

				/* which sheet (right_handed or left_handed) */
				for (f = 0; f < 2; f++)

					/* which scratch_curve[0] (meridian or longitude) */
					for (g = 0; g < 2; g++)

						/* which scratch_curve[1] (meridian or longitude) */
						for (h = 0; h < 2; h++)

							/*
							 *	Recall the convention (described at the top
							 *	of this file) that edge crossings are counted
							 *	only where scratch_curve[0] is entering --
							 *	not exiting -- the triangle.
							 */
							if (tet->scratch_curve[0][g][f][i][j] > 0)

								tet->cusp[i]->intersection_number[g][h]
								 +=	tet->scratch_curve[0][g][f][i][j]
								  * tet->scratch_curve[1][h][f][i][j];
			}


	/*
	 *	Count the intersections in the interiors of triangles.
	 */

	/* which Tetrahedron */
	for (tet = manifold->tet_list_begin.next;
		 tet != &manifold->tet_list_end;
		 tet = tet->next)

		/* which ideal vertex */
		for (i = 0; i < 4; i++)

			/* which side of the vertex */
			for (j = 0; j < 4; j++)
			{
				if (i == j)
					continue;

				/*
				 *	Name the two remaining faces of the Tetrahedron
				 *	according to the right_handed orientation of
				 *	the Tetrahedron.
				 */
				face_on_the_left	= remaining_face[i][j];
				face_on_the_right	= remaining_face[j][i];

				/* which scratch_curve[0] (meridian or longitude) */
				for (g = 0; g < 2; g++)

					/* which scratch_curve[1] (meridian or longitude) */
					for (h = 0; h < 2; h++)
					{
						/*
						 *	We'll count only those intersections on the
						 *	strand of scratch_curve[0] running from the
						 *	current side of the triangle (side j) towards
						 *	the right.  The other possibilities will be
						 *	handled by other values of j.
						 *
						 *	When we see the Tetrahedron as left_handed
						 *	relative to the Orientation of the cusp, the
						 *	face on the right is face_on_the_left.
						 *	Got that?
						 */

						tet->cusp[i]->intersection_number[g][h]
						 +=	FLOW(tet->scratch_curve[0][g][right_handed][i][j],
						  		 tet->scratch_curve[0][g][right_handed][i][face_on_the_right])
						  *	tet->scratch_curve[1][h][right_handed][i][face_on_the_right];

						tet->cusp[i]->intersection_number[g][h]
						 +=	FLOW(tet->scratch_curve[0][g][left_handed][i][j],
						  		 tet->scratch_curve[0][g][left_handed][i][face_on_the_left])
						  *	tet->scratch_curve[1][h][left_handed][i][face_on_the_left];
					}
			}
}


void copy_curves_to_scratch(
	Triangulation	*manifold,
	int				which_set,
	Boolean			double_copy_on_tori)
{
	Tetrahedron	*tet;
	int			i,
				j,
				k,
				l;

	/*
	 *	When computing intersection numbers on orientable cusps
	 *	(especially in nonorientable manifolds) there is a danger that
	 *	scratch_curves[0] will lie on one sheet of the Cusp's orientation
	 *	double cover while scratch_curves[1] lies on the other sheet.
	 *	To avoid this danger, copy_curves_to_scratch() offers the
	 *	option to copy the peripheral curves on orientable cusps to
	 *	both sheets of the double cover.  You should use this option
	 *	for one set of scratch_curves (e.g. scratch_curves[0]) but not
	 *	the other (scratch_curves[1]) to guarantee correct intersection
	 *	numbers.
	 */

	for (tet = manifold->tet_list_begin.next;
		 tet != &manifold->tet_list_end;
		 tet = tet->next)

		for (i = 0; i < 2; i++)

			for (k = 0; k < 4; k++)

				for (l = 0; l < 4; l++)

					if (tet->cusp[k]->topology == torus_cusp
					 && double_copy_on_tori == TRUE)

						tet->scratch_curve[which_set][i][right_handed][k][l] =
						tet->scratch_curve[which_set][i][ left_handed][k][l] =
							  tet->curve[i][right_handed][k][l]
							+ tet->curve[i][ left_handed][k][l];

					else
						/*
						 *		tet->cusp[k]->topology == Klein_cusp
						 *	 || double_copy_on_tori == FALSE
						 */

						for (j = 0; j < 2; j++)

							tet->scratch_curve[which_set][i][j][k][l]
								   = tet->curve[i][j][k][l];
}