particle_cell_3D.hpp 19 KB
Newer Older
Thomas's avatar
Thomas committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// #define DEBUG

#define DELTA 0.00001
//static const float DELTA=0.00001;

template <typename PFP>
void ParticleCell3D<PFP>::display()
{
//	std::cout << "position : " << m_position << std::endl;
}

template <typename PFP>
typename PFP::VEC3 ParticleCell3D<PFP>::pointInFace(Dart d)
{
	return Algo::Geometry::faceCentroid<PFP>(m,d,position);
//	const VEC3& p1(m_positions[d]);
//	Dart dd=m.phi1(d);
//	const VEC3& p2(m_positions[dd]);
//	dd=m.phi1(dd);
//	VEC3& p3(m_positions[dd]);
//
//	while(Geom::testOrientation2D(p3,p1,p2)==Geom::ALIGNED) {
//		dd = m.phi1(dd);
//		p3 = m_positions[dd];
//	}
//
//	CGoGNout << "pointInFace " << (p1+p3)*0.5f << CGoGNendl;
//
//	return (p1+p3)*0.5f;
}


template <typename PFP>
Geom::Orientation3D ParticleCell3D<PFP>::isLeftENextVertex(VEC3 c, Dart d, VEC3 base)
{
	VEC3 p = position[d];
	VEC3 p1 = position[m.phi1(m.phi2(d))];

	Geom::Plane3D<typename PFP::REAL> pl(p,base,p1);
	return pl.orient(c);
}

template <typename PFP>
bool ParticleCell3D<PFP>::isRightVertex(VEC3 c, Dart d, VEC3 base)
{
	VEC3 p = position[d];
	VEC3 p1 = position[m.phi_1(d)];

	Geom::Plane3D<typename PFP::REAL> pl(p,base,p1);
	return pl.orient(c)==Geom::UNDER;
}

template <typename PFP>
Geom::Orientation3D ParticleCell3D<PFP>::whichSideOfFace(VEC3 c, Dart d)
{
	Geom::Plane3D<typename PFP::REAL> pl = Algo::Geometry::facePlane<PFP>(m,d,position);
	return pl.orient(c);
}

template <typename PFP>
Geom::Orientation3D ParticleCell3D<PFP>::isLeftL1DVol(VEC3 c, Dart d, VEC3 base, VEC3 top)
{
	VEC3 p2 = position[d];

	Geom::Plane3D<typename PFP::REAL> pl(top,p2,base);

	return pl.orient(c);
}

template <typename PFP>
Geom::Orientation3D ParticleCell3D<PFP>::isRightDVol(VEC3 c, Dart d, VEC3 base, VEC3 top)
{
	VEC3 p1= position[m.phi1(d)];

	Geom::Plane3D<typename PFP::REAL> pl(top,p1,base);

	return pl.orient(c);
}

template <typename PFP>
Geom::Orientation3D ParticleCell3D<PFP>::isAbove(VEC3 c, Dart d, VEC3 top)
{
	VEC3 p1 = position[d];
	VEC3 p2 = position[m.phi1(d)];

	Geom::Plane3D<typename PFP::REAL> pl(top,p2,p1);


	return pl.orient(c);
}

template <typename PFP>
int ParticleCell3D<PFP>::isLeftL1DFace(VEC3 c, Dart d, VEC3 base, VEC3 normal)
{
	VEC3 p2 = position[d];

	VEC3 v2(p2-base);

	VEC3 np = normal ^ v2;

	Geom::Plane3D<typename PFP::REAL> pl(np,base*np);

	return pl.orient(c);
}

template <typename PFP>
bool ParticleCell3D<PFP>::isRightDFace(VEC3 c, Dart d, VEC3 base, VEC3 normal)
{
	VEC3 p1 = position[m.phi1(d)];

	VEC3 np = normal ^ VEC3(p1-base);

	Geom::Plane3D<typename PFP::REAL> pl(np,base*np);

	return pl.orient(c)==Geom::UNDER;
}


