[2740] | 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 |
|
---|
[2772] | 31 | #include "../objects/objects.h"
|
---|
| 32 |
|
---|
[2805] | 33 | //From MeshIo
|
---|
| 34 | #include <cstdio>
|
---|
| 35 | #include <iostream>
|
---|
| 36 | #include <fstream>
|
---|
| 37 | #include <cstring>
|
---|
| 38 | #include <cstdlib>
|
---|
| 39 | #include <cctype>
|
---|
| 40 | using namespace std;
|
---|
| 41 |
|
---|
[2740] | 42 | #include <stdlib.h>
|
---|
| 43 | #include <math.h>
|
---|
| 44 | #include <limits.h>
|
---|
| 45 | #include <time.h>
|
---|
| 46 | #if (defined(unix) || defined(__unix)) && !defined(__AIX)
|
---|
| 47 | #define SYSTIMES
|
---|
| 48 | #include <sys/times.h>
|
---|
| 49 | #include <unistd.h>
|
---|
| 50 | #endif
|
---|
| 51 |
|
---|
| 52 | extern int SHOW;
|
---|
| 53 | #include "meshtype.h"
|
---|
| 54 |
|
---|
| 55 | #include "error.hpp"
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 | #include "R2.h"
|
---|
| 59 |
|
---|
| 60 | namespace bamg {
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | const double Pi = 3.14159265358979323846264338328;
|
---|
| 65 | const float fPi = 3.14159265358979323846264338328;
|
---|
| 66 |
|
---|
| 67 | extern int hinterpole;
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 | typedef P2<Icoor1,Icoor2> I2;
|
---|
| 71 |
|
---|
| 72 | inline int BinaryRand(){
|
---|
| 73 | #ifdef RAND_MAX
|
---|
| 74 | const long HalfRandMax = RAND_MAX/2;
|
---|
| 75 | return rand() <HalfRandMax;
|
---|
| 76 | #else
|
---|
| 77 | return rand() & 16384; // 2^14 (for sun because RAND_MAX is not def in stdlib.h)
|
---|
| 78 | #endif
|
---|
| 79 |
|
---|
| 80 | }
|
---|
| 81 | typedef P2<Real8,Real8> R2;
|
---|
| 82 | typedef P2xP2<Int2,Int4> I2xI2;
|
---|
| 83 | typedef P2<Real4,Real8> R2xR2;
|
---|
| 84 |
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | #include "Metric.h"
|
---|
| 88 |
|
---|
| 89 | namespace bamg {
|
---|
| 90 | inline float OppositeAngle(float a)
|
---|
| 91 | {return a<0 ? fPi + a :a - fPi ;}
|
---|
| 92 | inline double OppositeAngle(double a)
|
---|
| 93 | {return a<0 ? Pi + a :a - Pi ;}
|
---|
| 94 |
|
---|
| 95 | Icoor2 inline det(const I2 &a,const I2 & b,const I2 &c)
|
---|
| 96 | {
|
---|
| 97 | register Icoor2 bax = b.x - a.x ,bay = b.y - a.y;
|
---|
| 98 | register Icoor2 cax = c.x - a.x ,cay = c.y - a.y;
|
---|
| 99 | return bax*cay - bay*cax;}
|
---|
| 100 |
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 | // def de numerotation dans un triangles
|
---|
| 104 | static const Int2 VerticesOfTriangularEdge[3][2] = {{1,2},{2,0},{0,1}};
|
---|
| 105 | static const Int2 EdgesVertexTriangle[3][2] = {{1,2},{2,0},{0,1}};
|
---|
| 106 | static const Int2 OppositeVertex[3] = {0,1,2};
|
---|
| 107 | static const Int2 OppositeEdge[3] = {0,1,2};
|
---|
| 108 | static const Int2 NextEdge[3] = {1,2,0};
|
---|
| 109 | static const Int2 PreviousEdge[3] = {2,0,1};
|
---|
| 110 | static const Int2 NextVertex[3] = {1,2,0};
|
---|
| 111 | static const Int2 PreviousVertex[3] = {2,0,1};
|
---|
| 112 |
|
---|
| 113 | Int4 AGoodNumberPrimeWith(Int4 n);
|
---|
| 114 |
|
---|
| 115 | // remark all the angle are in radian beetwen [-Pi,Pi]
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 | class Geometry;
|
---|
| 119 | //static Geometry *NULLGeometry=0;
|
---|
| 120 | class Triangles;
|
---|
| 121 | class Triangle;
|
---|
| 122 | class QuadTree;
|
---|
| 123 | class GeometricalEdge;
|
---|
| 124 | class VertexOnGeom;
|
---|
| 125 | class VertexOnEdge;
|
---|
| 126 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
| 127 | const int IsVertexOnGeom = 8;
|
---|
| 128 | const int IsVertexOnVertex = 16;
|
---|
| 129 | const int IsVertexOnEdge = 32;
|
---|
| 130 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
| 131 | #ifndef NOTFREEFEM
|
---|
| 132 | class ErrorMesh : public Error
|
---|
| 133 | {
|
---|
| 134 | public:
|
---|
| 135 | Triangles *Th;
|
---|
| 136 | ErrorMesh(const char * Text,int l,Triangles * TTh=0, const char *t2="") :
|
---|
| 137 | Error(MESH_ERROR,"Meshing error: ",Text,"\n number : ",l,", ",t2),Th(TTh) {}
|
---|
| 138 | };
|
---|
| 139 | #endif
|
---|
| 140 |
|
---|
| 141 | class Direction { //
|
---|
| 142 | private:
|
---|
| 143 | Icoor1 dir;
|
---|
| 144 | public:
|
---|
| 145 | Direction(): dir(MaxICoor){}; // no direction set
|
---|
| 146 | Direction(Icoor1 i,Icoor1 j) { Icoor2 n2 = 2*(Abs(i)+Abs(j));
|
---|
| 147 | Icoor2 r = MaxICoor* (Icoor2) i;
|
---|
| 148 | Icoor1 r1 = (Icoor1) (2*(r/ n2)); // odd number
|
---|
| 149 | dir = (j>0) ? r1 : r1+1; // odd -> j>0 even -> j<0
|
---|
| 150 | }
|
---|
| 151 | int sens( Icoor1 i,Icoor1 j) { int r =1;
|
---|
| 152 | if (dir!= MaxICoor) {
|
---|
| 153 | Icoor2 x(dir/2),y1(MaxICoor/2-Abs(x)),y(dir%2?-y1:y1);
|
---|
| 154 | r = (x*i + y*j) >=0;}
|
---|
| 155 | return r;}
|
---|
| 156 | };
|
---|
| 157 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
| 158 | class Vertex {public:
|
---|
| 159 | I2 i; // allow to use i.x, and i.y in long int (beware of scale and centering)
|
---|
| 160 | R2 r; // allow to use r.x, and r.y in double
|
---|
| 161 | Metric m;
|
---|
| 162 | Int4 ReferenceNumber;
|
---|
| 163 | Direction DirOfSearch;
|
---|
| 164 | union {
|
---|
| 165 | Triangle * t; // one triangle which contained the vertex
|
---|
| 166 | Int4 color;
|
---|
| 167 | Vertex * to;// use in geometry Vertex to now the Mesh Vertex associed
|
---|
| 168 | VertexOnGeom * on; // if vint 8; // set with Triangles::SetVertexFieldOn()
|
---|
| 169 | Vertex * onbv; // if vint == 16 on Background vertex Triangles::SetVertexFieldOnBTh()
|
---|
| 170 | VertexOnEdge * onbe; // if vint == 32 on Background edge
|
---|
| 171 | };
|
---|
| 172 | Int1 vint; // the vertex number in triangle; varies between 0 and 2 in t
|
---|
| 173 | operator I2 () const {return i;} // operator de cast
|
---|
| 174 | operator const R2 & () const {return r;}// operator de cast
|
---|
| 175 | // operator R2 & () {return r;}// operator de cast
|
---|
| 176 | Real8 operator()(R2 x) const { return m(x);}
|
---|
| 177 | operator Metric () const {return m;}// operator de cast
|
---|
| 178 | Int4 Optim(int = 1,int =0);
|
---|
| 179 | // Vertex(){}
|
---|
| 180 | // ~Vertex(){}
|
---|
| 181 | Real8 Smoothing(Triangles & ,const Triangles & ,Triangle * & ,Real8 =1);
|
---|
| 182 | int ref() const { return ReferenceNumber;}
|
---|
| 183 |
|
---|
| 184 | friend std::ostream& operator <<(std::ostream& f, const Vertex & v)
|
---|
| 185 | {f << "(" << v.i << "," << v.r << MatVVP2x2(v.m) << ")" ; return f;}
|
---|
| 186 | inline void Set(const Vertex & rec,const Triangles &,Triangles &);
|
---|
| 187 | };
|
---|
| 188 |
|
---|
| 189 | double QuadQuality(const Vertex &,const Vertex &,const Vertex &,const Vertex &);
|
---|
| 190 |
|
---|
| 191 | // extern Vertex *Meshend , *Meshbegin;
|
---|
| 192 |
|
---|
| 193 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
| 194 | class TriangleAdjacent {
|
---|
| 195 | friend std::ostream& operator <<(std::ostream& f, const TriangleAdjacent & ta)
|
---|
| 196 | {f << "{" << ta.t << "," << ((int) ta.a) << "}" ;
|
---|
| 197 | return f;}
|
---|
| 198 |
|
---|
| 199 | public:
|
---|
| 200 | Triangle * t; // le triangle
|
---|
| 201 | int a; // le numero de l arete
|
---|
| 202 |
|
---|
| 203 | TriangleAdjacent(Triangle * tt,int aa): t(tt),a(aa &3) {};
|
---|
| 204 | TriangleAdjacent() {};
|
---|
| 205 |
|
---|
| 206 | operator Triangle * () const {return t;}
|
---|
| 207 | operator Triangle & () const {return *t;}
|
---|
| 208 | operator int() const {return a;}
|
---|
| 209 | TriangleAdjacent & operator++()
|
---|
| 210 | {
|
---|
| 211 | a= NextEdge[a];
|
---|
| 212 | return *this;}
|
---|
| 213 | TriangleAdjacent operator--()
|
---|
| 214 | {
|
---|
| 215 | a= PreviousEdge[a];
|
---|
| 216 | return *this;}
|
---|
| 217 | inline TriangleAdjacent Adj() const ;
|
---|
| 218 | int swap();
|
---|
| 219 | inline void SetAdj2(const TriangleAdjacent& , int =0);
|
---|
| 220 | inline Vertex * EdgeVertex(const int &) const ;
|
---|
| 221 | inline Vertex * OppositeVertex() const ;
|
---|
| 222 | inline Icoor2 & det() const;
|
---|
| 223 | inline int Locked() const ;
|
---|
| 224 | inline int GetAllFlag_UnSwap() const ;
|
---|
| 225 | inline void SetLock();
|
---|
| 226 | inline int MarkUnSwap() const;
|
---|
| 227 | inline void SetMarkUnSwap();
|
---|
| 228 | inline void SetCracked();
|
---|
| 229 | inline int Cracked() const ;
|
---|
| 230 | };// end of Vertex class
|
---|
| 231 |
|
---|
| 232 |
|
---|
| 233 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
| 234 | class Edge { public:
|
---|
| 235 | Vertex * v[2];
|
---|
| 236 | Int4 ref;
|
---|
| 237 | GeometricalEdge * on;
|
---|
| 238 | Vertex & operator[](int i){return *v[i];};
|
---|
| 239 | Vertex * operator()(int i){return v[i];};
|
---|
| 240 |
|
---|
| 241 | void ReNumbering(Vertex *vb,Vertex *ve, Int4 *renu)
|
---|
| 242 | {
|
---|
| 243 | if (v[0] >=vb && v[0] <ve) v[0] = vb + renu[v[0]-vb];
|
---|
| 244 | if (v[1] >=vb && v[1] <ve) v[1] = vb + renu[v[1]-vb];
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | const Vertex & operator[](int i) const { return *v[i];};
|
---|
| 248 | R2 operator()(double t) const; // return the point
|
---|
| 249 | // on the curve edge a t in [0:1]
|
---|
| 250 | Edge * adj[2]; // the 2 adj edges if on the same curve
|
---|
| 251 | int Intersection(const Edge & e) const {
|
---|
| 252 | if (!(adj[0]==&e || adj[1]==&e))
|
---|
| 253 | std::cerr << "Bug : Intersection " << (void*) &e << " "
|
---|
| 254 | << adj[0] << " " << adj[1] << std::endl;
|
---|
| 255 | assert(adj[0]==&e || adj[1]==&e);
|
---|
| 256 | return adj[0]==&e ? 0 : 1;}
|
---|
| 257 | Real8 MetricLength() const ;
|
---|
| 258 | inline void Set(const Triangles &,Int4,Triangles &);
|
---|
| 259 |
|
---|
| 260 | }; // end of Edge class
|
---|
| 261 |
|
---|
| 262 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
| 263 | class GeometricalVertex :public Vertex {
|
---|
| 264 | int cas;
|
---|
| 265 | friend class Geometry;
|
---|
| 266 | GeometricalVertex * link; // link all the same GeometricalVertex circular (Crack)
|
---|
| 267 | public:
|
---|
| 268 | int Corner() const {return cas&4;}
|
---|
| 269 | int Required()const {return cas&6;}// a corner is required
|
---|
| 270 | void SetCorner(){ cas |= 4;}
|
---|
| 271 | void SetRequired(){ cas |= 2;}
|
---|
| 272 | void Set(){cas=0;}
|
---|
| 273 | GeometricalVertex() :cas(0), link(this) {};
|
---|
| 274 | GeometricalVertex * The() { assert(link); return link;}// return a unique vertices
|
---|
| 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 | assert(lBegin<= s && s <=lEnd);
|
---|
| 486 | return e->F(sBegin*c0+sEnd*c1);}
|
---|
| 487 | };
|
---|
| 488 |
|
---|
| 489 | int MaxSize; //
|
---|
| 490 | int Size; //
|
---|
| 491 | Real8 len; //
|
---|
| 492 | int state;
|
---|
| 493 | IntersectionTriangles * lIntTria;
|
---|
| 494 | int NbSeg;
|
---|
| 495 | int MaxNbSeg;
|
---|
| 496 | SegInterpolation * lSegsI;
|
---|
| 497 | public:
|
---|
| 498 | IntersectionTriangles & operator[](int i) {return lIntTria[i];}
|
---|
| 499 | operator int&() {return Size;}
|
---|
| 500 | ListofIntersectionTriangles(int n=256,int m=16)
|
---|
| 501 | : MaxSize(n), Size(0), len(-1),state(-1),lIntTria(new IntersectionTriangles[n]) ,
|
---|
| 502 | NbSeg(0), MaxNbSeg(m), lSegsI(new SegInterpolation[m])
|
---|
| 503 | {
|
---|
| 504 | long int verbosity=0;
|
---|
| 505 |
|
---|
| 506 | if (verbosity>9)
|
---|
| 507 | std::cout << " construct ListofIntersectionTriangles"
|
---|
| 508 | << MaxSize << " " << MaxNbSeg<< std::endl;};
|
---|
| 509 | ~ListofIntersectionTriangles(){
|
---|
| 510 | if (lIntTria) delete [] lIntTria,lIntTria=0;
|
---|
| 511 | if (lSegsI) delete [] lSegsI,lSegsI=0;}
|
---|
| 512 | void init(){state=0;len=0;Size=0;}
|
---|
| 513 |
|
---|
| 514 | int NewItem(Triangle * tt,Real8 d0,Real8 d1,Real8 d2);
|
---|
| 515 | int NewItem(R2,const Metric & );
|
---|
| 516 | void NewSubSeg(GeometricalEdge *e,Real8 s0,Real8 s1)
|
---|
| 517 | {
|
---|
| 518 | long int verbosity=0;
|
---|
| 519 |
|
---|
| 520 | if (NbSeg>=MaxNbSeg) {
|
---|
| 521 | int mneo= MaxNbSeg;
|
---|
| 522 | MaxNbSeg *= 2;
|
---|
| 523 | if (verbosity>3)
|
---|
| 524 | std::cout <<" reshape lSegsI from " << mneo << " to "
|
---|
| 525 | << MaxNbSeg <<std::endl;
|
---|
| 526 | SegInterpolation * lEn = new SegInterpolation[MaxNbSeg];
|
---|
| 527 | assert(lSegsI && NbSeg < MaxNbSeg);
|
---|
| 528 | for (int i=0;i< NbSeg;i++)
|
---|
| 529 | lEn[i] = lSegsI[MaxNbSeg]; // copy old to new
|
---|
| 530 | delete [] lSegsI; // remove old
|
---|
| 531 | lSegsI = lEn;
|
---|
| 532 | }
|
---|
| 533 | if (NbSeg)
|
---|
| 534 | lSegsI[NbSeg-1].last=Size;
|
---|
| 535 | lSegsI[NbSeg].e=e;
|
---|
| 536 | lSegsI[NbSeg].sBegin=s0;
|
---|
| 537 | lSegsI[NbSeg].sEnd=s1;
|
---|
| 538 | NbSeg++;
|
---|
| 539 | }
|
---|
| 540 |
|
---|
| 541 | // void CopyMetric(int i,int j){ lIntTria[j].m=lIntTria[i].m;}
|
---|
| 542 | // void CopyMetric(const Metric & mm,int j){ lIntTria[j].m=mm;}
|
---|
| 543 |
|
---|
| 544 | void ReShape() {
|
---|
| 545 | register int newsize = MaxSize*2;
|
---|
| 546 | IntersectionTriangles * nw = new IntersectionTriangles[newsize];
|
---|
| 547 | assert(nw);
|
---|
| 548 | for (int i=0;i<MaxSize;i++) // recopy
|
---|
| 549 | nw[i] = lIntTria[i];
|
---|
| 550 | long int verbosity=0;
|
---|
| 551 | if(verbosity>3)
|
---|
| 552 | std::cout << " ListofIntersectionTriangles ReShape MaxSize "
|
---|
| 553 | << MaxSize << " -> "
|
---|
| 554 | << newsize << std::endl;
|
---|
| 555 | MaxSize = newsize;
|
---|
| 556 | delete [] lIntTria;// remove old
|
---|
| 557 | lIntTria = nw; // copy pointer
|
---|
| 558 | }
|
---|
| 559 |
|
---|
| 560 | void SplitEdge(const Triangles & ,const R2 &,const R2 &,int nbegin=0);
|
---|
| 561 | Real8 Length();
|
---|
| 562 | Int4 NewPoints(Vertex *,Int4 & nbv,Int4 nbvx);
|
---|
| 563 | };
|
---|
| 564 |
|
---|
| 565 |
|
---|
| 566 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
| 567 | class GeometricalSubDomain {
|
---|
| 568 | public:
|
---|
| 569 | GeometricalEdge *edge;
|
---|
| 570 | int sens; // -1 or 1
|
---|
| 571 | Int4 ref;
|
---|
| 572 | inline void Set(const GeometricalSubDomain &,const Geometry & ,const Geometry &);
|
---|
| 573 |
|
---|
| 574 | };
|
---|
| 575 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
| 576 | class SubDomain {
|
---|
| 577 | public:
|
---|
| 578 | Triangle * head;
|
---|
| 579 | Int4 ref;
|
---|
| 580 | int sens; // -1 or 1
|
---|
| 581 | Edge * edge; // to geometrical
|
---|
| 582 | inline void Set(const Triangles &,Int4,Triangles &);
|
---|
| 583 |
|
---|
| 584 | };
|
---|
| 585 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
| 586 | class VertexOnGeom { public:
|
---|
| 587 |
|
---|
| 588 | Vertex * mv;
|
---|
| 589 | Real8 abscisse;
|
---|
| 590 | union{
|
---|
| 591 | GeometricalVertex * gv; // if abscisse <0;
|
---|
| 592 | GeometricalEdge * ge; // if abscisse in [0..1]
|
---|
| 593 | };
|
---|
| 594 | inline void Set(const VertexOnGeom&,const Triangles &,Triangles &);
|
---|
| 595 | int OnGeomVertex()const {return this? abscisse <0 :0;}
|
---|
| 596 | int OnGeomEdge() const {return this? abscisse >=0 :0;}
|
---|
| 597 | VertexOnGeom(): mv(0),abscisse(0){gv=0;}
|
---|
| 598 | VertexOnGeom(Vertex & m,GeometricalVertex &g) : mv(&m),abscisse(-1){gv=&g;}
|
---|
| 599 | // std::cout << " mv = " <<mv << " gv = " << gv << std::endl;}
|
---|
| 600 | VertexOnGeom(Vertex & m,GeometricalEdge &g,Real8 s) : mv(&m),abscisse(s){ge=&g;}
|
---|
| 601 | //std::cout << &g << " " << ge << std::endl;
|
---|
| 602 | operator Vertex * () const {return mv;}
|
---|
| 603 | operator GeometricalVertex * () const {return gv;}
|
---|
| 604 | operator GeometricalEdge * () const {return ge;}
|
---|
| 605 | // operator Real8 & () {return abscisse;}
|
---|
| 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 | assert(New[0] && New[1]);
|
---|
| 662 | T(i0) = New[0];
|
---|
| 663 | T(i1) = New[1];}
|
---|
| 664 | void UnCrack(){
|
---|
| 665 | Triangle & T(*t);
|
---|
| 666 | int i0=VerticesOfTriangularEdge[i][0];
|
---|
| 667 | int i1=VerticesOfTriangularEdge[i][0];
|
---|
| 668 | assert(New[0] && New[1]);
|
---|
| 669 | T(i0) = TheVertex(T(i0));
|
---|
| 670 | T(i1) = TheVertex(T(i1));}
|
---|
| 671 | void Set() {
|
---|
| 672 | TriangleAdjacent ta ( FindTriangleAdjacent(*edge));
|
---|
| 673 | t = ta;
|
---|
| 674 | i = ta;
|
---|
| 675 |
|
---|
| 676 | New[0] = ta.EdgeVertex(0);
|
---|
| 677 | New[1] = ta.EdgeVertex(1);
|
---|
| 678 | // warning the ref
|
---|
| 679 |
|
---|
| 680 | }
|
---|
| 681 |
|
---|
| 682 | }; // end of class CrackedTriangle
|
---|
| 683 | public:
|
---|
| 684 | CrackedTriangle a,b;
|
---|
| 685 | CrackedEdge() :a(),b() {}
|
---|
| 686 | CrackedEdge(Edge * start, Int4 i,Int4 j) : a(start+i),b(start+j) {};
|
---|
| 687 | CrackedEdge(Edge * e0, Edge * e1 ) : a(e0),b(e1) {};
|
---|
| 688 |
|
---|
| 689 | void Crack() { a.Crack(); b.Crack();}
|
---|
| 690 | void UnCrack() { a.UnCrack(); b.UnCrack();}
|
---|
| 691 | void Set() { a.Set(), b.Set();}
|
---|
| 692 | };
|
---|
| 693 |
|
---|
| 694 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
| 695 | class Triangles {
|
---|
| 696 | public:
|
---|
| 697 |
|
---|
| 698 | enum TypeFileMesh {
|
---|
| 699 | AutoMesh=0,BDMesh=1,NOPOMesh=2,amMesh=3,am_fmtMesh=4,amdbaMesh=5,
|
---|
| 700 | ftqMesh=6,mshMesh=7};
|
---|
| 701 |
|
---|
| 702 | int static counter; // to kown the number of mesh in memory
|
---|
| 703 | int OnDisk; // true if on disk
|
---|
| 704 | Geometry & Gh; // Geometry
|
---|
| 705 | Triangles & BTh; // Background Mesh Bth==*this =>no background
|
---|
| 706 |
|
---|
| 707 | Int4 NbRef; // counter of ref on the this class if 0 we can delete
|
---|
| 708 | Int4 nbvx,nbtx; // nombre max de sommets , de triangles
|
---|
| 709 |
|
---|
| 710 | Int4 nt,nbv,nbt,nbiv,nbe; // nb of legal triangles, nb of vertex, of triangles,
|
---|
| 711 | // of initial vertices, of edges with reference,
|
---|
| 712 | Int4 NbOfQuad; // nb of quadrangle
|
---|
| 713 |
|
---|
| 714 | Int4 NbSubDomains; //
|
---|
| 715 | Int4 NbOutT; // Nb of oudeside triangle
|
---|
| 716 | Int4 NbOfTriangleSearchFind;
|
---|
| 717 | Int4 NbOfSwapTriangle;
|
---|
| 718 | char * name, *identity;
|
---|
| 719 | Vertex * vertices; // data of vertices des sommets
|
---|
| 720 |
|
---|
| 721 | Int4 NbVerticesOnGeomVertex;
|
---|
| 722 | VertexOnGeom * VerticesOnGeomVertex;
|
---|
| 723 |
|
---|
| 724 | Int4 NbVerticesOnGeomEdge;
|
---|
| 725 | VertexOnGeom * VerticesOnGeomEdge;
|
---|
| 726 |
|
---|
| 727 | Int4 NbVertexOnBThVertex;
|
---|
| 728 | VertexOnVertex *VertexOnBThVertex;
|
---|
| 729 |
|
---|
| 730 | Int4 NbVertexOnBThEdge;
|
---|
| 731 | VertexOnEdge *VertexOnBThEdge;
|
---|
| 732 |
|
---|
| 733 |
|
---|
| 734 | Int4 NbCrackedVertices;
|
---|
| 735 |
|
---|
| 736 |
|
---|
| 737 | Int4 NbCrackedEdges;
|
---|
| 738 | CrackedEdge *CrackedEdges;
|
---|
| 739 |
|
---|
| 740 |
|
---|
| 741 | R2 pmin,pmax; // extrema
|
---|
| 742 | Real8 coefIcoor; // coef to integer Icoor1;
|
---|
| 743 |
|
---|
| 744 | Triangle * triangles;
|
---|
| 745 | Edge * edges;
|
---|
| 746 |
|
---|
| 747 | QuadTree *quadtree;
|
---|
| 748 | Vertex ** ordre;
|
---|
| 749 | SubDomain * subdomains;
|
---|
| 750 | ListofIntersectionTriangles lIntTria;
|
---|
| 751 | // end of variable
|
---|
| 752 |
|
---|
| 753 | Triangles(Int4 i);//:BTh(*this),Gh(*new Geometry()){PreInit(i);}
|
---|
| 754 |
|
---|
| 755 |
|
---|
| 756 | ~Triangles();
|
---|
| 757 | Triangles(const char * ,Real8=-1) ;
|
---|
[2790] | 758 | Triangles(BamgMesh* bamgmesh,BamgOpts* bamgopts);
|
---|
[2740] | 759 |
|
---|
| 760 | Triangles(Int4 nbvx,Triangles & BT,int keepBackVertices=1)
|
---|
| 761 | :Gh(BT.Gh),BTh(BT) {
|
---|
| 762 | try {GeomToTriangles1(nbvx,keepBackVertices);}
|
---|
| 763 | catch(...) { this->~Triangles(); throw; } }
|
---|
| 764 |
|
---|
| 765 | Triangles(Int4 nbvx,Geometry & G)
|
---|
| 766 | :Gh(G),BTh(*this){
|
---|
| 767 | try { GeomToTriangles0(nbvx);}
|
---|
| 768 | catch(...) { this->~Triangles(); throw; } }
|
---|
| 769 | Triangles(Triangles &,Geometry * pGh=0,Triangles* pBTh=0,Int4 nbvxx=0 ); // COPY OPERATEUR
|
---|
| 770 | // Triangles(Triangles &){ std::cerr << " BUG call copy opretor of Triangles" << std::endl;MeshError(111);}
|
---|
| 771 | Triangles(const Triangles &,const int *flag,const int *bb); // truncature
|
---|
| 772 |
|
---|
| 773 | void SetIntCoor(const char * from =0);
|
---|
| 774 |
|
---|
| 775 | // void RandomInit();
|
---|
| 776 | // void CubeInit(int ,int);
|
---|
| 777 |
|
---|
| 778 | Real8 MinimalHmin() {return 2.0/coefIcoor;}
|
---|
| 779 | Real8 MaximalHmax() {return Max(pmax.x-pmin.x,pmax.y-pmin.y);}
|
---|
| 780 | const Vertex & operator[] (Int4 i) const { return vertices[i];};
|
---|
| 781 | Vertex & operator[](Int4 i) { return vertices[i];};
|
---|
| 782 | const Triangle & operator() (Int4 i) const { return triangles[i];};
|
---|
| 783 | Triangle & operator()(Int4 i) { return triangles[i];};
|
---|
| 784 | I2 toI2(const R2 & P) const {
|
---|
| 785 | return I2( (Icoor1) (coefIcoor*(P.x-pmin.x))
|
---|
| 786 | ,(Icoor1) (coefIcoor*(P.y-pmin.y)) );}
|
---|
| 787 | R2 toR2(const I2 & P) const {
|
---|
| 788 | return R2( (double) P.x/coefIcoor+pmin.x, (double) P.y/coefIcoor+pmin.y);}
|
---|
| 789 | void Add( Vertex & s,Triangle * t,Icoor2 * =0) ;
|
---|
| 790 | void Insert();
|
---|
| 791 | // void InsertOld();
|
---|
| 792 | void ForceBoundary();
|
---|
| 793 | void Heap();
|
---|
| 794 | void FindSubDomain(int );
|
---|
| 795 | Int4 ConsRefTriangle(Int4 *) const;
|
---|
| 796 | void ShowHistogram() const;
|
---|
| 797 | void ShowRegulaty() const; // Add FH avril 2007
|
---|
| 798 | // void ConsLinkTriangle();
|
---|
| 799 |
|
---|
| 800 | void ReMakeTriangleContainingTheVertex();
|
---|
| 801 | void UnMarkUnSwapTriangle();
|
---|
| 802 | void SmoothMetric(Real8 raisonmax) ;
|
---|
| 803 | void BoundAnisotropy(Real8 anisomax,double hminaniso= 1e-100) ;
|
---|
| 804 | void MaxSubDivision(Real8 maxsubdiv);
|
---|
| 805 | void WriteMetric(std::ostream &,int iso) ;
|
---|
| 806 | Edge** MakeGeometricalEdgeToEdge();
|
---|
| 807 | void SetVertexFieldOn();
|
---|
| 808 | void SetVertexFieldOnBTh();
|
---|
| 809 | Int4 SplitInternalEdgeWithBorderVertices();
|
---|
| 810 | void MakeQuadrangles(double costheta);
|
---|
| 811 | int SplitElement(int choice);
|
---|
| 812 | void MakeQuadTree();
|
---|
| 813 | void NewPoints( Triangles &,int KeepBackVertex =1 );
|
---|
| 814 | Int4 InsertNewPoints(Int4 nbvold,Int4 & NbTSwap) ;
|
---|
| 815 | void NewPointsOld( Triangles & );
|
---|
| 816 | void NewPoints(int KeepBackVertex=1){ NewPoints(*this,KeepBackVertex);}
|
---|
| 817 | void ReNumberingTheTriangleBySubDomain(bool justcompress=false);
|
---|
| 818 | void ReNumberingVertex(Int4 * renu);
|
---|
| 819 | void SmoothingVertex(int =3,Real8=0.3);
|
---|
| 820 | Metric MetricAt (const R2 &) const;
|
---|
| 821 | GeometricalEdge * ProjectOnCurve( Edge & AB, Vertex & A, Vertex & B,Real8 theta,
|
---|
| 822 | Vertex & R,VertexOnEdge & BR,VertexOnGeom & GR);
|
---|
| 823 |
|
---|
| 824 | Int4 Number(const Triangle & t) const { return &t - triangles;}
|
---|
| 825 | Int4 Number(const Triangle * t) const { return t - triangles;}
|
---|
| 826 | Int4 Number(const Vertex & t) const { return &t - vertices;}
|
---|
| 827 | Int4 Number(const Vertex * t) const { return t - vertices;}
|
---|
| 828 | Int4 Number(const Edge & t) const { return &t - edges;}
|
---|
| 829 | Int4 Number(const Edge * t) const { return t - edges;}
|
---|
| 830 | Int4 Number2(const Triangle * t) const {
|
---|
| 831 | // if(t>= triangles && t < triangles + nbt )
|
---|
| 832 | return t - triangles;
|
---|
| 833 | // else return t - OutSidesTriangles;
|
---|
| 834 | }
|
---|
| 835 |
|
---|
| 836 | Vertex * NearestVertex(Icoor1 i,Icoor1 j) ;
|
---|
| 837 | Triangle * FindTriangleContening(const I2 & ,Icoor2 [3],Triangle *tstart=0) const;
|
---|
| 838 |
|
---|
[2790] | 839 | void ReadFromMatlabMesh(BamgMesh* bamgmesh, BamgOpts* bamgopts);
|
---|
[2806] | 840 | void WriteMesh(BamgMesh* bamgmesh,BamgOpts* bamgopts);
|
---|
[2740] | 841 |
|
---|
[2790] | 842 | void ReadMetric(BamgOpts* bamgopts,const Real8 hmin,const Real8 hmax,const Real8 coef);
|
---|
[2740] | 843 | void IntersectConsMetric(const double * s,const Int4 nbsol,const int * typsols,
|
---|
| 844 | const Real8 hmin,const Real8 hmax, const Real8 coef,
|
---|
| 845 | const Real8 anisomax,const Real8 CutOff=1.e-4,const int NbJacobi=1,
|
---|
| 846 | const int DoNormalisation=1,
|
---|
| 847 | const double power=1.0,
|
---|
| 848 | const int choise=0);
|
---|
| 849 | void IntersectGeomMetric(const Real8 err,const int iso);
|
---|
| 850 |
|
---|
| 851 |
|
---|
| 852 | int isCracked() const {return NbCrackedVertices != 0;}
|
---|
| 853 | int Crack();
|
---|
| 854 | int UnCrack();
|
---|
| 855 |
|
---|
| 856 | friend std::ostream& operator <<(std::ostream& f, const Triangles & Th);
|
---|
| 857 | void ConsGeometry(Real8 =-1.0,int *equiedges=0); // construct a geometry if no geo
|
---|
| 858 | void FillHoleInMesh() ;
|
---|
| 859 | int CrackMesh();
|
---|
| 860 | private:
|
---|
| 861 | void GeomToTriangles1(Int4 nbvx,int KeepBackVertices=1);// the real constructor mesh adaption
|
---|
| 862 | void GeomToTriangles0(Int4 nbvx);// the real constructor mesh generator
|
---|
| 863 | void PreInit(Int4,char * =0 );
|
---|
| 864 |
|
---|
| 865 | }; // End Class Triangles
|
---|
| 866 |
|
---|
| 867 |
|
---|
| 868 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
| 869 | class Geometry {
|
---|
| 870 | public:
|
---|
| 871 | int OnDisk;
|
---|
| 872 | Int4 NbRef; // counter of ref on the this class if 0 we can delete
|
---|
| 873 |
|
---|
| 874 | char *name;
|
---|
| 875 | Int4 nbvx,nbtx; // nombre max de sommets , de Geometry
|
---|
| 876 | Int4 nbv,nbt,nbiv,nbe; // nombre de sommets, de Geometry, de sommets initiaux,
|
---|
| 877 | Int4 NbSubDomains; //
|
---|
| 878 | Int4 NbEquiEdges;
|
---|
| 879 | Int4 NbCrackedEdges;
|
---|
| 880 | // Int4 nbtf;// de triangle frontiere
|
---|
| 881 | Int4 NbOfCurves;
|
---|
| 882 | int empty(){return (nbv ==0) && (nbt==0) && (nbe==0) && (NbSubDomains==0); }
|
---|
| 883 | GeometricalVertex * vertices; // data of vertices des sommets
|
---|
| 884 | Triangle * triangles;
|
---|
| 885 | GeometricalEdge * edges;
|
---|
| 886 | QuadTree *quadtree;
|
---|
| 887 | GeometricalSubDomain *subdomains;
|
---|
| 888 | Curve *curves;
|
---|
| 889 | ~Geometry();
|
---|
| 890 | Geometry(const Geometry & Gh); //Copy Operator
|
---|
| 891 | Geometry(int nbg,const Geometry ** ag); // intersection operator
|
---|
| 892 |
|
---|
| 893 | R2 pmin,pmax; // extrema
|
---|
| 894 | Real8 coefIcoor; // coef to integer Icoor1;
|
---|
| 895 | Real8 MaximalAngleOfCorner;
|
---|
| 896 |
|
---|
| 897 | // end of data
|
---|
| 898 |
|
---|
| 899 |
|
---|
| 900 | I2 toI2(const R2 & P) const {
|
---|
| 901 | return I2( (Icoor1) (coefIcoor*(P.x-pmin.x))
|
---|
| 902 | ,(Icoor1) (coefIcoor*(P.y-pmin.y)) );}
|
---|
| 903 |
|
---|
| 904 | Real8 MinimalHmin() {return 2.0/coefIcoor;}
|
---|
| 905 | Real8 MaximalHmax() {return Max(pmax.x-pmin.x,pmax.y-pmin.y);}
|
---|
[2790] | 906 | void ReadGeometry(BamgGeom* bamggeom, BamgOpts* bamgopts);
|
---|
[2740] | 907 | void EmptyGeometry();
|
---|
| 908 | Geometry() {EmptyGeometry();}// empty Geometry
|
---|
| 909 | void AfterRead();
|
---|
[2790] | 910 | Geometry(BamgGeom* bamggeom, BamgOpts* bamgopts) {EmptyGeometry();OnDisk=1;ReadGeometry(bamggeom,bamgopts);AfterRead();}
|
---|
[2740] | 911 |
|
---|
| 912 | const GeometricalVertex & operator[] (Int4 i) const { return vertices[i];};
|
---|
| 913 | GeometricalVertex & operator[](Int4 i) { return vertices[i];};
|
---|
| 914 | const GeometricalEdge & operator() (Int4 i) const { return edges[i];};
|
---|
| 915 | GeometricalEdge & operator()(Int4 i) { return edges[i];};
|
---|
| 916 | Int4 Number(const GeometricalVertex & t) const { return &t - vertices;}
|
---|
| 917 | Int4 Number(const GeometricalVertex * t) const { return t - vertices;}
|
---|
| 918 | Int4 Number(const GeometricalEdge & t) const { return &t - edges;}
|
---|
| 919 | Int4 Number(const GeometricalEdge * t) const { return t - edges;}
|
---|
| 920 | Int4 Number(const Curve * c) const { return c - curves;}
|
---|
[2796] | 921 |
|
---|
[2740] | 922 | void UnMarkEdges() {
|
---|
[2796] | 923 | for (Int4 i=0;i<nbe;i++) edges[i].SetUnMark();}
|
---|
[2740] | 924 |
|
---|
[2796] | 925 | GeometricalEdge * ProjectOnCurve(const Edge & ,Real8,Vertex &,VertexOnGeom &) const ;
|
---|
[2740] | 926 | GeometricalEdge * Contening(const R2 P, GeometricalEdge * start) const;
|
---|
[2796] | 927 | friend std::ostream& operator <<(std::ostream& f, const Geometry & Gh);
|
---|
| 928 | void WriteGeometry(BamgGeom* bamggeom, BamgOpts* bamgopts);
|
---|
[2740] | 929 | }; // End Class Geometry
|
---|
| 930 |
|
---|
| 931 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
| 932 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
| 933 | /////////////////// END CLASS ////////////////////////////////////
|
---|
| 934 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
| 935 | /////////////////////////////////////////////////////////////////////////////////////
|
---|
| 936 |
|
---|
| 937 | inline Triangles::Triangles(Int4 i) :Gh(*new Geometry()),BTh(*this){PreInit(i);}
|
---|
| 938 |
|
---|
| 939 | extern Triangles * CurrentTh;
|
---|
| 940 |
|
---|
| 941 | TriangleAdjacent CloseBoundaryEdge(I2 ,Triangle *, double &,double &) ;
|
---|
| 942 | TriangleAdjacent CloseBoundaryEdgeV2(I2 A,Triangle *t, double &a,double &b);
|
---|
| 943 |
|
---|
| 944 | Int4 FindTriangle(Triangles &Th, Real8 x, Real8 y, double* a,int & inside);
|
---|
| 945 |
|
---|
| 946 |
|
---|
| 947 |
|
---|
| 948 | inline Triangle * Triangle::Quadrangle(Vertex * & v0,Vertex * & v1,Vertex * & v2,Vertex * & v3) const
|
---|
| 949 | {
|
---|
| 950 | // return the other triangle of the quad if a quad or 0 if not a quat
|
---|
| 951 | Triangle * t =0;
|
---|
| 952 | if (link) {
|
---|
| 953 | int a=-1;
|
---|
| 954 | if (aa[0] & 16 ) a=0;
|
---|
| 955 | if (aa[1] & 16 ) a=1;
|
---|
| 956 | if (aa[2] & 16 ) a=2;
|
---|
| 957 | if (a>=0) {
|
---|
| 958 | t = at[a];
|
---|
| 959 | // if (t-this<0) return 0;
|
---|
| 960 | v2 = ns[VerticesOfTriangularEdge[a][0]];
|
---|
| 961 | v0 = ns[VerticesOfTriangularEdge[a][1]];
|
---|
| 962 | v1 = ns[OppositeEdge[a]];
|
---|
| 963 | v3 = t->ns[OppositeEdge[aa[a]&3]];
|
---|
| 964 | }
|
---|
| 965 | }
|
---|
| 966 | return t;
|
---|
| 967 | }
|
---|
| 968 |
|
---|
| 969 | inline double Triangle::QualityQuad(int a,int option) const
|
---|
| 970 | { // first do the logique part
|
---|
| 971 | double q;
|
---|
| 972 | if (!link || aa[a] &4)
|
---|
| 973 | q= -1;
|
---|
| 974 | else {
|
---|
| 975 | Triangle * t = at[a];
|
---|
| 976 | if (t-this<0) q= -1;// because we do 2 times
|
---|
| 977 | else if (!t->link ) q= -1;
|
---|
| 978 | else if (aa[0] & 16 || aa[1] & 16 || aa[2] & 16 || t->aa[0] & 16 || t->aa[1] & 16 || t->aa[2] & 16 )
|
---|
| 979 | q= -1;
|
---|
| 980 | else if(option)
|
---|
| 981 | {
|
---|
| 982 | const Vertex & v2 = *ns[VerticesOfTriangularEdge[a][0]];
|
---|
| 983 | const Vertex & v0 = *ns[VerticesOfTriangularEdge[a][1]];
|
---|
| 984 | const Vertex & v1 = *ns[OppositeEdge[a]];
|
---|
| 985 | const Vertex & v3 = * t->ns[OppositeEdge[aa[a]&3]];
|
---|
| 986 | q = QuadQuality(v0,v1,v2,v3); // do the float part
|
---|
| 987 | }
|
---|
| 988 | else q= 1;
|
---|
| 989 | }
|
---|
| 990 | return q;
|
---|
| 991 | }
|
---|
| 992 |
|
---|
| 993 |
|
---|
| 994 | inline void Vertex::Set(const Vertex & rec,const Triangles & ,Triangles & )
|
---|
| 995 | {
|
---|
| 996 | *this = rec;
|
---|
| 997 | }
|
---|
| 998 | inline void GeometricalVertex::Set(const GeometricalVertex & rec,const Geometry & ,const Geometry & )
|
---|
| 999 | {
|
---|
| 1000 | *this = rec;
|
---|
| 1001 | }
|
---|
| 1002 | inline void Edge::Set(const Triangles & Th ,Int4 i,Triangles & ThNew)
|
---|
| 1003 | {
|
---|
| 1004 | *this = Th.edges[i];
|
---|
| 1005 | v[0] = ThNew.vertices + Th.Number(v[0]);
|
---|
| 1006 | v[1] = ThNew.vertices + Th.Number(v[1]);
|
---|
| 1007 | if (on)
|
---|
| 1008 | on = ThNew.Gh.edges+Th.Gh.Number(on);
|
---|
| 1009 | if (adj[0]) adj[0] = ThNew.edges + Th.Number(adj[0]);
|
---|
| 1010 | if (adj[1]) adj[1] = ThNew.edges + Th.Number(adj[1]);
|
---|
| 1011 |
|
---|
| 1012 | }
|
---|
| 1013 | inline void GeometricalEdge::Set(const GeometricalEdge & rec,const Geometry & Gh ,Geometry & GhNew)
|
---|
| 1014 | {
|
---|
| 1015 | *this = rec;
|
---|
| 1016 | v[0] = GhNew.vertices + Gh.Number(v[0]);
|
---|
| 1017 | v[1] = GhNew.vertices + Gh.Number(v[1]);
|
---|
| 1018 | if (Adj[0]) Adj[0] = GhNew.edges + Gh.Number(Adj[0]);
|
---|
| 1019 | if (Adj[1]) Adj[1] = GhNew.edges + Gh.Number(Adj[1]);
|
---|
| 1020 | }
|
---|
| 1021 |
|
---|
| 1022 | inline void Curve::Set(const Curve & rec,const Geometry & Gh ,Geometry & GhNew)
|
---|
| 1023 | {
|
---|
| 1024 | *this = rec;
|
---|
| 1025 | be = GhNew.edges + Gh.Number(be);
|
---|
| 1026 | ee = GhNew.edges + Gh.Number(ee);
|
---|
| 1027 | if(next) next= GhNew.curves + Gh.Number(next);
|
---|
| 1028 | }
|
---|
| 1029 |
|
---|
| 1030 | inline void Triangle::Set(const Triangle & rec,const Triangles & Th ,Triangles & ThNew)
|
---|
| 1031 | {
|
---|
| 1032 | *this = rec;
|
---|
| 1033 | if ( ns[0] ) ns[0] = ThNew.vertices + Th.Number(ns[0]);
|
---|
| 1034 | if ( ns[1] ) ns[1] = ThNew.vertices + Th.Number(ns[1]);
|
---|
| 1035 | if ( ns[2] ) ns[2] = ThNew.vertices + Th.Number(ns[2]);
|
---|
| 1036 | if(at[0]) at[0] = ThNew.triangles + Th.Number(at[0]);
|
---|
| 1037 | if(at[1]) at[1] = ThNew.triangles + Th.Number(at[1]);
|
---|
| 1038 | if(at[2]) at[2] = ThNew.triangles + Th.Number(at[2]);
|
---|
| 1039 | if (link >= Th.triangles && link < Th.triangles + Th.nbt)
|
---|
| 1040 | link = ThNew.triangles + Th.Number(link);
|
---|
| 1041 | }
|
---|
| 1042 | inline void VertexOnVertex::Set(const Triangles & Th ,Int4 i,Triangles & ThNew)
|
---|
| 1043 | {
|
---|
| 1044 | *this = Th.VertexOnBThVertex[i];
|
---|
| 1045 | v = ThNew.vertices + Th.Number(v);
|
---|
| 1046 |
|
---|
| 1047 | }
|
---|
| 1048 | inline void SubDomain::Set(const Triangles & Th ,Int4 i,Triangles & ThNew)
|
---|
| 1049 | {
|
---|
| 1050 | *this = Th.subdomains[i];
|
---|
| 1051 | assert( head - Th.triangles >=0 && head - Th.triangles < Th.nbt);
|
---|
| 1052 | head = ThNew.triangles + Th.Number(head) ;
|
---|
| 1053 | assert(edge - Th.edges >=0 && edge - Th.edges < Th.nbe);
|
---|
| 1054 | edge = ThNew.edges+ Th.Number(edge);
|
---|
| 1055 | }
|
---|
| 1056 | inline void GeometricalSubDomain::Set(const GeometricalSubDomain & rec,const Geometry & Gh ,const Geometry & GhNew)
|
---|
| 1057 | {
|
---|
| 1058 | *this = rec;
|
---|
| 1059 | edge = Gh.Number(edge) + GhNew.edges;
|
---|
| 1060 | }
|
---|
| 1061 | inline void VertexOnEdge::Set(const Triangles & Th ,Int4 i,Triangles & ThNew)
|
---|
| 1062 | {
|
---|
| 1063 | *this = Th.VertexOnBThEdge[i];
|
---|
| 1064 | v = ThNew.vertices + Th.Number(v);
|
---|
| 1065 | }
|
---|
| 1066 |
|
---|
| 1067 | inline void VertexOnGeom::Set(const VertexOnGeom & rec,const Triangles & Th ,Triangles & ThNew)
|
---|
| 1068 | {
|
---|
| 1069 | *this = rec;
|
---|
| 1070 | mv = ThNew.vertices + Th.Number(mv);
|
---|
| 1071 | if (gv)
|
---|
| 1072 | if (abscisse < 0 )
|
---|
| 1073 | gv = ThNew.Gh.vertices + Th.Gh.Number(gv);
|
---|
| 1074 | else
|
---|
| 1075 | ge = ThNew.Gh.edges + Th.Gh.Number(ge);
|
---|
| 1076 |
|
---|
| 1077 | }
|
---|
| 1078 | inline Real8 Edge::MetricLength() const
|
---|
| 1079 | {
|
---|
| 1080 | return LengthInterpole(v[0]->m,v[1]->m,v[1]->r - v[0]->r) ;
|
---|
| 1081 | }
|
---|
| 1082 |
|
---|
| 1083 | inline void Triangles::ReMakeTriangleContainingTheVertex()
|
---|
| 1084 | {
|
---|
| 1085 | register Int4 i;
|
---|
| 1086 | for ( i=0;i<nbv;i++)
|
---|
| 1087 | {
|
---|
| 1088 | vertices[i].vint = 0;
|
---|
| 1089 | vertices[i].t=0;
|
---|
| 1090 | }
|
---|
| 1091 | for ( i=0;i<nbt;i++)
|
---|
| 1092 | triangles[i].SetTriangleContainingTheVertex();
|
---|
| 1093 | }
|
---|
| 1094 |
|
---|
| 1095 | inline void Triangles::UnMarkUnSwapTriangle()
|
---|
| 1096 | {
|
---|
| 1097 | register Int4 i;
|
---|
| 1098 | for ( i=0;i<nbt;i++)
|
---|
| 1099 | for(int j=0;j<3;j++)
|
---|
| 1100 | triangles[i].SetUnMarkUnSwap(j);
|
---|
| 1101 | }
|
---|
| 1102 |
|
---|
| 1103 | inline void Triangles::SetVertexFieldOn()
|
---|
| 1104 | {
|
---|
| 1105 | for (Int4 i=0;i<nbv;i++)
|
---|
| 1106 | vertices[i].on=0;
|
---|
| 1107 | for (Int4 j=0;j<NbVerticesOnGeomVertex;j++ )
|
---|
| 1108 | VerticesOnGeomVertex[j].SetOn();
|
---|
| 1109 | for (Int4 k=0;k<NbVerticesOnGeomEdge;k++ )
|
---|
| 1110 | VerticesOnGeomEdge[k].SetOn();
|
---|
| 1111 | }
|
---|
| 1112 | inline void Triangles::SetVertexFieldOnBTh()
|
---|
| 1113 | {
|
---|
| 1114 | for (Int4 i=0;i<nbv;i++)
|
---|
| 1115 | vertices[i].on=0;
|
---|
| 1116 | for (Int4 j=0;j<NbVertexOnBThVertex;j++ )
|
---|
| 1117 | VertexOnBThVertex[j].SetOnBTh();
|
---|
| 1118 | for (Int4 k=0;k<NbVertexOnBThEdge;k++ )
|
---|
| 1119 | VertexOnBThEdge[k].SetOnBTh();
|
---|
| 1120 |
|
---|
| 1121 | }
|
---|
| 1122 |
|
---|
| 1123 | inline void TriangleAdjacent::SetAdj2(const TriangleAdjacent & ta, int l )
|
---|
| 1124 | { // set du triangle adjacent
|
---|
| 1125 | if(t) {
|
---|
| 1126 | t->at[a]=ta.t;
|
---|
| 1127 | t->aa[a]=ta.a|l;}
|
---|
| 1128 | if(ta.t) {
|
---|
| 1129 | ta.t->at[ta.a] = t ;
|
---|
| 1130 | ta.t->aa[ta.a] = a| l ;
|
---|
| 1131 | }
|
---|
| 1132 | }
|
---|
| 1133 |
|
---|
| 1134 |
|
---|
| 1135 | inline int TriangleAdjacent::Locked() const
|
---|
| 1136 | { return t->aa[a] &4;}
|
---|
| 1137 | inline int TriangleAdjacent::Cracked() const
|
---|
| 1138 | { return t->aa[a] &32;}
|
---|
| 1139 | inline int TriangleAdjacent::GetAllFlag_UnSwap() const
|
---|
| 1140 | { return t->aa[a] & 1012;} // take all flag except MarkUnSwap
|
---|
| 1141 |
|
---|
| 1142 | inline int TriangleAdjacent::MarkUnSwap() const
|
---|
| 1143 | { return t->aa[a] &8;}
|
---|
| 1144 |
|
---|
| 1145 | inline void TriangleAdjacent::SetLock(){ t->SetLocked(a);}
|
---|
| 1146 |
|
---|
| 1147 | inline void TriangleAdjacent::SetCracked() { t->SetCracked(a);}
|
---|
| 1148 |
|
---|
| 1149 | inline TriangleAdjacent TriangleAdjacent::Adj() const
|
---|
| 1150 | { return t->Adj(a);}
|
---|
| 1151 |
|
---|
| 1152 | inline Vertex * TriangleAdjacent::EdgeVertex(const int & i) const
|
---|
| 1153 | {return t->ns[VerticesOfTriangularEdge[a][i]]; }
|
---|
| 1154 | inline Vertex * TriangleAdjacent::OppositeVertex() const
|
---|
| 1155 | {return t->ns[bamg::OppositeVertex[a]]; }
|
---|
| 1156 | inline Icoor2 & TriangleAdjacent::det() const
|
---|
| 1157 | { return t->det;}
|
---|
| 1158 | inline TriangleAdjacent Adj(const TriangleAdjacent & a)
|
---|
| 1159 | { return a.Adj();}
|
---|
| 1160 |
|
---|
| 1161 | inline TriangleAdjacent Next(const TriangleAdjacent & ta)
|
---|
| 1162 | { return TriangleAdjacent(ta.t,NextEdge[ta.a]);}
|
---|
| 1163 |
|
---|
| 1164 | inline TriangleAdjacent Previous(const TriangleAdjacent & ta)
|
---|
| 1165 | { return TriangleAdjacent(ta.t,PreviousEdge[ta.a]);}
|
---|
| 1166 |
|
---|
| 1167 | inline void Adj(GeometricalEdge * & on,int &i)
|
---|
| 1168 | {int j=i;i=on->SensAdj[i];on=on->Adj[j];}
|
---|
| 1169 |
|
---|
| 1170 | inline Real4 qualite(const Vertex &va,const Vertex &vb,const Vertex &vc)
|
---|
| 1171 | {
|
---|
| 1172 | Real4 ret;
|
---|
| 1173 | I2 ia=va,ib=vb,ic=vc;
|
---|
| 1174 | I2 ab=ib-ia,bc=ic-ib,ac=ic-ia;
|
---|
| 1175 | Icoor2 deta=Det(ab,ac);
|
---|
| 1176 | if (deta <=0) ret = -1;
|
---|
| 1177 | else {
|
---|
| 1178 | Real8 a = sqrt((Real8) (ac,ac)),
|
---|
| 1179 | b = sqrt((Real8) (bc,bc)),
|
---|
| 1180 | c = sqrt((Real8) (ab,ab)),
|
---|
| 1181 | p = a+b+c;
|
---|
| 1182 | Real8 h= Max(Max(a,b),c),ro=deta/p;
|
---|
| 1183 | ret = ro/h;}
|
---|
| 1184 | return ret;
|
---|
| 1185 | }
|
---|
| 1186 |
|
---|
| 1187 |
|
---|
| 1188 | inline Triangle::Triangle(Triangles *Th,Int4 i,Int4 j,Int4 k) {
|
---|
| 1189 | Vertex *v=Th->vertices;
|
---|
| 1190 | Int4 nbv = Th->nbv;
|
---|
| 1191 | assert(i >=0 && j >=0 && k >=0);
|
---|
| 1192 | assert(i < nbv && j < nbv && k < nbv);
|
---|
| 1193 | ns[0]=v+i;
|
---|
| 1194 | ns[1]=v+j;
|
---|
| 1195 | ns[2]=v+k;
|
---|
| 1196 | at[0]=at[1]=at[2]=0;
|
---|
| 1197 | aa[0]=aa[1]=aa[2]=0;
|
---|
| 1198 | det=0;
|
---|
| 1199 | }
|
---|
| 1200 |
|
---|
| 1201 | inline Triangle::Triangle(Vertex *v0,Vertex *v1,Vertex *v2){
|
---|
| 1202 | ns[0]=v0;
|
---|
| 1203 | ns[1]=v1;
|
---|
| 1204 | ns[2]=v2;
|
---|
| 1205 | at[0]=at[1]=at[2]=0;
|
---|
| 1206 | aa[0]=aa[1]=aa[2]=0;
|
---|
| 1207 | if (v0) det=0;
|
---|
| 1208 | else {
|
---|
| 1209 | det=-1;
|
---|
| 1210 | link=NULL;};
|
---|
| 1211 | }
|
---|
| 1212 |
|
---|
| 1213 | inline Real4 Triangle::qualite()
|
---|
| 1214 | {
|
---|
| 1215 | return det < 0 ? -1 : bamg::qualite(*ns[0],*ns[1],*ns[2]);
|
---|
| 1216 | }
|
---|
| 1217 |
|
---|
| 1218 | Int4 inline Vertex::Optim(int i,int koption)
|
---|
| 1219 | {
|
---|
| 1220 | Int4 ret=0;
|
---|
| 1221 | if ( t && (vint >= 0 ) && (vint <3) )
|
---|
| 1222 | {
|
---|
| 1223 | ret = t->Optim(vint,koption);
|
---|
| 1224 | if(!i)
|
---|
| 1225 | {
|
---|
| 1226 | t =0; // for no future optime
|
---|
| 1227 | vint= 0; }
|
---|
| 1228 | }
|
---|
| 1229 | return ret;
|
---|
| 1230 | }
|
---|
| 1231 |
|
---|
| 1232 | Icoor2 inline det(const Vertex & a,const Vertex & b,const Vertex & c)
|
---|
| 1233 | {
|
---|
| 1234 | register Icoor2 bax = b.i.x - a.i.x ,bay = b.i.y - a.i.y;
|
---|
| 1235 | register Icoor2 cax = c.i.x - a.i.x ,cay = c.i.y - a.i.y;
|
---|
| 1236 | return bax*cay - bay*cax;}
|
---|
| 1237 |
|
---|
| 1238 |
|
---|
| 1239 | void swap(Triangle *t1,Int1 a1,
|
---|
| 1240 | Triangle *t2,Int1 a2,
|
---|
| 1241 | Vertex *s1,Vertex *s2,Icoor2 det1,Icoor2 det2);
|
---|
| 1242 |
|
---|
| 1243 |
|
---|
| 1244 |
|
---|
| 1245 | int inline TriangleAdjacent::swap()
|
---|
| 1246 | { return t->swap(a);}
|
---|
| 1247 |
|
---|
| 1248 |
|
---|
| 1249 |
|
---|
| 1250 | int SwapForForcingEdge(Vertex * & pva ,Vertex * & pvb ,
|
---|
| 1251 | TriangleAdjacent & tt1,Icoor2 & dets1,
|
---|
| 1252 | Icoor2 & detsa,Icoor2 & detsb, int & nbswap);
|
---|
| 1253 |
|
---|
| 1254 | int ForceEdge(Vertex &a, Vertex & b,TriangleAdjacent & taret) ;
|
---|
| 1255 |
|
---|
| 1256 | // inline bofbof FH
|
---|
| 1257 | inline TriangleAdjacent FindTriangleAdjacent(Edge &E)
|
---|
| 1258 | {
|
---|
| 1259 | Vertex * a = E.v[0];
|
---|
| 1260 | Vertex * b = E.v[1];
|
---|
| 1261 |
|
---|
| 1262 | Triangle * t = a->t;
|
---|
| 1263 | int i = a->vint;
|
---|
| 1264 | TriangleAdjacent ta(t,EdgesVertexTriangle[i][0]); // Previous edge
|
---|
| 1265 | assert(t && i>=0 && i < 3);
|
---|
| 1266 | assert( a == (*t)(i));
|
---|
| 1267 | int k=0;
|
---|
| 1268 | do { // turn around vertex in direct sens (trigo)
|
---|
| 1269 | k++;assert(k< 20000);
|
---|
| 1270 | // in no crack => ta.EdgeVertex(1) == a otherwise ???
|
---|
| 1271 | if (ta.EdgeVertex(1) == a && ta.EdgeVertex(0) == b) return ta; // find
|
---|
| 1272 | ta = ta.Adj();
|
---|
| 1273 | if (ta.EdgeVertex(0) == a && ta.EdgeVertex(1) == b) return ta; // find
|
---|
| 1274 | --ta;
|
---|
| 1275 | } while (t != (Triangle *)ta);
|
---|
| 1276 | assert(0);
|
---|
| 1277 | return TriangleAdjacent(0,0);// error
|
---|
| 1278 | }
|
---|
| 1279 |
|
---|
| 1280 | inline Vertex * TheVertex(Vertex * a) // give a unique vertex with smallest number
|
---|
| 1281 | { // in case on crack in mesh
|
---|
| 1282 | Vertex * r(a), *rr;
|
---|
| 1283 | Triangle * t = a->t;
|
---|
| 1284 | int i = a->vint;
|
---|
| 1285 | TriangleAdjacent ta(t,EdgesVertexTriangle[i][0]); // Previous edge
|
---|
| 1286 | assert(t && i>=0 && i < 3);
|
---|
| 1287 | assert( a == (*t)(i));
|
---|
| 1288 | int k=0;
|
---|
| 1289 | do { // turn around vertex in direct sens (trigo)
|
---|
| 1290 | k++;assert(k< 20000);
|
---|
| 1291 | // in no crack => ta.EdgeVertex(1) == a
|
---|
| 1292 | if ((rr=ta.EdgeVertex(0)) < r) r = rr;
|
---|
| 1293 | ta = ta.Adj();
|
---|
| 1294 | if ((rr=ta.EdgeVertex(1)) < r) r =rr;
|
---|
| 1295 | --ta;
|
---|
| 1296 | } while (t != (Triangle*) ta);
|
---|
| 1297 | return r;
|
---|
| 1298 | }
|
---|
| 1299 |
|
---|
| 1300 | inline double CPUtime(){
|
---|
| 1301 | #ifdef SYSTIMES
|
---|
| 1302 | struct tms buf;
|
---|
| 1303 | if (times(&buf)!=-1)
|
---|
| 1304 | return ((double)buf.tms_utime+(double)buf.tms_stime)/(long) sysconf(_SC_CLK_TCK);
|
---|
| 1305 | else
|
---|
| 1306 | #endif
|
---|
| 1307 | return ((double) clock())/CLOCKS_PER_SEC;
|
---|
| 1308 | }
|
---|
| 1309 |
|
---|
| 1310 | }
|
---|
| 1311 | #endif
|
---|