Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

tetrahedralization.hpp 39.1 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/subdivision.h"
26
27
#include "Algo/Modelisation/subdivision3.h"
#include "Topology/generic/traversor/traversor3.h"
untereiner's avatar
untereiner committed
28

29

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

namespace Algo
{

36
37
38
namespace Volume
{

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

untereiner's avatar
untereiner committed
42
namespace Tetrahedralization
Pierre Kraemer's avatar
Pierre Kraemer committed
43
{
untereiner's avatar
untereiner committed
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
template<typename PFP>
bool EarTriangulation<PFP>::inTriangle(const typename PFP::VEC3& P, const typename PFP::VEC3& normal, const typename PFP::VEC3& Ta,  const typename PFP::VEC3& Tb, const typename PFP::VEC3& Tc)
{
	typedef typename PFP::VEC3 VECT ;
	typedef typename VECT::DATA_TYPE T ;

	if (Geom::tripleProduct(P-Ta, (Tb-Ta), normal) >= T(0))
		return false;

	if (Geom::tripleProduct(P-Tb, (Tc-Tb), normal) >= T(0))
		return false;

	if (Geom::tripleProduct(P-Tc, (Ta-Tc), normal) >= T(0))
		return false;

	return true;
}

template<typename PFP>
void EarTriangulation<PFP>::recompute2Ears( Dart d, const typename PFP::VEC3& normalPoly, bool convex)
{
	Dart d2 = m_map.phi_1(d);
	Dart d_p = m_map.phi_1(d2);
	Dart d_n = m_map.phi1(d);

	const typename PFP::VEC3& Ta = m_position[d2];
	const typename PFP::VEC3& Tb = m_position[d];
	const typename PFP::VEC3& Tc = m_position[d_p];
	const typename PFP::VEC3& Td = m_position[d_n];

	// compute angle
	typename PFP::VEC3 v1= Tb - Ta;
	typename PFP::VEC3 v2= Tc - Ta;
	typename PFP::VEC3 v3= Td - Tb;

	v1.normalize();
	v2.normalize();
	v3.normalize();

//	float dotpr1 = 1.0f - (v1*v2);
//	float dotpr2 = 1.0f + (v1*v3);
	float dotpr1 = acos(v1*v2) / (M_PI/2.0f);
	float dotpr2 = acos(-(v1*v3)) / (M_PI/2.0f);

	if (!convex)	// if convex no need to test if vertex is an ear (yes)
	{
		typename PFP::VEC3 nv1 = v1^v2;
		typename PFP::VEC3 nv2 = v1^v3;

		if (nv1*normalPoly < 0.0)
			dotpr1 = 10.0f - dotpr1;// not an ears  (concave)
		if (nv2*normalPoly < 0.0)
			dotpr2 = 10.0f - dotpr2;// not an ears  (concave)

		bool finished = (dotpr1>=5.0f) && (dotpr2>=5.0f);
		for (typename VPMS::reverse_iterator it = m_ears.rbegin(); (!finished)&&(it != m_ears.rend())&&(it->angle > 5.0f); ++it)
		{
			Dart dx = it->dart;
			const typename PFP::VEC3& P = m_position[dx];

			if ((dotpr1 < 5.0f) && (d != d_p))
				if (inTriangle(P, normalPoly,Tb,Tc,Ta))
					dotpr1 = 5.0f;// not an ears !

			if ((dotpr2 < 5.0f) && (d != d_n) )
				if (inTriangle(P, normalPoly,Td,Ta,Tb))
					dotpr2 = 5.0f;// not an ears !

			finished = ((dotpr1 >= 5.0f)&&(dotpr2 >= 5.0f));
		}
	}

	float length = (Tb-Tc).norm2();
	m_dartEars[d2] = m_ears.insert(VertexPoly(d2,dotpr1,length));

	length = (Td-Ta).norm2();
	m_dartEars[d] = m_ears.insert(VertexPoly(d,dotpr2,length));
}

template<typename PFP>
float EarTriangulation<PFP>::computeEarInit(Dart d, const typename PFP::VEC3& normalPoly, float& val)
{
	Dart e =  m_map.phi1(d);
	Dart f =  m_map.phi1(e);

	const typename PFP::VEC3& Ta = m_position[e];
	const typename PFP::VEC3& Tb = m_position[f];
	const typename PFP::VEC3& Tc = m_position[d];

	typename PFP::VEC3 v1 = Tc-Ta;
	typename PFP::VEC3 v2 = Tb-Ta;
	v1.normalize();
	v2.normalize();

//	val = 1.0f - (v1*v2);
	val = acos(v1*v2) / (M_PI/2.0f);

	typename PFP::VEC3 vn = v1^v2;
	if (vn*normalPoly > 0.0f)
		val = 10.0f - val; 		// not an ears  (concave, store at the end for optimized use for intersections)

	if (val>5.0f)
		return 0.0f;

	//INTERSECTION
	f =  m_map.phi1(f);
	while (f != d)
	{
		if (inTriangle(m_position[f], normalPoly,Tb,Tc,Ta))
		{
			val = 5.0f;
			return 0.0f;
		}
		f =  m_map.phi1(f);
	}

	return (Tb-Tc).norm2();
}

template<typename PFP>
//void EarTriangulation<PFP>::trianguleFace(Dart d, DartMarker& mark)
void EarTriangulation<PFP>::trianguleFace(Dart d)
{
	// compute normal to polygon
	typename PFP::VEC3 normalPoly = Algo::Surface::Geometry::newellNormal<PFP>(m_map, d, m_position);

	// first pass create polygon in chained list witht angle computation
	unsigned int nbv = 0;
	unsigned int nbe = 0;
	Dart a = d;

	if (m_map.template phi<111>(d) ==d)
	{
//		mark.markOrbit<FACE>(d);	// mark the face
		return;
	}

	do
	{
		float val;
		float length = computeEarInit(a,normalPoly,val);
		a = m_map.phi1(a);	// phi here because ears is next of a
		m_dartEars[a] = m_ears.insert(VertexPoly(a,val,length));
		if (length!=0)
			nbe++;
		nbv++;
	}while (a!=d);

	// NO WE HAVE THE POLYGON AND EARS
	// LET'S REMOVE THEM

	bool convex = nbe==nbv;

	while (nbv>3)
	{
		// take best (and valid!) ear
		typename VPMS::iterator be_it = m_ears.begin(); // best ear
		Dart d_e = be_it->dart;
		Dart e1 = m_map.phi1(d_e);
		Dart e2 = m_map.phi_1(d_e);

		m_map.splitFace(e1,e2);

		Dart d_1 = m_map.phi_1(e1);
		std::vector<Dart> edges;
		edges.push_back(d_1);
		edges.push_back(m_map.phi1(m_map.phi2(m_map.phi1(d_1))));
		edges.push_back(m_map.phi_1(m_map.phi2(m_map.phi_1(d_1))));
		m_map.splitVolume(edges);

		d_1 = m_map.phi3(m_map.phi_1(e1));
		edges.clear();
		edges.push_back(d_1);
		edges.push_back(m_map.phi1(m_map.phi2(m_map.phi1(d_1))));
		edges.push_back(m_map.phi_1(m_map.phi2(m_map.phi_1(d_1))));
		m_map.splitVolume(edges);

		m_resTets.push_back(d_e);
		m_resTets.push_back(m_map.phi3(d_e));

//		mark.markOrbit<FACE>(d_e);
		nbv--;

		if (nbv>3)	// do not recompute if only one triangle left
		{
			//remove ears and two sided ears

			m_ears.erase(be_it);					// from map of ears
			m_ears.erase(m_dartEars[e1]);
			m_ears.erase(m_dartEars[e2]);

			recompute2Ears(e1,normalPoly,convex);

			convex = (m_ears.rbegin()->angle) < 5.0f;
		}
		else
		{
			m_resTets.push_back(e1);
			m_resTets.push_back(m_map.phi3(e1));
		}
//		else
//			mark.markOrbit<FACE>(e1);	// mark last face
	}
	m_ears.clear();
}

template<typename PFP>
void EarTriangulation<PFP>::triangule(unsigned int thread)
{
//	DartMarker m(m_map, thread);
//
//	for(Dart d = m_map.begin(); d != m_map.end(); m_map.next(d))
//	{
//		if(!m.isMarked(d))
//		{
//			Dart e = m_map.template phi<111>(d);
//			if (e!=d)
//				trianguleFace(d, m);
//		}
//	}
//	m.unmarkAll();

	TraversorF<typename PFP::MAP> trav(m_map,thread);

	for(Dart d = trav.begin(); d != trav.end(); d = trav.next())
	{
		Dart e = m_map.template phi<111>(d);
		if (e!=d)
			trianguleFace(d);
	}
}

277
278
279
280
281
282
283
//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))));
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
//	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
309
//            if(!cmv.isMarked(*it) && !map.isBoundaryMarked3(*it))
310
311
312
313
314
315
316
317
318
319
320
//            {
//                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
321
//                if(cmv.isMarked(*it) && !map.isBoundaryMarked3(*it))
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
426
427
//                {
//                    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;
//}
428

untereiner's avatar
untereiner committed
429

430
/************************************************************************************************
431
432
 * 									Collapse / Split Operators
 ************************************************************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
433

434
435
436
template <typename PFP>
Dart splitVertex(typename PFP::MAP& map, std::vector<Dart>& vd)
{
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
    //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;
        map.splitVolume(v);
    }

    return dres;
466
467
}

468
469
470
/*************************************************************************************************
 *		 								Tetrahedron functions									 *
 *************************************************************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
471
472

template <typename PFP>
473
bool isTetrahedron(typename PFP::MAP& map, Vol v, unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
474
{
475
476
477
    unsigned int nbFaces = 0;

    //Test the number of faces end its valency
478
	Traversor3WF<typename PFP::MAP> travWF(map, v, false, thread);
479
480
481
482
483
484
485
486
    for(Dart dit = travWF.begin() ; dit != travWF.end(); dit = travWF.next())
    {
        //increase the number of faces
        nbFaces++;
        if(nbFaces > 4)	//too much faces
            return false;

        //test the valency of this face
487
		if(!map.isCycleTriangle(dit))
488
489
490
491
            return false;
    }

    return true;
Pierre Kraemer's avatar
Pierre Kraemer committed
492
493
}

494
template <typename PFP>
495
bool isTetrahedralization(typename PFP::MAP& map)
496
{
497
498
499
500
501
502
503
504
    TraversorW<typename PFP::MAP> travW(map);
    for(Dart dit = travW.begin() ; dit != travW.end() ; dit = travW.next())
    {
        if(!isTetrahedron<PFP>(map, dit))
            return false;
    }

    return true;
505
506
}

507
508
509
/***********************************************************************************************
 * 										swap functions										   *
 ***********************************************************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
510

511
template <typename PFP>
512
Dart swap2To2(typename PFP::MAP& map, Dart d)
513
{
514
    std::vector<Dart> edges;
515

516
517
518
519
    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)));
520

521
522
523
524
525
526
527
528
        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);
529

530
        map.splitVolume(edges);
Pierre Kraemer's avatar
Pierre Kraemer committed
531

532
    return map.phi2(stop);
Pierre Kraemer's avatar
Pierre Kraemer committed
533
534
535
}

template <typename PFP>
536
Dart swap4To4(typename PFP::MAP& map, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
537
{
538
539
    Dart e = map.phi2(map.phi3(d));
    Dart dd = map.phi2(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
540

541
542
543
    //unsew middle crossing darts
    map.unsewVolumes(d);
    map.unsewVolumes(map.phi2(map.phi3(dd)));
Pierre Kraemer's avatar
Pierre Kraemer committed
544

545
546
    Dart d1 = Tetrahedralization::swap2To2<PFP>(map, dd);
    Dart d2 = Tetrahedralization::swap2To2<PFP>(map, e);
Pierre Kraemer's avatar
Pierre Kraemer committed
547

548
549
550
    //sew middle darts so that they do not cross
    map.sewVolumes(map.phi2(d1),map.phi2(map.phi3(d2)));
    map.sewVolumes(map.phi2(map.phi3(d1)),map.phi2(d2));
551
	return d1;
Pierre Kraemer's avatar
Pierre Kraemer committed
552
553
554
}

template <typename PFP>
555
Dart swap3To2(typename PFP::MAP& map, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
556
{
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
    std::vector<Dart> edges;

    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);

    Dart dit = stop;
    do
    {
        edges.push_back(dit);
        dit = map.phi1(map.phi2(map.phi1(dit)));
    }
    while(dit != stop);
    map.splitVolume(edges);

575
	return map.phi2(edges[0]);
Pierre Kraemer's avatar
Pierre Kraemer committed
576
577
578
}

//[precond] le brin doit venir d'une face partagé par 2 tetraèdres
579
// renvoie un brin de la nouvelle orbite arete creee
Pierre Kraemer's avatar
Pierre Kraemer committed
580
template <typename PFP>
581
Dart swap2To3(typename PFP::MAP& map, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
582
{
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
    std::vector<Dart> edges;

    Dart d2_1 = map.phi_1(map.phi2(d));
    map.mergeVolumes(d);

    //
    // Cut the 1st tetrahedron
    //
    Dart stop = d2_1;
    Dart dit = stop;
    do
    {
        edges.push_back(dit);
        dit = map.phi1(map.phi2(map.phi1(dit)));
    }
    while(dit != stop);

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

    //
    // 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)));
    }
    while(dit != stop);
    map.splitVolume(edges);

617
	return stop;
618
}
untereiner's avatar
untereiner committed
619

620
621
622
template <typename PFP>
Dart swap5To4(typename PFP::MAP& map, Dart d)
{
623
624
    Dart t1 = map.phi3(d);
    Dart t2 = map.phi3(map.phi2(d));
untereiner's avatar
untereiner committed
625

626
627
    Dart d323 = map.phi_1(map.phi2(map.phi1(d)));
    Dart dswap = map.phi2(map.phi3(d323));
untereiner's avatar
untereiner committed
628

629
630
631
632
633
    map.unsewVolumes(t1);
    map.unsewVolumes(t2);
    map.unsewVolumes(d323);
    map.unsewVolumes(map.phi2(d323));
    map.deleteVolume(d);
untereiner's avatar
untereiner committed
634

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

637
638
    map.sewVolumes(map.phi2(d1), t1);
    map.sewVolumes(map.phi2(map.phi3(d1)),t2);
untereiner's avatar
untereiner committed
639

640
    return t1;
641
}
untereiner's avatar
untereiner committed
642

643
template <typename PFP>
644
Dart swapGen3To2(typename PFP::MAP& map, Dart d)
645
{
646
	Dart stop = map.phi1(map.phi2(map.phi_1(d)));
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
	if(map.deleteEdge(d) == NIL)
	{
		std::cout << "boundary" << std::endl;

		std::vector<Dart> edges;
		Dart dbegin = map.findBoundaryFaceOfEdge(d);
		Traversor3EW<typename PFP::MAP> t(map, d);
		for(Dart dit = t.begin() ; dit != t.end() ; dit = t.next())
			edges.push_back(dit);

		for(unsigned int i = 0 ; i < edges.size() ; ++i)
			map.mergeVolumes(edges[i]);

		Dart d  = dbegin;
		Dart e = map.phi2(d);
		map.flipBackEdge(d);
		map.template copyDartEmbedding<VERTEX>(d, map.phi1(e)) ;
		map.template copyDartEmbedding<VERTEX>(e, map.phi1(d)) ;

		d  = map.phi3(dbegin);
		e = map.phi2(d);
		map.flipEdge(d);
		map.template copyDartEmbedding<VERTEX>(d, map.phi1(e)) ;
		map.template copyDartEmbedding<VERTEX>(e, map.phi1(d)) ;
	}
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

	std::vector<Dart> edges;
	Dart dit = stop;
	do
	{
		edges.push_back(dit);
		dit = map.phi1(map.phi2(map.phi1(dit)));
	}
	while(dit != stop);
	map.splitVolume(edges);

	Dart v = map.phi1(map.phi2(stop));
	dit = map.phi_1(map.phi_1(v));
	do
	{
		Dart save = map.phi_1(dit);
		map.splitFace(v,dit);

		//decoupe des tetraedres d'un cote du plan
		Dart d_1 = map.phi_1(v);
		std::vector<Dart> edges;
		edges.push_back(d_1);
		edges.push_back(map.phi1(map.phi2(map.phi1(d_1))));
		edges.push_back(map.phi_1(map.phi2(map.phi_1(d_1))));
		map.splitVolume(edges);

		//decoupe des tetraedres d'un cote du plan
		d_1 = map.phi3(map.phi_1(v));
		edges.clear();
		edges.push_back(d_1);
		edges.push_back(map.phi1(map.phi2(map.phi1(d_1))));
		edges.push_back(map.phi_1(map.phi2(map.phi_1(d_1))));
		map.splitVolume(edges);

		dit = save;
	}
	while(map.phi_1(dit) != v);

	return stop;
}
712
713
714
715
716

template <typename PFP>
std::vector<Dart> swapGen3To2Optimized(typename PFP::MAP& map, Dart d)
{
	Dart stop = map.phi1(map.phi2(map.phi_1(d)));
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
	if(map.deleteEdge(d) == NIL)
	{
		std::cout << "boundary" << std::endl;

		std::vector<Dart> edges;
		Dart dbegin = map.findBoundaryFaceOfEdge(d);
		Traversor3EW<typename PFP::MAP> t(map, d);
		for(Dart dit = t.begin() ; dit != t.end() ; dit = t.next())
			edges.push_back(dit);

		for(unsigned int i = 0 ; i < edges.size() ; ++i)
			map.mergeVolumes(edges[i]);

		Dart d  = dbegin;
		Dart e = map.phi2(d);
		map.flipBackEdge(d);
		map.template copyDartEmbedding<VERTEX>(d, map.phi1(e)) ;
		map.template copyDartEmbedding<VERTEX>(e, map.phi1(d)) ;

		d  = map.phi3(dbegin);
		e = map.phi2(d);
		map.flipEdge(d);
		map.template copyDartEmbedding<VERTEX>(d, map.phi1(e)) ;
		map.template copyDartEmbedding<VERTEX>(e, map.phi1(d)) ;
	}
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758

	std::vector<Dart> edges;
	Dart dit = stop;
	do
	{
		edges.push_back(dit);
		dit = map.phi1(map.phi2(map.phi1(dit)));
	}
	while(dit != stop);
	map.splitVolume(edges);

	Tetrahedralization::EarTriangulation<PFP> triangulation(map);
	triangulation.trianguleFace(map.phi1(map.phi2(stop)));

	return triangulation.getResultingTets();
}

759
//unsigned int n = map.edgeDegree(d);
760

761
762
763
764
765
766
767
768
769
//    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));
//    }
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

//	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);
//	}
800
801
802
803

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

806
//- a single 2-3 swap, followed by n − 3 3-2 swaps, or
807
//- a single 4-4 swap, followed by n − 4 3-2 swaps.
808
809
}

810
811
812
/************************************************************************************************
 *										Flip Functions 											*
 ************************************************************************************************/
untereiner's avatar
untereiner committed
813

814
template <typename PFP>
815
Dart flip1To4(typename PFP::MAP& map, Dart d)
816
{
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
    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);

    Dart x = Surface::Modelisation::trianguleFace<PFP>(map,map.phi2(d));

    //
    // 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;
859
860
}

861
template <typename PFP>
862
Dart flip1To3(typename PFP::MAP& map, Dart d)
863
{
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
    std::vector<Dart> edges;

    //
    // Triangule one face
    //
    Dart x = Surface::Modelisation::trianguleFace<PFP>(map,d);

    //
    // 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);

    // Cut the 2nd Tetrahedron
    map.splitFace(map.phi1(map.phi2(edges[0])),map.phi1(map.phi2(edges[2])));

    // Cut the 3rd 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;
900
}
untereiner's avatar
untereiner committed
901

902
/************************************************************************************************
903
 *                				 Bisection Functions                                            *
904
 ************************************************************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
905

906
template <typename PFP>
907
Dart edgeBisection(typename PFP::MAP& map, Dart d)
908
{
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
    //coupe l'arete en 2
    map.cutEdge(d);
    Dart e = map.phi1(d);

    Dart dit = e;
    do
    {
        map.splitFace(dit, map.phi1(map.phi1(dit)));
        dit = map.alpha2(dit);
    }
    while(dit != e);

    dit = e;
    std::vector<Dart> edges;
    do
    {
untereiner's avatar
untereiner committed
925
		if(!map.isBoundaryMarked(3,dit))
926
927
928
929
930
931
932
933
934
935
936
937
        {
            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();
        }
        dit = map.alpha2(dit);
    }
    while(dit != e);

    return e;
Pierre Kraemer's avatar
Pierre Kraemer committed
938
}
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
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
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194

//namespace Tetgen
//{


//template <typename PFP>
//bool tetrahedralize(const typename PFP::MAP2& map2, const VertexAttribute<typename PFP::VEC3> position2,
//                    typename PFP::MAP3& map3, VertexAttribute<typename PFP::VEC3> position3,
//                    bool add_steiner_points_on_exterior_boundary, bool add_steiner_points_on_interior_boundary, double max_volume, double max_shape)
//{
//    //
//    // 1. map to tetgen
//    //

//    tetgenio surface;

//    // memory initialization
//    surface.initialize();

//    // 0-based indexing
//    surface.firstnumber = 0;

//    // input vertices
//    surface.numberofpoints = map2.nbOrbits<VERTEX>();
//    surface.pointlist = new REAL[surface.numberofpoints * 3];

//    //for each vertex
//    unsigned int i = 0;
//    TraversorV tv(map2);
//    for(Dart it = tv.begin() ; it != tv.end() ; it = tv.next())
//    {
//        surface.pointlist[i] = position2[it][0] ; i++ ; //x
//        surface.pointlist[i] = position2[it][1] ; i++ ; //y
//        surface.pointlist[i] = position2[it][2] ; i++ ; //z
//    }

//    tetgenio::facet* f ;
//    tetgenio::polygon* p ;
//    surface.numberoffacets = map2.nbOrbits<FACE>();
//    surface.facetlist = new tetgenio::facet[surface.numberoffacets] ;


//    //for each facet
//    i = 0;
//    TraversorF tf(map2);
//    for(Dart it = tf.begin() ; it != tf.end() ; it = tf.next())
//    {
//        f = &(surface.facetlist[i]) ;
//        f->numberofpolygons = 1 ;
//        f->polygonlist = new tetgenio::polygon[f->numberofpolygons] ;
//        p = f->polygonlist ;
//        p->numberofvertices = map2.faceDegree(it);
//        p->vertexlist = new int[p->numberofvertices] ;

//        unsigned int j = 0;
//        Dart dit = it;
//        do
//        {
//            p->vertexlist[j] = map2.getEmbedding<VERTEX>(dit);
//            dit = map.phi1(dit);
//            j++;
//        }while(dit != it);

//        f->numberofholes = 0 ;
//        f->holelist = nil ;
//        i++ ;
//    }

//    //
//    // 2. tetgen argument list
//    //
//    std::ostringstream s ;

//    // Q: Quiet: No terminal output except errors
//    // p: PLC : input data is surfacic
//    // n: output tet neighbors

//    // q: desired quality
//    if(max_volume > 0 && max_shape > 0.0)
//    {
//        s << "Qpna" << max_volume << "q"<< max_shape;
//    }
//    else if(max_volume > 0.0)
//    {
//        s << "Qpna" << max_volume ;
//    }
//    else if(max_shape > 0.0)
//    {
//        s << "Qpnq" << max_shape ;
//    }
//    else
//    {
//        s << "Qpn";
//    }

//    // YY: prohibit steiner points on boundaries
//    // (first Y for exterior boundary, second Y for the
//    // other ones).

//    if( add_steiner_points_on_exterior_boundary && !add_steiner_points_on_interior_boundary)
//    {
//       //Invalid combination of flags (do not preserve exterior boundary and preserve interior ones) - preserving exterior boundary as well
//        add_steiner_points_on_exterior_boundary = false ;
//    }

//    if(!add_steiner_points_on_exterior_boundary)
//    {
//        s << "Y" ;
//    }

//    if(!add_steiner_points_on_interior_boundary)
//    {
//        s << "Y" ;
//    }
//    std::string params = s.str() ;

//    //
//    // 3. tetrahedralization
//    //
//    tetgenio volume;
//    ::tetrahedralize(params.c_str(), &surface, &volume) ;


//    //
//    // 4. tetgen to map
//    //

//    //create vertices
//    double* p = volume.pointlist ;
//    std::vector<unsigned int> verticesID;
//    verticesID.reserve(volume.numberofpoints);
//    AttributeContainer& container = map3.template getAttributeContainer<VERTEX>() ;

//    for(unsigned int i = 0; i < volume.numberofpoints; i++)
//    {
//        typename PFP::VEC3 pos(p[0], p[1], p[2]);
//        unsigned int id = container.insertLine();

//        position3[id] = pos;
//        verticesID.push_back(id);

//        p += 3 ;
//    }

//    //create tetrahedrons
//    int* t = volume.tetrahedronlist ;
//    for(unsigned int i = 0; i < volume.numberoftetrahedra; i++)
//    {
//        Dart d = Algo::Surface::Modelisation::createTetrahedron<PFP>(map3, false);

//        for(unsigned int j = 0; j < 3; j++)
//        {
//            FunctorSetEmb<typename PFP::MAP, VERTEX> fsetemb(map, verticesID[t[j] - volume.firstnumber]);
//            map.template foreach_dart_of_orbit<PFP::MAP::VERTEX_OF_PARENT>(d, fsetemb);

////            //store darts per vertices to optimize reconstruction
////            Dart dd = d;
////            do
////            {
////                m.mark(dd) ;
////                vecDartsPerVertex[pt[2-j]].push_back(dd);
////                dd = map.phi1(map.phi2(dd));
////            } while(dd != d);

//            d = map.phi1(d);

//            set_cell_vertex(d, j, verticesID[t[j] - volume.firstnumber]) ;
//        }

//        t += 4 ;
//    }

//    //create adjacency
//    int* pn = volume.neighborlist ;
//    for(unsigned int i = 0; i < volume.numberoftetrahedra; i++)
//    {
//        for(int j=0; j<4; j++)
//        {
//            int adjacent = pn[j] ;

//            if(adjacent >= 0)
//            {
//                set_cell_adjacent( cells[i], j, cells[adjacent - volume.firstnumber]
//                ) ;
//            }
//        }
//        pn += 4 ;
//    }
//}

///**
// * generate tetrahedra based on an surface mesh object
// */
//template <typename PFP>
//bool process(const std::string& filename, typename PFP::MAP3& map3, bool add_steiner_points_on_exterior_boundary,
//             bool add_steiner_points_on_interior_boundary, double max_volume, double max_shape)
//{

//}



///**
// * generate tetrahedra based on an surface mesh object
// * -INT_MAX for surf/vol-id inherits from the mesh
// */
//template <typename PFP2, typename PFP3>
//typename PFP3::MAP process(typename PFP2::MAP& map, double volume, double quality, int volid = -INT_MAX, int surfid = -INT_MAX)
//{
//    //
//    // map to tetgen
//    //


//    tetgenio surface;
//    tetgenio::facet *f;
//    tetgenio::polygon *p;
//    int *elements, *surfaces;
//    int i, j, n, *ele, *tet;
//    char params [512];


//    // memory initialization
//    surface.initialize();

//    // 0-based indexing
//    surface.firstnumber = 0;

//    // input vertices
//    surface.numberofpoints =
//    surface.pointlist = new REAL[surface.numberofpoints * 3];


//    // input faces

//}

///**
// * generate tetrahedra based on an surface mesh object
// * -INT_MAX for surf/vol-id inherits from the mesh
// */
//template <typename PFP3>
//typename PFP3::MAP process(const std::string& filename, double volume, double quality, int volid = -INT_MAX, int surfid = -INT_MAX)
//{

//}

//} //namespace Tetgen








untereiner's avatar
untereiner committed
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
///**
// * 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
1434
} // namespace Tetrahedralization
untereiner's avatar
untereiner committed
1435

Pierre Kraemer's avatar
Pierre Kraemer committed
1436
} // namespace Modelisation
Pierre Kraemer's avatar
Pierre Kraemer committed
1437

Pierre Kraemer's avatar
Pierre Kraemer committed
1438
1439
} // namespace Volume

Pierre Kraemer's avatar
Pierre Kraemer committed
1440
} // namespace Algo
Pierre Kraemer's avatar
Pierre Kraemer committed
1441

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