template <typename PFP>
120
Dart ParticleCell3D<PFP>::nextDartOfVertexNotMarked(Dart d, CellMarkerGen& mark)
Thomas's avatar
Thomas committed
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
{
	// lock a marker
	Dart d1;
	DartMarkerNoUnmark markCC(m);

	// init algo with parameter dart
	std::list<Dart> darts_list;
	darts_list.push_back(d);
	markCC.mark(d);

	// use iterator for begin of not yet treated darts
	std::list<Dart>::iterator beg = darts_list.begin();

	// until all darts treated
	while (beg != darts_list.end())
	{
		d1 = *beg;
		// add phi1, phi2 and phi3 successor if they are not yet marked
		Dart d2 = m.phi1(m.phi2(d1));
		Dart d3 = m.phi1(m.phi3(d1));

		if (!markCC.isMarked(d2)) {
			darts_list.push_back(d2);
			markCC.mark(d2);
		}

		if (!markCC.isMarked(d3)) {
			darts_list.push_back(d3);
			markCC.mark(d3);
		}

		beg++;

		// apply functor
		if (!mark.isMarked(d1)) {
			for (std::list<Dart>::iterator it=darts_list.begin(); it!=darts_list.end(); ++it)
				markCC.unmark(*it);
			return d1;
		}
	}

	// clear markers
	for (std::list<Dart>::iterator it=darts_list.begin(); it!=darts_list.end(); ++it)
		markCC.unmark(*it);

	return d;
}

template <typename PFP>
Dart ParticleCell3D<PFP>::nextNonPlanar(Dart d)
{
	// lock a marker
	Dart d1;
	DartMarkerNoUnmark markCC(m);

	// init algo with parameter dart
	std::list<Dart> darts_list;
	darts_list.push_back(d);
	markCC.mark(d);

	// use iterator for begin of not yet treated darts
	std::list<Dart>::iterator beg = darts_list.begin();

	// until all darts treated
	while (beg != darts_list.end()) {
		d1 = *beg;
		// add phi1, phi2 and phi3 successor if they are not yet marked
		Dart d2 = m.phi1(d1);
		Dart d3 = m.phi2(d1);
		Dart d4 = m.phi_1(d1);

		if (!markCC.isMarked(d2)) {
			darts_list.push_back(d2);
			markCC.mark(d2);
		}

		if (!markCC.isMarked(d3)) {
			darts_list.push_back(d3);
			markCC.mark(d3);
		}

		if (!markCC.isMarked(d4)) {
			darts_list.push_back(d4);
			markCC.mark(d4);
		}

		beg++;

		// apply functor
		Geom::Plane3D<typename PFP::REAL> pl1 = Algo::Geometry::facePlane<PFP>(m,d,position);
		Geom::Plane3D<typename PFP::REAL> pl2 = Algo::Geometry::facePlane<PFP>(m,d1,position);
		if ((pl1.normal()-pl2.normal()).norm2()>0.000001)
			beg = darts_list.end();
		// remove the head of the list
	}
	// clear markers
	for (std::list<Dart>::iterator it=darts_list.begin(); it!=darts_list.end(); ++it)
		markCC.unmark(*it);

	return d1;
}

