tetrahedralization.hpp 23.2 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
 * Contact information: cgogn@unistra.fr                                        *
 *                                                                              *
 *******************************************************************************/

25
#include "Algo/Modelisation/subdivision3.h"
untereiner's avatar
untereiner committed
26
#include "Topology/generic/traversor3.h"
27
#include "Algo/Modelisation/subdivision.h"
untereiner's avatar
untereiner committed
28

Pierre Kraemer's avatar
Pierre Kraemer committed
29
30
31
32
33
34
namespace CGoGN
{

namespace Algo
{

35
36
37
namespace Volume
{

Pierre Kraemer's avatar
Pierre Kraemer committed
38
39
40
namespace Modelisation
{

untereiner's avatar
untereiner committed
41
namespace Tetrahedralization
Pierre Kraemer's avatar
Pierre Kraemer committed
42
{
untereiner's avatar
untereiner committed
43

44
45
46
47
48
49
50
//template <typename PFP>
//void hexahedronToTetrahedron(typename PFP::MAP& map, Dart d)
//{
//	Dart d1 = d;
//	Dart d2 = map.phi1(map.phi1(d));
//	Dart d3 = map.phi_1(map.phi2(d));
//	Dart d4 = map.phi1(map.phi1(map.phi2(map.phi_1(d3))));
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
//	Algo::Modelisation::cut3Ear<PFP>(map,d1);
//	Algo::Modelisation::cut3Ear<PFP>(map,d2);
//	Algo::Modelisation::cut3Ear<PFP>(map,d3);
//	Algo::Modelisation::cut3Ear<PFP>(map,d4);
//}
//
//template <typename PFP>
//void hexahedronsToTetrahedrons(typename PFP::MAP& map)
//{
//    TraversorV<typename PFP::MAP> tv(map);
//
//    //for each vertex
//    for(Dart d = tv.begin() ; d != tv.end() ; d = tv.next())
//    {
//        bool vertToTet=true;
//        std::vector<Dart> dov;
//        dov.reserve(32);
//        FunctorStore fs(dov);
//        map.foreach_dart_of_vertex(d,fs);
//        CellMarkerStore<VOLUME> cmv(map);
//
//        //check if all vertices degree is equal to 3 (= no direct adjacent vertex has been split)
//        for(std::vector<Dart>::iterator it=dov.begin();vertToTet && it!=dov.end();++it)
//        {
Thery Sylvain's avatar
Thery Sylvain committed
76
//            if(!cmv.isMarked(*it) && !map.isBoundaryMarked3(*it))
77
78
79
80
81
82
83
84
85
86
87
//            {
//                cmv.mark(*it);
//                vertToTet = (map.phi1(map.phi2(map.phi1(map.phi2(map.phi1(map.phi2(*it))))))==*it); //degree = 3
//            }
//        }
//
//        //if ok : create tetrahedrons around the vertex
//        if(vertToTet)
//        {
//            for(std::vector<Dart>::iterator it=dov.begin();it!=dov.end();++it)
//            {
Thery Sylvain's avatar
Thery Sylvain committed
88
//                if(cmv.isMarked(*it) && !map.isBoundaryMarked3(*it))
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
//                {
//                    cmv.unmark(*it);
//                    cut3Ear<PFP>(map,*it);
//                }
//            }
//        }
//    }
//}
//
//template <typename PFP>
//void tetrahedrizeVolume(typename PFP::MAP& map, VertexAttribute<typename PFP::VEC3>& position)
//{
//	//mark bad edges
//	DartMarkerStore mBadEdge(map);
//
//	std::vector<Dart> vEdge;
//	vEdge.reserve(1024);
//
////	unsignzed int i = 0;
//
//	unsigned int nbEdges = map.template getNbOrbits<EDGE>();
//	unsigned int i = 0;
//
//	for(Dart dit = map.begin() ; dit != map.end() ; map.next(dit))
//	{
//		//check if this edge is an "ear-edge"
//		if(!mBadEdge.isMarked(dit))
//		{
//			++i;
//			std::cout << i << " / " << nbEdges << std::endl;
//
//			//search three positions
//			typename PFP::VEC3 tris1[3];
//			tris1[0] = position[dit];
//			tris1[1] = position[map.phi_1(dit)];
//			tris1[2] = position[map.phi_1(map.phi2(dit))];
//
//			//search if the triangle formed by these three points intersect the rest of the mesh (intersection triangle/triangle)
//			TraversorF<typename PFP::MAP> travF(map);
//			for(Dart ditF = travF.begin() ; ditF != travF.end() ; ditF = travF.next())
//			{
//				//get vertices position
//				typename PFP::VEC3 tris2[3];
//				tris2[0] = position[ditF];
//				tris2[1] = position[map.phi1(ditF)];
//				tris2[2] = position[map.phi_1(ditF)];
//
//				bool intersection = false;
//
//				for (unsigned int i = 0; i < 3 && !intersection; ++i)
//				{
//					typename PFP::VEC3 inter;
//					intersection = Geom::intersectionSegmentTriangle(tris1[i], tris1[(i+1)%3], tris2[0], tris2[1], tris2[2], inter);
//				}
//
//				if(!intersection)
//				{
//					for (unsigned int i = 0; i < 3 && !intersection; ++i)
//					{
//						typename PFP::VEC3 inter;
//						intersection = Geom::intersectionSegmentTriangle(tris2[i], tris2[(i+1)%3], tris1[0], tris1[1], tris1[2], inter);
//					}
//				}
//
//				//std::cout << "intersection ? " << (intersection ? "true" : "false") << std::endl;
//
//				if(intersection)
//				{
//					mBadEdge.markOrbit<EDGE>(dit);
//				}
//				else //cut a tetrahedron
//				{
//					vEdge.push_back(dit);
//				}
//
//
////
////				if(i == 16)
////					return;
//			}
//		}
//	}
//
//	std::cout << "nb edges to split = " << vEdge.size() << std::endl;
//	i = 0;
//	for(std::vector<Dart>::iterator it = vEdge.begin() ; it != vEdge.end() ; ++it)
//	{
//		++i;
//		std::cout << i << " / " << vEdge.size() << std::endl;
//
//		Dart dit = *it;
//
//		//std::cout << "cut cut " << std::endl;
//		std::vector<Dart> vPath;
//
//		vPath.push_back(map.phi1(dit));
//		vPath.push_back(map.phi1(map.phi2(map.phi_1(dit))));
//		vPath.push_back(map.phi_1(map.phi2(dit)));
//
//		map.splitVolume(vPath);
//
//		map.splitFace(map.phi2(map.phi1(dit)), map.phi2(map.phi1(map.phi2(dit))));
//	}
//
//	std::cout << "finished " << std::endl;
//}
195

untereiner's avatar
untereiner committed
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
 * 									Collapse / Split Operators
 ************************************************************************************************/
template <typename PFP>
Dart splitVertex(typename PFP::MAP& map, std::vector<Dart>& vd)
{
	//split the vertex
	Dart dres = map.splitVertex(vd);

	//split the faces incident to the new vertex
	Dart dbegin = map.phi1(map.phi2(vd.front()));
	Dart dit = dbegin;
	do
	{
		map.splitFace(map.phi1(dit),map.phi_1(dit));
		dit = map.alpha2(dit);
	}
	while(dbegin != dit);

	//split the volumes incident to the new vertex
	for(unsigned int i = 0; i < vd.size(); ++i)
	{
		Dart dit = vd[i];

		std::vector<Dart> v;
		v.push_back(map.phi1(map.phi1(map.phi2(dit))));
		std::cout << "[" << v.back();
		v.push_back(map.phi1(dit));
		std::cout << " - " << v.back();
		v.push_back(map.phi1(map.phi2(map.phi_1(dit))));
		std::cout << " - " << v.back() << "]" << std::endl;
228
		map.splitVolume(v);
229
230
231
232
233
	}

	return dres;
}

234
235
236
/*************************************************************************************************
 *		 								Tetrahedron functions									 *
 *************************************************************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
237
238

template <typename PFP>
239
bool isTetrahedron(typename PFP::MAP& the_map, Dart d, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
240
{
untereiner's avatar
untereiner committed
241
	unsigned int nbFaces = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
242
243

	//Test the number of faces end its valency
244
	Traversor3WF<typename PFP::MAP> travWF(the_map, d, false, thread);
untereiner's avatar
untereiner committed
245
	for(Dart dit = travWF.begin() ; dit != travWF.end(); dit = travWF.next())
Pierre Kraemer's avatar
Pierre Kraemer committed
246
	{
untereiner's avatar
untereiner committed
247
248
249
250
251
252
253
254
		//increase the number of faces
		nbFaces++;
		if(nbFaces > 4)	//too much faces
			return false;

		//test the valency of this face
		if(the_map.faceDegree(dit) != 3)
			return false;
Pierre Kraemer's avatar
Pierre Kraemer committed
255
256
	}

Thomas's avatar
Thomas committed
257
	return true;
Pierre Kraemer's avatar
Pierre Kraemer committed
258
259
}

260
template <typename PFP>
261
bool isTetrahedralization(typename PFP::MAP& map)
262
{
263
	TraversorW<typename PFP::MAP> travW(map);
264
	for(Dart dit = travW.begin() ; dit != travW.end() ; dit = travW.next())
265
266
267
268
269
270
271
272
	{
		if(!isTetrahedron<PFP>(map, dit))
			return false;
	}

	return true;
}

273
274
275
/***********************************************************************************************
 * 										swap functions										   *
 ***********************************************************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
276

277
template <typename PFP>
278
Dart swap2To2(typename PFP::MAP& map, Dart d)
279
{
280
	std::vector<Dart> edges;
281

282
283
284
285
	Dart d2_1 = map.phi_1(map.phi2(d));
	map.mergeVolumes(d);
	map.mergeFaces(map.phi1(d2_1));
	map.splitFace(d2_1, map.phi1(map.phi1(d2_1)));
286

287
288
289
290
291
292
293
294
		Dart stop = map.phi_1(d2_1);
		Dart dit = stop;
		do
		{
			edges.push_back(dit);
			dit = map.phi1(map.phi2(map.phi1(dit)));
		}
		while(dit != stop);
295

296
		map.splitVolume(edges);
Pierre Kraemer's avatar
Pierre Kraemer committed
297

298
	return map.phi2(stop);
Pierre Kraemer's avatar
Pierre Kraemer committed
299
300
301
}

template <typename PFP>
302
void swap4To4(typename PFP::MAP& map, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
303
{
304
305
	Dart e = map.phi2(map.phi3(d));
	Dart dd = map.phi2(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
306
307

	//unsew middle crossing darts
308
309
	map.unsewVolumes(d);
	map.unsewVolumes(map.phi2(map.phi3(dd)));
Pierre Kraemer's avatar
Pierre Kraemer committed
310

311
312
	Dart d1 = Tetrahedralization::swap2To2<PFP>(map, dd);
	Dart d2 = Tetrahedralization::swap2To2<PFP>(map, e);
Pierre Kraemer's avatar
Pierre Kraemer committed
313
314

	//sew middle darts so that they do not cross
315
316
	map.sewVolumes(map.phi2(d1),map.phi2(map.phi3(d2)));
	map.sewVolumes(map.phi2(map.phi3(d1)),map.phi2(d2));
Pierre Kraemer's avatar
Pierre Kraemer committed
317
318
319
}

template <typename PFP>
320
Dart swap3To2(typename PFP::MAP& map, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
321
{
322
	std::vector<Dart> edges;
323

324
325
326
327
328
329
	Dart stop = map.phi_1(map.phi2(map.phi1(d)));
	Dart d2 = map.phi2(d);
	Dart d21 = map.phi1(d2);
	map.mergeVolumes(d);
	map.mergeFaces(d2);
	map.mergeVolumes(d21);
330

331
332
333
334
335
336
337
338
	Dart dit = stop;
	do
	{
		edges.push_back(dit);
		dit = map.phi1(map.phi2(map.phi1(dit)));
	}
	while(dit != stop);
	map.splitVolume(edges);
Pierre Kraemer's avatar
Pierre Kraemer committed
339

340
	return map.phi3(stop);
Pierre Kraemer's avatar
Pierre Kraemer committed
341
342
343
344
345
}

//[precond] le brin doit venir d'une face partagé par 2 tetraèdres
// renvoie un brin de l'ancienne couture entre les 2 tetras qui est devenu une arête
template <typename PFP>
346
Dart swap2To3(typename PFP::MAP& map, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
347
{
348
	std::vector<Dart> edges;
untereiner's avatar
untereiner committed
349

350
351
	Dart d2_1 = map.phi_1(map.phi2(d));
	map.mergeVolumes(d);
untereiner's avatar
untereiner committed
352

353
354
355
356
357
358
	//
	// Cut the 1st tetrahedron
	//
	Dart stop = d2_1;
	Dart dit = stop;
	do
untereiner's avatar
untereiner committed
359
	{
360
361
362
363
		edges.push_back(dit);
		dit = map.phi1(map.phi2(map.phi1(dit)));
	}
	while(dit != stop);
untereiner's avatar
untereiner committed
364

365
366
	map.splitVolume(edges);
	map.splitFace(map.alpha2(edges[0]), map.alpha2(edges[2]));
untereiner's avatar
untereiner committed
367

368
369
370
371
372
373
374
375
376
377
	//
	// Cut the 2nd tetrahedron
	//
	edges.clear();
	stop = map.phi1(map.phi2(d2_1));
	dit = stop;
	do
	{
		edges.push_back(dit);
		dit = map.phi1(map.phi2(map.phi1(dit)));
untereiner's avatar
untereiner committed
378
	}
379
380
	while(dit != stop);
	map.splitVolume(edges);
untereiner's avatar
untereiner committed
381

382
383
	return map.phi1(d2_1);
}
untereiner's avatar
untereiner committed
384

385
386
387
388
389
template <typename PFP>
Dart swap5To4(typename PFP::MAP& map, Dart d)
{
	Dart t1 = map.phi3(d);
	Dart t2 = map.phi3(map.phi2(d));
untereiner's avatar
untereiner committed
390

391
392
	Dart d323 = map.phi_1(map.phi2(map.phi1(d)));
	Dart dswap = map.phi2(map.phi3(d323));
untereiner's avatar
untereiner committed
393

394
395
396
397
398
	map.unsewVolumes(t1);
	map.unsewVolumes(t2);
	map.unsewVolumes(d323);
	map.unsewVolumes(map.phi2(d323));
	map.deleteVolume(d);
untereiner's avatar
untereiner committed
399

400
	Dart d1 = Tetrahedralization::swap2To2<PFP>(map, dswap);
untereiner's avatar
untereiner committed
401

402
403
	map.sewVolumes(map.phi2(d1), t1);
	map.sewVolumes(map.phi2(map.phi3(d1)),t2);
untereiner's avatar
untereiner committed
404

405
406
	return t1;
}
untereiner's avatar
untereiner committed
407

408
409
410
411
412
413
template <typename PFP>
void swapGen3To2(typename PFP::MAP& map, Dart d)
{
	unsigned int n = map.edgeDegree(d);


414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
    if(n >= 4)
    {
        Dart dit = d;
        for(unsigned int i = 0 ; i < n - 4 ; ++i)
        {
            dit = map.phi2(Tetrahedralization::swap2To3<PFP>(map, dit));
        }
        Tetrahedralization::swap4To4<PFP>(map,  map.alpha2(dit));
    }




//	if(n >= 4)
//	{
//		Dart dit = d;
//		if(map.isBoundaryEdge(dit))
//		{
//			for(unsigned int i = 0 ; i < n - 2 ; ++i)
//			{
//				dit = map.phi2(Tetrahedralization::swap2To3<PFP>(map, dit));
//			}
//			Tetrahedralization::swap2To2<PFP>(map, dit);
//		}
//		else
//		{
//			for(unsigned int i = 0 ; i < n - 4 ; ++i)
//			{
//				dit = map.phi2(Tetrahedralization::swap2To3<PFP>(map, dit));
//			}
//			Tetrahedralization::swap4To4<PFP>(map,  map.alpha2(dit));
//		}
//	}
//	else if (n == 3)
//	{
//		Dart dres = Tetrahedralization::swap2To3<PFP>(map, d);
//		Tetrahedralization::swap2To2<PFP>(map, map.phi2(dres));
//	}
//	else // si (n == 2)
//	{
//		Tetrahedralization::swap2To2<PFP>(map, d);
//	}
456
457
458
459
460
461

}

template <typename PFP>
void swapGen2To3(typename PFP::MAP& map, Dart d)
{
462
//	unsigned int n = map.edgeDegree(d);
463

464
//- a single 2-3 swap, followed by n − 3 3-2 swaps, or
465
//- a single 4-4 swap, followed by n − 4 3-2 swaps.
466
467
468
469
470
}




471
472
473
/************************************************************************************************
 *										Flip Functions 											*
 ************************************************************************************************/
untereiner's avatar
untereiner committed
474

475
template <typename PFP>
476
Dart flip1To4(typename PFP::MAP& map, Dart d)
477
478
479
480
481
482
483
484
485
486
487
{
	std::vector<Dart> edges;

	//
	// Cut the 1st tetrahedron
	//
	edges.push_back(map.phi2(d));
	edges.push_back(map.phi2(map.phi1(d)));
	edges.push_back(map.phi2(map.phi_1(d)));
	map.splitVolume(edges);

488
	Dart x = Surface::Modelisation::trianguleFace<PFP>(map,map.phi2(d));
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519

	//
	// Cut the 2nd tetrahedron
	//
	Dart dit = map.phi2(map.phi3(x));
	edges.clear();
	edges.push_back(dit);
	dit = map.phi1(map.phi2(map.phi1(dit)));
	edges.push_back(dit);
	dit = map.phi1(dit);
	edges.push_back(dit);
	dit = map.phi1(map.phi2(map.phi1(dit)));
	edges.push_back(dit);

	map.splitVolume(edges);
	map.splitFace(map.phi1(map.phi2(edges[0])),map.phi1(map.phi2(edges[2])));

	//
	// Cut the 3rd tetrahedron
	//
	dit = map.phi3(map.phi1(map.phi2(edges[0])));
	edges.clear();
	edges.push_back(dit);
	dit = map.phi1(map.phi2(map.phi1(dit)));
	edges.push_back(dit);
	dit = map.phi1(map.phi2(map.phi1(dit)));
	edges.push_back(dit);

	map.splitVolume(edges);

	return x;
520
521
}

522
template <typename PFP>
523
Dart flip1To3(typename PFP::MAP& map, Dart d)
524
525
526
527
528
529
{
	std::vector<Dart> edges;

	//
	// Triangule one face
	//
530
	Dart x = Surface::Modelisation::trianguleFace<PFP>(map,d);
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559

	//
	// Cut the 1st Tetrahedron
	//
	Dart dit = x;
	edges.push_back(dit);
	dit = map.phi1(map.phi2(map.phi1(dit)));
	edges.push_back(dit);
	dit = map.phi1(map.phi2(map.phi1(dit)));
	edges.push_back(dit);
	dit = map.phi1(map.phi2(map.phi1(dit)));
	edges.push_back(dit);

	map.splitVolume(edges);
	map.splitFace(map.phi1(map.phi2(edges[0])),map.phi1(map.phi2(edges[2])));

	// Cut the 2nd Tetrahedron
	dit = map.phi1(map.phi2(edges[0]));
	edges.clear();
	edges.push_back(dit);
	dit = map.phi1(map.phi2(map.phi1(dit)));
	edges.push_back(dit);
	dit = map.phi1(map.phi2(map.phi1(dit)));
	edges.push_back(dit);

	map.splitVolume(edges);

	return x;
}
untereiner's avatar
untereiner committed
560
561


562
/************************************************************************************************
563
 *                				 Bisection Functions                                            *
564
 ************************************************************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
565

566
template <typename PFP>
567
Dart edgeBisection(typename PFP::MAP& map, Dart d)
568
569
570
571
572
{
	//coupe l'arete en 2
	map.cutEdge(d);
	Dart e = map.phi1(d);

573
	Dart dit = e;
574
	do
575
	{
576
		map.splitFace(dit, map.phi1(map.phi1(dit)));
577
578
579
		dit = map.alpha2(dit);
	}
	while(dit != e);
Pierre Kraemer's avatar
Pierre Kraemer committed
580

581
582
583
584
	dit = e;
	std::vector<Dart> edges;
	do
	{
Thery Sylvain's avatar
Thery Sylvain committed
585
		if(!map.isBoundaryMarked3(dit))
586
587
588
589
590
591
592
		{
			edges.push_back(map.phi_1(dit));
			edges.push_back(map.phi_1(map.phi2(map.phi_1(edges[0]))));
			edges.push_back(map.phi1(map.phi2(dit)));
			map.splitVolume(edges);
			edges.clear();
		}
593
		dit = map.alpha2(dit);
594
595
	}
	while(dit != e);
Pierre Kraemer's avatar
Pierre Kraemer committed
596

597
	return e;
Pierre Kraemer's avatar
Pierre Kraemer committed
598
599
}

Pierre Kraemer's avatar
Pierre Kraemer committed
600

untereiner's avatar
untereiner committed
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
///**
// * create a tetra based on the two triangles that have a common dart and phi2(dart)
// * return a new dart inside the tetra
// */
//template<typename PFP>
//Dart extractTetra(typename PFP::MAP& the_map, Dart d)
//{
//
//
//	Dart e = the_map.phi2(d);
//
//	//create the new faces
//	Dart dd = the_map.newFace(3);
//	Dart ee = the_map.newFace(3);
//
//	//update their sew
//	the_map.sewFaces(dd,ee);
//	the_map.sewFaces(the_map.phi3(dd),the_map.phi3(ee));
//
//	//add the two new faces in the mesh to obtain a tetra
//	Dart s2d = the_map.phi2(the_map.phi_1(d));
//	the_map.unsewFaces(the_map.phi_1(d));
//	the_map.sewFaces(the_map.phi_1(d),the_map.phi_1(dd));
//	the_map.sewFaces(s2d,the_map.phi3(the_map.phi_1(dd)));
//
//	Dart s2e = the_map.phi2(the_map.phi_1(e));
//	the_map.unsewFaces(the_map.phi_1(e));
//	the_map.sewFaces(the_map.phi_1(e),the_map.phi_1(ee));
//	the_map.sewFaces(s2e,the_map.phi3(the_map.phi_1(ee)));
//
//	Dart ss2d = the_map.phi2(the_map.phi1(d));
//	the_map.unsewFaces(the_map.phi1(d));
//	the_map.sewFaces(the_map.phi1(d),the_map.phi1(ee));
//	the_map.sewFaces(ss2d,the_map.phi3(the_map.phi1(ee)));
//
//	Dart ss2e = the_map.phi2(the_map.phi1(e));
//	the_map.unsewFaces(the_map.phi1(e));
//	the_map.sewFaces(the_map.phi1(e),the_map.phi1(dd));
//	the_map.sewFaces(ss2e,the_map.phi3(the_map.phi1(dd)));
//
//	//embed the coords
//	the_map.setVertexEmb(d,the_map.getVertexEmb(d));
//	the_map.setVertexEmb(e,the_map.getVertexEmb(e));
//	the_map.setVertexEmb(the_map.phi_1(d),the_map.getVertexEmb(the_map.phi_1(d)));
//	the_map.setVertexEmb(the_map.phi_1(e),the_map.getVertexEmb(the_map.phi_1(e)));
//
//	return dd;
//}
//
///**
// * tetrahedrization of the volume
// * @param the map
// * @param a dart of the volume
// * @param true if the faces are in CCW order
// * @return success of the tetrahedrization
// */
//template<typename PFP>
//bool smartVolumeTetrahedrization(typename PFP::MAP& the_map, Dart d, bool CCW=true)
//{
//
//	typedef typename PFP::EMB EMB;
//
//	bool ret=true;
//
//	if (!the_map.isTetrahedron(d))
//	{
//		//only works on a 3-map
//		assert(Dart::nbInvolutions()>=2 || "cannot be applied on this map, nbInvolutions must be at least 2");
//
//		if (Geometry::isConvex<PFP>(the_map,d,CCW))
//		{
//			the_map.tetrahedrizeVolume(d);
//		}
//		else
//		{
//
//			//get all the dart of the volume
//			std::vector<Dart> vStore;
//			FunctorStore fs(vStore);
//			the_map.foreach_dart_of_volume(d,fs);
//
//			if (vStore.size()==0)
//			{
//				if (the_map.phi1(d)==d)
//					CGoGNout << "plop" << CGoGNendl;
//				if (the_map.phi2(d)==d)
//					CGoGNout << "plip" << CGoGNendl;
//
//				CGoGNout << the_map.getVertexEmb(d)->getPosition() << CGoGNendl;
//				CGoGNout << "tiens tiens, c'est etrange" << CGoGNendl;
//			}
//			//prepare the list of embeddings of the current volume
//			std::vector<EMB *> lstEmb;
//
//			//get a marker
//			DartMarker m(the_map);
//
//			//all the darts from a vertex that can generate a tetra (3 adjacent faces)
//			std::vector<Dart> allowTetra;
//
//			//all the darts that are not in otherTetra
//			std::vector<Dart> otherTetra;
//
//			//for each dart of the volume
//			for (typename std::vector<Dart>::iterator it = vStore.begin() ; it != vStore.end() ; ++it )
//			{
//				Dart e = *it;
//				//if the vertex is not treated
//				if (!m.isMarked(e))
//				{
//					//store the embedding
//					lstEmb.push_back(reinterpret_cast<EMB*>(the_map.getVertexEmb(e)));
//					Dart ee=e;
//
//					//count the number of adjacent faces and mark the darts
//					int nbe=0;
//					do
//					{
//						nbe++;
//						m.markOrbit(DART,e);
//						ee=the_map.phi1(the_map.phi2(ee));
//					}
//					while (ee!=e);
//
//					//if 3 adjacents faces, we can create a tetra on this vertex
//					if (nbe==3)
//						allowTetra.push_back(e);
//					else
//						otherTetra.push_back(e);
//				}
//			}
//
//			//we haven't created a tetra yet
//			bool decoupe=false;
//
//			//if we have vertex that can be base
//			if (allowTetra.size()!=0)
//			{
//				//foreach possible vertex while we haven't done any cut
//				for (typename std::vector<Dart>::iterator it=allowTetra.begin();it!=allowTetra.end() && !decoupe ;++it)
//				{
//					//get the dart
//					Dart s=*it;
//					//store the emb
//					std::vector<EMB*> lstCurEmb;
//					lstCurEmb.push_back(reinterpret_cast<EMB*>(the_map.getVertexEmb(s)));
//					lstCurEmb.push_back(reinterpret_cast<EMB*>(the_map.getVertexEmb(the_map.phi1(s))));
//					lstCurEmb.push_back(reinterpret_cast<EMB*>(the_map.getVertexEmb(the_map.phi_1(s))));
//					lstCurEmb.push_back(reinterpret_cast<EMB*>(the_map.getVertexEmb(the_map.phi_1(the_map.phi2(s)))));
//
//					//store the coords of the point
//					gmtl::Vec3f points[4];
//					for (int i=0;i<4;++i)
//					{
//						points[i] = lstCurEmb[i]->getPosition();
//					}
//
//					//test if the future tetra is well oriented (concave case)
//					if (Geometry::isTetrahedronWellOriented(points,CCW))
//					{
//						//test if we haven't any point inside the future tetra
//						bool isEmpty=true;
//						for (typename std::vector<EMB *>::iterator iter = lstEmb.begin() ; iter != lstEmb.end() && isEmpty ; ++iter)
//						{
//							//we don't test the vertex that composes the new tetra
//							if (std::find(lstCurEmb.begin(),lstCurEmb.end(),*iter)==lstCurEmb.end())
//							{
//								isEmpty = !Geometry::isPointInTetrahedron(points, (*iter)->getPosition(), CCW);
//							}
//						}
//
//						//if no point inside the new tetra
//						if (isEmpty)
//						{
//							//cut the spike to make a tet
//							Dart dRes = the_map.cutSpike(*it);
//							decoupe=true;
//							//and continue with the rest of the volume
//							ret = ret && smartVolumeTetrahedrization<PFP>(the_map,the_map.phi3(dRes),CCW);
//						}
//					}
//				}
//			}
//
//			if (!decoupe)
//			{
//				//foreach other vertex while we haven't done any cut
//				for (typename std::vector<Dart>::iterator it=otherTetra.begin();it!=otherTetra.end() && !decoupe ;++it)
//				{
//					//get the dart
//					Dart s=*it;
//					//store the emb
//					std::vector<EMB*> lstCurEmb;
//					lstCurEmb.push_back(reinterpret_cast<EMB*>(the_map.getVertexEmb(s)));
//					lstCurEmb.push_back(reinterpret_cast<EMB*>(the_map.getVertexEmb(the_map.phi1(s))));
//					lstCurEmb.push_back(reinterpret_cast<EMB*>(the_map.getVertexEmb(the_map.phi_1(s))));
//					lstCurEmb.push_back(reinterpret_cast<EMB*>(the_map.getVertexEmb(the_map.phi_1(the_map.phi2(s)))));
//
//					//store the coords of the point
//					gmtl::Vec3f points[4];
//					for (int i=0;i<4;++i)
//					{
//						points[i] = lstCurEmb[i]->getPosition();
//					}
//
//					//test if the future tetra is well oriented (concave case)
//					if (Geometry::isTetrahedronWellOriented(points,CCW))
//					{
//						//test if we haven't any point inside the future tetra
//						bool isEmpty=true;
//						for (typename std::vector<EMB *>::iterator iter = lstEmb.begin() ; iter != lstEmb.end() && isEmpty ; ++iter)
//						{
//							//we don't test the vertex that composes the new tetra
//							if (std::find(lstCurEmb.begin(),lstCurEmb.end(),*iter)==lstCurEmb.end())
//							{
//								isEmpty = !Geometry::isPointInTetrahedron(points, (*iter)->getPosition(), CCW);
//							}
//						}
//
//						//if no point inside the new tetra
//						if (isEmpty)
//						{
//							//cut the spike to make a tet
//							Dart dRes = extractTetra<PFP>(the_map,*it);
//							decoupe=true;
//							//and continue with the rest of the volume
//							smartVolumeTetrahedrization<PFP>(the_map,the_map.phi3(dRes),CCW);
//						}
//					}
//				}
//			}
//
//			if (!decoupe)
//				ret=false;
//		}
//	}
//	return ret;
//}

Pierre Kraemer's avatar
Pierre Kraemer committed
840
} // namespace Tetrahedralization
untereiner's avatar
untereiner committed
841

842
843
}

Pierre Kraemer's avatar
Pierre Kraemer committed
844
} // namespace Modelisation
Pierre Kraemer's avatar
Pierre Kraemer committed
845

Pierre Kraemer's avatar
Pierre Kraemer committed
846
} // namespace Algo
Pierre Kraemer's avatar
Pierre Kraemer committed
847

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