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

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

removed DEBUG OPTION

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