template <typename PFP>
224
Dart ParticleCell3D<PFP>::nextFaceNotMarked(Dart d, CellMarkerGen& mark)
Thomas's avatar
Thomas committed
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
{
	// lock a marker
	Dart d1;
	DartMarkerNoUnmark markCC(m);

	// init algo with parameter dart
	std::list<Dart> darts_list;
	darts_list.push_back(d);
	markCC.mark(d);

	// use iterator for begin of not yet treated darts
	std::list<Dart>::iterator beg = darts_list.begin();

	// until all darts treated
	while (beg != darts_list.end())
	{
		d1 = *beg;

		if(!mark.isMarked(d1))
		{
245
246
247
248
249
250
			for (std::list<Dart>::iterator it=darts_list.begin(); it!=darts_list.end(); ++it)
			{
				markCC.unmark(*it);
			}

			return d1;
Thomas's avatar
Thomas committed
251
252
253
254
255
256
		}

		// add phi1, phi2 and phi3 successor if they are not yet marked
		Dart d2 = m.phi1(d1);
		Dart d3 = m.phi2(d1);
		Dart d4 = m.phi_1(d1);
257

Thomas's avatar
Thomas committed
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
		if (!markCC.isMarked(d2))
		{
			darts_list.push_back(d2);
			markCC.mark(d2);
		}
		if (!markCC.isMarked(d3))
		{
			darts_list.push_back(d3);
			markCC.mark(d3);
		}
		if (!markCC.isMarked(d4))
		{
			darts_list.push_back(d4);
			markCC.mark(d4);
		}
		beg++;
	}
Thomas's avatar
Thomas committed
275

Thomas's avatar
Thomas committed
276
277
278
279
280
281
	// clear markers
	for (std::list<Dart>::iterator it=darts_list.begin(); it!=darts_list.end(); ++it)
	{
		markCC.unmark(*it);
	}

282
//	if(beg==darts_list.end())
Thomas's avatar
Thomas committed
283
284
		return d;

285
//	return d1;
Thomas's avatar
Thomas committed
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
}

template <typename PFP>
Geom::Orientation3D ParticleCell3D<PFP>::whichSideOfEdge(VEC3 c, Dart d)
{
	VEC3 p1 = position[m.phi1(d)];
	VEC3 p2 = position[d];

	Geom::Plane3D<typename PFP::REAL> pl = Algo::Geometry::facePlane<PFP>(m,d,position);
	VEC3 norm = pl.normal();
	VEC3 n2 = norm ^ VEC3(p2-p1);

	Geom::Plane3D<typename PFP::REAL> pl2(n2,p1*n2);

	return pl2.orient(c);
}

template <typename PFP>
bool ParticleCell3D<PFP>::isOnHalfEdge(VEC3 c, Dart d)
{
	VEC3 p1 = position[d];
	VEC3 p2 = position[m.phi1(d)];

	VEC3 norm(p2-p1);
	norm.normalize();

	Geom::Plane3D<typename PFP::REAL> pl(norm,p1*norm);

	return pl.orient(c)==Geom::OVER && !Geom::arePointsEquals(c,p1);
}


