Changeset 3232
- Timestamp:
- 03/09/10 13:09:19 (15 years ago)
- Location:
- issm/trunk/src/c/Bamgx
- Files:
-
- 22 added
- 4 deleted
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/c/Bamgx/Bamgx.cpp
r3231 r3232 18 18 #include <string.h> 19 19 #include "Mesh2.h" 20 #include " QuadTree.h"20 #include "objects/QuadTree.h" 21 21 22 22 using namespace bamg; -
issm/trunk/src/c/Bamgx/Mesh2.h
r3231 r3232 8 8 9 9 #include "meshtype.h" 10 #include "Metric.h" 10 11 #include "objects/Metric.h" 12 #include "objects/DoubleAndInt4.h" 13 #include "objects/Direction.h" 14 #include "objects/Vertex.h" 15 #include "objects/TriangleAdjacent.h" 16 #include "objects/Edge.h" 17 #include "objects/GeometricalVertex.h" 18 #include "objects/GeometricalEdge.h" 19 #include "objects/Curve.h" 20 #include "objects/Triangle.h" 21 #include "objects/ListofIntersectionTriangles.h" 22 #include "objects/GeometricalSubDomain.h" 23 #include "objects/SubDomain.h" 24 #include "objects/VertexOnGeom.h" 25 #include "objects/VertexOnVertex.h" 26 #include "objects/VertexOnEdge.h" 27 #include "objects/CrackedEdge.h" 28 #include "objects/Triangles.h" 29 #include "objects/Geometry.h" 11 30 12 31 namespace bamg { 13 14 //classes15 class Geometry;16 class Triangles;17 class Triangle;18 class QuadTree;19 class GeometricalEdge;20 class VertexOnGeom;21 class VertexOnEdge;22 23 /*CLASS: DoubleAndInt4 {{{1*/24 class DoubleAndInt4 {25 //class used by Triangles::MakeQuadrangles26 27 public:28 double q;29 Int4 i3j;30 31 //Operators32 int operator<(DoubleAndInt4 a){return q > a.q;}33 };34 /*}}}1*/35 /*CLASS: Direction{{{1*/36 class Direction { //37 private:38 Icoor1 dir;39 40 public:41 //Methods42 Direction(): dir(MaxICoor){}; // no direction set43 Direction(Icoor1 i,Icoor1 j) {44 Icoor2 n2 = 2*(Abs(i)+Abs(j));45 Icoor2 r = MaxICoor* (Icoor2) i;46 Icoor1 r1 = (Icoor1) (2*(r/ n2)); // odd number47 dir = (j>0) ? r1 : r1+1; // odd-> j>0 even-> j<048 }49 int sens(Icoor1 i,Icoor1 j) {50 int r =1;51 if (dir!= MaxICoor) {52 Icoor2 x(dir/2),y1(MaxICoor/2-Abs(x)),y(dir%2?-y1:y1);53 r = (x*i + y*j) >=0;54 }55 return r;56 }57 };58 /*}}}1*/59 /*CLASS: Vertex{{{1*/60 class Vertex {61 62 public:63 I2 i; // integer coordinates64 R2 r; // real coordinates65 Metric m;66 Int4 ReferenceNumber;67 Direction DirOfSearch;68 Int1 vint; // the vertex number in triangle; varies between 0 and 2 in t69 union {70 Triangle* t; // one triangle which is containing the vertex71 Int4 color;72 Vertex* to; // use in geometry Vertex to now the Mesh Vertex associed73 VertexOnGeom* onGeometry; // if vint == 8; // set with Triangles::SetVertexFieldOn()74 Vertex* onBackgroundVertex; // if vint == 16 on Background vertex Triangles::SetVertexFieldOnBTh()75 VertexOnEdge* onBackgroundEdge; // if vint == 32 on Background edge76 };77 78 //Operators79 operator I2() const {return i;} // Cast operator80 operator const R2 & () const {return r;} // Cast operator81 operator Metric () const {return m;} // Cast operator82 Real8 operator()(R2 x) const { return m(x);} // Get x in the metric m83 84 //methods (No constructor and no destructors...)85 Int4 Optim(int =1,int =0);86 Real8 Smoothing(Triangles & ,const Triangles & ,Triangle * & ,Real8 =1);87 void MetricFromHessian(const double Hxx,const double Hyx, const double Hyy, const double smin,const double smax,const double s,const double err,BamgOpts* bamgopts);88 void Echo();89 int ref() const { return ReferenceNumber;}90 91 //inline functions92 inline void Set(const Vertex & rec,const Triangles &,Triangles &);93 };94 /*}}}1*/95 inline Vertex* TheVertex(Vertex * a); // for remove crak in mesh96 double QuadQuality(const Vertex &,const Vertex &,const Vertex &,const Vertex &);97 /*CLASS: TriangleAdjacent{{{1*/98 class TriangleAdjacent {99 100 public:101 Triangle* t; //pointer toward the triangle102 int a; //Edge number103 104 //Constructors105 TriangleAdjacent() {};106 TriangleAdjacent(Triangle * tt,int aa): t(tt),a(aa &3) {};107 108 //Operators109 operator Triangle * () const {return t;}110 operator Triangle & () const {return *t;}111 operator int() const {return a;}112 TriangleAdjacent & operator++(){ a= NextEdge[a]; return *this; }113 TriangleAdjacent operator--(){ a= PreviousEdge[a]; return *this; }114 115 //Methods116 int swap();117 118 //Inline methods119 inline TriangleAdjacent Adj() const ;120 inline void SetAdj2(const TriangleAdjacent& , int =0);121 inline Vertex * EdgeVertex(const int &) const ;122 inline Vertex * OppositeVertex() const ;123 inline Icoor2 & det() const;124 inline int Locked() const ;125 inline int GetAllFlag_UnSwap() const ;126 inline void SetLock();127 inline int MarkUnSwap() const;128 inline void SetMarkUnSwap();129 inline void SetCracked();130 inline int Cracked() const ;131 };132 /*}}}1*/133 /*CLASS: Edge{{{1*/134 class Edge {135 136 public:137 Vertex* v[2];138 Int4 ref;139 GeometricalEdge* onGeometry;140 Edge* adj[2]; // the 2 adj edges if on the same curve141 142 //Operators143 Vertex & operator[](int i){return *v[i];};144 Vertex * operator()(int i){return v[i];};145 R2 operator()(double t) const; // return the point146 const Vertex & operator[](int i) const { return *v[i];};147 148 //Methods149 void ReNumbering(Vertex *vb,Vertex *ve, Int4 *renu){150 if (v[0] >=vb && v[0] <ve) v[0] = vb + renu[v[0]-vb];151 if (v[1] >=vb && v[1] <ve) v[1] = vb + renu[v[1]-vb];152 }153 int Intersection(const Edge & e) const {154 if (!(adj[0]==&e || adj[1]==&e)){155 throw ErrorException(__FUNCT__,exprintf("Intersection bug"));156 }157 if (adj[0]!=&e && adj[1]!=&e){158 throw ErrorException(__FUNCT__,exprintf("adj[0]!=&e && adj[1]!=&e"));159 }160 return adj[0]==&e ? 0 : 1;161 }162 163 //Inline methods164 inline void Set(const Triangles &,Int4,Triangles &);165 166 };167 /*}}}1*/168 inline TriangleAdjacent FindTriangleAdjacent(Edge &E);169 /*CLASS: GeometricalVertex{{{1*/170 class GeometricalVertex : public Vertex {171 172 public:173 friend class Geometry;174 175 int cas;176 GeometricalVertex* link; // link all the same GeometricalVertex circular (Crack)177 178 //Methods179 int Corner() const {return cas&4;}180 int Required()const {return cas&6;}// a corner is required181 int IsThe() const { return link == this;}182 void SetCorner(){ cas |= 4;}183 void SetRequired(){ cas |= 2;}184 void Set(){cas=0;}185 GeometricalVertex() :cas(0), link(this) {};186 GeometricalVertex* The() {187 if (!link){ throw ErrorException(__FUNCT__,exprintf("!link"));}188 return link;189 }// return a unique vertex190 191 //Inline methods192 inline void Set(const GeometricalVertex & rec,const Geometry & Gh ,const Geometry & GhNew);193 };194 /*}}}1*/195 /*CLASS: GeometricalEdge{{{1*/196 class GeometricalEdge {197 198 public:199 GeometricalVertex* v[2];200 Int4 ref;201 Int4 CurveNumber;202 R2 tg[2]; // the 2 tangentes (tg[0] =0 => no continuity)203 GeometricalEdge* Adj[2];204 int DirAdj[2];205 int flag ;206 GeometricalEdge* link; // if Cracked() or Equi()207 208 //Operators209 GeometricalVertex & operator[](int i){return *v[i];};210 const GeometricalVertex & operator[](int i) const { return *v[i];};211 GeometricalVertex * operator()(int i){return v[i];};212 213 //Methods214 R2 F(Real8 theta) const ; // parametrization of the curve edge215 Real8 R1tg(Real8 theta,R2 &t) const ; // 1/radius of curvature + tangente216 int Cracked() const {return flag & 1;}217 int Dup() const { return flag & 32;}218 int Equi()const {return flag & 2;}219 int ReverseEqui()const {return flag & 128;}220 int TgA()const {return flag &4;}221 int TgB()const {return flag &8;}222 int Tg(int i) const{return i==0 ? TgA() : TgB();}223 int Mark()const {return flag &16;}224 int Required() { return flag & 64;}225 void SetCracked() { flag |= 1;}226 void SetDup() { flag |= 32;} // not a real edge227 void SetEqui() { flag |= 2;}228 void SetTgA() { flag|=4;}229 void SetTgB() { flag|=8;}230 void SetMark() { flag|=16;}231 void SetUnMark() { flag &= 1007 /* 1023-16*/;}232 void SetRequired() { flag |= 64;}233 void SetReverseEqui() {flag |= 128;}234 235 //Inline methods236 inline void Set(const GeometricalEdge & rec,const Geometry & Th ,Geometry & ThNew);237 };238 /*}}}1*/239 /*CLASS: Curve{{{1*/240 class Curve {241 public:242 GeometricalEdge * be,*ee; // begin et end edge243 int kb,ke; // begin vetex and end vertex244 Curve *next; // next curve equi to this245 bool master; // true => of equi curve point on this curve246 247 //Methods248 Curve() : be(0),ee(0),kb(0),ke(0),next(0),master(true) {}249 void Reverse() { Exchange(be,ee); Exchange(kb,ke);} // revese the sens of the curse250 251 //Inline methods252 inline void Set(const Curve & rec,const Geometry & Th ,Geometry & ThNew);253 };254 /*}}}1*/255 /*CLASS: Triangle{{{1*/256 class Triangle {257 258 friend class TriangleAdjacent;259 260 private:261 Vertex* TriaVertices[3]; // 3 vertices if t is triangle, t[i] allowed by access function, (*t)[i] if pointer262 Triangle* TriaAdjTriangles[3]; // 3 pointers toward the adjacent triangles263 Int1 TriaAdjSharedEdge[3]; // number of the edges in the adjacent triangles the edge number 1 is the edge number TriaAdjSharedEdge[1] in the Adjacent triangle 1264 265 public:266 Icoor2 det; // determinant du triangle (2 fois l aire des vertices entieres)267 union {268 Triangle * link ;269 Int4 color;270 };271 272 //Constructors/Destructors273 Triangle() {}274 Triangle(Triangles *Th,Int4 i,Int4 j,Int4 k);275 Triangle(Vertex *v0,Vertex *v1,Vertex *v2);276 277 //Operators278 const Vertex & operator[](int i) const {return *TriaVertices[i];};279 Vertex & operator[](int i) {return *TriaVertices[i];};280 const Vertex * operator()(int i) const {return TriaVertices[i];};281 Vertex * & operator()(int i) {return TriaVertices[i];};282 283 //Methods284 void Echo();285 int swap(Int2 a1,int=0);286 Int4 Optim(Int2 a,int =0);287 int Locked(int a)const { return TriaAdjSharedEdge[a]&4;}288 int Hidden(int a)const { return TriaAdjSharedEdge[a]&16;}289 int Cracked(int a) const { return TriaAdjSharedEdge[a] & 32;}290 int GetAllflag(int a){return TriaAdjSharedEdge[a] & 1020;}291 void SetAllFlag(int a,int f){TriaAdjSharedEdge[a] = (TriaAdjSharedEdge[a] &3) + (1020 & f);}292 double QualityQuad(int a,int option=1) const;293 Int1 NuEdgeTriangleAdj(int i) const {return TriaAdjSharedEdge[i&3]&3;} // Number of the adjacent edge in adj tria294 TriangleAdjacent FindBoundaryEdge(int i) const;295 TriangleAdjacent Adj(int i) const {return TriangleAdjacent(TriaAdjTriangles[i],TriaAdjSharedEdge[i]&3);};296 Triangle* TriangleAdj(int i) const {return TriaAdjTriangles[i&3];}297 Triangle* Quadrangle(Vertex * & v0,Vertex * & v1,Vertex * & v2,Vertex * & v3) const ;298 void ReNumbering(Triangle *tb,Triangle *te, Int4 *renu){299 if (link >=tb && link <te) link = tb + renu[link -tb];300 if (TriaAdjTriangles[0] >=tb && TriaAdjTriangles[0] <te) TriaAdjTriangles[0] = tb + renu[TriaAdjTriangles[0]-tb];301 if (TriaAdjTriangles[1] >=tb && TriaAdjTriangles[1] <te) TriaAdjTriangles[1] = tb + renu[TriaAdjTriangles[1]-tb];302 if (TriaAdjTriangles[2] >=tb && TriaAdjTriangles[2] <te) TriaAdjTriangles[2] = tb + renu[TriaAdjTriangles[2]-tb];303 }304 void ReNumbering(Vertex *vb,Vertex *ve, Int4 *renu){305 if (TriaVertices[0] >=vb && TriaVertices[0] <ve) TriaVertices[0] = vb + renu[TriaVertices[0]-vb];306 if (TriaVertices[1] >=vb && TriaVertices[1] <ve) TriaVertices[1] = vb + renu[TriaVertices[1]-vb];307 if (TriaVertices[2] >=vb && TriaVertices[2] <ve) TriaVertices[2] = vb + renu[TriaVertices[2]-vb];308 }309 void SetAdjAdj(Int1 a){310 a &= 3;311 register Triangle *tt=TriaAdjTriangles[a];312 TriaAdjSharedEdge [a] &= 55; // remove MarkUnSwap313 register Int1 aatt = TriaAdjSharedEdge[a] & 3;314 if(tt){315 tt->TriaAdjTriangles[aatt]=this;316 tt->TriaAdjSharedEdge[aatt]=a + (TriaAdjSharedEdge[a] & 60 ) ;}// Copy all the mark317 }318 void SetAdj2(Int1 a,Triangle *t,Int1 aat){319 TriaAdjTriangles[a]=t; //the adjacent triangle to the edge a is t320 TriaAdjSharedEdge[a]=aat; //position of the edge in the adjacent triangle321 if(t) { //if t!=NULL add adjacent triangle to t (this)322 t->TriaAdjTriangles[aat]=this;323 t->TriaAdjSharedEdge[aat]=a;324 }325 }326 void SetTriangleContainingTheVertex() {327 if (TriaVertices[0]) (TriaVertices[0]->t=this,TriaVertices[0]->vint=0);328 if (TriaVertices[1]) (TriaVertices[1]->t=this,TriaVertices[1]->vint=1);329 if (TriaVertices[2]) (TriaVertices[2]->t=this,TriaVertices[2]->vint=2);330 }331 void SetHidden(int a){332 //Get Adjacent Triangle number a333 register Triangle* t = TriaAdjTriangles[a];334 //if it exist335 //C|=D -> C=(C|D) bitwise inclusive OR336 if(t) t->TriaAdjSharedEdge[TriaAdjSharedEdge[a] & 3] |=16;337 TriaAdjSharedEdge[a] |= 16;338 }339 void SetCracked(int a){340 register Triangle * t = TriaAdjTriangles[a];341 if(t) t->TriaAdjSharedEdge[TriaAdjSharedEdge[a] & 3] |=32;342 TriaAdjSharedEdge[a] |= 32;343 }344 345 void SetLocked(int a){346 //mark the edge as on Boundary347 register Triangle * t = TriaAdjTriangles[a];348 t->TriaAdjSharedEdge[TriaAdjSharedEdge[a] & 3] |=4;349 TriaAdjSharedEdge[a] |= 4;350 }351 void SetMarkUnSwap(int a){352 register Triangle * t = TriaAdjTriangles[a];353 t->TriaAdjSharedEdge[TriaAdjSharedEdge[a] & 3] |=8;354 TriaAdjSharedEdge[a] |=8 ;355 }356 void SetUnMarkUnSwap(int a){357 register Triangle * t = TriaAdjTriangles[a];358 t->TriaAdjSharedEdge[TriaAdjSharedEdge[a] & 3] &=55; // 23 + 32359 TriaAdjSharedEdge[a] &=55 ;360 }361 void SetDet() {362 if(TriaVertices[0] && TriaVertices[1] && TriaVertices[2]) det = bamg::det(*TriaVertices[0],*TriaVertices[1],*TriaVertices[2]);363 else det = -1; }364 365 //Inline methods366 inline Real4 qualite() ;367 inline void Set(const Triangle &,const Triangles &,Triangles &);368 inline int In(Vertex *v) const { return TriaVertices[0]==v || TriaVertices[1]==v || TriaVertices[2]==v ;}369 370 371 }; // end of Triangle class372 /*}}}1*/373 /*CLASS: ListofIntersectionTriangles{{{1*/374 class ListofIntersectionTriangles {375 376 class IntersectionTriangles {377 public:378 Triangle* t;379 Real8 bary[3]; // use if t != 0380 R2 x;381 Metric m;382 Real8 s; // curvilinear coordinate383 Real8 sp;// length of the previous segment in m384 Real8 sn;// length of the next segment in m385 };386 387 class SegInterpolation {388 public:389 GeometricalEdge * e;390 Real8 sBegin,sEnd; // abscisse of the seg on edge parameter391 Real8 lBegin,lEnd; // length abscisse set in ListofIntersectionTriangles::Length392 int last;// last index in ListofIntersectionTriangles for this Sub seg of edge393 394 //Methods395 R2 F(Real8 s){396 Real8 c01=lEnd-lBegin, c0=(lEnd-s)/c01, c1=(s-lBegin)/c01;397 if (lBegin>s || s>lEnd){398 throw ErrorException(__FUNCT__,exprintf("lBegin>s || s>lEnd"));399 }400 return e->F(sBegin*c0+sEnd*c1);401 }402 };403 404 public:405 406 int MaxSize;407 int Size;408 Real8 len;409 int state;410 IntersectionTriangles * lIntTria;411 int NbSeg;412 int MaxNbSeg;413 SegInterpolation * lSegsI;414 415 //Constructors/Destructors416 ListofIntersectionTriangles(int n=256,int m=16)417 : MaxSize(n), Size(0), len(-1),state(-1),lIntTria(new IntersectionTriangles[n]) ,418 NbSeg(0), MaxNbSeg(m), lSegsI(new SegInterpolation[m]){419 long int verbosity=0;420 if (verbosity>9) printf(" construct ListofIntersectionTriangles %i %i\n",MaxSize,MaxNbSeg);421 };422 ~ListofIntersectionTriangles(){423 if (lIntTria) delete [] lIntTria,lIntTria=0;424 if (lSegsI) delete [] lSegsI,lSegsI=0;425 }426 427 //Operators428 IntersectionTriangles & operator[](int i) {return lIntTria[i];}429 operator int&() {return Size;}430 431 //Methods432 void init(){state=0;len=0;Size=0;}433 int NewItem(Triangle * tt,Real8 d0,Real8 d1,Real8 d2);434 int NewItem(R2,const Metric & );435 void SplitEdge(const Triangles & ,const R2 &,const R2 &,int nbegin=0);436 Real8 Length();437 Int4 NewPoints(Vertex *,Int4 & nbv,Int4 nbvx);438 void NewSubSeg(GeometricalEdge *e,Real8 s0,Real8 s1){439 long int verbosity=0;440 if (NbSeg>=MaxNbSeg) {441 int mneo= MaxNbSeg;442 MaxNbSeg *= 2;443 if (verbosity>3){444 printf(" reshape lSegsI from %i to %i\n",mneo,MaxNbSeg);445 }446 SegInterpolation * lEn = new SegInterpolation[MaxNbSeg];447 if (!lSegsI || NbSeg>=MaxNbSeg){448 throw ErrorException(__FUNCT__,exprintf("!lSegsI || NbSeg>=MaxNbSeg"));449 }450 for (int i=0;i< NbSeg;i++)451 lEn[i] = lSegsI[MaxNbSeg]; // copy old to new452 delete [] lSegsI; // remove old453 lSegsI = lEn;454 }455 if (NbSeg) lSegsI[NbSeg-1].last=Size;456 lSegsI[NbSeg].e=e;457 lSegsI[NbSeg].sBegin=s0;458 lSegsI[NbSeg].sEnd=s1;459 NbSeg++;460 }461 void ReShape(){462 register int newsize = MaxSize*2;463 IntersectionTriangles* nw = new IntersectionTriangles[newsize];464 if (!nw){ throw ErrorException(__FUNCT__,exprintf("!nw"));}465 // recopy466 for (int i=0;i<MaxSize;i++) nw[i] = lIntTria[i];467 long int verbosity=0;468 if(verbosity>3) printf(" ListofIntersectionTriangles ReShape Maxsize %i -> %i\n",MaxSize,MaxNbSeg);469 MaxSize = newsize;470 delete [] lIntTria;// remove old471 lIntTria = nw; // copy pointer472 }473 474 };475 /*}}}1*/476 /*CLASS: GeometricalSubDomain{{{1*/477 class GeometricalSubDomain {478 public:479 GeometricalEdge *edge;480 int sens; // -1 or 1481 Int4 ref;482 483 //Inline methods484 inline void Set(const GeometricalSubDomain &,const Geometry & ,const Geometry &);485 486 };487 /*}}}1*/488 /*CLASS: SubDomain{{{1*/489 class SubDomain {490 public:491 Triangle * head;492 Int4 ref;493 int sens; // -1 or 1494 Edge * edge; // to geometrical495 496 //Inline methods497 inline void Set(const Triangles &,Int4,Triangles &);498 };499 /*}}}1*/500 /*CLASS: VertexOnGeom{{{1*/501 class VertexOnGeom{502 503 public:504 505 Vertex* mv;506 Real8 abscisse;507 union{508 GeometricalVertex * gv; // if abscisse <0;509 GeometricalEdge * ge; // if abscisse in [0..1]510 };511 512 //Constructors/Destructors513 VertexOnGeom(): mv(0),abscisse(0){gv=0;}514 VertexOnGeom(Vertex & m,GeometricalVertex &g) : mv(&m),abscisse(-1){gv=&g;}515 VertexOnGeom(Vertex & m,GeometricalEdge &g,Real8 s) : mv(&m),abscisse(s){ge=&g;}516 517 //Operators518 operator Vertex * () const {return mv;}519 operator GeometricalVertex * () const {return gv;}520 operator GeometricalEdge * () const {return ge;}521 operator const Real8 & () const {return abscisse;}522 523 //Methods524 int OnGeomVertex()const {return this? abscisse <0 :0;}525 int OnGeomEdge() const {return this? abscisse >=0 :0;}526 int IsRequiredVertex(){ return this? (( abscisse<0 ? (gv?gv->Required():0):0 )) : 0;}527 void SetOn(){mv->onGeometry=this;mv->vint=IsVertexOnGeom;}528 529 //Inline methods530 inline void Set(const Triangles &,Int4,Triangles &);531 inline void Set(const VertexOnGeom&,const Triangles &,Triangles &);532 533 };534 /*}}}1*/535 /*CLASS: VertexOnVertex{{{1*/536 class VertexOnVertex {537 538 public:539 Vertex* v;540 Vertex* bv;541 542 //Constructors543 VertexOnVertex(Vertex * w,Vertex *bw) :v(w),bv(bw){}544 VertexOnVertex() {};545 546 //Methods547 void SetOnBTh(){v->onBackgroundVertex=bv;v->vint=IsVertexOnVertex;}548 549 //Inline methods550 inline void Set(const Triangles &,Int4,Triangles &);551 };552 /*}}}1*/553 /*CLASS: VertexOnEdge{{{1*/554 class VertexOnEdge {555 556 public:557 Vertex* v;558 Edge* be;559 Real8 abcisse;560 561 //Constructors562 VertexOnEdge( Vertex * w, Edge *bw,Real8 s) :v(w),be(bw),abcisse(s) {}563 VertexOnEdge(){}564 565 //Operators566 operator Real8 () const { return abcisse;}567 operator Vertex* () const { return v;}568 operator Edge* () const { return be;}569 Vertex & operator[](int i) const { return (*be)[i];}570 571 //Methods572 void SetOnBTh(){v->onBackgroundEdge=this;v->vint=IsVertexOnEdge;}573 574 //Inline methods575 inline void Set(const Triangles &,Int4,Triangles &);576 };577 /*}}}1*/578 /*CLASS: CrackedEdge{{{1*/579 class CrackedEdge {580 581 friend class Triangles;582 583 class CrackedTriangle {584 friend class Triangles;585 friend class CrackedEdge;586 Triangle* t; // edge of triangle t587 int i; // edge number of in triangle588 Edge *edge; // the 2 edge589 Vertex *New[2]; // new vertex number590 591 //Constructors592 CrackedTriangle() : t(0),i(0),edge(0) { New[0]=New[1]=0;}593 CrackedTriangle(Edge * a) : t(0),i(0),edge(a) { New[0]=New[1]=0;}594 595 //Methods596 void Crack(){597 Triangle & T(*t);598 int i0=VerticesOfTriangularEdge[i][0];599 int i1=VerticesOfTriangularEdge[i][0];600 if (!New[0] && !New[1]){601 throw ErrorException(__FUNCT__,exprintf("!New[0] && !New[1]"));602 }603 T(i0) = New[0];604 T(i1) = New[1];605 }606 void UnCrack(){607 Triangle & T(*t);608 int i0=VerticesOfTriangularEdge[i][0];609 int i1=VerticesOfTriangularEdge[i][0];610 if (!New[0] && !New[1]){611 throw ErrorException(__FUNCT__,exprintf("!New[0] && !New[1]"));612 }613 T(i0) = TheVertex(T(i0));614 T(i1) = TheVertex(T(i1));615 }616 void Set() {617 TriangleAdjacent ta ( FindTriangleAdjacent(*edge));618 t = ta;619 i = ta;620 621 New[0] = ta.EdgeVertex(0);622 New[1] = ta.EdgeVertex(1);623 // warning the ref624 }625 };626 627 public:628 CrackedTriangle a,b;629 630 //Constructors631 CrackedEdge() :a(),b() {}632 CrackedEdge(Edge * start, Int4 i,Int4 j) : a(start+i),b(start+j) {};633 CrackedEdge(Edge * e0, Edge * e1 ) : a(e0),b(e1) {};634 635 //Methods636 void Crack() { a.Crack(); b.Crack();}637 void UnCrack() { a.UnCrack(); b.UnCrack();}638 void Set() { a.Set(), b.Set();}639 };640 /*}}}1*/641 /*CLASS: Triangles{{{1*/642 class Triangles {643 public:644 645 Geometry & Gh; // Geometry646 Triangles & BTh; // Background Mesh Bth==*this =>no background647 Int4 NbRef; // counter of ref on the this class if 0 we can delete648 Int4 nbvx,nbtx; // nombre max de sommets , de triangles649 Int4 nt,nbv,nbt,nbiv,nbe; // nb of legal triangles, nb of vertex, of triangles, of initial vertices, of edges with reference,650 Int4 NbOfQuad; // nb of quadrangle651 Int4 NbSubDomains;652 Int4 NbOutT; // Nb of oudeside triangle653 Int4 NbOfTriangleSearchFind;654 Int4 NbOfSwapTriangle;655 Vertex* vertices;656 Int4 NbVerticesOnGeomVertex;657 VertexOnGeom * VerticesOnGeomVertex;658 Int4 NbVerticesOnGeomEdge;659 VertexOnGeom * VerticesOnGeomEdge;660 Int4 NbVertexOnBThVertex;661 VertexOnVertex *VertexOnBThVertex;662 Int4 NbVertexOnBThEdge;663 VertexOnEdge *VertexOnBThEdge;664 Int4 NbCrackedVertices;665 Int4 NbCrackedEdges;666 CrackedEdge *CrackedEdges;667 R2 pmin,pmax; // extrema668 Real8 coefIcoor; // coef to integer Icoor1;669 Triangle* triangles;670 Edge* edges;671 QuadTree *quadtree;672 Vertex** ordre;673 SubDomain* subdomains;674 ListofIntersectionTriangles lIntTria;675 676 //Constructors/Destructors677 Triangles(BamgMesh* bamgmesh,BamgOpts* bamgopts);678 Triangles(double* index,double* x,double* y,int nods,int nels);679 Triangles(Triangles &,Geometry * pGh=0,Triangles* pBTh=0,Int4 nbvxx=0 ); //copy operator680 Triangles(const Triangles &,const int *flag,const int *bb,BamgOpts* bamgopts); // truncature681 Triangles(Int4 nbvx,Triangles & BT,BamgOpts* bamgopts,int keepBackVertices=1) :Gh(BT.Gh),BTh(BT) {682 try {GeomToTriangles1(nbvx,bamgopts,keepBackVertices);}683 catch(...) { this->~Triangles(); throw; }684 }685 Triangles(Int4 nbvx,Geometry & G,BamgOpts* bamgopts) :Gh(G),BTh(*this){686 try { GeomToTriangles0(nbvx,bamgopts);}687 catch(...) { this->~Triangles(); throw; }688 }689 ~Triangles();690 691 //Operators692 const Vertex & operator[] (Int4 i) const { return vertices[i];};693 Vertex & operator[](Int4 i) { return vertices[i];};694 const Triangle & operator() (Int4 i) const { return triangles[i];};695 Triangle & operator()(Int4 i) { return triangles[i];};696 697 //Methods698 void SetIntCoor(const char * from =0);699 Real8 MinimalHmin() {return 2.0/coefIcoor;}700 Real8 MaximalHmax() {return Max(pmax.x-pmin.x,pmax.y-pmin.y);}701 I2 toI2(const R2 & P) const {702 return I2( (Icoor1) (coefIcoor*(P.x-pmin.x))703 ,(Icoor1) (coefIcoor*(P.y-pmin.y)) );}704 R2 toR2(const I2 & P) const {705 return R2( (double) P.x/coefIcoor+pmin.x, (double) P.y/coefIcoor+pmin.y);706 }707 void AddVertex(Vertex & s,Triangle * t,Icoor2 * =0) ;708 void Insert();709 void ForceBoundary();710 void Renumber(BamgOpts* bamgopts);711 void FindSubDomain(int OutSide=0);712 Int4 TriangleReferenceList(Int4 *) const;713 void ShowHistogram() const;714 void ShowRegulaty() const;715 void ReMakeTriangleContainingTheVertex();716 void UnMarkUnSwapTriangle();717 void SmoothMetric(Real8 raisonmax) ;718 void BoundAnisotropy(Real8 anisomax,double hminaniso= 1e-100) ;719 void MaxSubDivision(Real8 maxsubdiv);720 Edge** MakeGeometricalEdgeToEdge();721 void SetVertexFieldOn();722 void SetVertexFieldOnBTh();723 Int4 SplitInternalEdgeWithBorderVertices();724 void MakeQuadrangles(double costheta);725 int SplitElement(int choice);726 void MakeQuadTree();727 void NewPoints(Triangles &,BamgOpts* bamgopts,int KeepVertices=1);728 Int4 InsertNewPoints(Int4 nbvold,Int4 & NbTSwap) ;729 void ReNumberingTheTriangleBySubDomain(bool justcompress=false);730 void ReNumberingVertex(Int4 * renu);731 void SmoothingVertex(int =3,Real8=0.3);732 Metric MetricAt (const R2 &) const;733 GeometricalEdge* ProjectOnCurve( Edge & AB, Vertex & A, Vertex & B,Real8 theta, Vertex & R,VertexOnEdge & BR,VertexOnGeom & GR);734 Int4 Number(const Triangle & t) const { return &t - triangles;}735 Int4 Number(const Triangle * t) const { return t - triangles;}736 Int4 Number(const Vertex & t) const { return &t - vertices;}737 Int4 Number(const Vertex * t) const { return t - vertices;}738 Int4 Number(const Edge & t) const { return &t - edges;}739 Int4 Number(const Edge * t) const { return t - edges;}740 Int4 Number2(const Triangle * t) const {741 return t - triangles;742 }743 Vertex* NearestVertex(Icoor1 i,Icoor1 j) ;744 Triangle* FindTriangleContaining(const I2 & ,Icoor2 [3],Triangle *tstart=0) const;745 void ReadMesh(double* index,double* x,double* y,int nods,int nels);746 void ReadMesh(BamgMesh* bamgmesh, BamgOpts* bamgopts);747 void WriteMesh(BamgMesh* bamgmesh,BamgOpts* bamgopts);748 void ReadMetric(BamgOpts* bamgopts,const Real8 hmin,const Real8 hmax,const Real8 coef);749 void WriteMetric(BamgOpts* bamgopts);750 void AddMetric(BamgOpts* bamgopts);751 void BuildMetric0(BamgOpts* bamgopts);752 void BuildMetric1(BamgOpts* bamgopts);753 void AddGeometryMetric(BamgOpts* bamgopts);754 int isCracked() const {return NbCrackedVertices != 0;}755 int Crack();756 int UnCrack();757 void BuildGeometryFromMesh(BamgOpts* bamgopts=NULL);758 void GenerateMeshProperties() ;759 int CrackMesh();760 761 private:762 void GeomToTriangles1(Int4 nbvx,BamgOpts* bamgopts,int KeepVertices=1);// the real constructor mesh adaption763 void GeomToTriangles0(Int4 nbvx,BamgOpts* bamgopts);// the real constructor mesh generator764 void PreInit(Int4);765 766 };767 /*}}}1*/768 /*CLASS: Geometry{{{1*/769 class Geometry {770 771 public:772 Int4 NbRef; // counter of ref on the this class if 0 we can delete773 Int4 nbvx,nbtx; // maximum number of vertices774 Int4 nbv,nbt,nbiv,nbe; // number of vertices775 Int4 NbSubDomains; //776 Int4 NbOfCurves;777 GeometricalVertex* vertices;778 Triangle* triangles;779 GeometricalEdge* edges;780 QuadTree* quadtree;781 GeometricalSubDomain* subdomains;782 Curve* curves;783 R2 pmin,pmax; // extrema784 Real8 coefIcoor; // coef to integer Icoor1;785 Real8 MaximalAngleOfCorner;786 787 //Constructor/Destructors788 ~Geometry();789 Geometry(const Geometry & Gh); //Copy Operator790 Geometry(int nbg,const Geometry** ag); // intersection operator791 792 //Operators793 const GeometricalVertex & operator[] (Int4 i) const { return vertices[i];};794 GeometricalVertex & operator[](Int4 i) { return vertices[i];};795 const GeometricalEdge & operator() (Int4 i) const { return edges[i];};796 GeometricalEdge & operator()(Int4 i) { return edges[i];};797 798 //Methods799 int empty(){return (nbv ==0) && (nbt==0) && (nbe==0) && (NbSubDomains==0); }800 void Echo();801 I2 toI2(const R2 & P) const {802 return I2( (Icoor1) (coefIcoor*(P.x-pmin.x))803 ,(Icoor1) (coefIcoor*(P.y-pmin.y)) );}804 Real8 MinimalHmin() {return 2.0/coefIcoor;}805 Real8 MaximalHmax() {return Max(pmax.x-pmin.x,pmax.y-pmin.y);}806 void ReadGeometry(BamgGeom* bamggeom, BamgOpts* bamgopts);807 void EmptyGeometry();808 Geometry() {EmptyGeometry();}// empty Geometry809 void AfterRead();810 Geometry(BamgGeom* bamggeom, BamgOpts* bamgopts) {EmptyGeometry();ReadGeometry(bamggeom,bamgopts);AfterRead();}811 Int4 Number(const GeometricalVertex & t) const { return &t - vertices;}812 Int4 Number(const GeometricalVertex * t) const { return t - vertices;}813 Int4 Number(const GeometricalEdge & t) const { return &t - edges;}814 Int4 Number(const GeometricalEdge * t) const { return t - edges;}815 Int4 Number(const Curve * c) const { return c - curves;}816 void UnMarkEdges() {for (Int4 i=0;i<nbe;i++) edges[i].SetUnMark();}817 GeometricalEdge * ProjectOnCurve(const Edge & ,Real8,Vertex &,VertexOnGeom &) const ;818 GeometricalEdge * Contening(const R2 P, GeometricalEdge * start) const;819 void WriteGeometry(BamgGeom* bamggeom, BamgOpts* bamgopts);820 };821 /*}}}1*/822 32 823 33 /*INLINE functions{{{1*/ … … 980 190 /*}}}1*/ 981 191 982 /*INLINE functions of CLASS Vertex{{{1*/983 inline void Vertex::Set(const Vertex & rec,const Triangles & ,Triangles & ){984 *this = rec;985 }986 Int4 inline Vertex::Optim(int i,int koption){987 Int4 ret=0;988 if ( t && (vint >= 0 ) && (vint <3) )989 {990 ret = t->Optim(vint,koption);991 if(!i)992 {993 t =0; // for no future optime994 vint= 0; }995 }996 return ret;997 }998 /*}}}1*/999 192 /*INLINE functions of CLASS GeometricalVertex{{{1*/ 1000 193 inline void GeometricalVertex::Set(const GeometricalVertex & rec,const Geometry & ,const Geometry & ){ … … 1189 382 } 1190 383 /*}}}1*/ 384 /*INLINE functions of CLASS Vertex{{{1*/ 385 Int4 inline Vertex::Optim(int i,int koption){ 386 Int4 ret=0; 387 if ( t && (vint >= 0 ) && (vint <3) ){ 388 ret = t->Optim(vint,koption); 389 if(!i){ 390 t =0; // for no future optime 391 vint= 0; 392 } 393 } 394 return ret; 395 } 396 inline void Vertex::Set(const Vertex & rec,const Triangles & ,Triangles & ){ 397 *this = rec; 398 } 399 /*}}}1*/ 1191 400 /*INLINE functions of CLASS VertexOnEdge{{{1*/ 1192 401 inline void VertexOnEdge::Set(const Triangles & Th ,Int4 i,Triangles & ThNew) -
issm/trunk/src/c/Bamgx/meshtype.h
r3230 r3232 2 2 #define MESHTYPE_H 3 3 4 #include "R2.h" 4 #include "objects/R2.h" 5 #include <cstdio> 6 #include <cstdlib> 7 #include <cstring> 8 #include <cmath> 9 #include <ctime> 5 10 6 11 namespace bamg { -
issm/trunk/src/c/Bamgx/objects/GeometricalEdge.cpp
r2865 r3232 4 4 #include <time.h> 5 5 6 #include "../Mesh2.h" 7 #include "../QuadTree.h" 8 #include "../SetOfE4.h" 9 10 #include "../../shared/shared.h" 11 #include "../../include/macros.h" 12 #include "../../toolkits/toolkits.h" 6 #include "GeometricalEdge.h" 13 7 14 8 #undef __FUNCT__ -
issm/trunk/src/c/Bamgx/objects/Geometry.cpp
r3217 r3232 5 5 6 6 #include "../Mesh2.h" 7 #include "../QuadTree.h"8 #include "../SetOfE4.h"9 10 #include "../../shared/shared.h"11 #include "../../include/macros.h"12 #include "../../toolkits/toolkits.h"13 7 14 8 #undef __FUNCT__ -
issm/trunk/src/c/Bamgx/objects/ListofIntersectionTriangles.cpp
r3165 r3232 5 5 6 6 #include "../Mesh2.h" 7 #include "../QuadTree.h"8 #include "../SetOfE4.h"9 10 #include "../../shared/shared.h"11 #include "../../include/macros.h"12 #include "../../toolkits/toolkits.h"13 7 14 8 #undef __FUNCT__ -
issm/trunk/src/c/Bamgx/objects/MatVVP2x2.cpp
r2981 r3232 4 4 #include <ctime> 5 5 6 #include "../Mesh2.h" 7 #include "../QuadTree.h" 8 #include "../SetOfE4.h" 9 10 #include "../../shared/shared.h" 11 #include "../../include/macros.h" 12 #include "../../toolkits/toolkits.h" 6 #include "Metric.h" 13 7 14 8 #undef __FUNCT__ -
issm/trunk/src/c/Bamgx/objects/Metric.cpp
r3138 r3232 4 4 #include <time.h> 5 5 6 #include "../Mesh2.h" 7 #include "../QuadTree.h" 8 #include "../SetOfE4.h" 9 10 #include "../../shared/shared.h" 11 #include "../../include/macros.h" 12 #include "../../toolkits/toolkits.h" 6 #include "Metric.h" 13 7 14 8 #undef __FUNCT__ -
issm/trunk/src/c/Bamgx/objects/QuadTree.cpp
r2980 r3232 3 3 #include <stdlib.h> 4 4 5 //#include "QuadTree.h" 5 6 #include "../Mesh2.h" 6 #include "../QuadTree.h"7 8 #include "../../shared/shared.h"9 #include "../../include/macros.h"10 #include "../../toolkits/toolkits.h"11 7 12 8 #undef __FUNCT__ -
issm/trunk/src/c/Bamgx/objects/SetOfE4.cpp
r2958 r3232 1 #include "../../shared/shared.h" 2 #include "../../include/macros.h" 3 #include "../../toolkits/toolkits.h" 4 #include "../meshtype.h" 5 #include "../SetOfE4.h" 1 2 #include "../Mesh2.h" 6 3 7 4 #undef __FUNCT__ -
issm/trunk/src/c/Bamgx/objects/Triangle.cpp
r3148 r3232 5 5 6 6 #include "../Mesh2.h" 7 #include "../QuadTree.h"8 #include "../SetOfE4.h"9 10 #include "../../shared/shared.h"11 #include "../../include/macros.h"12 #include "../../toolkits/toolkits.h"13 7 14 8 #undef __FUNCT__ -
issm/trunk/src/c/Bamgx/objects/Triangles.cpp
r3231 r3232 5 5 6 6 #include "../Mesh2.h" 7 #include "../QuadTree.h" 8 #include "../SetOfE4.h" 9 10 #include "../../shared/shared.h" 11 #include "../../include/macros.h" 12 #include "../../toolkits/toolkits.h" 7 #include "QuadTree.h" 8 #include "SetOfE4.h" 13 9 14 10 #undef __FUNCT__ -
issm/trunk/src/c/Bamgx/objects/Vertex.cpp
r3230 r3232 5 5 6 6 #include "../Mesh2.h" 7 #include "../QuadTree.h"8 #include "../SetOfE4.h"9 10 #include "../../shared/shared.h"11 #include "../../include/macros.h"12 #include "../../toolkits/toolkits.h"13 7 14 8 #undef __FUNCT__
Note:
See TracChangeset
for help on using the changeset viewer.