Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BOP_Face.cpp « intern « boolop « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 01308de3e5de50c867287877ec7226eca9195830 (plain)
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
/**
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 * All rights reserved.
 *
 * The Original Code is: all of this file.
 *
 * Contributor(s): none yet.
 *
 * ***** END GPL LICENSE BLOCK *****
 */
 
#include "BOP_Face.h"

/******************************************************************************/
/*** BOP_Face                                                               ***/
/******************************************************************************/

/**
 * Constructs a new face.
 * @param plane face plane
 * @param originalFace index of the original face
 */
BOP_Face::BOP_Face(MT_Plane3 plane, BOP_Index originalFace)
{
	m_plane        = plane;
	m_tag          = UNCLASSIFIED;
	m_originalFace = originalFace;
	m_split        = 0;
	m_bbox         = NULL;
}

/**
 * Inverts this face.
 */
void BOP_Face::invert()
{
	getPlane().Invert();
	BOP_Index aux = m_indexs[0];
	m_indexs[0] = m_indexs[2];
	m_indexs[2] = aux;
}

/******************************************************************************/
/*** BOP_Face                                                              ***/
/******************************************************************************/

/**
 * Constructs a new triangle face.
 * @param v1 vertex index
 * @param v2 vertex index
 * @param v3 vertex index
 * @param plane face plane
 * @param originalFace index of the original face
 */
BOP_Face3::BOP_Face3(BOP_Index v1, BOP_Index v2, BOP_Index v3, MT_Plane3 plane, BOP_Index originalFace): BOP_Face(plane,originalFace) 
{
	m_indexs[0] = v1;
	m_indexs[1] = v2;
	m_indexs[2] = v3;	
	m_size = 3;
}

/**
 * Returns the relative edge index (1,2,3) for the specified vertex indexs.
 * @param v1 vertex index
 * @param v2 vertex index
 * @param e relative edge index (1,2,3)
 * @return true if (v1,v2) is an edge of this face, false otherwise
 */
bool BOP_Face3::getEdgeIndex(BOP_Index v1, BOP_Index v2, unsigned int &e)
{
	if (m_indexs[0] == v1) {
		if (m_indexs[1] == v2) {
			e = 1;
		}
		else if (m_indexs[2] == v2) {
			e = 3;
		}
		else
		  return false;
	}
	else if (m_indexs[1] == v1) {
		if (m_indexs[0] == v2) {
			e = 1;
		}
		else if (m_indexs[2] == v2) {
			e = 2;
		}
		else
		  return false;
	}
	else if (m_indexs[2] == v1) {
		if (m_indexs[0] == v2) {
			e = 3;
		}
		else if (m_indexs[1] == v2) {
			e = 2;
		}
		else
		  return false;
	}else {
	  return false;
	}
	
	return  true;
} 

/**
 * Returns if this face contains the specified vertex index.
 * @param v vertex index
 * @return true if this face contains the specified vertex index, false otherwise
 */
bool BOP_Face3::containsVertex(BOP_Index v) 
{
	return (m_indexs[0] == v || m_indexs[1] == v || m_indexs[2] == v);
}

/**
 * Returns the neighbours of the specified vertex index.
 * @param v vertex index
 * @param prev previous vertex index
 * @param next next vertex index
 * @return true if this face contains the vertex index v, false otherwise
 */
bool BOP_Face3::getNeighbours(BOP_Index v, BOP_Index &prev, BOP_Index &next) 
{
	if (m_indexs[0] == v) {
	  prev = m_indexs[2];
	  next = m_indexs[1];
	}
	else if (m_indexs[1] == v) {
	  prev = m_indexs[0];
	  next = m_indexs[2];
	}
        else if (m_indexs[2] == v) {
	  prev = m_indexs[1];
	  next = m_indexs[0];
	}
	else return false;
	
	return true;
}

/**
 * Returns the previous neighbour of the specified vertex index.
 * @param v vertex index
 * @param w previous vertex index
 * @return true if this face contains the specified vertex index, false otherwise
 */