/**when the ParticleCell3D trajectory go through a vertex
*  searching the good volume "umbrella" where the ParticleCell3D is
*  if the ParticleCell3D is on the vertex, do nothing */
template <typename PFP>
void ParticleCell3D<PFP>::vertexState(const VEC3& current)
{
	#ifdef DEBUG
	std::cout << "vertexState" << d << std::endl;
	#endif

328
329
	crossCell = CROSS_OTHER ;

Thomas's avatar
Thomas committed
330
331
332
333
	VEC3 som = position[d];

	if(Geom::arePointsEquals(current, m_position)) {
		m_position = m_positionFace = som;
334
		state = VERTEX;
Thomas's avatar
Thomas committed
335
336
337
338
339
		return;
	}

	Dart dd=d;
	Geom::Orientation3D wsof;
340
	CellMarkerStore mark(m, FACE);
Thomas's avatar
Thomas committed
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
428
429
430
431
432
433
434
435
436
437
438
439
440

	do {
		VEC3 dualsp = (som+ Algo::Geometry::vertexNormal<PFP>(m,d,position));
		Dart ddd=d;

		mark.mark(d);

		//searching the good orientation in a volume
		if(isLeftENextVertex(current,d,dualsp)!=Geom::UNDER) {

			d=m.phi1(m.phi2(d));
			while(isLeftENextVertex(current,d,dualsp)!=Geom::UNDER && ddd!=d)
				d=m.phi1(m.phi2(d));

			if(ddd==d) {
				if(isnan(current[0]) || isnan(current[1]) || isnan(current[2])) {
					std::cout << __FILE__ << " " << __LINE__ << " NaN !" << std::endl;
				}

				bool verif = true;
				do {
					if(whichSideOfFace(current,d)!=Geom::OVER)
						verif = false;
					else
						d=m.alpha1(d);
				} while(verif && d!=ddd);

				if(verif) {
					volumeState(current);
					return;
				}
			}
		}
		else {
			while(isRightVertex(current,d,dualsp) && dd!=m.alpha_1(d))
				d=m.phi2(m.phi_1(d));
		}

		wsof=whichSideOfFace(current,d);

		//if c is before the vertex on the edge, we have to change of umbrella, we are symetric to the good umbrella
		if(wsof!=Geom::OVER) {

			VEC3 p1=position[d];
			VEC3 p2=position[m.phi1(d)];
			VEC3 norm(p2-p1);
			norm.normalize();
			Geom::Plane3D<typename PFP::REAL> plane(norm,p1*norm);

			wsof = plane.orient(current);
		}

		//if c is on the other side of the face, we have to change umbrella
		//if the umbrella has already been tested, we just take another arbitrary one
		if(wsof==1) {

			mark.mark(d);

			if(!mark.isMarked(m.alpha1(d)))
				d=m.alpha1(d);
			else {

				Dart dtmp=d;
				d = nextDartOfVertexNotMarked(d,mark);
				if(dtmp==d) {
					std::cout << "numerical rounding ?" << std::endl;

					d = dd;
					m_position = pointInFace(d);
					m_positionFace = m_position;
					volumeState(current);
					return;
				}
			}
		}
	}while(wsof==1);

	if(wsof!=0)
	{
		m_position = pointInFace(d);
		d = nextNonPlanar(d);
		m_positionFace = pointInFace(d);
		volumeState(current);
	}
	else
	{
		Dart ddd=d;

		edgeState(current);
	}
}

