polyhedron.hpp 26.8 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library 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 Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
Pierre Kraemer's avatar
Pierre Kraemer committed
21
22
23
24
25
26
27
28
29
30
31
32
33
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{

namespace Algo
{

namespace Modelisation
{

34
35
36
37
/**
 * create a n-sided pyramid
 */
template <typename PFP>
38
Dart createPyramid(typename PFP::MAP& map, unsigned int n, bool withBoundary)
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
{
	Dart dres = Dart::nil();
	std::vector<Dart> m_tableVertDarts;
	m_tableVertDarts.reserve(n);

	// creation of triangles around circunference and storing vertices
	for (unsigned int i = 0; i < n; ++i)
	{
		Dart d = map.newFace(3, false);
		m_tableVertDarts.push_back(d);
	}

	// sewing the triangles
	for (unsigned int i = 0; i < n-1; ++i)
	{
		Dart d = m_tableVertDarts[i];
		d = map.phi_1(d);
		Dart e = m_tableVertDarts[i+1];
		e = map.phi1(e);
		map.sewFaces(d, e, false);
	}
	//sewing the last with the first
	map.sewFaces(map.phi1(m_tableVertDarts[0]), map.phi_1(m_tableVertDarts[n-1]), false);

	//sewing the bottom face
64
65
	Dart base = map.newFace(n, false);
	dres = base;
66
67
	for(unsigned int i = 0; i < n ; ++i)
	{
68
69
70
71
		map.sewFaces(m_tableVertDarts[i], base, false);
		base = map.phi1(base);
	}

72
	if(map.dimension() == 3 && withBoundary)
73
74
		map.closeMap();

75
76
77
78
79
80
81
82
	//return a dart from the base
	return dres;
}

/**
 * create a n-sided prism
 */
template <typename PFP>
83
Dart createPrism(typename PFP::MAP& map, unsigned int n, bool withBoundary)
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
{
	Dart dres = Dart::nil();
	unsigned int nb = n*2;
	std::vector<Dart> m_tableVertDarts;
	m_tableVertDarts.reserve(nb);

	// creation of quads around circunference and storing vertices
	for (unsigned int i = 0; i < n; ++i)
	{
		Dart d = map.newFace(4, false);
		m_tableVertDarts.push_back(d);
	}

	// storing a dart from the vertex pointed by phi1(phi1(d))
	for (unsigned int i = 0; i < n; ++i)
	{
		m_tableVertDarts.push_back(map.phi1(map.phi1(m_tableVertDarts[i])));
	}

	// sewing the quads
	for (unsigned int i = 0; i < n-1; ++i)
	{
		Dart d = m_tableVertDarts[i];
		d = map.phi_1(d);
		Dart e = m_tableVertDarts[i+1];
		e = map.phi1(e);
		map.sewFaces(d, e, false);
	}
	//sewing the last with the first
	map.sewFaces(map.phi1(m_tableVertDarts[0]), map.phi_1(m_tableVertDarts[n-1]), false);

	//sewing the top & bottom faces
116
117
118
	Dart top = map.newFace(n, false);
	Dart bottom = map.newFace(n, false);
	dres = top;
119
120
	for(unsigned int i = 0; i < n ; ++i)
	{
121
122
123
124
		map.sewFaces(m_tableVertDarts[i], top, false);
		map.sewFaces(m_tableVertDarts[n+i], bottom, false);
		top = map.phi1(top);
		bottom = map.phi_1(bottom);
125
126
	}

127
	if(map.dimension() == 3 && withBoundary)
128
129
		map.closeMap();

130
131
132
133
134
135
136
137
	//return a dart from the base
	return dres;
}

/**
 * create a n-sided diamond
 */
template <typename PFP>
138
Dart createDiamond(typename PFP::MAP& map, unsigned int nbSides, bool withBoundary)
139
140
141
{
	Dart res = Dart::nil();

142
143
	Dart firstP = createPyramid<PFP>(map,nbSides, withBoundary);
	Dart secondP = createPyramid<PFP>(map,nbSides, withBoundary);
144
145
146
147

	res = map.phi2(firstP);

	map.sewVolumes(firstP, secondP);
untereiner's avatar
untereiner committed
148
	map.mergeVolumes(firstP);
149
150
151
152
153
154
155
156
157
158

	return res;
}



/**
 * create a 3-sided prism
 */
template <typename PFP>
159
Dart createTriangularPrism(typename PFP::MAP& map, bool withBoundary)
160
{
161
	return createPrism<PFP>(map, 3, withBoundary);
162
163
164
165
166
167
}

/**
 * create a hexahedron
 */
template <typename PFP>
168
Dart createHexahedron(typename PFP::MAP& map, bool withBoundary)
169
{
170
	return createPrism<PFP>(map, 4, withBoundary);
171
172
173
174
175
176
}

/**
 * create a tetrahedron
 */
template <typename PFP>
177
Dart createTetrahedron(typename PFP::MAP& map, bool withBoundary)
178
{
179
	return createPyramid<PFP>(map, 3, withBoundary);
180
181
182
183
184
185
}

/**
 * create a 4-sided pyramid
 */
template <typename PFP>
186
Dart createQuadrangularPyramid(typename PFP::MAP& map, bool withBoundary)
187
{
188
	return createPyramid<PFP>(map, 4, withBoundary);
189
190
191
192
193
194
}

/**
 * create an octahedron (i.e. 4-sided diamond)
 */
template <typename PFP>
195
Dart createOctahedron(typename PFP::MAP& map, bool withBoundary)
196
{
197
	return createDiamond<PFP>(map,4, withBoundary);
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

template <typename PFP>
bool isPyra(typename PFP::MAP& map, Dart d, unsigned int thread)
{
	unsigned int nbFacesT = 0;
	unsigned int nbFacesQ = 0;

	//Test the number of faces end its valency
	Traversor3WF<typename PFP::MAP> travWF(map, d, false, thread);
	for(Dart dit = travWF.begin() ; dit != travWF.end(); dit = travWF.next())
	{
		//increase the number of faces
		if(map.faceDegree(dit) == 3)
			nbFacesT++;
		else if(map.faceDegree(dit) == 4)
			nbFacesQ++;
		else
			return false;
	}

	if((nbFacesT != 4) || (nbFacesQ != 1))	//too much faces
		return false;

	return true;
}

template <typename PFP>
bool isPrism(typename PFP::MAP& map, Dart d, unsigned int thread)
{
	unsigned int nbFacesT = 0;
	unsigned int nbFacesQ = 0;

	//Test the number of faces end its valency
	Traversor3WF<typename PFP::MAP> travWF(map, d, false, thread);
	for(Dart dit = travWF.begin() ; dit != travWF.end(); dit = travWF.next())
	{
		//increase the number of faces
		if(map.faceDegree(dit) == 3)
			nbFacesT++;
		else if(map.faceDegree(dit) == 4)
			nbFacesQ++;
		else
			return false;
	}

	if((nbFacesT != 2) || (nbFacesQ != 3))	//too much faces
		return false;

	return true;
}






untereiner's avatar
untereiner committed
260
template <typename PFP>
Sylvain Thery's avatar
Sylvain Thery committed
261
void explodPolyhedron(typename PFP::MAP& map, Dart d,  VertexAttribute<typename PFP::VEC3>& position)
untereiner's avatar
untereiner committed
262
263
264
265
266
267
{
	map.unsewVertexUmbrella(d);
	unsigned int newFaceDegree = map.closeHole(map.phi1(d));

	if(newFaceDegree != 3)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
268
		// chercher le brin ou demarrer
untereiner's avatar
untereiner committed
269
270
271
272
273
274

		std::multimap<Dart, int> edges ;
		typename std::multimap<Dart, int>::iterator it ;

		Dart d12 = map.phi2(map.phi1(d));
		Dart fit = d12;
Pierre Kraemer's avatar
Pierre Kraemer committed
275
		unsigned int i;
untereiner's avatar
untereiner committed
276
277
278
279
280
281

		do
		{
			i = map.faceDegree(map.phi2(fit));
			std::cout << "edge(" << fit << "," << i << ")" << std::endl;
			edges.insert(std::make_pair(fit, i));
Pierre Kraemer's avatar
Pierre Kraemer committed
282
			fit = map.phi1(fit);
untereiner's avatar
untereiner committed
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
		}
		while(fit != d12);

		do
		{
			//44 44
			if(edges.find(fit)->second == 4 && edges.find(map.phi1(fit))->second == 4
				&& !map.sameFace(map.phi2(fit), map.phi2(map.phi1(fit))))
			{
				map.splitFace(fit, map.phi1(map.phi1(fit)));
				fit = map.phi2(map.phi_1(fit));
				int i = map.faceDegree(fit);
				edges.insert(std::make_pair(fit, i));

//				Dart fit2 = map.phi2(fit) ;
//				typename PFP::VEC3 p1 = position[fit] ;
//				typename PFP::VEC3 p2 = position[fit2] ;
//
//				map.cutEdge(fit) ;
//				position[map.phi1(fit)] = typename PFP::REAL(0.5) * (p1 + p2);


				std::cout << "flip cas quad quad " << std::endl;
			}

			//3 3
			if(edges.find(fit)->second == 3 && edges.find(map.phi1(fit))->second == 3
				&& !map.sameFace(map.phi2(fit), map.phi2(map.phi1(fit))))
			{
				map.splitFace(fit, map.phi1(fit));
				fit = map.phi2(map.phi_1(fit));
				int i = map.faceDegree(fit);
				edges.insert(std::make_pair(fit, i));

				std::cout << "flip cas tri tri" << std::endl;
			}

			//3 44 ou 44 3
			if( ((edges.find(fit)->second == 4 && edges.find(map.phi1(fit))->second == 3)
				|| (edges.find(fit)->second == 3 && edges.find(map.phi1(fit))->second == 4))
					&& !map.sameFace(map.phi2(fit), map.phi2(map.phi1(fit))))
			{
				map.splitFace(fit, map.phi1(map.phi1(fit)));
				fit = map.phi2(map.phi_1(fit));
				int i = map.faceDegree(fit);
				edges.insert(std::make_pair(fit, i));

				std::cout << "flip cas quad tri" << std::endl;
			}

			fit = map.phi1(fit);
		}
		while(map.faceDegree(fit) > 4 && fit != d12);

	}
}

Pierre Kraemer's avatar
Pierre Kraemer committed
340
template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
341
342
343
344
345
346
347
Polyhedron<PFP>::Polyhedron(const Polyhedron<PFP>& p1, const Polyhedron<PFP>& p2) :
	m_map(p1.m_map),
	m_dart(p1.m_dart),
	m_kind(COMPOSED),
	m_nx(-1), m_ny(-1), m_nz(-1),
	m_top_closed(false), m_bottom_closed(false),
	m_positions(p1.m_positions)
Pierre Kraemer's avatar
Pierre Kraemer committed
348
{
349
	if (&(p1.m_map) != &(p2.m_map))
Pierre Kraemer's avatar
Pierre Kraemer committed
350
	{
351
		CGoGNerr << "Warning, can not merge to Polyhedrons of different maps"<< CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
352
353
354
355
	}

	m_tableVertDarts.reserve(p1.m_tableVertDarts.size() + p2.m_tableVertDarts.size()); // can be too much but ...

356
	VEC3 center(0);
Pierre Kraemer's avatar
Pierre Kraemer committed
357

Pierre Kraemer's avatar
Pierre Kraemer committed
358
	for(typename std::vector<Dart>::const_iterator di = p1.m_tableVertDarts.begin(); di != p1.m_tableVertDarts.end(); ++di)
Pierre Kraemer's avatar
Pierre Kraemer committed
359
360
361
362
363
364
	{
		m_tableVertDarts.push_back(*di);
		center += m_positions[*di];
	}

	// O(n2) pas terrible !!
Pierre Kraemer's avatar
Pierre Kraemer committed
365
	for(typename std::vector<Dart>::const_iterator di = p2.m_tableVertDarts.begin(); di != p2.m_tableVertDarts.end(); ++di)
Pierre Kraemer's avatar
Pierre Kraemer committed
366
	{
367
		unsigned int em = m_map.template getEmbedding<VERTEX>(*di);
Pierre Kraemer's avatar
Pierre Kraemer committed
368
369
370
371
372

		typename std::vector<Dart>::const_iterator dj=p1.m_tableVertDarts.begin();
		bool found = false;
		while ((dj !=p1.m_tableVertDarts.end()) && (!found))
		{
373
			unsigned int xm = m_map.template getEmbedding<VERTEX>(*dj);
Pierre Kraemer's avatar
Pierre Kraemer committed
374
			if (xm == em)
Pierre Kraemer's avatar
Pierre Kraemer committed
375
376
377
378
379
380
381
382
383
384
385
386
387
388
				found = true;
			else
				++dj;
		}
		if (!found)
		{
			m_tableVertDarts.push_back(*di);
			center += m_positions[*di];
		}
	}

	m_center = center / typename PFP::REAL(m_tableVertDarts.size());
}

389
390


Pierre Kraemer's avatar
Pierre Kraemer committed
391
template <typename PFP>
392
Dart Polyhedron<PFP>::grid_topo_open(unsigned int x, unsigned int y)
Pierre Kraemer's avatar
Pierre Kraemer committed
393
394
395
396
397
398
399
400
401
402
403
404
405
{
	if (m_kind != NONE) return m_dart;

	m_kind = GRID;
	m_nx = x;
	m_ny = y;
	// nb vertices
	int nb = (x+1)*(y+1);

	// vertice reservation
	m_tableVertDarts.reserve(nb);

	// creation of quads and storing vertices
Pierre Kraemer's avatar
Pierre Kraemer committed
406
	for (unsigned int i = 0; i < y; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
407
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
408
		for (unsigned int j = 1; j <= x; ++j)
Pierre Kraemer's avatar
Pierre Kraemer committed
409
		{
410
			Dart d = m_map.newFace(4, false);
Pierre Kraemer's avatar
Pierre Kraemer committed
411
			m_tableVertDarts.push_back(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
412
			if (j == x)
Pierre Kraemer's avatar
Pierre Kraemer committed
413
414
415
				m_tableVertDarts.push_back(m_map.phi1(d));
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
416

Pierre Kraemer's avatar
Pierre Kraemer committed
417
	// store last row of vertices
Pierre Kraemer's avatar
Pierre Kraemer committed
418
	for (unsigned int i = 0; i < x; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
419
420
421
422
423
424
	{
		m_tableVertDarts.push_back( m_map.phi_1(m_tableVertDarts[(y-1)*(x+1) + i]) );	
	}
	m_tableVertDarts.push_back( m_map.phi1(m_tableVertDarts[(y-1)*(x+1) +x]) );	

	//sewing the quads
Pierre Kraemer's avatar
Pierre Kraemer committed
425
	for (unsigned int i = 0; i < y; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
426
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
427
		for (unsigned int j = 0; j < x; ++j)
Pierre Kraemer's avatar
Pierre Kraemer committed
428
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
429
			if (i > 0) // sew with preceeding row
Pierre Kraemer's avatar
Pierre Kraemer committed
430
431
432
433
434
			{
				int pos = i*(x+1)+j;
				Dart d = m_tableVertDarts[pos];
				Dart e = m_tableVertDarts[pos-(x+1)];
				e = m_map.phi1(m_map.phi1(e));
435
				m_map.sewFaces(d, e, false);
Pierre Kraemer's avatar
Pierre Kraemer committed
436
			}
Pierre Kraemer's avatar
Pierre Kraemer committed
437
			if (j > 0) // sew with preceeding column
Pierre Kraemer's avatar
Pierre Kraemer committed
438
439
440
441
442
443
			{
				int pos = i*(x+1)+j;
				Dart d = m_tableVertDarts[pos];
				d = m_map.phi_1(d);
				Dart e = m_tableVertDarts[pos-1];
				e = m_map.phi1(e);
444
				m_map.sewFaces(d, e, false);
Pierre Kraemer's avatar
Pierre Kraemer committed
445
446
447
448
449
450
			}
		}
	}

	// store & return reference dart
	m_dart = m_tableVertDarts[0]; // util ?
451

452
453
454
455
456
457
458
459
460
461
	return m_dart;
}

template <typename PFP>
Dart Polyhedron<PFP>::grid_topo(unsigned int x, unsigned int y)
{
	if (m_kind != NONE) return m_dart;

	m_dart = grid_topo_open(x,y);

462
463
	m_map.closeHole(m_dart) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
464
465
466
467
	return m_dart;
}

template <typename PFP>
468
Dart Polyhedron<PFP>::cylinder_topo_open(unsigned int n, unsigned int z)
Pierre Kraemer's avatar
Pierre Kraemer committed
469
470
471
472
473
474
475
{
	if (m_kind != NONE) return m_dart;

	m_kind = CYLINDER;
	m_nx = n;
	m_nz = z;

476
	int nb = (n)*(z+1)+2;
Pierre Kraemer's avatar
Pierre Kraemer committed
477
478
479
480
481

	// vertice reservation
	m_tableVertDarts.reserve(nb);

	// creation of quads and storing vertices
Pierre Kraemer's avatar
Pierre Kraemer committed
482
	for (unsigned int i = 0; i < z; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
483
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
484
		for (unsigned int j = 0; j < n; ++j)
Pierre Kraemer's avatar
Pierre Kraemer committed
485
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
486
			Dart d = m_map.newFace(4, false);
Pierre Kraemer's avatar
Pierre Kraemer committed
487
488
489
			m_tableVertDarts.push_back(d);
		}
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
490
	for (unsigned int i = 0; i < n; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
491
492
493
494
495
	{
		m_tableVertDarts.push_back( m_map.phi_1(m_tableVertDarts[(z-1)*n+i]) );	
	}

	//sewing the quads
Pierre Kraemer's avatar
Pierre Kraemer committed
496
	for (unsigned int i = 0; i < z; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
497
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
498
		for (unsigned int j = 0; j < n; ++j)
Pierre Kraemer's avatar
Pierre Kraemer committed
499
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
500
			if (i > 0) // sew with preceeding row
Pierre Kraemer's avatar
Pierre Kraemer committed
501
502
503
504
505
			{
				int pos = i*n+j;
				Dart d = m_tableVertDarts[pos];
				Dart e = m_tableVertDarts[pos-n];
				e = m_map.phi1(m_map.phi1(e));
Pierre Kraemer's avatar
Pierre Kraemer committed
506
				m_map.sewFaces(d, e, false);
Pierre Kraemer's avatar
Pierre Kraemer committed
507
			}
Pierre Kraemer's avatar
Pierre Kraemer committed
508
			if (j > 0) // sew with preceeding column
Pierre Kraemer's avatar
Pierre Kraemer committed
509
510
511
512
513
514
			{
				int pos = i*n+j;
				Dart d = m_tableVertDarts[pos];
				d = m_map.phi_1(d);
				Dart e = m_tableVertDarts[pos-1];
				e = m_map.phi1(e);
Pierre Kraemer's avatar
Pierre Kraemer committed
515
				m_map.sewFaces(d, e, false);
Pierre Kraemer's avatar
Pierre Kraemer committed
516
517
518
519
520
521
522
523
			}
			else 
			{
				int pos = i*n;
				Dart d = m_tableVertDarts[pos];
				d = m_map.phi_1(d);
				Dart e = m_tableVertDarts[pos+(n-1)];
				e = m_map.phi1(e);
Pierre Kraemer's avatar
Pierre Kraemer committed
524
				m_map.sewFaces(d, e, false);
Pierre Kraemer's avatar
Pierre Kraemer committed
525
526
527
528
			}
		}
	}

529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
	m_dart = m_tableVertDarts.front();
	return m_dart;
}


template <typename PFP>
Dart Polyhedron<PFP>::cylinder_topo(unsigned int n, unsigned int z, bool top_closed, bool bottom_closed)
{
	if (m_kind != NONE) return m_dart;

	m_dart = cylinder_topo_open(n, z);

	m_bottom_closed = bottom_closed;
	m_top_closed = top_closed;


Pierre Kraemer's avatar
Pierre Kraemer committed
545
546
547
	if (bottom_closed)
	{
		Dart d = m_tableVertDarts[0];
548
		if(m_map.closeHole(d, false))
Pierre Kraemer's avatar
Pierre Kraemer committed
549
550
		{
			d = m_map.phi2(d);
551
			if(m_map.faceDegree(d) > 3)
Pierre Kraemer's avatar
Pierre Kraemer committed
552
			{
553
				Algo::Modelisation::trianguleFace<PFP>(m_map, d);
Pierre Kraemer's avatar
Pierre Kraemer committed
554
555
556
557
				m_tableVertDarts.push_back(m_map.phi_1(d));
			}
		}
	}
558
559
	else
		m_map.closeHole(m_tableVertDarts[0]);
Pierre Kraemer's avatar
Pierre Kraemer committed
560
561
562
563

	if (top_closed)
	{
		Dart d =  m_map.phi_1(m_tableVertDarts[n*z]);
564
		if(m_map.closeHole(d, false))
Pierre Kraemer's avatar
Pierre Kraemer committed
565
566
		{
			d = m_map.phi2(d);
567
			if(m_map.faceDegree(d) > 3)
Pierre Kraemer's avatar
Pierre Kraemer committed
568
			{
569
				Algo::Modelisation::trianguleFace<PFP>(m_map, d);
Pierre Kraemer's avatar
Pierre Kraemer committed
570
571
572
573
				m_tableVertDarts.push_back(m_map.phi_1(d));
			}
		}
	}
574
575
	else
		m_map.closeHole(m_map.phi_1(m_tableVertDarts[n*z]));
Pierre Kraemer's avatar
Pierre Kraemer committed
576

577
//	m_dart = m_tableVertDarts.front();
Pierre Kraemer's avatar
Pierre Kraemer committed
578
579
580
581
582
	return m_dart;
}


template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
583
Dart Polyhedron<PFP>::cube_topo(unsigned int x, unsigned int y, unsigned int z)
Pierre Kraemer's avatar
Pierre Kraemer committed
584
585
586
{
	if (m_kind != NONE) return m_dart;

587
	m_dart = cylinder_topo_open(2*(x+y), z);
Pierre Kraemer's avatar
Pierre Kraemer committed
588
589
590
591
592
593
594
595
596
597
	m_kind = CUBE;
	m_nx = x;
	m_ny = y;
	m_nz = z;

	int nb = 2*(x+y)*(z+1) + 2*(x-1)*(y-1);
	m_tableVertDarts.reserve(nb);
	
	// we now have the 4 sides, just need to create store and sew top & bottom
	// the top
598
	Polyhedron<PFP> primTop(m_map, m_positions);
599
	primTop.grid_topo_open(x,y);
Pierre Kraemer's avatar
Pierre Kraemer committed
600
601
602
	std::vector<Dart>& tableTop = primTop.getVertexDarts();

	int index_side = 2*(x+y)*z;
Pierre Kraemer's avatar
Pierre Kraemer committed
603
	for(unsigned int i = 0; i < x; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
604
605
606
	{
		Dart d = m_map.phi_1(m_tableVertDarts[index_side++]);
		Dart e = tableTop[i];
Pierre Kraemer's avatar
Pierre Kraemer committed
607
		m_map.sewFaces(d, e, false);
Pierre Kraemer's avatar
Pierre Kraemer committed
608
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
609
	for(unsigned int i = 0; i < y; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
610
611
612
	{
		Dart d = m_map.phi_1(m_tableVertDarts[index_side++]);
		Dart e = tableTop[x+i*(x+1)];
Pierre Kraemer's avatar
Pierre Kraemer committed
613
		m_map.sewFaces(d, e, false);
Pierre Kraemer's avatar
Pierre Kraemer committed
614
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
615
	for(unsigned int i = 0; i < x; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
616
617
618
619
	{
		Dart d = m_map.phi_1(m_tableVertDarts[index_side++]);
		Dart e = tableTop[(x+1)*(y+1)-2 - i];
		e = m_map.phi_1(e);
Pierre Kraemer's avatar
Pierre Kraemer committed
620
		m_map.sewFaces(d, e, false);
Pierre Kraemer's avatar
Pierre Kraemer committed
621
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
622
	for(unsigned int i = 0; i < y; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
623
624
625
626
	{
		Dart d = m_map.phi_1(m_tableVertDarts[index_side++]);
		Dart e = tableTop[(y-1-i)*(x+1)];
		e = m_map.phi_1(e);
Pierre Kraemer's avatar
Pierre Kraemer committed
627
		m_map.sewFaces(d, e, false);
Pierre Kraemer's avatar
Pierre Kraemer committed
628
629
630
	}

	// the bottom
631
	Polyhedron<PFP> primBottom(m_map,m_positions);
632
	primBottom.grid_topo_open(x,y);
Pierre Kraemer's avatar
Pierre Kraemer committed
633
634
635
	std::vector<Dart>& tableBottom = primBottom.getVertexDarts();

	index_side = 3*(x+y)+(x-1);
Pierre Kraemer's avatar
Pierre Kraemer committed
636
	for(unsigned int i = 0; i < x; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
637
638
639
	{
		Dart d = m_tableVertDarts[(index_side--)%(2*(x+y))];
		Dart e = tableBottom[i];
Pierre Kraemer's avatar
Pierre Kraemer committed
640
		m_map.sewFaces(d, e, false);
Pierre Kraemer's avatar
Pierre Kraemer committed
641
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
642
	for(unsigned int i = 0; i < y; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
643
644
645
	{
		Dart d = m_tableVertDarts[(index_side--)%(2*(x+y))];
		Dart e = tableBottom[x+i*(x+1)];
Pierre Kraemer's avatar
Pierre Kraemer committed
646
		m_map.sewFaces(d, e, false);
Pierre Kraemer's avatar
Pierre Kraemer committed
647
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
648
	for(unsigned int i = 0; i < x; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
649
650
651
652
	{
		Dart d = m_tableVertDarts[(index_side--)%(2*(x+y))];
		Dart e = tableBottom[(x+1)*(y+1)-2 - i];
		e = m_map.phi_1(e);
Pierre Kraemer's avatar
Pierre Kraemer committed
653
		m_map.sewFaces(d, e, false);
Pierre Kraemer's avatar
Pierre Kraemer committed
654
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
655
	for(unsigned int i = 0; i < y; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
656
657
658
659
	{
		Dart d = m_tableVertDarts[(index_side--)%(2*(x+y))];
		Dart e = tableBottom[(y-1-i)*(x+1)];
		e = m_map.phi_1(e);
Pierre Kraemer's avatar
Pierre Kraemer committed
660
		m_map.sewFaces(d, e, false);
Pierre Kraemer's avatar
Pierre Kraemer committed
661
662
663
664
	}

	// and add new vertex in m_tableVertDarts
	//top  first
Pierre Kraemer's avatar
Pierre Kraemer committed
665
	for(unsigned int i = 1; i < y; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
666
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
667
		for(unsigned int j = 1; j < x; ++j)
Pierre Kraemer's avatar
Pierre Kraemer committed
668
669
670
671
			m_tableVertDarts.push_back(tableTop[i*(x+1)+j]);
	}

	// then bottom
Pierre Kraemer's avatar
Pierre Kraemer committed
672
	for(unsigned int i = 1; i < y; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
673
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
674
		for(unsigned int j = 1; j < x; ++j)
Pierre Kraemer's avatar
Pierre Kraemer committed
675
676
677
678
679
680
681
			m_tableVertDarts.push_back(tableBottom[i*(x+1)+j]);
	}

	return m_dart;
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
682
Dart Polyhedron<PFP>::tore_topo(unsigned int m, unsigned int n)
Pierre Kraemer's avatar
Pierre Kraemer committed
683
684
685
686
{
	if (m_kind != NONE) return m_dart;

	m_dart = cylinder_topo(n, m, false, false);
Pierre Kraemer's avatar
Pierre Kraemer committed
687
688
	m_nx = n;
	m_ny = m;
Pierre Kraemer's avatar
Pierre Kraemer committed
689
690
	m_kind = TORE;

Pierre Kraemer's avatar
Pierre Kraemer committed
691
	// just finish to sew
Pierre Kraemer's avatar
Pierre Kraemer committed
692
	for(unsigned int i = 0; i < n; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
693
694
695
696
	{
		Dart d = m_tableVertDarts[i];
		Dart e = m_tableVertDarts[(m*n)+i];
		e = m_map.phi_1(e);
Pierre Kraemer's avatar
Pierre Kraemer committed
697
		m_map.sewFaces(d, e);
Pierre Kraemer's avatar
Pierre Kraemer committed
698
699
700
701
702
703
704
705
706
707
	}

	// remove the last n vertex darts that are no more necessary (sewed with n first)
	// memory not freed (but will be when destroy the Polyhedron), not important ??
	m_tableVertDarts.resize(m*n); 

	return m_dart;
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
708
void Polyhedron<PFP>::embedGrid(float x, float y, float z)
Pierre Kraemer's avatar
Pierre Kraemer committed
709
710
711
{
	typedef typename PFP::VEC3 VEC3 ;

Pierre Kraemer's avatar
Pierre Kraemer committed
712
713
	if (m_kind != GRID)
	{
714
		CGoGNerr << "Warning try to embedGrid something that is not a grid"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
715
716
717
		return;
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
718
719
	float dx = x / float(m_nx);
	float dy = y / float(m_ny);
Pierre Kraemer's avatar
Pierre Kraemer committed
720

Pierre Kraemer's avatar
Pierre Kraemer committed
721
	for(unsigned int i = 0; i <= m_ny; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
722
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
723
		for(unsigned int j = 0; j <= m_nx;++j)
Pierre Kraemer's avatar
Pierre Kraemer committed
724
		{
725
			m_positions[ m_tableVertDarts[i*(m_nx+1)+j] ] = VEC3(-x/2 + dx*float(j), -y/2 + dy*float(i), z);
Pierre Kraemer's avatar
Pierre Kraemer committed
726
727
728
729
730
		}
	}
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
731
void Polyhedron<PFP>::embedCylinder(float bottom_radius, float top_radius, float height)
Pierre Kraemer's avatar
Pierre Kraemer committed
732
733
734
{
	typedef typename PFP::VEC3 VEC3 ;

Pierre Kraemer's avatar
Pierre Kraemer committed
735
736
	if (m_kind != CYLINDER)
	{
737
		CGoGNerr << "Warning try to embedCylinder something that is not a cylnder"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
738
739
740
741
742
743
		return;
	}

	float alpha = float(2.0*M_PI/m_nx);
	float dz = height/float(m_nz);

Pierre Kraemer's avatar
Pierre Kraemer committed
744
	for(unsigned int i = 0; i <= m_nz; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
745
746
747
	{
		float a = float(i)/float(m_nz);
		float radius = a*top_radius + (1.0f-a)*bottom_radius;
Pierre Kraemer's avatar
Pierre Kraemer committed
748
		for(unsigned int j = 0; j < m_nx; ++j)
Pierre Kraemer's avatar
Pierre Kraemer committed
749
750
751
752
		{
	
			float x = radius*cos(alpha*float(j));
			float y = radius*sin(alpha*float(j));
753
			m_positions[ m_tableVertDarts[i*(m_nx)+j] ] = VEC3(x, y, -height/2 + dz*float(i));
Pierre Kraemer's avatar
Pierre Kraemer committed
754
755
756
757
758
759
		}
	}

	int indexUmbrella = m_nx*(m_nz+1);
	if (m_bottom_closed)
	{
760
		m_positions[ m_tableVertDarts[indexUmbrella++] ] = VEC3(0.0f, 0.0f, -height/2 );
Pierre Kraemer's avatar
Pierre Kraemer committed
761
762
763
764
	}

	if (m_top_closed)
	{
765
		m_positions[ m_tableVertDarts[indexUmbrella] ] = VEC3(0.0f, 0.0f, height/2 );
Pierre Kraemer's avatar
Pierre Kraemer committed
766
767
768
769
	}
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
770
void Polyhedron<PFP>::embedCone(float radius, float height)
Pierre Kraemer's avatar
Pierre Kraemer committed
771
772
773
{
	typedef typename PFP::VEC3 VEC3 ;

774
	if (!((m_kind == CYLINDER) && (m_top_closed)) )
Pierre Kraemer's avatar
Pierre Kraemer committed
775
	{
776
		CGoGNerr << "Warning try to embedCone something that is not a cone"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
777
778
779
780
		return;
	}

	float alpha = float(2.0*M_PI/m_nx);
781
782
	float dz = height/float(m_nz+1);
	for( unsigned int i = 0; i <= m_nz; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
783
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
784
		for(unsigned int j = 0; j < m_nx; ++j)
Pierre Kraemer's avatar
Pierre Kraemer committed
785
		{
786
			float rad = radius * float(m_nz+1-i)/float(m_nz+1);
Pierre Kraemer's avatar
Pierre Kraemer committed
787
788
789
790
			float h = -height/2 + dz*float(i);
			float x = rad*cos(alpha*float(j));
			float y = rad*sin(alpha*float(j));

791
			m_positions[ m_tableVertDarts[i*(m_nx)+j] ] = VEC3(x, y, h);
Pierre Kraemer's avatar
Pierre Kraemer committed
792
793
794
		}
	}

795
	int indexUmbrella = m_nx*(m_nz+1);
Pierre Kraemer's avatar
Pierre Kraemer committed
796
797
	if (m_bottom_closed)
	{
798
		m_positions[ m_tableVertDarts[indexUmbrella++] ] = VEC3(0.0f, 0.0f, -height/2 );
Pierre Kraemer's avatar
Pierre Kraemer committed
799
800
801
	}

	//  top always closed in cone 
802
	m_positions[ m_tableVertDarts[indexUmbrella] ] = VEC3(0.0f, 0.0f, height/2 );
Pierre Kraemer's avatar
Pierre Kraemer committed
803
804
805
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
806
void Polyhedron<PFP>::embedSphere(float radius)
Pierre Kraemer's avatar
Pierre Kraemer committed
807
808
809
{
	typedef typename PFP::VEC3 VEC3 ;

Pierre Kraemer's avatar
Pierre Kraemer committed
810
811
	if (!((m_kind == CYLINDER) && (m_top_closed) && (m_bottom_closed)))
	{
812
		CGoGNerr << "Warning try to embedSphere something that is not a sphere (closed cylinder)"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
813
814
815
816
817
818
		return;
	}

	float alpha = float(2.0*M_PI/m_nx);
	float beta = float(M_PI/(m_nz+2));

Pierre Kraemer's avatar
Pierre Kraemer committed
819
	for(unsigned int i = 0; i <= m_nz; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
820
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
821
		for(unsigned int j = 0; j < m_nx; ++j)
Pierre Kraemer's avatar
Pierre Kraemer committed
822
823
824
825
826
827
		{
			float h = float(radius * sin(-M_PI/2.0+(i+1)*beta));
			float rad = float(radius * cos(-M_PI/2.0+(i+1)*beta));

			float x = rad*cos(alpha*float(j));
			float y = rad*sin(alpha*float(j));
828
829

			m_positions[ m_tableVertDarts[i*(m_nx)+j] ] = VEC3(x, y, h );
Pierre Kraemer's avatar
Pierre Kraemer committed
830
831
832
833
		}
	}

	// bottom  pole
834
	m_positions[ m_tableVertDarts[m_nx*(m_nz+1)] ] = VEC3(0.0f, 0.0f, -radius);
Pierre Kraemer's avatar
Pierre Kraemer committed
835
836

	//  top pole
837
838
	m_positions[ m_tableVertDarts[m_nx*(m_nz+1)+1] ] = VEC3(0.0f, 0.0f, radius);

Pierre Kraemer's avatar
Pierre Kraemer committed
839
840
841
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
842
void Polyhedron<PFP>::embedTore(float big_radius, float small_radius)
Pierre Kraemer's avatar
Pierre Kraemer committed
843
844
845
{
	typedef typename PFP::VEC3 VEC3 ;

Pierre Kraemer's avatar
Pierre Kraemer committed
846
847
	if (m_kind != TORE)
	{
848
		CGoGNerr << "Warning try to embedTore something that is not a tore"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
849
850
851
852
853
854
		return;
	}

	float alpha = float(2.0*M_PI/m_nx);
	float beta = float(2.0*M_PI/m_ny);

Pierre Kraemer's avatar
Pierre Kraemer committed
855
	for (unsigned int i = 0; i < m_nx; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
856
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
857
		for(unsigned int j = 0; j < m_ny; ++j)
Pierre Kraemer's avatar
Pierre Kraemer committed
858
859
860
861
862
		{
			float z = small_radius*sin(beta*float(j));
			float r = big_radius + small_radius*cos(beta*float(j));
			float x = r*cos(alpha*float(i));
			float y = r*sin(alpha*float(i));
863
			m_positions[ m_tableVertDarts[j*(m_nx)+i] ] = VEC3(x, y, z);
Pierre Kraemer's avatar
Pierre Kraemer committed
864
865
866
867
868
		}
	}
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
869
void Polyhedron<PFP>::embedCube(float sx, float sy, float sz)
Pierre Kraemer's avatar
Pierre Kraemer committed
870
871
872
{
	typedef typename PFP::VEC3 VEC3 ;

Pierre Kraemer's avatar
Pierre Kraemer committed
873
874
	if (m_kind != CUBE)
	{
875
		CGoGNerr << "Warning try to embedCube something that is not a cube"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
876
877
878
879
880
881
882
883
884
		return;
	}

	float dz = sz/float(m_nz);
	float dy = sy/float(m_ny);
	float dx = sx/float(m_nx);

	// first embedding the sides
	int index = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
885
	for (unsigned int k = 0; k <= m_nz; ++k)
Pierre Kraemer's avatar
Pierre Kraemer committed
886
887
	{
		float z = float(k)*dz - sz/2.0f;
Pierre Kraemer's avatar
Pierre Kraemer committed
888
		for (unsigned int i = 0; i < m_nx; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
889
890
		{
			float x = float(i)*dx - sx/2.0f;
891
			m_positions[ m_tableVertDarts[ index++ ] ] = VEC3(x, -sy/2.0f, z);
Pierre Kraemer's avatar
Pierre Kraemer committed
892
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
893
		for (unsigned int i = 0; i < m_ny; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
894
895
		{
			float y = float(i)*dy - sy/2.0f;
896
			m_positions[ m_tableVertDarts[ index++ ] ] = VEC3(sx/2.0f, y, z);
Pierre Kraemer's avatar
Pierre Kraemer committed
897
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
898
		for (unsigned int i = 0; i < m_nx; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
899
900
		{
			float x = sx/2.0f-float(i)*dx;
901
			m_positions[ m_tableVertDarts[ index++ ] ] = VEC3(x, sy/2.0f, z);
Pierre Kraemer's avatar
Pierre Kraemer committed
902
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
903
		for (unsigned int i = 0; i < m_ny ;++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
904
905
		{
			float y = sy/2.0f - float(i)*dy;
906
			m_positions[ m_tableVertDarts[ index++ ] ] = VEC3(-sx/2.0f, y, z);
Pierre Kraemer's avatar
Pierre Kraemer committed
907
908
909
910
		}
	}

	// the top
Pierre Kraemer's avatar
Pierre Kraemer committed
911
	for(unsigned int i = 1; i  <m_ny; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
912
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
913
		for(unsigned int j = 1; j < m_nx; ++j)
Pierre Kraemer's avatar
Pierre Kraemer committed
914
915
		{
			VEC3 pos(-sx/2.0f+float(j)*dx, -sy/2.0f+float(i)*dy, sz/2.0f);
916
			m_positions[ m_tableVertDarts[ index++ ] ] = pos;
Pierre Kraemer's avatar
Pierre Kraemer committed
917
918
919
920
		}
	}

	// the bottom
Pierre Kraemer's avatar
Pierre Kraemer committed
921
	for(unsigned int i = 1; i < m_ny; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
922
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
923
		for(unsigned int j = 1; j < m_nx; ++j)
Pierre Kraemer's avatar
Pierre Kraemer committed
924
925
		{
			VEC3 pos(-sx/2.0f+float(j)*dx, sy/2.0f-float(i)*dy, -sz/2.0f);
926
			m_positions[ m_tableVertDarts[ index++ ] ] = pos;
Pierre Kraemer's avatar
Pierre Kraemer committed
927
928
929
930
931
932
933
934
935
		}
	}
}

template <typename PFP>
void Polyhedron<PFP>::computeCenter()
{
	typename PFP::VEC3 center(0);

Pierre Kraemer's avatar
Pierre Kraemer committed
936
	for(typename std::vector<Dart>::iterator di = m_tableVertDarts.begin(); di != m_tableVertDarts.end(); ++di)
Pierre Kraemer's avatar
Pierre Kraemer committed
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
	{
		center += m_positions[*di];
	}

	m_center = center / typename PFP::REAL(m_tableVertDarts.size());
}

template <typename PFP>
//void Polyhedron<PFP>::transform(float* matrice)
void Polyhedron<PFP>::transform(const Geom::Matrix44f& matrice)
{
//	Geom::Vec4f v1(matrice[0],matrice[4],matrice[8], matrice[12]);
//	Geom::Vec4f v2(matrice[1],matrice[5],matrice[9], matrice[13]);
//	Geom::Vec4f v3(matrice[2],matrice[6],matrice[10],matrice[14]);
//	Geom::Vec4f v4(matrice[3],matrice[7],matrice[11],matrice[15]);

Pierre Kraemer's avatar
Pierre Kraemer committed
953
	for(typename std::vector<Dart>::iterator di = m_tableVertDarts.begin(); di != m_tableVertDarts.end(); ++di)
Pierre Kraemer's avatar
Pierre Kraemer committed
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
	{

		typename PFP::VEC3& pos = m_positions[*di];
//
//		Geom::Vec4f VA(pos[0],pos[1],pos[2],1.0f);
//
//		Geom::Vec4f VB((VA*v1),(VA*v2),(VA*v3),(VA*v4));
//		VEC3 newPos(VB[0]/VB[3],VB[1]/VB[3],VB[2]/VB[3]);
		
		pos = Geom::transform(pos, matrice);
	}
	// transform the center
	m_center = Geom::transform(m_center, matrice);

}

template <typename PFP>
971
void Polyhedron<PFP>::mark(CellMarker<VERTEX>& m)
Pierre Kraemer's avatar
Pierre Kraemer committed
972
{
Pierre Kraemer's avatar
Pierre Kraemer committed
973
	for(typename std::vector<Dart>::iterator di = m_tableVertDarts.begin(); di != m_tableVertDarts.end(); ++di)
Pierre Kraemer's avatar
Pierre Kraemer committed
974
	{
Sylvain Thery's avatar
Sylvain Thery committed
975
		m.mark(*di);
Pierre Kraemer's avatar
Pierre Kraemer committed
976
977
978
979
	}
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
980
void Polyhedron<PFP>::embedTwistedStrip(float radius_min,  float radius_max, float turns)
Pierre Kraemer's avatar
Pierre Kraemer committed
981
982
983
984
985
986
987
988
989
{
	typedef typename PFP::VEC3 VEC3 ;

	float alpha = float(2.0*M_PI/m_ny);
	float beta = turns/float(m_ny);

	float radius = (radius_max + radius_min)/2.0f;
	float rdiff = (radius_max - radius_min)/2.0f;

Pierre Kraemer's avatar
Pierre Kraemer committed
990
	for(unsigned int i = 0; i <= m_ny; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
991
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
992
		for(unsigned int j = 0; j <= m_nx; ++j)
Pierre Kraemer's avatar
Pierre Kraemer committed
993
994
995
996
		{
			float rw = -rdiff + float(j)*2.0f*rdiff/float(m_nx);
			float r = radius + rw*cos(beta*float(i));
			VEC3 pos(r*cos(alpha*float(i)), r*sin(alpha*float(i)), rw*sin(beta*float(i)));
997
			m_positions[ m_tableVertDarts[ i*(m_nx+1)+j ] ] = pos;
Pierre Kraemer's avatar
Pierre Kraemer committed
998
999
1000
1001
1002
		}
	}
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
1003
void Polyhedron<PFP>::embedHelicoid(float radius_min, float radius_max, float maxHeight, float nbTurn, int orient)
Pierre Kraemer's avatar
Pierre Kraemer committed
1004
1005
1006
1007
1008
1009
1010
1011
1012
{
	typedef typename PFP::VEC3 VEC3 ;

	float alpha = float(2.0*M_PI/m_nx)*nbTurn;
	float hS = maxHeight/m_nx;

// 	float radius = (radius_max + radius_min)/2.0f;
// 	float rdiff = (radius_max - radius_min)/2.0f;

Pierre Kraemer's avatar
Pierre Kraemer committed
1013
	for(unsigned int i = 0; i <= m_ny; ++i)
Pierre Kraemer's avatar
Pierre Kraemer committed
1014
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
1015
		for(unsigned int j = 0; j <= m_nx; ++j)
Pierre Kraemer's avatar
Pierre Kraemer committed
1016
1017
1018
		{
// 			float r = radius_max + radius_min*cos(beta*float(j));
			float r,x,y;
Thomas's avatar
Thomas committed
1019
1020
1021
1022
// 			if(i==1) {
// 				r = radius_max;
// 			}
// 			else {
Pierre Kraemer's avatar
Pierre Kraemer committed
1023
				r = radius_min+(radius_max-radius_min)*float(i)/float(m_ny);
Thomas's avatar
Thomas committed
1024
1025
1026
// 			}
			x = orient*r*sin(alpha*float(j));
			y = orient*r*cos(alpha*float(j));
Pierre Kraemer's avatar
Pierre Kraemer committed
1027
1028
1029

			VEC3 pos(x, y, j*hS);
			Dart d = m_tableVertDarts[i*(m_nx+1)+j];
Pierre Kraemer's avatar
Pierre Kraemer committed
1030
			m_positions[d] = pos;
Pierre Kraemer's avatar
Pierre Kraemer committed
1031
1032
1033
1034
		}
	}
}

Sylvain Thery's avatar
Sylvain Thery committed
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
 template <typename PFP>
 void quads2TrianglesCC(typename PFP::MAP& the_map, Dart primd)
 {
 	DartMarker m(the_map);

 	// list of faces to process and processed(before pos iterator)
 	std::list<Dart> ld;
 	ld.push_back(primd);
 	// current position in list
 	typename std::list<Dart>::iterator pos = ld.begin();
 	do
 	{
 		Dart d = *pos;

 		// cut the face of first dart of list
 		Dart d1 = the_map.phi1(d);
 		Dart e = the_map.phi1(d1);
 		Dart e1 = the_map.phi1(e);
 		Dart f = the_map.phi1(e1);
 		if (f==d) // quad
 		{
 			the_map.splitFace(d,e);
 			// mark the face
 			m.markOrbit<FACE>(d);
 			m.markOrbit<FACE>(e);
 		}
 		else m.markOrbit<FACE>(d);

 		// and store neighbours faces in the list
 		d = the_map.phi2(d);
 		e = the_map.phi2(e);
 		d1 = the_map.phi1(the_map.phi2(d1));
 		e1 = the_map.phi1(the_map.phi2(e1));

 		if (!m.isMarked(d))
 			ld.push_back(d);
 		if (!m.isMarked(e))
 			ld.push_back(e);
 		if (!m.isMarked(d1))
 			ld.push_back(d1);
 		if ((f==d) && (!m.isMarked(e1)))
 			ld.push_back(e1);
 		pos++;
 	}while (pos!=ld.end()); // stop when no more face to process
 }
Pierre Kraemer's avatar
Pierre Kraemer committed
1080
1081
1082
1083

// template <typename PFP>
// Dart triangleFan_topo(typename PFP::MAP& the_map, int n)
// {
1084
// 	Dart d = the_map.newFace(3,false);
Pierre Kraemer's avatar
Pierre Kraemer committed
1085
1086
1087
// 	Dart e = the_map.phi1(d);
// 	for(int i=1;i<n;++i)
// 	{
1088
// 		Dart f = the_map.newFace(3,false);
Pierre Kraemer's avatar
Pierre Kraemer committed
1089
1090
1091
1092
1093
1094
1095
// 		the_map.sewFaces(the_map.phi_1(f),e);
// 		e = the_map.phi1(f);
// 	}
// 	the_map.sewFaces(the_map.phi_1(d),e);
// 	return d;
// }

Pierre Kraemer's avatar
Pierre Kraemer committed
1096
} // namespace Modelisation
Pierre Kraemer's avatar
Pierre Kraemer committed
1097

Pierre Kraemer's avatar
Pierre Kraemer committed
1098
} // namespace Algo
Pierre Kraemer's avatar
Pierre Kraemer committed
1099

Pierre Kraemer's avatar
Pierre Kraemer committed
1100
} // namespace CGoGN