bool BOP_Face3::getPreviousVertex(BOP_Index v, BOP_Index &w) 
{
	if (m_indexs[0] == v) w = m_indexs[2];
	else if (m_indexs[1] == v) w = m_indexs[0];
	else if (m_indexs[2] == v) w = m_indexs[1];
	else return false;
	
	return true;
}

/**
 * Returns the next neighbour of the specified vertex index.
 * @param v vertex index
 * @param w vertex index
 * @return true if this face contains the specified vertex index, false otherwise
 */
bool BOP_Face3::getNextVertex(BOP_Index v, BOP_Index &w) 
{
	if (m_indexs[0] == v) w = m_indexs[1];
	else if (m_indexs[1] == v) w = m_indexs[2];
	else if (m_indexs[2] == v) w = m_indexs[0];
	else return false;
	
	return true;
} 

/**
 * Replaces a face vertex index.
 * @param oldIndex old vertex index
 * @param newIndex new vertex index
 */
void BOP_Face3::replaceVertexIndex(BOP_Index oldIndex, BOP_Index newIndex)
{
	/* if the old index really exists, and new index also exists already,
	 * don't create an edge with both vertices == newIndex */

	if( (m_indexs[0] == oldIndex || m_indexs[1] == oldIndex || m_indexs[2] == oldIndex) &&
			(m_indexs[0] == newIndex || m_indexs[1] == newIndex || m_indexs[2] == newIndex) ) {
		setTAG(BROKEN);
	}

	if (m_indexs[0] == oldIndex) m_indexs[0] = newIndex;
	else if (m_indexs[1] == oldIndex) m_indexs[1] = newIndex;
	else if (m_indexs[2] == oldIndex) m_indexs[2] = newIndex;
}

/******************************************************************************/
/*** BOP_Face4                                                              ***/
/******************************************************************************/

/**
 * Constructs a new quad face.
 * @param v1 vertex index
 * @param v2 vertex index
 * @param v3 vertex index
 * @param v4 vertex index
 * @param plane face plane
 * @param originalFace index of the original face
 */
BOP_Face4::BOP_Face4(BOP_Index v1, BOP_Index v2, BOP_Index v3, BOP_Index v4, MT_Plane3 plane, 
					 BOP_Index originalFace): 
					 BOP_Face(plane,originalFace) 
{
	m_indexs[0] = v1;
	m_indexs[1] = v2;
	m_indexs[2] = v3;
	m_indexs[3] = v4;
	
	m_size = 4;
}

/**
 * Returns if this face contains the specified vertex index.
 * @param v vertex index
 * @return true if this face contains the specified vertex index, false otherwise
 */
bool BOP_Face4::containsVertex(BOP_Index v) 
{
	return (m_indexs[0] == v || m_indexs[1] == v || m_indexs[2] == v || m_indexs[3]==v);
}

/**
 * Returns the neighbours of the specified vertex index.
 * @param v vertex index
 * @param prev previous vertex index
 * @param next next vertex index
 * @param opp opposite vertex index
 * @return true if this face contains the vertex index v, false otherwise
 */
bool BOP_Face4::getNeighbours(BOP_Index v, BOP_Index &prev, BOP_Index &next, BOP_Index &opp) 
{
	if (m_indexs[0] == v) {
	  prev = m_indexs[3];
	  next = m_indexs[1];
	  opp = m_indexs[2];
	}
	else if (m_indexs[1] == v) {
	  prev = m_indexs[0];
	  next = m_indexs[2];
	  opp = m_indexs[3];
	}
	else if (m_indexs[2] == v) {
	  prev = m_indexs[1];
	  next = m_indexs[3];
	  opp = m_indexs[0];
	}
	else if (m_indexs[3] == v) {
	  prev = m_indexs[2];
	  next = m_indexs[0];
	  opp = m_indexs[1];
	}
	else return false;

	return true;
}

/**
 * Returns the previous neighbour of the specified vertex index.
 * @param v vertex index
 * @param w previous vertex index
 * @return true if this face contains the specified vertex index, false otherwise
 */