template <typename PFP>
void ParticleCell3D<PFP>::edgeState(const VEC3& current)
{
	#ifdef DEBUG
	std::cout << "edgeState" <<  d <<  " " << m_position << std::endl;

	#endif

441
442
	crossCell = CROSS_OTHER ;

Thomas's avatar
Thomas committed
443
444
445
446
447
448
449
450
451
452
453
454
	bool onEdge=false;
	Dart dd=d;
	Geom::Orientation3D wsof = whichSideOfFace(current,m.alpha2(d));
	if(wsof!=Geom::UNDER) {
		do {
			d = m.alpha2(d);
			wsof = whichSideOfFace(current,m.alpha2(d));
		}while(wsof!=1 && dd!=d);

		if(d==dd)
			onEdge = true;

455
		if(wsof==Geom::ON) {
Thomas's avatar
Thomas committed
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
			switch(whichSideOfEdge(current,d)) {
			case Geom::ON :
				 onEdge=true;
					break;
			case Geom::UNDER :
					d = m.phi2(d);
					break;
			default :
				break;
			}
		}

		wsof = whichSideOfFace(current,d);
	}
	else {
		wsof = whichSideOfFace(current,d);

473
		while(wsof==Geom::UNDER && dd != m.alpha_2(d)) {
Thomas's avatar
Thomas committed
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
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
520
521
522
523
			d = m.alpha_2(d);
			wsof = whichSideOfFace(current,d);
		}

		switch(whichSideOfEdge(current,d)) {
			case Geom::ON : onEdge=true;
					break;
			default :
					break;
		}
	}

	if(wsof==-1)  {

		m_position = pointInFace(d);
		d = nextNonPlanar(m.phi1(d));
		m_positionFace = pointInFace(d);
		volumeState(current);
		return;
	}
	else {
		if(onEdge) {
			if(isOnHalfEdge(current,d))
				if (isOnHalfEdge(current,m.phi3(d))) {
					state=2;
					m_position = m_positionFace = current;
				}
				else {
					d=m.phi1(d);
					vertexState(current);
				}
			else {
				vertexState(current);
			}
		}
		else {
			m_positionFace = m_position;
			d=m.phi1(d);
			faceState(current,wsof);
		}
	}
}

 template <typename PFP>
 void ParticleCell3D<PFP>::faceState(const VEC3& current, Geom::Orientation3D wsof)
{
	#ifdef DEBUG
	std::cout << "faceState" <<  d << std::endl;
	#endif

524
	crossCell = CROSS_FACE ;
Thomas's avatar
Thomas committed
525
526
527
528
529
530
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

	if(wsof==Geom::ON)
		wsof = whichSideOfFace(current,d);

	if (wsof==Geom::OVER) {
		d = m.phi3(d);
		d = nextNonPlanar(d);
		m_positionFace = pointInFace(d);
		volumeState(current);
		return;
	}
	else if(wsof==Geom::UNDER) {
		d = nextNonPlanar(d);
		m_positionFace = pointInFace(d);
		volumeState(current);
		return;
	}

	VEC3 norm = Algo::Geometry::faceNormal<PFP>(m,d,position);

	Dart dd=d;
	if(isLeftL1DFace(current,d,m_positionFace,norm)!=Geom::UNDER) {
		d = m.phi_1(d);
		while(isLeftL1DFace(current,d,m_positionFace,norm)!=Geom::UNDER && dd!=d)
			d = m.phi_1(d);

		if(dd==d) {
			std::cout << "sortie ?(1)" << std::endl;
			do {
				switch (whichSideOfEdge(current,d)) {
				case Geom::OVER : d=m.phi_1(d);
					break;
				case Geom::ON :m_position = current;
558
					state = EDGE;
Thomas's avatar
Thomas committed
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
					return;
				default :
					Geom::Plane3D<typename PFP::REAL> pl = Algo::Geometry::facePlane<PFP>(m,d,position);
					VEC3 p3 = pl.normal()+m_position;
					Geom::Plane3D<typename PFP::REAL> plOrtho(m_position,current,p3);
					VEC3 e(position[m.phi1(d)]-position[d]);

					Geom::intersectionPlaneRay(plOrtho,m_position,current-m_position,m_position);

					edgeState(current);
					return;
				}
			} while(d!=dd);

			m_position = m_positionFace = current;
574
			state = FACE;
Thomas's avatar
Thomas committed
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
			return;
		}
	}
	else {
		while(isRightDFace(current,d,m_positionFace,norm) && m.phi1(d)!=dd)
			d = m.phi1(d);

		if(m.phi_1(d)==dd) {
			d = m.phi1(d);
			do {
				switch (whichSideOfEdge(current,d))
				{
				case Geom::OVER :
					d=m.phi_1(d);
					break;
				case Geom::ON :m_position = current;
591
					state = EDGE;
Thomas's avatar
Thomas committed
592
593
594
595
596
597
598
599
600
601
602
603
604
605
					return;
				default :
					 Geom::Plane3D<typename PFP::REAL> pl = Algo::Geometry::facePlane<PFP>(m,d,position);
					 VEC3 p3 = pl.normal()+m_position;
					 Geom::Plane3D<typename PFP::REAL> plOrtho(m_position,current,p3);
					 VEC3 e(position[m.phi1(d)]-position[d]);

					 Geom::intersectionPlaneRay(plOrtho,m_position,current-m_position,m_position);
					edgeState(current);
					return;
				}
			}while(d!=dd);

			m_position = m_positionFace = current;
606
			state = FACE;
Thomas's avatar
Thomas committed
607
608
609
610
611
612
613
614
615
			return;
		}
	}


	switch (whichSideOfEdge(current,d))
	{
	case Geom::OVER :
		 m_position = m_positionFace = current;
616
		 state = FACE;
Thomas's avatar
Thomas committed
617
618
619
		 break;
	case Geom::ON :
		 m_position = m_positionFace = current;
620
		 state = EDGE;
Thomas's avatar
Thomas committed
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
		 break;
	default :
		 Geom::Plane3D<typename PFP::REAL> pl = Algo::Geometry::facePlane<PFP>(m,d,position);
		 VEC3 p3 = pl.normal()+m_position;
		 Geom::Plane3D<typename PFP::REAL> plOrtho(m_position,current,p3);
		 VEC3 e(position[m.phi1(d)]-position[d]);

		 Geom::intersectionPlaneRay(plOrtho,m_position,current-m_position,m_position);

		 m_positionFace = m_position;

		 edgeState(current);
	}
}

