source: issm/trunk/src/c/Bamgx/Mesh2.h@ 2856

Last change on this file since 2856 was 2856, checked in by Mathieu Morlighem, 15 years ago

removed some cout(s) (TBC)

File size: 42.3 KB
Line 
1#ifndef _MESH2_H_
2#define _MESH2_H_
3
4#include "../objects/objects.h"
5#include "../shared/shared.h"
6#include "../include/macros.h"
7#include "../toolkits/toolkits.h"
8
9//From MeshIo
10#include <cstdio>
11#include <iostream>
12#include <fstream>
13#include <cstring>
14#include <cstdlib>
15#include <cctype>
16#include <stdlib.h>
17#include <math.h>
18#include <limits.h>
19#include <time.h>
20
21#if (defined(unix) || defined(__unix)) && !defined(__AIX)
22#define SYSTIMES
23#include <sys/times.h>
24#include <unistd.h>
25#endif
26
27#include "meshtype.h"
28#include "R2.h"
29
30using namespace std;
31namespace bamg {
32
33const double Pi = 3.14159265358979323846264338328;
34const float fPi = 3.14159265358979323846264338328;
35
36extern int hinterpole;
37
38typedef P2<Icoor1,Icoor2> I2;
39
40inline int BinaryRand(){
41#ifdef RAND_MAX
42 const long HalfRandMax = RAND_MAX/2;
43 return rand() <HalfRandMax;
44#else
45 return rand() & 16384; // 2^14 (for sun because RAND_MAX is not def in stdlib.h)
46#endif
47
48}
49typedef P2<Real8,Real8> R2;
50typedef P2xP2<Int2,Int4> I2xI2;
51typedef P2<Real4,Real8> R2xR2;
52}
53
54#include "Metric.h"
55
56namespace bamg {
57inline float OppositeAngle(float a)
58 {return a<0 ? fPi + a :a - fPi ;}
59inline double OppositeAngle(double a)
60 {return a<0 ? Pi + a :a - Pi ;}
61
62Icoor2 inline det(const I2 &a,const I2 & b,const I2 &c)
63{
64 register Icoor2 bax = b.x - a.x ,bay = b.y - a.y;
65 register Icoor2 cax = c.x - a.x ,cay = c.y - a.y;
66 return bax*cay - bay*cax;}
67
68
69// def de numerotation dans un triangles
70static const Int2 VerticesOfTriangularEdge[3][2] = {{1,2},{2,0},{0,1}};
71static const Int2 EdgesVertexTriangle[3][2] = {{1,2},{2,0},{0,1}};
72static const Int2 OppositeVertex[3] = {0,1,2};
73static const Int2 OppositeEdge[3] = {0,1,2};
74static const Int2 NextEdge[3] = {1,2,0};
75static const Int2 PreviousEdge[3] = {2,0,1};
76static const Int2 NextVertex[3] = {1,2,0};
77static const Int2 PreviousVertex[3] = {2,0,1};
78
79Int4 AGoodNumberPrimeWith(Int4 n);
80
81// remark all the angle are in radian beetwen [-Pi,Pi]
82
83
84class Geometry;
85//static Geometry *NULLGeometry=0;
86class Triangles;
87class Triangle;
88class QuadTree;
89class GeometricalEdge;
90class VertexOnGeom;
91class VertexOnEdge;
92/////////////////////////////////////////////////////////////////////////////////////
93const int IsVertexOnGeom = 8;
94const int IsVertexOnVertex = 16;
95const int IsVertexOnEdge = 32;
96/////////////////////////////////////////////////////////////////////////////////////
97
98//class from MeshGeom
99class DoubleAndInt4 {
100public: double q; Int4 i3j;
101 int operator<(DoubleAndInt4 a){return q > a.q;}
102};// to sort by decroissant
103template<class T> inline void HeapSort(T *c,long n){
104 long l,j,r,i;
105 T crit;
106 c--; // on decale de 1 pour que le tableau commence a 1
107 if( n <= 1) return;
108 l = n/2 + 1;
109 r = n;
110 while (1) { // label 2
111 if(l <= 1 ) { // label 20
112 crit = c[r];
113 c[r--] = c[1];
114 if ( r == 1 ) { c[1]=crit; return;}
115 } else crit = c[--l];
116 j=l;
117 while (1) {// label 4
118 i=j;
119 j=2*j;
120 if (j>r) {c[i]=crit;break;} // L8 -> G2
121 if ((j<r) && (c[j] < c[j+1])) j++; // L5
122 if (crit < c[j]) c[i]=c[j]; // L6+1 G4
123 else {c[i]=crit;break;} //L8 -> G2
124 }
125 }
126}
127//End from MeshGeom
128
129
130class Direction { //
131 private:
132 Icoor1 dir;
133 public:
134 Direction(): dir(MaxICoor){}; // no direction set
135 Direction(Icoor1 i,Icoor1 j) { Icoor2 n2 = 2*(Abs(i)+Abs(j));
136 Icoor2 r = MaxICoor* (Icoor2) i;
137 Icoor1 r1 = (Icoor1) (2*(r/ n2)); // odd number
138 dir = (j>0) ? r1 : r1+1; // odd -> j>0 even -> j<0
139 }
140 int sens( Icoor1 i,Icoor1 j) { int r =1;
141 if (dir!= MaxICoor) {
142 Icoor2 x(dir/2),y1(MaxICoor/2-Abs(x)),y(dir%2?-y1:y1);
143 r = (x*i + y*j) >=0;}
144 return r;}
145};
146/////////////////////////////////////////////////////////////////////////////////////
147class Vertex {public:
148 I2 i; // allow to use i.x, and i.y in long int (beware of scale and centering)
149 R2 r; // allow to use r.x, and r.y in double
150 Metric m;
151 Int4 ReferenceNumber;
152 Direction DirOfSearch;
153 union {
154 Triangle * t; // one triangle which contained the vertex
155 Int4 color;
156 Vertex * to;// use in geometry Vertex to now the Mesh Vertex associed
157 VertexOnGeom * on; // if vint 8; // set with Triangles::SetVertexFieldOn()
158 Vertex * onbv; // if vint == 16 on Background vertex Triangles::SetVertexFieldOnBTh()
159 VertexOnEdge * onbe; // if vint == 32 on Background edge
160 };
161 Int1 vint; // the vertex number in triangle; varies between 0 and 2 in t
162 operator I2 () const {return i;} // operator de cast
163 operator const R2 & () const {return r;}// operator de cast
164// operator R2 & () {return r;}// operator de cast
165 Real8 operator()(R2 x) const { return m(x);}
166 operator Metric () const {return m;}// operator de cast
167 Int4 Optim(int = 1,int =0);
168 // Vertex(){}
169 // ~Vertex(){}
170 Real8 Smoothing(Triangles & ,const Triangles & ,Triangle * & ,Real8 =1);
171 int ref() const { return ReferenceNumber;}
172
173 friend std::ostream& operator <<(std::ostream& f, const Vertex & v)
174 {f << "(" << v.i << "," << v.r << MatVVP2x2(v.m) << ")" ; return f;}
175 inline void Set(const Vertex & rec,const Triangles &,Triangles &);
176};
177
178double QuadQuality(const Vertex &,const Vertex &,const Vertex &,const Vertex &);
179
180// extern Vertex *Meshend , *Meshbegin;
181
182/////////////////////////////////////////////////////////////////////////////////////
183class TriangleAdjacent {
184 friend std::ostream& operator <<(std::ostream& f, const TriangleAdjacent & ta)
185 {f << "{" << ta.t << "," << ((int) ta.a) << "}" ;
186 return f;}
187
188public:
189 Triangle * t; // le triangle
190 int a; // le numero de l arete
191
192 TriangleAdjacent(Triangle * tt,int aa): t(tt),a(aa &3) {};
193 TriangleAdjacent() {};
194
195 operator Triangle * () const {return t;}
196 operator Triangle & () const {return *t;}
197 operator int() const {return a;}
198 TriangleAdjacent & operator++()
199 {
200 a= NextEdge[a];
201 return *this;}
202 TriangleAdjacent operator--()
203 {
204 a= PreviousEdge[a];
205 return *this;}
206 inline TriangleAdjacent Adj() const ;
207 int swap();
208 inline void SetAdj2(const TriangleAdjacent& , int =0);
209 inline Vertex * EdgeVertex(const int &) const ;
210 inline Vertex * OppositeVertex() const ;
211 inline Icoor2 & det() const;
212 inline int Locked() const ;
213 inline int GetAllFlag_UnSwap() const ;
214 inline void SetLock();
215 inline int MarkUnSwap() const;
216 inline void SetMarkUnSwap();
217 inline void SetCracked();
218 inline int Cracked() const ;
219};// end of Vertex class
220
221
222/////////////////////////////////////////////////////////////////////////////////////
223class Edge { public:
224 Vertex * v[2];
225 Int4 ref;
226 GeometricalEdge * on;
227 Vertex & operator[](int i){return *v[i];};
228 Vertex * operator()(int i){return v[i];};
229
230 void ReNumbering(Vertex *vb,Vertex *ve, Int4 *renu)
231 {
232 if (v[0] >=vb && v[0] <ve) v[0] = vb + renu[v[0]-vb];
233 if (v[1] >=vb && v[1] <ve) v[1] = vb + renu[v[1]-vb];
234 }
235
236 const Vertex & operator[](int i) const { return *v[i];};
237 R2 operator()(double t) const; // return the point
238 // on the curve edge a t in [0:1]
239 Edge * adj[2]; // the 2 adj edges if on the same curve
240
241 int Intersection(const Edge & e) const {
242 if (!(adj[0]==&e || adj[1]==&e)){
243 throw ErrorException(__FUNCT__,exprintf("Intersection bug"));
244 }
245 if (adj[0]!=&e && adj[1]!=&e){
246 throw ErrorException(__FUNCT__,exprintf("adj[0]!=&e && adj[1]!=&e"));
247 }
248 return adj[0]==&e ? 0 : 1;
249 }
250 Real8 MetricLength() const ;
251 inline void Set(const Triangles &,Int4,Triangles &);
252
253}; // end of Edge class
254
255/////////////////////////////////////////////////////////////////////////////////////
256class GeometricalVertex :public Vertex {
257 int cas;
258 friend class Geometry;
259 GeometricalVertex * link; // link all the same GeometricalVertex circular (Crack)
260public:
261 int Corner() const {return cas&4;}
262 int Required()const {return cas&6;}// a corner is required
263 void SetCorner(){ cas |= 4;}
264 void SetRequired(){ cas |= 2;}
265 void Set(){cas=0;}
266 GeometricalVertex() :cas(0), link(this) {};
267
268 GeometricalVertex * The() {
269 if (!link){
270 throw ErrorException(__FUNCT__,exprintf("!link"));
271 }
272 return link;
273 }// return a unique vertices
274
275 int IsThe() const { return link == this;}
276
277inline void Set(const GeometricalVertex & rec,const Geometry & Gh ,const Geometry & GhNew);
278 inline friend std::ostream& operator <<(std::ostream& f, const GeometricalVertex & s)
279 { f << s.r << "," << s.cas << ".";return f; }
280};
281
282/////////////////////////////////////////////////////////////////////////////////////
283class GeometricalEdge {
284 public:
285 GeometricalVertex * v[2];
286 Int4 ref;
287 Int4 CurveNumber;
288 R2 tg[2]; // the 2 tangente
289 // if tg[0] =0 => no continuite
290 GeometricalEdge * Adj [2];
291 int SensAdj[2];
292// private:
293 int flag ;
294 public:
295 GeometricalEdge * link; // if Cracked() or Equi()
296
297// end of data
298
299 GeometricalVertex & operator[](int i){return *v[i];};
300 const GeometricalVertex & operator[](int i) const { return *v[i];};
301 GeometricalVertex * operator()(int i){return v[i];};
302 // inline void Set(const Geometry &,Int4,Geometry &);
303
304 R2 F(Real8 theta) const ; // parametrization of the curve edge
305 Real8 R1tg(Real8 theta,R2 &t) const ; // 1/radius of curvature + tangente
306 int Cracked() const {return flag & 1;}
307 int Dup() const { return flag & 32;}
308 int Equi()const {return flag & 2;}
309 int ReverseEqui()const {return flag & 128;}
310 int TgA()const {return flag &4;}
311 int TgB()const {return flag &8;}
312 int Tg(int i) const{return i==0 ? TgA() : TgB();}
313 int Mark()const {return flag &16;}
314 int Required() { return flag & 64;}
315 void SetCracked() { flag |= 1;}
316 void SetDup() { flag |= 32;} // not a real edge
317 void SetEqui() { flag |= 2;}
318 void SetTgA() { flag|=4;}
319 void SetTgB() { flag|=8;}
320 void SetMark() { flag|=16;}
321 void SetUnMark() { flag &= 1007 /* 1023-16*/;}
322 void SetRequired() { flag |= 64;}
323 void SetReverseEqui() {flag |= 128;}
324
325 inline void Set(const GeometricalEdge & rec,const Geometry & Th ,Geometry & ThNew);
326
327};
328
329class Curve {public:
330 GeometricalEdge * be,*ee; // begin et end edge
331 int kb,ke; // begin vetex and end vertex
332 Curve *next; // next curve equi to this
333 bool master; // true => of equi curve point on this curve
334 inline void Set(const Curve & rec,const Geometry & Th ,Geometry & ThNew);
335 Curve() : be(0),ee(0),kb(0),ke(0),next(0),master(true) {}
336 void Reverse() { Exchange(be,ee); Exchange(kb,ke);} // revese the sens of the curse
337};
338
339
340
341/////////////////////////////////////////////////////////////////////////////////////
342class Triangle {
343 friend class TriangleAdjacent;
344 friend std::ostream& operator <<(std::ostream& f, const Triangle & ta);
345
346
347 private: // les arete sont opposes a un sommet
348 Vertex * ns [3]; // 3 vertices if t is triangle, t[i] allowed by access function, (*t)[i] if pointer
349 Triangle * at [3]; // nu triangle adjacent
350 Int1 aa[3]; // les nu des arete dans le triangles (mod 4)
351 public:
352 Icoor2 det; // determinant du triangle (2 fois l aire des vertices entieres)
353 union {
354 Triangle * link ;
355 Int4 color;
356 };
357 void SetDet() {
358 if(ns[0] && ns[1] && ns[2]) det = bamg::det(*ns[0],*ns[1],*ns[2]);
359 else det = -1; }
360 Triangle() {}
361 Triangle(Triangles *Th,Int4 i,Int4 j,Int4 k);
362 Triangle(Vertex *v0,Vertex *v1,Vertex *v2);
363 inline void Set(const Triangle &,const Triangles &,Triangles &);
364 inline int In(Vertex *v) const { return ns[0]==v || ns[1]==v || ns[2]==v ;}
365 TriangleAdjacent FindBoundaryEdge(int ) const;
366
367 void ReNumbering(Triangle *tb,Triangle *te, Int4 *renu)
368 {
369 if (link >=tb && link <te) link = tb + renu[link -tb];
370 if (at[0] >=tb && at[0] <te) at[0] = tb + renu[at[0]-tb];
371 if (at[1] >=tb && at[1] <te) at[1] = tb + renu[at[1]-tb];
372 if (at[2] >=tb && at[2] <te) at[2] = tb + renu[at[2]-tb];
373 }
374 void ReNumbering(Vertex *vb,Vertex *ve, Int4 *renu)
375 {
376 if (ns[0] >=vb && ns[0] <ve) ns[0] = vb + renu[ns[0]-vb];
377 if (ns[1] >=vb && ns[1] <ve) ns[1] = vb + renu[ns[1]-vb];
378 if (ns[2] >=vb && ns[2] <ve) ns[2] = vb + renu[ns[2]-vb];
379 }
380
381
382 const Vertex & operator[](int i) const {return *ns[i];};
383 Vertex & operator[](int i) {return *ns[i];};
384
385 const Vertex * operator()(int i) const {return ns[i];};
386 Vertex * & operator()(int i) {return ns[i];};
387
388 TriangleAdjacent Adj(int i) const // triangle adjacent + arete
389 { return TriangleAdjacent(at[i],aa[i]&3);};
390
391 Triangle * TriangleAdj(int i) const
392 {return at[i&3];} // triangle adjacent + arete
393 Int1 NuEdgeTriangleAdj(int i) const
394 {return aa[i&3]&3;} // Number of the adjacent edge in adj tria
395
396 inline Real4 qualite() ;
397
398
399 void SetAdjAdj(Int1 a)
400 { a &= 3;
401 register Triangle *tt=at[a];
402 aa [a] &= 55; // remove MarkUnSwap
403 register Int1 aatt = aa[a] & 3;
404 if(tt){
405 tt->at[aatt]=this;
406 tt->aa[aatt]=a + (aa[a] & 60 ) ;}// Copy all the mark
407 }
408
409 void SetAdj2(Int1 a,Triangle *t,Int1 aat)
410 { at[a]=t;aa[a]=aat;
411 if(t) {t->at[aat]=this;t->aa[aat]=a;}
412 }
413
414 void SetTriangleContainingTheVertex()
415 {
416 if (ns[0]) (ns[0]->t=this,ns[0]->vint=0);
417 if (ns[1]) (ns[1]->t=this,ns[1]->vint=1);
418 if (ns[2]) (ns[2]->t=this,ns[2]->vint=2);
419 }
420
421 int swap(Int2 a1,int=0);
422 Int4 Optim(Int2 a,int =0);
423
424 int Locked(int a)const { return aa[a]&4;}
425 int Hidden(int a)const { return aa[a]&16;}
426 int Cracked(int a) const { return aa[a] & 32;}
427 // for optimisation
428 int GetAllflag(int a){return aa[a] & 1020;}
429 void SetAllFlag(int a,int f){aa[a] = (aa[a] &3) + (1020 & f);}
430
431 void SetHidden(int a){
432 register Triangle * t = at[a];
433 if(t) t->aa[aa[a] & 3] |=16;
434 aa[a] |= 16;}
435 void SetCracked(int a){
436 register Triangle * t = at[a];
437 if(t) t->aa[aa[a] & 3] |=32;
438 aa[a] |= 32;}
439
440 double QualityQuad(int a,int option=1) const;
441 Triangle * Quadrangle(Vertex * & v0,Vertex * & v1,Vertex * & v2,Vertex * & v3) const ;
442
443 void SetLocked(int a){
444 register Triangle * t = at[a];
445 t->aa[aa[a] & 3] |=4;
446 aa[a] |= 4;}
447
448 void SetMarkUnSwap(int a){
449 register Triangle * t = at[a];
450 t->aa[aa[a] & 3] |=8;
451 aa[a] |=8 ;}
452
453
454 void SetUnMarkUnSwap(int a){
455 register Triangle * t = at[a];
456 t->aa[aa[a] & 3] &=55; // 23 + 32
457 aa[a] &=55 ;}
458
459}; // end of Triangle class
460
461
462
463
464class ListofIntersectionTriangles {
465/////////////////////////////////////////////////////////////////////////////////////
466class IntersectionTriangles {
467public:
468 Triangle *t;
469 Real8 bary[3]; // use if t != 0
470 R2 x;
471 Metric m;
472 Real8 s;// abscisse curviline
473 Real8 sp; // len of the previous seg in m
474 Real8 sn;// len of the next seg in m
475};
476/////////////////////////////////////////////////////////////////////////////////////
477class SegInterpolation {
478 public:
479 GeometricalEdge * e;
480 Real8 sBegin,sEnd; // abscisse of the seg on edge parameter
481 Real8 lBegin,lEnd; // length abscisse set in ListofIntersectionTriangles::Length
482 int last;// last index in ListofIntersectionTriangles for this Sub seg of edge
483 R2 F(Real8 s){
484 Real8 c01=lEnd-lBegin, c0=(lEnd-s)/c01, c1=(s-lBegin)/c01;
485 if (lBegin>s || s>lEnd){
486 throw ErrorException(__FUNCT__,exprintf("lBegin>s || s>lEnd"));
487 }
488 return e->F(sBegin*c0+sEnd*c1);}
489};
490
491 int MaxSize; //
492 int Size; //
493 Real8 len; //
494 int state;
495 IntersectionTriangles * lIntTria;
496 int NbSeg;
497 int MaxNbSeg;
498 SegInterpolation * lSegsI;
499 public:
500 IntersectionTriangles & operator[](int i) {return lIntTria[i];}
501 operator int&() {return Size;}
502
503ListofIntersectionTriangles(int n=256,int m=16)
504: MaxSize(n), Size(0), len(-1),state(-1),lIntTria(new IntersectionTriangles[n]) ,
505 NbSeg(0), MaxNbSeg(m), lSegsI(new SegInterpolation[m])
506{
507 long int verbosity=0;
508 if (verbosity>9) printf(" construct ListofIntersectionTriangles %i %i\n",MaxSize,MaxNbSeg);
509};
510
511 ~ListofIntersectionTriangles(){
512 if (lIntTria) delete [] lIntTria,lIntTria=0;
513 if (lSegsI) delete [] lSegsI,lSegsI=0;}
514 void init(){state=0;len=0;Size=0;}
515
516 int NewItem(Triangle * tt,Real8 d0,Real8 d1,Real8 d2);
517 int NewItem(R2,const Metric & );
518 void NewSubSeg(GeometricalEdge *e,Real8 s0,Real8 s1)
519 {
520 long int verbosity=0;
521
522 if (NbSeg>=MaxNbSeg) {
523 int mneo= MaxNbSeg;
524 MaxNbSeg *= 2;
525 if (verbosity>3){
526 printf(" reshape lSegsI from %i to %i\n",mneo,MaxNbSeg);
527 }
528 SegInterpolation * lEn = new SegInterpolation[MaxNbSeg];
529 if (!lSegsI || NbSeg>=MaxNbSeg){
530 throw ErrorException(__FUNCT__,exprintf("!lSegsI || NbSeg>=MaxNbSeg"));
531 }
532 for (int i=0;i< NbSeg;i++)
533 lEn[i] = lSegsI[MaxNbSeg]; // copy old to new
534 delete [] lSegsI; // remove old
535 lSegsI = lEn;
536 }
537 if (NbSeg)
538 lSegsI[NbSeg-1].last=Size;
539 lSegsI[NbSeg].e=e;
540 lSegsI[NbSeg].sBegin=s0;
541 lSegsI[NbSeg].sEnd=s1;
542 NbSeg++;
543 }
544
545// void CopyMetric(int i,int j){ lIntTria[j].m=lIntTria[i].m;}
546// void CopyMetric(const Metric & mm,int j){ lIntTria[j].m=mm;}
547
548 void ReShape() {
549 register int newsize = MaxSize*2;
550 IntersectionTriangles* nw = new IntersectionTriangles[newsize];
551 if (!nw){
552 throw ErrorException(__FUNCT__,exprintf("!nw"));
553 }
554 for (int i=0;i<MaxSize;i++) // recopy
555 nw[i] = lIntTria[i];
556 long int verbosity=0;
557 if(verbosity>3) printf(" ListofIntersectionTriangles ReShape Maxsize %i -> %i\n",MaxSize,MaxNbSeg);
558 MaxSize = newsize;
559 delete [] lIntTria;// remove old
560 lIntTria = nw; // copy pointer
561 }
562
563 void SplitEdge(const Triangles & ,const R2 &,const R2 &,int nbegin=0);
564 Real8 Length();
565 Int4 NewPoints(Vertex *,Int4 & nbv,Int4 nbvx);
566};
567
568
569/////////////////////////////////////////////////////////////////////////////////////
570class GeometricalSubDomain {
571public:
572 GeometricalEdge *edge;
573 int sens; // -1 or 1
574 Int4 ref;
575 inline void Set(const GeometricalSubDomain &,const Geometry & ,const Geometry &);
576
577};
578/////////////////////////////////////////////////////////////////////////////////////
579class SubDomain {
580public:
581 Triangle * head;
582 Int4 ref;
583 int sens; // -1 or 1
584 Edge * edge; // to geometrical
585 inline void Set(const Triangles &,Int4,Triangles &);
586
587};
588/////////////////////////////////////////////////////////////////////////////////////
589class VertexOnGeom { public:
590
591 Vertex * mv;
592 Real8 abscisse;
593 union{
594 GeometricalVertex * gv; // if abscisse <0;
595 GeometricalEdge * ge; // if abscisse in [0..1]
596 };
597 inline void Set(const VertexOnGeom&,const Triangles &,Triangles &);
598 int OnGeomVertex()const {return this? abscisse <0 :0;}
599 int OnGeomEdge() const {return this? abscisse >=0 :0;}
600 VertexOnGeom(): mv(0),abscisse(0){gv=0;}
601 VertexOnGeom(Vertex & m,GeometricalVertex &g) : mv(&m),abscisse(-1){gv=&g;}
602 VertexOnGeom(Vertex & m,GeometricalEdge &g,Real8 s) : mv(&m),abscisse(s){ge=&g;}
603 operator Vertex * () const {return mv;}
604 operator GeometricalVertex * () const {return gv;}
605 operator GeometricalEdge * () const {return ge;}
606 operator const Real8 & () const {return abscisse;}
607 int IsRequiredVertex(){ return this? (( abscisse<0 ? (gv?gv->Required():0):0 )) : 0;}
608 void SetOn(){mv->on=this;mv->vint=IsVertexOnGeom;}
609 friend std::ostream& operator <<(std::ostream& f, const VertexOnGeom & vog){
610 f << vog.abscisse << " " << vog.mv << " " << vog.gv << " ; ";
611 if (vog.abscisse < 0) f << *vog.gv << " ;; " ;
612 // else f << *vog.ge << " ;; " ;
613 return f;}
614 inline void Set(const Triangles &,Int4,Triangles &);
615
616};
617/////////////////////////////////////////////////////////////////////////////////////
618class VertexOnVertex {public:
619 Vertex * v, *bv;
620 VertexOnVertex(Vertex * w,Vertex *bw) :v(w),bv(bw){}
621 VertexOnVertex() {};
622 inline void Set(const Triangles &,Int4,Triangles &);
623 void SetOnBTh(){v->onbv=bv;v->vint=IsVertexOnVertex;}
624};
625/////////////////////////////////////////////////////////////////////////////////////
626class VertexOnEdge {public:
627 Vertex * v;
628 Edge * be;
629 Real8 abcisse;
630 VertexOnEdge( Vertex * w, Edge *bw,Real8 s) :v(w),be(bw),abcisse(s) {}
631 VertexOnEdge(){}
632 inline void Set(const Triangles &,Int4,Triangles &);
633 void SetOnBTh(){v->onbe=this;v->vint=IsVertexOnEdge;}
634 Vertex & operator[](int i) const { return (*be)[i];}
635 operator Real8 () const { return abcisse;}
636 operator Vertex * () const { return v;}
637 operator Edge * () const { return be;}
638};
639
640 inline TriangleAdjacent FindTriangleAdjacent(Edge &E);
641 inline Vertex * TheVertex(Vertex * a); // for remove crak in mesh
642/////////////////////////////////////////////////////////////////////////////////////
643
644class CrackedEdge { // a small class to store on crack an uncrack information
645 friend class Triangles;
646 friend std::ostream& operator <<(std::ostream& f, const Triangles & Th) ;
647 class CrackedTriangle {
648 friend class Triangles;
649 friend class CrackedEdge;
650 friend std::ostream& operator <<(std::ostream& f, const Triangles & Th) ;
651 Triangle * t; // edge of triangle t
652 int i; // edge number of in triangle
653 Edge *edge; // the 2 edge
654 Vertex *New[2]; // new vertex number
655 CrackedTriangle() : t(0),i(0),edge(0) { New[0]=New[1]=0;}
656 CrackedTriangle(Edge * a) : t(0),i(0),edge(a) { New[0]=New[1]=0;}
657 void Crack(){
658 Triangle & T(*t);
659 int i0=VerticesOfTriangularEdge[i][0];
660 int i1=VerticesOfTriangularEdge[i][0];
661 if (!New[0] && !New[1]){
662 throw ErrorException(__FUNCT__,exprintf("!New[0] && !New[1]"));
663 }
664 T(i0) = New[0];
665 T(i1) = New[1];}
666 void UnCrack(){
667 Triangle & T(*t);
668 int i0=VerticesOfTriangularEdge[i][0];
669 int i1=VerticesOfTriangularEdge[i][0];
670 if (!New[0] && !New[1]){
671 throw ErrorException(__FUNCT__,exprintf("!New[0] && !New[1]"));
672 }
673 T(i0) = TheVertex(T(i0));
674 T(i1) = TheVertex(T(i1));}
675 void Set() {
676 TriangleAdjacent ta ( FindTriangleAdjacent(*edge));
677 t = ta;
678 i = ta;
679
680 New[0] = ta.EdgeVertex(0);
681 New[1] = ta.EdgeVertex(1);
682 // warning the ref
683
684 }
685
686 }; // end of class CrackedTriangle
687 public:
688 CrackedTriangle a,b;
689 CrackedEdge() :a(),b() {}
690 CrackedEdge(Edge * start, Int4 i,Int4 j) : a(start+i),b(start+j) {};
691 CrackedEdge(Edge * e0, Edge * e1 ) : a(e0),b(e1) {};
692
693 void Crack() { a.Crack(); b.Crack();}
694 void UnCrack() { a.UnCrack(); b.UnCrack();}
695 void Set() { a.Set(), b.Set();}
696};
697
698/////////////////////////////////////////////////////////////////////////////////////
699class Triangles {
700public:
701
702 enum TypeFileMesh {
703 AutoMesh=0,BDMesh=1,NOPOMesh=2,amMesh=3,am_fmtMesh=4,amdbaMesh=5,
704 ftqMesh=6,mshMesh=7};
705
706 int static counter; // to kown the number of mesh in memory
707 int OnDisk; // true if on disk
708 Geometry & Gh; // Geometry
709 Triangles & BTh; // Background Mesh Bth==*this =>no background
710
711 Int4 NbRef; // counter of ref on the this class if 0 we can delete
712 Int4 nbvx,nbtx; // nombre max de sommets , de triangles
713
714 Int4 nt,nbv,nbt,nbiv,nbe; // nb of legal triangles, nb of vertex, of triangles,
715 // of initial vertices, of edges with reference,
716 Int4 NbOfQuad; // nb of quadrangle
717
718 Int4 NbSubDomains; //
719 Int4 NbOutT; // Nb of oudeside triangle
720 Int4 NbOfTriangleSearchFind;
721 Int4 NbOfSwapTriangle;
722 char * name, *identity;
723 Vertex * vertices; // data of vertices des sommets
724
725 Int4 NbVerticesOnGeomVertex;
726 VertexOnGeom * VerticesOnGeomVertex;
727
728 Int4 NbVerticesOnGeomEdge;
729 VertexOnGeom * VerticesOnGeomEdge;
730
731 Int4 NbVertexOnBThVertex;
732 VertexOnVertex *VertexOnBThVertex;
733
734 Int4 NbVertexOnBThEdge;
735 VertexOnEdge *VertexOnBThEdge;
736
737
738 Int4 NbCrackedVertices;
739
740
741 Int4 NbCrackedEdges;
742 CrackedEdge *CrackedEdges;
743
744
745 R2 pmin,pmax; // extrema
746 Real8 coefIcoor; // coef to integer Icoor1;
747
748 Triangle * triangles;
749 Edge * edges;
750
751 QuadTree *quadtree;
752 Vertex ** ordre;
753 SubDomain * subdomains;
754 ListofIntersectionTriangles lIntTria;
755// end of variable
756
757 Triangles(Int4 i);//:BTh(*this),Gh(*new Geometry()){PreInit(i);}
758
759
760 ~Triangles();
761 Triangles(const char * ,Real8=-1) ;
762 Triangles(BamgMesh* bamgmesh,BamgOpts* bamgopts);
763
764 Triangles(Int4 nbvx,Triangles & BT,int keepBackVertices=1)
765 :Gh(BT.Gh),BTh(BT) {
766 try {GeomToTriangles1(nbvx,keepBackVertices);}
767 catch(...) { this->~Triangles(); throw; } }
768
769 Triangles(Int4 nbvx,Geometry & G)
770 :Gh(G),BTh(*this){
771 try { GeomToTriangles0(nbvx);}
772 catch(...) { this->~Triangles(); throw; } }
773 Triangles(Triangles &,Geometry * pGh=0,Triangles* pBTh=0,Int4 nbvxx=0 ); // COPY OPERATEUR
774 Triangles(const Triangles &,const int *flag,const int *bb); // truncature
775
776 void SetIntCoor(const char * from =0);
777
778 // void RandomInit();
779 // void CubeInit(int ,int);
780
781 Real8 MinimalHmin() {return 2.0/coefIcoor;}
782 Real8 MaximalHmax() {return Max(pmax.x-pmin.x,pmax.y-pmin.y);}
783 const Vertex & operator[] (Int4 i) const { return vertices[i];};
784 Vertex & operator[](Int4 i) { return vertices[i];};
785 const Triangle & operator() (Int4 i) const { return triangles[i];};
786 Triangle & operator()(Int4 i) { return triangles[i];};
787 I2 toI2(const R2 & P) const {
788 return I2( (Icoor1) (coefIcoor*(P.x-pmin.x))
789 ,(Icoor1) (coefIcoor*(P.y-pmin.y)) );}
790 R2 toR2(const I2 & P) const {
791 return R2( (double) P.x/coefIcoor+pmin.x, (double) P.y/coefIcoor+pmin.y);}
792 void Add( Vertex & s,Triangle * t,Icoor2 * =0) ;
793 void Insert();
794 // void InsertOld();
795 void ForceBoundary();
796 void Heap();
797 void FindSubDomain(int );
798 Int4 ConsRefTriangle(Int4 *) const;
799 void ShowHistogram() const;
800 void ShowRegulaty() const; // Add FH avril 2007
801// void ConsLinkTriangle();
802
803 void ReMakeTriangleContainingTheVertex();
804 void UnMarkUnSwapTriangle();
805 void SmoothMetric(Real8 raisonmax) ;
806 void BoundAnisotropy(Real8 anisomax,double hminaniso= 1e-100) ;
807 void MaxSubDivision(Real8 maxsubdiv);
808 Edge** MakeGeometricalEdgeToEdge();
809 void SetVertexFieldOn();
810 void SetVertexFieldOnBTh();
811 Int4 SplitInternalEdgeWithBorderVertices();
812 void MakeQuadrangles(double costheta);
813 int SplitElement(int choice);
814 void MakeQuadTree();
815 void NewPoints( Triangles &,int KeepBackVertex =1 );
816 Int4 InsertNewPoints(Int4 nbvold,Int4 & NbTSwap) ;
817 void NewPointsOld( Triangles & );
818 void NewPoints(int KeepBackVertex=1){ NewPoints(*this,KeepBackVertex);}
819 void ReNumberingTheTriangleBySubDomain(bool justcompress=false);
820 void ReNumberingVertex(Int4 * renu);
821 void SmoothingVertex(int =3,Real8=0.3);
822 Metric MetricAt (const R2 &) const;
823 GeometricalEdge * ProjectOnCurve( Edge & AB, Vertex & A, Vertex & B,Real8 theta,
824 Vertex & R,VertexOnEdge & BR,VertexOnGeom & GR);
825
826 Int4 Number(const Triangle & t) const { return &t - triangles;}
827 Int4 Number(const Triangle * t) const { return t - triangles;}
828 Int4 Number(const Vertex & t) const { return &t - vertices;}
829 Int4 Number(const Vertex * t) const { return t - vertices;}
830 Int4 Number(const Edge & t) const { return &t - edges;}
831 Int4 Number(const Edge * t) const { return t - edges;}
832 Int4 Number2(const Triangle * t) const {
833 // if(t>= triangles && t < triangles + nbt )
834 return t - triangles;
835 // else return t - OutSidesTriangles;
836 }
837
838 Vertex * NearestVertex(Icoor1 i,Icoor1 j) ;
839 Triangle * FindTriangleContening(const I2 & ,Icoor2 [3],Triangle *tstart=0) const;
840
841 void ReadMesh(BamgMesh* bamgmesh, BamgOpts* bamgopts);
842 void WriteMesh(BamgMesh* bamgmesh,BamgOpts* bamgopts);
843
844 void ReadMetric(BamgOpts* bamgopts,const Real8 hmin,const Real8 hmax,const Real8 coef);
845 void WriteMetric(BamgOpts* bamgopts);
846 void IntersectConsMetric(const double * s,const Int4 nbsol,const int * typsols,
847 const Real8 hmin,const Real8 hmax, const Real8 coef,
848 const Real8 anisomax,const Real8 CutOff=1.e-4,const int NbJacobi=1,
849 const int DoNormalisation=1,
850 const double power=1.0,
851 const int choise=0);
852 void IntersectGeomMetric(const Real8 err,const int iso);
853
854
855 int isCracked() const {return NbCrackedVertices != 0;}
856 int Crack();
857 int UnCrack();
858
859 friend std::ostream& operator <<(std::ostream& f, const Triangles & Th);
860 void ConsGeometry(Real8 =-1.0,int *equiedges=0); // construct a geometry if no geo
861 void FillHoleInMesh() ;
862 int CrackMesh();
863 private:
864 void GeomToTriangles1(Int4 nbvx,int KeepBackVertices=1);// the real constructor mesh adaption
865 void GeomToTriangles0(Int4 nbvx);// the real constructor mesh generator
866 void PreInit(Int4,char * =0 );
867
868}; // End Class Triangles
869
870
871/////////////////////////////////////////////////////////////////////////////////////
872class Geometry {
873public:
874 int OnDisk;
875 Int4 NbRef; // counter of ref on the this class if 0 we can delete
876
877 char *name;
878 Int4 nbvx,nbtx; // nombre max de sommets , de Geometry
879 Int4 nbv,nbt,nbiv,nbe; // nombre de sommets, de Geometry, de sommets initiaux,
880 Int4 NbSubDomains; //
881 Int4 NbEquiEdges;
882 Int4 NbCrackedEdges;
883// Int4 nbtf;// de triangle frontiere
884 Int4 NbOfCurves;
885 int empty(){return (nbv ==0) && (nbt==0) && (nbe==0) && (NbSubDomains==0); }
886 GeometricalVertex * vertices; // data of vertices des sommets
887 Triangle * triangles;
888 GeometricalEdge * edges;
889 QuadTree *quadtree;
890 GeometricalSubDomain *subdomains;
891 Curve *curves;
892 ~Geometry();
893 Geometry(const Geometry & Gh); //Copy Operator
894 Geometry(int nbg,const Geometry ** ag); // intersection operator
895
896 R2 pmin,pmax; // extrema
897 Real8 coefIcoor; // coef to integer Icoor1;
898 Real8 MaximalAngleOfCorner;
899
900// end of data
901
902
903 I2 toI2(const R2 & P) const {
904 return I2( (Icoor1) (coefIcoor*(P.x-pmin.x))
905 ,(Icoor1) (coefIcoor*(P.y-pmin.y)) );}
906
907 Real8 MinimalHmin() {return 2.0/coefIcoor;}
908 Real8 MaximalHmax() {return Max(pmax.x-pmin.x,pmax.y-pmin.y);}
909 void ReadGeometry(BamgGeom* bamggeom, BamgOpts* bamgopts);
910 void EmptyGeometry();
911 Geometry() {EmptyGeometry();}// empty Geometry
912 void AfterRead();
913 Geometry(BamgGeom* bamggeom, BamgOpts* bamgopts) {EmptyGeometry();OnDisk=1;ReadGeometry(bamggeom,bamgopts);AfterRead();}
914
915 const GeometricalVertex & operator[] (Int4 i) const { return vertices[i];};
916 GeometricalVertex & operator[](Int4 i) { return vertices[i];};
917 const GeometricalEdge & operator() (Int4 i) const { return edges[i];};
918 GeometricalEdge & operator()(Int4 i) { return edges[i];};
919 Int4 Number(const GeometricalVertex & t) const { return &t - vertices;}
920 Int4 Number(const GeometricalVertex * t) const { return t - vertices;}
921 Int4 Number(const GeometricalEdge & t) const { return &t - edges;}
922 Int4 Number(const GeometricalEdge * t) const { return t - edges;}
923 Int4 Number(const Curve * c) const { return c - curves;}
924
925 void UnMarkEdges() {
926 for (Int4 i=0;i<nbe;i++) edges[i].SetUnMark();}
927
928 GeometricalEdge * ProjectOnCurve(const Edge & ,Real8,Vertex &,VertexOnGeom &) const ;
929 GeometricalEdge * Contening(const R2 P, GeometricalEdge * start) const;
930 friend std::ostream& operator <<(std::ostream& f, const Geometry & Gh);
931 void WriteGeometry(BamgGeom* bamggeom, BamgOpts* bamgopts);
932}; // End Class Geometry
933
934//From Metric.cpp
935inline Real8 det3x3(Real8 A[3] ,Real8 B[3],Real8 C[3])
936{ return A[0] * ( B[1]*C[2]-B[2]*C[1])
937 - A[1] * ( B[0]*C[2]-B[2]*C[0])
938 + A[2] * ( B[0]*C[1]-B[1]*C[0]);
939}
940
941/////////////////////////////////////////////////////////////////////////////////////
942/////////////////////////////////////////////////////////////////////////////////////
943/////////////////// END CLASS ////////////////////////////////////
944/////////////////////////////////////////////////////////////////////////////////////
945/////////////////////////////////////////////////////////////////////////////////////
946
947inline Triangles::Triangles(Int4 i) :Gh(*new Geometry()),BTh(*this){PreInit(i);}
948
949extern Triangles * CurrentTh;
950
951TriangleAdjacent CloseBoundaryEdge(I2 ,Triangle *, double &,double &) ;
952TriangleAdjacent CloseBoundaryEdgeV2(I2 A,Triangle *t, double &a,double &b);
953
954Int4 FindTriangle(Triangles &Th, Real8 x, Real8 y, double* a,int & inside);
955
956
957
958inline Triangle * Triangle::Quadrangle(Vertex * & v0,Vertex * & v1,Vertex * & v2,Vertex * & v3) const
959{
960// return the other triangle of the quad if a quad or 0 if not a quat
961 Triangle * t =0;
962 if (link) {
963 int a=-1;
964 if (aa[0] & 16 ) a=0;
965 if (aa[1] & 16 ) a=1;
966 if (aa[2] & 16 ) a=2;
967 if (a>=0) {
968 t = at[a];
969 // if (t-this<0) return 0;
970 v2 = ns[VerticesOfTriangularEdge[a][0]];
971 v0 = ns[VerticesOfTriangularEdge[a][1]];
972 v1 = ns[OppositeEdge[a]];
973 v3 = t->ns[OppositeEdge[aa[a]&3]];
974 }
975 }
976 return t;
977}
978
979inline double Triangle::QualityQuad(int a,int option) const
980{ // first do the logique part
981 double q;
982 if (!link || aa[a] &4)
983 q= -1;
984 else {
985 Triangle * t = at[a];
986 if (t-this<0) q= -1;// because we do 2 times
987 else if (!t->link ) q= -1;
988 else if (aa[0] & 16 || aa[1] & 16 || aa[2] & 16 || t->aa[0] & 16 || t->aa[1] & 16 || t->aa[2] & 16 )
989 q= -1;
990 else if(option)
991 {
992 const Vertex & v2 = *ns[VerticesOfTriangularEdge[a][0]];
993 const Vertex & v0 = *ns[VerticesOfTriangularEdge[a][1]];
994 const Vertex & v1 = *ns[OppositeEdge[a]];
995 const Vertex & v3 = * t->ns[OppositeEdge[aa[a]&3]];
996 q = QuadQuality(v0,v1,v2,v3); // do the float part
997 }
998 else q= 1;
999 }
1000 return q;
1001}
1002
1003
1004inline void Vertex::Set(const Vertex & rec,const Triangles & ,Triangles & )
1005 {
1006 *this = rec;
1007 }
1008inline void GeometricalVertex::Set(const GeometricalVertex & rec,const Geometry & ,const Geometry & )
1009 {
1010 *this = rec;
1011 }
1012inline void Edge::Set(const Triangles & Th ,Int4 i,Triangles & ThNew)
1013 {
1014 *this = Th.edges[i];
1015 v[0] = ThNew.vertices + Th.Number(v[0]);
1016 v[1] = ThNew.vertices + Th.Number(v[1]);
1017 if (on)
1018 on = ThNew.Gh.edges+Th.Gh.Number(on);
1019 if (adj[0]) adj[0] = ThNew.edges + Th.Number(adj[0]);
1020 if (adj[1]) adj[1] = ThNew.edges + Th.Number(adj[1]);
1021
1022 }
1023inline void GeometricalEdge::Set(const GeometricalEdge & rec,const Geometry & Gh ,Geometry & GhNew)
1024 {
1025 *this = rec;
1026 v[0] = GhNew.vertices + Gh.Number(v[0]);
1027 v[1] = GhNew.vertices + Gh.Number(v[1]);
1028 if (Adj[0]) Adj[0] = GhNew.edges + Gh.Number(Adj[0]);
1029 if (Adj[1]) Adj[1] = GhNew.edges + Gh.Number(Adj[1]);
1030 }
1031
1032inline void Curve::Set(const Curve & rec,const Geometry & Gh ,Geometry & GhNew)
1033{
1034 *this = rec;
1035 be = GhNew.edges + Gh.Number(be);
1036 ee = GhNew.edges + Gh.Number(ee);
1037 if(next) next= GhNew.curves + Gh.Number(next);
1038}
1039
1040inline void Triangle::Set(const Triangle & rec,const Triangles & Th ,Triangles & ThNew)
1041 {
1042 *this = rec;
1043 if ( ns[0] ) ns[0] = ThNew.vertices + Th.Number(ns[0]);
1044 if ( ns[1] ) ns[1] = ThNew.vertices + Th.Number(ns[1]);
1045 if ( ns[2] ) ns[2] = ThNew.vertices + Th.Number(ns[2]);
1046 if(at[0]) at[0] = ThNew.triangles + Th.Number(at[0]);
1047 if(at[1]) at[1] = ThNew.triangles + Th.Number(at[1]);
1048 if(at[2]) at[2] = ThNew.triangles + Th.Number(at[2]);
1049 if (link >= Th.triangles && link < Th.triangles + Th.nbt)
1050 link = ThNew.triangles + Th.Number(link);
1051 }
1052inline void VertexOnVertex::Set(const Triangles & Th ,Int4 i,Triangles & ThNew)
1053{
1054 *this = Th.VertexOnBThVertex[i];
1055 v = ThNew.vertices + Th.Number(v);
1056
1057}
1058inline void SubDomain::Set(const Triangles & Th ,Int4 i,Triangles & ThNew)
1059{
1060 *this = Th.subdomains[i];
1061 if ( head-Th.triangles<0 || head-Th.triangles>=Th.nbt){
1062 throw ErrorException(__FUNCT__,exprintf("head-Th.triangles<0 || head-Th.triangles>=Th.nbt"));
1063 }
1064 head = ThNew.triangles + Th.Number(head) ;
1065 if (edge-Th.edges<0 || edge-Th.edges>=Th.nbe);{
1066 throw ErrorException(__FUNCT__,exprintf("edge-Th.edges<0 || edge-Th.edges>=Th.nbe"));
1067 }
1068 edge = ThNew.edges+ Th.Number(edge);
1069}
1070 inline void GeometricalSubDomain::Set(const GeometricalSubDomain & rec,const Geometry & Gh ,const Geometry & GhNew)
1071{
1072 *this = rec;
1073 edge = Gh.Number(edge) + GhNew.edges;
1074}
1075inline void VertexOnEdge::Set(const Triangles & Th ,Int4 i,Triangles & ThNew)
1076{
1077 *this = Th.VertexOnBThEdge[i];
1078 v = ThNew.vertices + Th.Number(v);
1079}
1080
1081inline void VertexOnGeom::Set(const VertexOnGeom & rec,const Triangles & Th ,Triangles & ThNew)
1082{
1083 *this = rec;
1084 mv = ThNew.vertices + Th.Number(mv);
1085 if (gv)
1086 if (abscisse < 0 )
1087 gv = ThNew.Gh.vertices + Th.Gh.Number(gv);
1088 else
1089 ge = ThNew.Gh.edges + Th.Gh.Number(ge);
1090
1091}
1092inline Real8 Edge::MetricLength() const
1093 {
1094 return LengthInterpole(v[0]->m,v[1]->m,v[1]->r - v[0]->r) ;
1095 }
1096
1097inline void Triangles::ReMakeTriangleContainingTheVertex()
1098 {
1099 register Int4 i;
1100 for ( i=0;i<nbv;i++)
1101 {
1102 vertices[i].vint = 0;
1103 vertices[i].t=0;
1104 }
1105 for ( i=0;i<nbt;i++)
1106 triangles[i].SetTriangleContainingTheVertex();
1107 }
1108
1109inline void Triangles::UnMarkUnSwapTriangle()
1110 {
1111 register Int4 i;
1112 for ( i=0;i<nbt;i++)
1113 for(int j=0;j<3;j++)
1114 triangles[i].SetUnMarkUnSwap(j);
1115 }
1116
1117inline void Triangles::SetVertexFieldOn()
1118 {
1119 for (Int4 i=0;i<nbv;i++)
1120 vertices[i].on=0;
1121 for (Int4 j=0;j<NbVerticesOnGeomVertex;j++ )
1122 VerticesOnGeomVertex[j].SetOn();
1123 for (Int4 k=0;k<NbVerticesOnGeomEdge;k++ )
1124 VerticesOnGeomEdge[k].SetOn();
1125 }
1126inline void Triangles::SetVertexFieldOnBTh()
1127 {
1128 for (Int4 i=0;i<nbv;i++)
1129 vertices[i].on=0;
1130 for (Int4 j=0;j<NbVertexOnBThVertex;j++ )
1131 VertexOnBThVertex[j].SetOnBTh();
1132 for (Int4 k=0;k<NbVertexOnBThEdge;k++ )
1133 VertexOnBThEdge[k].SetOnBTh();
1134
1135 }
1136
1137inline void TriangleAdjacent::SetAdj2(const TriangleAdjacent & ta, int l )
1138{ // set du triangle adjacent
1139 if(t) {
1140 t->at[a]=ta.t;
1141 t->aa[a]=ta.a|l;}
1142 if(ta.t) {
1143 ta.t->at[ta.a] = t ;
1144 ta.t->aa[ta.a] = a| l ;
1145 }
1146}
1147
1148
1149inline int TriangleAdjacent::Locked() const
1150{ return t->aa[a] &4;}
1151inline int TriangleAdjacent::Cracked() const
1152{ return t->aa[a] &32;}
1153inline int TriangleAdjacent::GetAllFlag_UnSwap() const
1154{ return t->aa[a] & 1012;} // take all flag except MarkUnSwap
1155
1156inline int TriangleAdjacent::MarkUnSwap() const
1157{ return t->aa[a] &8;}
1158
1159inline void TriangleAdjacent::SetLock(){ t->SetLocked(a);}
1160
1161inline void TriangleAdjacent::SetCracked() { t->SetCracked(a);}
1162
1163inline TriangleAdjacent TriangleAdjacent::Adj() const
1164{ return t->Adj(a);}
1165
1166inline Vertex * TriangleAdjacent::EdgeVertex(const int & i) const
1167 {return t->ns[VerticesOfTriangularEdge[a][i]]; }
1168inline Vertex * TriangleAdjacent::OppositeVertex() const
1169{return t->ns[bamg::OppositeVertex[a]]; }
1170inline Icoor2 & TriangleAdjacent::det() const
1171{ return t->det;}
1172inline TriangleAdjacent Adj(const TriangleAdjacent & a)
1173{ return a.Adj();}
1174
1175inline TriangleAdjacent Next(const TriangleAdjacent & ta)
1176{ return TriangleAdjacent(ta.t,NextEdge[ta.a]);}
1177
1178inline TriangleAdjacent Previous(const TriangleAdjacent & ta)
1179{ return TriangleAdjacent(ta.t,PreviousEdge[ta.a]);}
1180
1181inline void Adj(GeometricalEdge * & on,int &i)
1182 {int j=i;i=on->SensAdj[i];on=on->Adj[j];}
1183
1184inline Real4 qualite(const Vertex &va,const Vertex &vb,const Vertex &vc)
1185{
1186 Real4 ret;
1187 I2 ia=va,ib=vb,ic=vc;
1188 I2 ab=ib-ia,bc=ic-ib,ac=ic-ia;
1189 Icoor2 deta=Det(ab,ac);
1190 if (deta <=0) ret = -1;
1191 else {
1192 Real8 a = sqrt((Real8) (ac,ac)),
1193 b = sqrt((Real8) (bc,bc)),
1194 c = sqrt((Real8) (ab,ab)),
1195 p = a+b+c;
1196 Real8 h= Max(Max(a,b),c),ro=deta/p;
1197 ret = ro/h;}
1198 return ret;
1199}
1200
1201
1202inline Triangle::Triangle(Triangles *Th,Int4 i,Int4 j,Int4 k) {
1203 Vertex *v=Th->vertices;
1204 Int4 nbv = Th->nbv;
1205 if (i<0 || j<0 || k<0){
1206 throw ErrorException(__FUNCT__,exprintf("i<0 || j<0 || k<0"));
1207 }
1208 if (i>=nbv || j>=nbv || k>=nbv){
1209 throw ErrorException(__FUNCT__,exprintf("i>=nbv || j>=nbv || k>=nbv"));
1210 }
1211 ns[0]=v+i;
1212 ns[1]=v+j;
1213 ns[2]=v+k;
1214 at[0]=at[1]=at[2]=0;
1215 aa[0]=aa[1]=aa[2]=0;
1216 det=0;
1217}
1218
1219inline Triangle::Triangle(Vertex *v0,Vertex *v1,Vertex *v2){
1220 ns[0]=v0;
1221 ns[1]=v1;
1222 ns[2]=v2;
1223 at[0]=at[1]=at[2]=0;
1224 aa[0]=aa[1]=aa[2]=0;
1225 if (v0) det=0;
1226 else {
1227 det=-1;
1228 link=NULL;};
1229}
1230
1231inline Real4 Triangle::qualite()
1232{
1233 return det < 0 ? -1 : bamg::qualite(*ns[0],*ns[1],*ns[2]);
1234}
1235
1236Int4 inline Vertex::Optim(int i,int koption)
1237{
1238 Int4 ret=0;
1239 if ( t && (vint >= 0 ) && (vint <3) )
1240 {
1241 ret = t->Optim(vint,koption);
1242 if(!i)
1243 {
1244 t =0; // for no future optime
1245 vint= 0; }
1246 }
1247 return ret;
1248}
1249
1250Icoor2 inline det(const Vertex & a,const Vertex & b,const Vertex & c)
1251{
1252 register Icoor2 bax = b.i.x - a.i.x ,bay = b.i.y - a.i.y;
1253 register Icoor2 cax = c.i.x - a.i.x ,cay = c.i.y - a.i.y;
1254 return bax*cay - bay*cax;}
1255
1256
1257void swap(Triangle *t1,Int1 a1,
1258 Triangle *t2,Int1 a2,
1259 Vertex *s1,Vertex *s2,Icoor2 det1,Icoor2 det2);
1260
1261
1262
1263int inline TriangleAdjacent::swap()
1264{ return t->swap(a);}
1265
1266
1267
1268int SwapForForcingEdge(Vertex * & pva ,Vertex * & pvb ,
1269 TriangleAdjacent & tt1,Icoor2 & dets1,
1270 Icoor2 & detsa,Icoor2 & detsb, int & nbswap);
1271
1272int ForceEdge(Vertex &a, Vertex & b,TriangleAdjacent & taret) ;
1273
1274// inline bofbof FH
1275inline TriangleAdjacent FindTriangleAdjacent(Edge &E)
1276 {
1277 Vertex * a = E.v[0];
1278 Vertex * b = E.v[1];
1279
1280 Triangle * t = a->t;
1281 int i = a->vint;
1282 TriangleAdjacent ta(t,EdgesVertexTriangle[i][0]); // Previous edge
1283 if (!t || i<0 || i>=3){
1284 throw ErrorException(__FUNCT__,exprintf("!t || i<0 !! i>=3"));
1285 }
1286 if ( a!=(*t)(i)){
1287 throw ErrorException(__FUNCT__,exprintf("a!=(*t)(i)"));
1288 }
1289 int k=0;
1290 do { // turn around vertex in direct sens (trigo)
1291 k++;
1292 if (k>=20000){
1293 throw ErrorException(__FUNCT__,exprintf("k>=20000"));
1294 }
1295 // in no crack => ta.EdgeVertex(1) == a otherwise ???
1296 if (ta.EdgeVertex(1) == a && ta.EdgeVertex(0) == b) return ta; // find
1297 ta = ta.Adj();
1298 if (ta.EdgeVertex(0) == a && ta.EdgeVertex(1) == b) return ta; // find
1299 --ta;
1300 } while (t != (Triangle *)ta);
1301 throw ErrorException(__FUNCT__,exprintf("FindTriangleAdjacent: triangle not found"));
1302 return TriangleAdjacent(0,0);//for compiler
1303 }
1304
1305inline Vertex * TheVertex(Vertex * a) // give a unique vertex with smallest number
1306{ // in case on crack in mesh
1307 Vertex * r(a), *rr;
1308 Triangle * t = a->t;
1309 int i = a->vint;
1310 TriangleAdjacent ta(t,EdgesVertexTriangle[i][0]); // Previous edge
1311 if (!t || i<0 || i>=3){
1312 throw ErrorException(__FUNCT__,exprintf("!t || i<0 !! i>=3"));
1313 }
1314 if ( a!=(*t)(i)){
1315 throw ErrorException(__FUNCT__,exprintf("a!=(*t)(i)"));
1316 }
1317 int k=0;
1318 do { // turn around vertex in direct sens (trigo)
1319 k++;
1320 if (k>=20000){
1321 throw ErrorException(__FUNCT__,exprintf("k>=20000"));
1322 }
1323 // in no crack => ta.EdgeVertex(1) == a
1324 if ((rr=ta.EdgeVertex(0)) < r) r = rr;
1325 ta = ta.Adj();
1326 if ((rr=ta.EdgeVertex(1)) < r) r =rr;
1327 --ta;
1328 } while (t != (Triangle*) ta);
1329 return r;
1330}
1331
1332inline double CPUtime(){
1333#ifdef SYSTIMES
1334 struct tms buf;
1335 if (times(&buf)!=-1)
1336 return ((double)buf.tms_utime+(double)buf.tms_stime)/(long) sysconf(_SC_CLK_TCK);
1337 else
1338#endif
1339 return ((double) clock())/CLOCKS_PER_SEC;
1340}
1341
1342}
1343#endif
Note: See TracBrowser for help on using the repository browser.