bool BOP_Face4::getPreviousVertex(BOP_Index v, BOP_Index &w) 
{
	if (m_indexs[0] == v) w = m_indexs[3];
	else if (m_indexs[1] == v) w = m_indexs[0];
	else if (m_indexs[2] == v) w = m_indexs[1];
	else if (m_indexs[3] == v) w = m_indexs[2];
	else return false;

	return true;
}

/**
 * Returns the next neighbour of the specified vertex index.
 * @param v vertex index
 * @param w next vertex index
 * @return true if this face contains the specified vertex index, false otherwise
 */
bool BOP_Face4::getNextVertex(BOP_Index v, BOP_Index &w) 
{
	if (m_indexs[0] == v) w = m_indexs[1];
	else if (m_indexs[1] == v) w = m_indexs[2];
	else if (m_indexs[2] == v) w = m_indexs[3];
	else if (m_indexs[3] == v) w = m_indexs[0];
	else return false;

	return true;
} 

/**
 * Returns the opposite  neighbour of the specified vertex index.
 * @param v vertex index
 * @param w opposite vertex index
 * @return true if this face contains the specified vertex index, false otherwise
 */
bool BOP_Face4::getOppositeVertex(BOP_Index v, BOP_Index &w)
{
	if (m_indexs[0] == v) 
		w = m_indexs[2];
	else if (m_indexs[1] == v) 
		w = m_indexs[3];
	else if (m_indexs[2] == v) 
		w = m_indexs[0];
	else if (m_indexs[3] == v) 
		w = m_indexs[1];
	else
	  return false;

	return true;
}

/**
 * Replaces a face vertex index.
 * @param oldIndex old vertex index
 * @param newIndex new vertex index
 */
void BOP_Face4::replaceVertexIndex(BOP_Index oldIndex, BOP_Index newIndex)
{
	if (m_indexs[0] == oldIndex) m_indexs[0] = newIndex;
	else if (m_indexs[1] == oldIndex) m_indexs[1] = newIndex;
	else if (m_indexs[2] == oldIndex) m_indexs[2] = newIndex;
	else if (m_indexs[3] == oldIndex) m_indexs[3] = newIndex;
}

/**
 * Returns the relative edge index (1,2,3,4) for the specified vertex indexs.
 * @param v1 vertex index
 * @param v2 vertex index
 * @param e relative edge index (1,2,3,4)
 * @return true if (v1,v2) is an edge of this face, false otherwise
 */
bool BOP_Face4::getEdgeIndex(BOP_Index v1, BOP_Index v2, unsigned int &e)
{
	if (m_indexs[0] == v1) {
		if (m_indexs[1] == v2) {
			e = 1;
		}
		else if (m_indexs[3] == v2) {
			e = 4;
		}
		else
		  return false;
	}
	else if (m_indexs[1] == v1) {
		if (m_indexs[0] == v2) {
			e = 1;
		}
		else if (m_indexs[2] == v2) {
			e = 2;
		}
		else
		  return false;
	}
	else if (m_indexs[2] == v1) {
		if (m_indexs[1] == v2) {
			e = 2;
		}
		else if (m_indexs[3] == v2) {
			e = 3;
		}
		else
		  return false;
	}
	else if (m_indexs[3] == v1) {
		if (m_indexs[2] == v2) {
			e = 3;
		}
		else if (m_indexs[0] == v2) {
			e = 4;
		}
		else
		  return false;
	}
	else return false;
	
	return  true;
}  

#ifdef BOP_DEBUG
/**
 * Implements operator <<.
 */
ostream &operator<<(ostream &stream, BOP_Face *f)
{
	char aux[20];
	BOP_stringTAG(f->m_tag,aux);
	if (f->size()==3) {
		stream << "Face[" << f->getVertex(0) << "," << f->getVertex(1) << ",";
		stream << f->getVertex(2) << "] ("  <<  aux  <<  ") <-- " << f->m_originalFace;
	}
	else {
		stream << "Face[" << f->getVertex(0) << "," << f->getVertex(1) << ",";
		stream << f->getVertex(2) << "," << f->getVertex(3) << "] ("  <<  aux;
		stream <<  ") <-- " << f->m_originalFace;
	}

	return stream;
}
#endif