template <typename PFP>
void ParticleCell3D<PFP>::volumeState(const VEC3& current)
{
	#ifdef DEBUG
	std::cout << "volumeState " <<  d << std::endl;
	#endif

643
	CellMarkerStore mark(m,FACE);
Thomas's avatar
Thomas committed
644
645
646
647
648
649
650
651
652
653
654
655
	bool above;

	Geom::Orientation3D testRight=Geom::OVER;

	do {
		above=false;

		Dart dd=d;
		bool particularcase=false;
		Geom::Orientation3D testLeft = isLeftL1DVol(current,d,m_positionFace,m_position);

		if(testLeft!=Geom::UNDER) {
Thomas's avatar
Thomas committed
656

Thomas's avatar
Thomas committed
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
			d = m.phi_1(d);

			while(dd!=d && isLeftL1DVol(current,d,m_positionFace,m_position)!=Geom::UNDER)
				d = m.phi_1(d);

			if(dd==d)
				particularcase=true;
		}
		else {

			testRight = isRightDVol(current,d,m_positionFace,m_position);


			while(testRight!=Geom::OVER && dd!=m.phi1(d)) {
				d = m.phi1(d);
				testRight = isRightDVol(current,d,m_positionFace,m_position);
			}

			if(testLeft==0 && dd==m.phi1(d))
				particularcase=true;
		}

		if(particularcase) //(m_position,m_positionFace,c) presque alignés et si c est proche de la face
				  //aucun des "above" sur les dart ne va donner de résultats concluant (proche de 0 pour tous)
		{
			if(isnan(current[0]) || isnan(current[1]) || isnan(current[2]))
			{
				std::cout << __FILE__ << " " << __LINE__ << " NaN !" << std::endl;
				display();
				m_position = current;
				return;
			}

			volumeSpecialCase(current);
			return;
		}

		Geom::Orientation3D testAbove = isAbove(current,d,m_position);

		if(testAbove!=Geom::UNDER || (testRight==Geom::ON && isAbove(current,m.phi_1(d),m_position)!=Geom::UNDER)) {

			if(testAbove==Geom::OVER || whichSideOfFace(current,d)==Geom::UNDER) {

				mark.mark(d);

				above=true;
				d = m.phi2(d);

				if(mark.isMarked(d)) {
					dd = d;
					d = nextFaceNotMarked(d,mark);
Thomas's avatar
Thomas committed
708
					mark.mark(d);
Thomas's avatar
Thomas committed
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724

					if(d==dd) {
						volumeSpecialCase(current);
						return;
					}
				}

				m_positionFace = pointInFace(d);
			}
		}
	} while(above);

	Geom::Orientation3D wsof = whichSideOfFace(current,d);

	if(wsof==Geom::UNDER) {
		m_position = current;
725
		state = VOLUME;
Thomas's avatar
Thomas committed
726
727
728
729
	}
	else if(wsof==Geom::ON) {
		if(isAbove(current,d,m_position)==Geom::UNDER) {
			m_position = m_positionFace = current;
730
			state = FACE;
Thomas's avatar
Thomas committed
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
		}
		else {
			m_position = m_positionFace = current;
			edgeState(current);
		}
	}
	else {
		if(isAbove(current,d,m_position)==Geom::UNDER) {
//			m_position = m.intersectDartPlaneLine(d,m_position,current);
			Algo::Geometry::intersectionLineConvexFace<PFP>(m,d,position,m_position,current-m_position,m_position);
			faceState(current,wsof);
		}
		else {
//			m_position = m.intersectDartPlaneLineEdge(d,m_position,current);
			Algo::Geometry::intersectionLineConvexFace<PFP>(m,d,position,m_position,current-m_position,m_position);
			edgeState(current);
		}
	}
}

