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 |
|
---|
30 | using namespace std;
|
---|
31 | namespace bamg {
|
---|
32 |
|
---|
33 | const double Pi = 3.14159265358979323846264338328;
|
---|
34 | const float fPi = 3.14159265358979323846264338328;
|
---|
35 |
|
---|
36 | extern int hinterpole;
|
---|
37 |
|
---|
38 | typedef P2<Icoor1,Icoor2> I2;
|
---|
39 |
|
---|
40 | inline 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 | }
|
---|
49 | typedef P2<Real8,Real8> R2;
|
---|
50 | typedef P2xP2<Int2,Int4> I2xI2;
|
---|
51 | typedef P2<Real4,Real8> R2xR2;
|
---|
52 | }
|
---|
53 |
|
---|
54 | #include "Metric.h"
|
---|
55 |
|
---|
56 | namespace bamg {
|
---|
57 | inline float OppositeAngle(float a)
|
---|
58 | {return a<0 ? fPi + a :a - fPi ;}
|
---|
59 | inline double OppositeAngle(double a)
|
---|
60 | {return a<0 ? Pi + a :a - Pi ;}
|
---|
61 |
|
---|
62 | Icoor2 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
|
---|
70 | static const Int2 VerticesOfTriangularEdge[3][2] = {{1,2},{2,0},{0,1}};
|
---|
71 | static const Int2 EdgesVertexTriangle[3][2] = {{1,2},{2,0},{0,1}};
|
---|
72 | static const Int2 OppositeVertex[3] = {0,1,2};
|
---|
73 | static const Int2 OppositeEdge[3] = {0,1,2};
|
---|
74 | static const Int2 NextEdge[3] = {1,2,0};
|
---|
75 | static const Int2 PreviousEdge[3] = {2,0,1};
|
---|
76 | static const Int2 NextVertex[3] = {1,2,0};
|
---|
77 | static const Int2 PreviousVertex[3] = {2,0,1};
|
---|
78 |
|
---|
79 | Int4 AGoodNumberPrimeWith(Int4 n);
|
---|
80 |
|
---|
81 | // remark all the angle are in radian beetwen [-Pi,Pi]
|
---|
82 |
|
---|
83 |
|
---|
84 | class Geometry;
|
---|
85 | //static Geometry *NULLGeometry=0;
|
---|
86 | class Triangles;
|
---|
87 | class Triangle;
|
---|
88 | class QuadTree;
|
---|
89 | class GeometricalEdge;
|
---|
90 | class VertexOnGeom;
|
---|
91 | class VertexOnEdge;
|
---|
92 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
93 | const int IsVertexOnGeom = 8;
|
---|
94 | const int IsVertexOnVertex = 16;
|
---|
95 | const int IsVertexOnEdge = 32;
|
---|
96 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
97 |
|
---|
98 | //class from MeshGeom
|
---|
99 | class DoubleAndInt4 {
|
---|
100 | public: double q; Int4 i3j;
|
---|
101 | int operator<(DoubleAndInt4 a){return q > a.q;}
|
---|
102 | };// to sort by decroissant
|
---|
103 | template<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 |
|
---|
130 | class 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 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
147 | class 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 |
|
---|
178 | double QuadQuality(const Vertex &,const Vertex &,const Vertex &,const Vertex &);
|
---|
179 |
|
---|
180 | // extern Vertex *Meshend , *Meshbegin;
|
---|
181 |
|
---|
182 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
183 | class TriangleAdjacent {
|
---|
184 | friend std::ostream& operator <<(std::ostream& f, const TriangleAdjacent & ta)
|
---|
185 | {f << "{" << ta.t << "," << ((int) ta.a) << "}" ;
|
---|
186 | return f;}
|
---|
187 |
|
---|
188 | public:
|
---|
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 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
223 | class 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 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
256 | class GeometricalVertex :public Vertex {
|
---|
257 | int cas;
|
---|
258 | friend class Geometry;
|
---|
259 | GeometricalVertex * link; // link all the same GeometricalVertex circular (Crack)
|
---|
260 | public:
|
---|
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 |
|
---|
277 | inline 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 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
283 | class 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 |
|
---|
329 | class 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 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
342 | class 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 |
|
---|
464 | class ListofIntersectionTriangles {
|
---|
465 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
466 | class IntersectionTriangles {
|
---|
467 | public:
|
---|
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 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
477 | class 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 |
|
---|
503 | ListofIntersectionTriangles(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 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
570 | class GeometricalSubDomain {
|
---|
571 | public:
|
---|
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 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
579 | class SubDomain {
|
---|
580 | public:
|
---|
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 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
589 | class 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 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
618 | class 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 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
626 | class 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 |
|
---|
644 | class 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 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
699 | class Triangles {
|
---|
700 | public:
|
---|
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 NewPoints(int KeepBackVertex=1){ NewPoints(*this,KeepBackVertex);}
|
---|
818 | void ReNumberingTheTriangleBySubDomain(bool justcompress=false);
|
---|
819 | void ReNumberingVertex(Int4 * renu);
|
---|
820 | void SmoothingVertex(int =3,Real8=0.3);
|
---|
821 | Metric MetricAt (const R2 &) const;
|
---|
822 | GeometricalEdge * ProjectOnCurve( Edge & AB, Vertex & A, Vertex & B,Real8 theta,
|
---|
823 | Vertex & R,VertexOnEdge & BR,VertexOnGeom & GR);
|
---|
824 |
|
---|
825 | Int4 Number(const Triangle & t) const { return &t - triangles;}
|
---|
826 | Int4 Number(const Triangle * t) const { return t - triangles;}
|
---|
827 | Int4 Number(const Vertex & t) const { return &t - vertices;}
|
---|
828 | Int4 Number(const Vertex * t) const { return t - vertices;}
|
---|
829 | Int4 Number(const Edge & t) const { return &t - edges;}
|
---|
830 | Int4 Number(const Edge * t) const { return t - edges;}
|
---|
831 | Int4 Number2(const Triangle * t) const {
|
---|
832 | // if(t>= triangles && t < triangles + nbt )
|
---|
833 | return t - triangles;
|
---|
834 | // else return t - OutSidesTriangles;
|
---|
835 | }
|
---|
836 |
|
---|
837 | Vertex * NearestVertex(Icoor1 i,Icoor1 j) ;
|
---|
838 | Triangle * FindTriangleContening(const I2 & ,Icoor2 [3],Triangle *tstart=0) const;
|
---|
839 |
|
---|
840 | void ReadMesh(BamgMesh* bamgmesh, BamgOpts* bamgopts);
|
---|
841 | void WriteMesh(BamgMesh* bamgmesh,BamgOpts* bamgopts);
|
---|
842 |
|
---|
843 | void ReadMetric(BamgOpts* bamgopts,const Real8 hmin,const Real8 hmax,const Real8 coef);
|
---|
844 | void WriteMetric(BamgOpts* bamgopts);
|
---|
845 | void IntersectConsMetric(const double * s,const Int4 nbsol,const int * typsols,
|
---|
846 | const Real8 hmin,const Real8 hmax, const Real8 coef,
|
---|
847 | const Real8 anisomax,const Real8 CutOff=1.e-4,const int NbJacobi=1,
|
---|
848 | const int DoNormalisation=1,
|
---|
849 | const double power=1.0,
|
---|
850 | const int choise=0);
|
---|
851 | void IntersectGeomMetric(const Real8 err,const int iso);
|
---|
852 |
|
---|
853 |
|
---|
854 | int isCracked() const {return NbCrackedVertices != 0;}
|
---|
855 | int Crack();
|
---|
856 | int UnCrack();
|
---|
857 |
|
---|
858 | friend std::ostream& operator <<(std::ostream& f, const Triangles & Th);
|
---|
859 | void ConsGeometry(Real8 =-1.0,int *equiedges=0); // construct a geometry if no geo
|
---|
860 | void FillHoleInMesh() ;
|
---|
861 | int CrackMesh();
|
---|
862 | private:
|
---|
863 | void GeomToTriangles1(Int4 nbvx,int KeepBackVertices=1);// the real constructor mesh adaption
|
---|
864 | void GeomToTriangles0(Int4 nbvx);// the real constructor mesh generator
|
---|
865 | void PreInit(Int4,char * =0 );
|
---|
866 |
|
---|
867 | }; // End Class Triangles
|
---|
868 |
|
---|
869 |
|
---|
870 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
871 | class Geometry {
|
---|
872 | public:
|
---|
873 | int OnDisk;
|
---|
874 | Int4 NbRef; // counter of ref on the this class if 0 we can delete
|
---|
875 |
|
---|
876 | char *name;
|
---|
877 | Int4 nbvx,nbtx; // nombre max de sommets , de Geometry
|
---|
878 | Int4 nbv,nbt,nbiv,nbe; // nombre de sommets, de Geometry, de sommets initiaux,
|
---|
879 | Int4 NbSubDomains; //
|
---|
880 | Int4 NbEquiEdges;
|
---|
881 | Int4 NbCrackedEdges;
|
---|
882 | // Int4 nbtf;// de triangle frontiere
|
---|
883 | Int4 NbOfCurves;
|
---|
884 | int empty(){return (nbv ==0) && (nbt==0) && (nbe==0) && (NbSubDomains==0); }
|
---|
885 | GeometricalVertex * vertices; // data of vertices des sommets
|
---|
886 | Triangle * triangles;
|
---|
887 | GeometricalEdge * edges;
|
---|
888 | QuadTree *quadtree;
|
---|
889 | GeometricalSubDomain *subdomains;
|
---|
890 | Curve *curves;
|
---|
891 | ~Geometry();
|
---|
892 | Geometry(const Geometry & Gh); //Copy Operator
|
---|
893 | Geometry(int nbg,const Geometry ** ag); // intersection operator
|
---|
894 |
|
---|
895 | R2 pmin,pmax; // extrema
|
---|
896 | Real8 coefIcoor; // coef to integer Icoor1;
|
---|
897 | Real8 MaximalAngleOfCorner;
|
---|
898 |
|
---|
899 | // end of data
|
---|
900 |
|
---|
901 |
|
---|
902 | I2 toI2(const R2 & P) const {
|
---|
903 | return I2( (Icoor1) (coefIcoor*(P.x-pmin.x))
|
---|
904 | ,(Icoor1) (coefIcoor*(P.y-pmin.y)) );}
|
---|
905 |
|
---|
906 | Real8 MinimalHmin() {return 2.0/coefIcoor;}
|
---|
907 | Real8 MaximalHmax() {return Max(pmax.x-pmin.x,pmax.y-pmin.y);}
|
---|
908 | void ReadGeometry(BamgGeom* bamggeom, BamgOpts* bamgopts);
|
---|
909 | void EmptyGeometry();
|
---|
910 | Geometry() {EmptyGeometry();}// empty Geometry
|
---|
911 | void AfterRead();
|
---|
912 | Geometry(BamgGeom* bamggeom, BamgOpts* bamgopts) {EmptyGeometry();OnDisk=1;ReadGeometry(bamggeom,bamgopts);AfterRead();}
|
---|
913 |
|
---|
914 | const GeometricalVertex & operator[] (Int4 i) const { return vertices[i];};
|
---|
915 | GeometricalVertex & operator[](Int4 i) { return vertices[i];};
|
---|
916 | const GeometricalEdge & operator() (Int4 i) const { return edges[i];};
|
---|
917 | GeometricalEdge & operator()(Int4 i) { return edges[i];};
|
---|
918 | Int4 Number(const GeometricalVertex & t) const { return &t - vertices;}
|
---|
919 | Int4 Number(const GeometricalVertex * t) const { return t - vertices;}
|
---|
920 | Int4 Number(const GeometricalEdge & t) const { return &t - edges;}
|
---|
921 | Int4 Number(const GeometricalEdge * t) const { return t - edges;}
|
---|
922 | Int4 Number(const Curve * c) const { return c - curves;}
|
---|
923 |
|
---|
924 | void UnMarkEdges() {
|
---|
925 | for (Int4 i=0;i<nbe;i++) edges[i].SetUnMark();}
|
---|
926 |
|
---|
927 | GeometricalEdge * ProjectOnCurve(const Edge & ,Real8,Vertex &,VertexOnGeom &) const ;
|
---|
928 | GeometricalEdge * Contening(const R2 P, GeometricalEdge * start) const;
|
---|
929 | friend std::ostream& operator <<(std::ostream& f, const Geometry & Gh);
|
---|
930 | void WriteGeometry(BamgGeom* bamggeom, BamgOpts* bamgopts);
|
---|
931 | }; // End Class Geometry
|
---|
932 |
|
---|
933 | //From Metric.cpp
|
---|
934 | inline Real8 det3x3(Real8 A[3] ,Real8 B[3],Real8 C[3])
|
---|
935 | { return A[0] * ( B[1]*C[2]-B[2]*C[1])
|
---|
936 | - A[1] * ( B[0]*C[2]-B[2]*C[0])
|
---|
937 | + A[2] * ( B[0]*C[1]-B[1]*C[0]);
|
---|
938 | }
|
---|
939 |
|
---|
940 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
941 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
942 | /////////////////// END CLASS ////////////////////////////////////
|
---|
943 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
944 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
945 |
|
---|
946 | inline Triangles::Triangles(Int4 i) :Gh(*new Geometry()),BTh(*this){PreInit(i);}
|
---|
947 |
|
---|
948 | extern Triangles * CurrentTh;
|
---|
949 |
|
---|
950 | TriangleAdjacent CloseBoundaryEdge(I2 ,Triangle *, double &,double &) ;
|
---|
951 | TriangleAdjacent CloseBoundaryEdgeV2(I2 A,Triangle *t, double &a,double &b);
|
---|
952 |
|
---|
953 | Int4 FindTriangle(Triangles &Th, Real8 x, Real8 y, double* a,int & inside);
|
---|
954 |
|
---|
955 |
|
---|
956 |
|
---|
957 | inline Triangle * Triangle::Quadrangle(Vertex * & v0,Vertex * & v1,Vertex * & v2,Vertex * & v3) const
|
---|
958 | {
|
---|
959 | // return the other triangle of the quad if a quad or 0 if not a quat
|
---|
960 | Triangle * t =0;
|
---|
961 | if (link) {
|
---|
962 | int a=-1;
|
---|
963 | if (aa[0] & 16 ) a=0;
|
---|
964 | if (aa[1] & 16 ) a=1;
|
---|
965 | if (aa[2] & 16 ) a=2;
|
---|
966 | if (a>=0) {
|
---|
967 | t = at[a];
|
---|
968 | // if (t-this<0) return 0;
|
---|
969 | v2 = ns[VerticesOfTriangularEdge[a][0]];
|
---|
970 | v0 = ns[VerticesOfTriangularEdge[a][1]];
|
---|
971 | v1 = ns[OppositeEdge[a]];
|
---|
972 | v3 = t->ns[OppositeEdge[aa[a]&3]];
|
---|
973 | }
|
---|
974 | }
|
---|
975 | return t;
|
---|
976 | }
|
---|
977 |
|
---|
978 | inline double Triangle::QualityQuad(int a,int option) const
|
---|
979 | { // first do the logique part
|
---|
980 | double q;
|
---|
981 | if (!link || aa[a] &4)
|
---|
982 | q= -1;
|
---|
983 | else {
|
---|
984 | Triangle * t = at[a];
|
---|
985 | if (t-this<0) q= -1;// because we do 2 times
|
---|
986 | else if (!t->link ) q= -1;
|
---|
987 | else if (aa[0] & 16 || aa[1] & 16 || aa[2] & 16 || t->aa[0] & 16 || t->aa[1] & 16 || t->aa[2] & 16 )
|
---|
988 | q= -1;
|
---|
989 | else if(option)
|
---|
990 | {
|
---|
991 | const Vertex & v2 = *ns[VerticesOfTriangularEdge[a][0]];
|
---|
992 | const Vertex & v0 = *ns[VerticesOfTriangularEdge[a][1]];
|
---|
993 | const Vertex & v1 = *ns[OppositeEdge[a]];
|
---|
994 | const Vertex & v3 = * t->ns[OppositeEdge[aa[a]&3]];
|
---|
995 | q = QuadQuality(v0,v1,v2,v3); // do the float part
|
---|
996 | }
|
---|
997 | else q= 1;
|
---|
998 | }
|
---|
999 | return q;
|
---|
1000 | }
|
---|
1001 |
|
---|
1002 |
|
---|
1003 | inline void Vertex::Set(const Vertex & rec,const Triangles & ,Triangles & )
|
---|
1004 | {
|
---|
1005 | *this = rec;
|
---|
1006 | }
|
---|
1007 | inline void GeometricalVertex::Set(const GeometricalVertex & rec,const Geometry & ,const Geometry & )
|
---|
1008 | {
|
---|
1009 | *this = rec;
|
---|
1010 | }
|
---|
1011 | inline void Edge::Set(const Triangles & Th ,Int4 i,Triangles & ThNew)
|
---|
1012 | {
|
---|
1013 | *this = Th.edges[i];
|
---|
1014 | v[0] = ThNew.vertices + Th.Number(v[0]);
|
---|
1015 | v[1] = ThNew.vertices + Th.Number(v[1]);
|
---|
1016 | if (on)
|
---|
1017 | on = ThNew.Gh.edges+Th.Gh.Number(on);
|
---|
1018 | if (adj[0]) adj[0] = ThNew.edges + Th.Number(adj[0]);
|
---|
1019 | if (adj[1]) adj[1] = ThNew.edges + Th.Number(adj[1]);
|
---|
1020 |
|
---|
1021 | }
|
---|
1022 | inline void GeometricalEdge::Set(const GeometricalEdge & rec,const Geometry & Gh ,Geometry & GhNew)
|
---|
1023 | {
|
---|
1024 | *this = rec;
|
---|
1025 | v[0] = GhNew.vertices + Gh.Number(v[0]);
|
---|
1026 | v[1] = GhNew.vertices + Gh.Number(v[1]);
|
---|
1027 | if (Adj[0]) Adj[0] = GhNew.edges + Gh.Number(Adj[0]);
|
---|
1028 | if (Adj[1]) Adj[1] = GhNew.edges + Gh.Number(Adj[1]);
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | inline void Curve::Set(const Curve & rec,const Geometry & Gh ,Geometry & GhNew)
|
---|
1032 | {
|
---|
1033 | *this = rec;
|
---|
1034 | be = GhNew.edges + Gh.Number(be);
|
---|
1035 | ee = GhNew.edges + Gh.Number(ee);
|
---|
1036 | if(next) next= GhNew.curves + Gh.Number(next);
|
---|
1037 | }
|
---|
1038 |
|
---|
1039 | inline void Triangle::Set(const Triangle & rec,const Triangles & Th ,Triangles & ThNew)
|
---|
1040 | {
|
---|
1041 | *this = rec;
|
---|
1042 | if ( ns[0] ) ns[0] = ThNew.vertices + Th.Number(ns[0]);
|
---|
1043 | if ( ns[1] ) ns[1] = ThNew.vertices + Th.Number(ns[1]);
|
---|
1044 | if ( ns[2] ) ns[2] = ThNew.vertices + Th.Number(ns[2]);
|
---|
1045 | if(at[0]) at[0] = ThNew.triangles + Th.Number(at[0]);
|
---|
1046 | if(at[1]) at[1] = ThNew.triangles + Th.Number(at[1]);
|
---|
1047 | if(at[2]) at[2] = ThNew.triangles + Th.Number(at[2]);
|
---|
1048 | if (link >= Th.triangles && link < Th.triangles + Th.nbt)
|
---|
1049 | link = ThNew.triangles + Th.Number(link);
|
---|
1050 | }
|
---|
1051 | inline void VertexOnVertex::Set(const Triangles & Th ,Int4 i,Triangles & ThNew)
|
---|
1052 | {
|
---|
1053 | *this = Th.VertexOnBThVertex[i];
|
---|
1054 | v = ThNew.vertices + Th.Number(v);
|
---|
1055 |
|
---|
1056 | }
|
---|
1057 | inline void SubDomain::Set(const Triangles & Th ,Int4 i,Triangles & ThNew)
|
---|
1058 | {
|
---|
1059 | *this = Th.subdomains[i];
|
---|
1060 | if ( head-Th.triangles<0 || head-Th.triangles>=Th.nbt){
|
---|
1061 | throw ErrorException(__FUNCT__,exprintf("head-Th.triangles<0 || head-Th.triangles>=Th.nbt"));
|
---|
1062 | }
|
---|
1063 | head = ThNew.triangles + Th.Number(head) ;
|
---|
1064 | if (edge-Th.edges<0 || edge-Th.edges>=Th.nbe);{
|
---|
1065 | throw ErrorException(__FUNCT__,exprintf("edge-Th.edges<0 || edge-Th.edges>=Th.nbe"));
|
---|
1066 | }
|
---|
1067 | edge = ThNew.edges+ Th.Number(edge);
|
---|
1068 | }
|
---|
1069 | inline void GeometricalSubDomain::Set(const GeometricalSubDomain & rec,const Geometry & Gh ,const Geometry & GhNew)
|
---|
1070 | {
|
---|
1071 | *this = rec;
|
---|
1072 | edge = Gh.Number(edge) + GhNew.edges;
|
---|
1073 | }
|
---|
1074 | inline void VertexOnEdge::Set(const Triangles & Th ,Int4 i,Triangles & ThNew)
|
---|
1075 | {
|
---|
1076 | *this = Th.VertexOnBThEdge[i];
|
---|
1077 | v = ThNew.vertices + Th.Number(v);
|
---|
1078 | }
|
---|
1079 |
|
---|
1080 | inline void VertexOnGeom::Set(const VertexOnGeom & rec,const Triangles & Th ,Triangles & ThNew)
|
---|
1081 | {
|
---|
1082 | *this = rec;
|
---|
1083 | mv = ThNew.vertices + Th.Number(mv);
|
---|
1084 | if (gv)
|
---|
1085 | if (abscisse < 0 )
|
---|
1086 | gv = ThNew.Gh.vertices + Th.Gh.Number(gv);
|
---|
1087 | else
|
---|
1088 | ge = ThNew.Gh.edges + Th.Gh.Number(ge);
|
---|
1089 |
|
---|
1090 | }
|
---|
1091 | inline Real8 Edge::MetricLength() const
|
---|
1092 | {
|
---|
1093 | return LengthInterpole(v[0]->m,v[1]->m,v[1]->r - v[0]->r) ;
|
---|
1094 | }
|
---|
1095 |
|
---|
1096 | inline void Triangles::ReMakeTriangleContainingTheVertex()
|
---|
1097 | {
|
---|
1098 | register Int4 i;
|
---|
1099 | for ( i=0;i<nbv;i++)
|
---|
1100 | {
|
---|
1101 | vertices[i].vint = 0;
|
---|
1102 | vertices[i].t=0;
|
---|
1103 | }
|
---|
1104 | for ( i=0;i<nbt;i++)
|
---|
1105 | triangles[i].SetTriangleContainingTheVertex();
|
---|
1106 | }
|
---|
1107 |
|
---|
1108 | inline void Triangles::UnMarkUnSwapTriangle()
|
---|
1109 | {
|
---|
1110 | register Int4 i;
|
---|
1111 | for ( i=0;i<nbt;i++)
|
---|
1112 | for(int j=0;j<3;j++)
|
---|
1113 | triangles[i].SetUnMarkUnSwap(j);
|
---|
1114 | }
|
---|
1115 |
|
---|
1116 | inline void Triangles::SetVertexFieldOn()
|
---|
1117 | {
|
---|
1118 | for (Int4 i=0;i<nbv;i++)
|
---|
1119 | vertices[i].on=0;
|
---|
1120 | for (Int4 j=0;j<NbVerticesOnGeomVertex;j++ )
|
---|
1121 | VerticesOnGeomVertex[j].SetOn();
|
---|
1122 | for (Int4 k=0;k<NbVerticesOnGeomEdge;k++ )
|
---|
1123 | VerticesOnGeomEdge[k].SetOn();
|
---|
1124 | }
|
---|
1125 | inline void Triangles::SetVertexFieldOnBTh()
|
---|
1126 | {
|
---|
1127 | for (Int4 i=0;i<nbv;i++)
|
---|
1128 | vertices[i].on=0;
|
---|
1129 | for (Int4 j=0;j<NbVertexOnBThVertex;j++ )
|
---|
1130 | VertexOnBThVertex[j].SetOnBTh();
|
---|
1131 | for (Int4 k=0;k<NbVertexOnBThEdge;k++ )
|
---|
1132 | VertexOnBThEdge[k].SetOnBTh();
|
---|
1133 |
|
---|
1134 | }
|
---|
1135 |
|
---|
1136 | inline void TriangleAdjacent::SetAdj2(const TriangleAdjacent & ta, int l )
|
---|
1137 | { // set du triangle adjacent
|
---|
1138 | if(t) {
|
---|
1139 | t->at[a]=ta.t;
|
---|
1140 | t->aa[a]=ta.a|l;}
|
---|
1141 | if(ta.t) {
|
---|
1142 | ta.t->at[ta.a] = t ;
|
---|
1143 | ta.t->aa[ta.a] = a| l ;
|
---|
1144 | }
|
---|
1145 | }
|
---|
1146 |
|
---|
1147 |
|
---|
1148 | inline int TriangleAdjacent::Locked() const
|
---|
1149 | { return t->aa[a] &4;}
|
---|
1150 | inline int TriangleAdjacent::Cracked() const
|
---|
1151 | { return t->aa[a] &32;}
|
---|
1152 | inline int TriangleAdjacent::GetAllFlag_UnSwap() const
|
---|
1153 | { return t->aa[a] & 1012;} // take all flag except MarkUnSwap
|
---|
1154 |
|
---|
1155 | inline int TriangleAdjacent::MarkUnSwap() const
|
---|
1156 | { return t->aa[a] &8;}
|
---|
1157 |
|
---|
1158 | inline void TriangleAdjacent::SetLock(){ t->SetLocked(a);}
|
---|
1159 |
|
---|
1160 | inline void TriangleAdjacent::SetCracked() { t->SetCracked(a);}
|
---|
1161 |
|
---|
1162 | inline TriangleAdjacent TriangleAdjacent::Adj() const
|
---|
1163 | { return t->Adj(a);}
|
---|
1164 |
|
---|
1165 | inline Vertex * TriangleAdjacent::EdgeVertex(const int & i) const
|
---|
1166 | {return t->ns[VerticesOfTriangularEdge[a][i]]; }
|
---|
1167 | inline Vertex * TriangleAdjacent::OppositeVertex() const
|
---|
1168 | {return t->ns[bamg::OppositeVertex[a]]; }
|
---|
1169 | inline Icoor2 & TriangleAdjacent::det() const
|
---|
1170 | { return t->det;}
|
---|
1171 | inline TriangleAdjacent Adj(const TriangleAdjacent & a)
|
---|
1172 | { return a.Adj();}
|
---|
1173 |
|
---|
1174 | inline TriangleAdjacent Next(const TriangleAdjacent & ta)
|
---|
1175 | { return TriangleAdjacent(ta.t,NextEdge[ta.a]);}
|
---|
1176 |
|
---|
1177 | inline TriangleAdjacent Previous(const TriangleAdjacent & ta)
|
---|
1178 | { return TriangleAdjacent(ta.t,PreviousEdge[ta.a]);}
|
---|
1179 |
|
---|
1180 | inline void Adj(GeometricalEdge * & on,int &i)
|
---|
1181 | {int j=i;i=on->SensAdj[i];on=on->Adj[j];}
|
---|
1182 |
|
---|
1183 | inline Real4 qualite(const Vertex &va,const Vertex &vb,const Vertex &vc)
|
---|
1184 | {
|
---|
1185 | Real4 ret;
|
---|
1186 | I2 ia=va,ib=vb,ic=vc;
|
---|
1187 | I2 ab=ib-ia,bc=ic-ib,ac=ic-ia;
|
---|
1188 | Icoor2 deta=Det(ab,ac);
|
---|
1189 | if (deta <=0) ret = -1;
|
---|
1190 | else {
|
---|
1191 | Real8 a = sqrt((Real8) (ac,ac)),
|
---|
1192 | b = sqrt((Real8) (bc,bc)),
|
---|
1193 | c = sqrt((Real8) (ab,ab)),
|
---|
1194 | p = a+b+c;
|
---|
1195 | Real8 h= Max(Max(a,b),c),ro=deta/p;
|
---|
1196 | ret = ro/h;}
|
---|
1197 | return ret;
|
---|
1198 | }
|
---|
1199 |
|
---|
1200 |
|
---|
1201 | inline Triangle::Triangle(Triangles *Th,Int4 i,Int4 j,Int4 k) {
|
---|
1202 | Vertex *v=Th->vertices;
|
---|
1203 | Int4 nbv = Th->nbv;
|
---|
1204 | if (i<0 || j<0 || k<0){
|
---|
1205 | throw ErrorException(__FUNCT__,exprintf("i<0 || j<0 || k<0"));
|
---|
1206 | }
|
---|
1207 | if (i>=nbv || j>=nbv || k>=nbv){
|
---|
1208 | throw ErrorException(__FUNCT__,exprintf("i>=nbv || j>=nbv || k>=nbv"));
|
---|
1209 | }
|
---|
1210 | ns[0]=v+i;
|
---|
1211 | ns[1]=v+j;
|
---|
1212 | ns[2]=v+k;
|
---|
1213 | at[0]=at[1]=at[2]=0;
|
---|
1214 | aa[0]=aa[1]=aa[2]=0;
|
---|
1215 | det=0;
|
---|
1216 | }
|
---|
1217 |
|
---|
1218 | inline Triangle::Triangle(Vertex *v0,Vertex *v1,Vertex *v2){
|
---|
1219 | ns[0]=v0;
|
---|
1220 | ns[1]=v1;
|
---|
1221 | ns[2]=v2;
|
---|
1222 | at[0]=at[1]=at[2]=0;
|
---|
1223 | aa[0]=aa[1]=aa[2]=0;
|
---|
1224 | if (v0) det=0;
|
---|
1225 | else {
|
---|
1226 | det=-1;
|
---|
1227 | link=NULL;};
|
---|
1228 | }
|
---|
1229 |
|
---|
1230 | inline Real4 Triangle::qualite()
|
---|
1231 | {
|
---|
1232 | return det < 0 ? -1 : bamg::qualite(*ns[0],*ns[1],*ns[2]);
|
---|
1233 | }
|
---|
1234 |
|
---|
1235 | Int4 inline Vertex::Optim(int i,int koption)
|
---|
1236 | {
|
---|
1237 | Int4 ret=0;
|
---|
1238 | if ( t && (vint >= 0 ) && (vint <3) )
|
---|
1239 | {
|
---|
1240 | ret = t->Optim(vint,koption);
|
---|
1241 | if(!i)
|
---|
1242 | {
|
---|
1243 | t =0; // for no future optime
|
---|
1244 | vint= 0; }
|
---|
1245 | }
|
---|
1246 | return ret;
|
---|
1247 | }
|
---|
1248 |
|
---|
1249 | Icoor2 inline det(const Vertex & a,const Vertex & b,const Vertex & c)
|
---|
1250 | {
|
---|
1251 | register Icoor2 bax = b.i.x - a.i.x ,bay = b.i.y - a.i.y;
|
---|
1252 | register Icoor2 cax = c.i.x - a.i.x ,cay = c.i.y - a.i.y;
|
---|
1253 | return bax*cay - bay*cax;}
|
---|
1254 |
|
---|
1255 |
|
---|
1256 | void swap(Triangle *t1,Int1 a1,
|
---|
1257 | Triangle *t2,Int1 a2,
|
---|
1258 | Vertex *s1,Vertex *s2,Icoor2 det1,Icoor2 det2);
|
---|
1259 |
|
---|
1260 |
|
---|
1261 |
|
---|
1262 | int inline TriangleAdjacent::swap()
|
---|
1263 | { return t->swap(a);}
|
---|
1264 |
|
---|
1265 |
|
---|
1266 |
|
---|
1267 | int SwapForForcingEdge(Vertex * & pva ,Vertex * & pvb ,
|
---|
1268 | TriangleAdjacent & tt1,Icoor2 & dets1,
|
---|
1269 | Icoor2 & detsa,Icoor2 & detsb, int & nbswap);
|
---|
1270 |
|
---|
1271 | int ForceEdge(Vertex &a, Vertex & b,TriangleAdjacent & taret) ;
|
---|
1272 |
|
---|
1273 | // inline bofbof FH
|
---|
1274 | inline TriangleAdjacent FindTriangleAdjacent(Edge &E)
|
---|
1275 | {
|
---|
1276 | Vertex * a = E.v[0];
|
---|
1277 | Vertex * b = E.v[1];
|
---|
1278 |
|
---|
1279 | Triangle * t = a->t;
|
---|
1280 | int i = a->vint;
|
---|
1281 | TriangleAdjacent ta(t,EdgesVertexTriangle[i][0]); // Previous edge
|
---|
1282 | if (!t || i<0 || i>=3){
|
---|
1283 | throw ErrorException(__FUNCT__,exprintf("!t || i<0 !! i>=3"));
|
---|
1284 | }
|
---|
1285 | if ( a!=(*t)(i)){
|
---|
1286 | throw ErrorException(__FUNCT__,exprintf("a!=(*t)(i)"));
|
---|
1287 | }
|
---|
1288 | int k=0;
|
---|
1289 | do { // turn around vertex in direct sens (trigo)
|
---|
1290 | k++;
|
---|
1291 | if (k>=20000){
|
---|
1292 | throw ErrorException(__FUNCT__,exprintf("k>=20000"));
|
---|
1293 | }
|
---|
1294 | // in no crack => ta.EdgeVertex(1) == a otherwise ???
|
---|
1295 | if (ta.EdgeVertex(1) == a && ta.EdgeVertex(0) == b) return ta; // find
|
---|
1296 | ta = ta.Adj();
|
---|
1297 | if (ta.EdgeVertex(0) == a && ta.EdgeVertex(1) == b) return ta; // find
|
---|
1298 | --ta;
|
---|
1299 | } while (t != (Triangle *)ta);
|
---|
1300 | throw ErrorException(__FUNCT__,exprintf("FindTriangleAdjacent: triangle not found"));
|
---|
1301 | return TriangleAdjacent(0,0);//for compiler
|
---|
1302 | }
|
---|
1303 |
|
---|
1304 | inline Vertex * TheVertex(Vertex * a) // give a unique vertex with smallest number
|
---|
1305 | { // in case on crack in mesh
|
---|
1306 | Vertex * r(a), *rr;
|
---|
1307 | Triangle * t = a->t;
|
---|
1308 | int i = a->vint;
|
---|
1309 | TriangleAdjacent ta(t,EdgesVertexTriangle[i][0]); // Previous edge
|
---|
1310 | if (!t || i<0 || i>=3){
|
---|
1311 | throw ErrorException(__FUNCT__,exprintf("!t || i<0 !! i>=3"));
|
---|
1312 | }
|
---|
1313 | if ( a!=(*t)(i)){
|
---|
1314 | throw ErrorException(__FUNCT__,exprintf("a!=(*t)(i)"));
|
---|
1315 | }
|
---|
1316 | int k=0;
|
---|
1317 | do { // turn around vertex in direct sens (trigo)
|
---|
1318 | k++;
|
---|
1319 | if (k>=20000){
|
---|
1320 | throw ErrorException(__FUNCT__,exprintf("k>=20000"));
|
---|
1321 | }
|
---|
1322 | // in no crack => ta.EdgeVertex(1) == a
|
---|
1323 | if ((rr=ta.EdgeVertex(0)) < r) r = rr;
|
---|
1324 | ta = ta.Adj();
|
---|
1325 | if ((rr=ta.EdgeVertex(1)) < r) r =rr;
|
---|
1326 | --ta;
|
---|
1327 | } while (t != (Triangle*) ta);
|
---|
1328 | return r;
|
---|
1329 | }
|
---|
1330 |
|
---|
1331 | inline double CPUtime(){
|
---|
1332 | #ifdef SYSTIMES
|
---|
1333 | struct tms buf;
|
---|
1334 | if (times(&buf)!=-1)
|
---|
1335 | return ((double)buf.tms_utime+(double)buf.tms_stime)/(long) sysconf(_SC_CLK_TCK);
|
---|
1336 | else
|
---|
1337 | #endif
|
---|
1338 | return ((double) clock())/CLOCKS_PER_SEC;
|
---|
1339 | }
|
---|
1340 |
|
---|
1341 | }
|
---|
1342 | #endif
|
---|