template <typename PFP>
void ParticleCell3D<PFP>::volumeSpecialCase(const VEC3& current)
{
	#ifdef DEBUG
	std::cout << "volumeSpecialCase " <<  d << std::endl;
	#endif

	Dart dd;
Thomas's avatar
Thomas committed
759
	CellMarkerStore mark(m,FACE);
Thomas's avatar
Thomas committed
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
840
841

	Dart d_min;

	std::vector<Dart> dart_list;
	std::vector<float> dist_list;

	std::list<Dart> visitedFaces;			// Faces that are traversed
	visitedFaces.push_back(d);				// Start with the face of d
	std::list<Dart>::iterator face;

	// For every face added to the list
	for (face = visitedFaces.begin();face != visitedFaces.end(); ++face)
	{
		if (!mark.isMarked(*face))
		{	// Face has not been visited yet

			Geom::Orientation3D wsof = whichSideOfFace(current,*face);
			if(wsof==Geom::OVER)
			{
				d = *face;

				if(isAbove(current,d,m_position)==Geom::UNDER)
				{
//					m_position = m.intersectDartPlaneLine(d,m_position,current);
					Algo::Geometry::intersectionLineConvexFace<PFP>(m,d,position,m_position,current-m_position,m_position);
					faceState(current,Geom::OVER);
				}
				else
				{
//					m_position = m.intersectDartPlaneLineEdge(d,m_position,current);
					Algo::Geometry::intersectionLineConvexFace<PFP>(m,d,position,m_position,current-m_position,m_position);
					edgeState(current);
				}

				return;
			}
			else if(wsof==Geom::ON)
			{
				m_position = current;
				d = *face;

				faceState(current);
				return;
			}

			Geom::Plane3D<typename PFP::REAL> pl = Algo::Geometry::facePlane<PFP>(m,*face,position);
			if(pl.normal()*VEC3(current-m_position)>0)
			{
				dist_list.push_back(-pl.distance(current));
				dart_list.push_back(*face);
			}

			// If the face wasn't crossed then mark visited darts (current face)
			// and add non visited adjacent faces to the list of face
			Dart ddd = *face;
			do {
					mark.mark(ddd);
					Dart adj = m.phi2(ddd);			// Get adjacent face
					if (adj != ddd && !mark.isMarked(adj))
						visitedFaces.push_back(adj);// Add it
			} while(ddd!=*face);
		}
	}

	if(dist_list.size()>0) {
		float min=dist_list[0];
		for(unsigned int i = 1;i<dist_list.size();++i)
		{
			if(dist_list[i]<min)
			{
				d=dart_list[i];
				min = dist_list[i];
			}
		}
	}

	m_positionFace = pointInFace(d);

	Geom::Orientation3D wsof = whichSideOfFace(current,d);

	if(wsof==Geom::UNDER) {
		m_position = current;
842
		state = VOLUME;
Thomas's avatar
Thomas committed
843
844
845
846
	}
	else if(wsof==Geom::ON) {
		if(isAbove(current,d,m_position)==Geom::UNDER) {
			m_position = current;
847
			state = FACE;
Thomas's avatar
Thomas committed
848
849
850
		}
		else {
			m_position = current;
851
			state = EDGE;
Thomas's avatar
Thomas committed
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
		}
	}
	else {
		if(isAbove(current,d,m_position)==Geom::UNDER)
		{
//			m_position = m.intersectDartPlaneLine(d,m_position,current);
			Algo::Geometry::intersectionLineConvexFace<PFP>(m,d,position,m_position,current-m_position,m_position);
			faceState(current,wsof);
		}
		else {
//			m_position = m.intersectDartPlaneLineEdge(d,m_position,current);
			Algo::Geometry::intersectionLineConvexFace<PFP>(m,d,position,m_position,current-m_position,m_position);
			edgeState(current);
		}
	}
}