[3913] | 1 | #ifndef _TRIANGLE_H_
|
---|
| 2 | #define _TRIANGLE_H_
|
---|
| 3 |
|
---|
| 4 | #include "./include.h"
|
---|
| 5 | #include "TriangleAdjacent.h"
|
---|
| 6 |
|
---|
| 7 | namespace bamg {
|
---|
| 8 |
|
---|
| 9 | //classes
|
---|
[5095] | 10 | class Mesh;
|
---|
[5120] | 11 | class BamgVertex;
|
---|
[3913] | 12 | class Triangle;
|
---|
| 13 |
|
---|
| 14 | class Triangle {
|
---|
| 15 |
|
---|
| 16 | friend class TriangleAdjacent;
|
---|
| 17 |
|
---|
| 18 | private:
|
---|
[5120] | 19 | BamgVertex* TriaVertices[3]; // 3 vertices if t is triangle, t[i] allowed by access function, (*t)[i] if pointer
|
---|
[3913] | 20 | Triangle* TriaAdjTriangles[3]; // 3 pointers toward the adjacent triangles
|
---|
| 21 | short TriaAdjSharedEdge[3]; // number of the edges in the adjacent triangles the edge number 1 is the edge number TriaAdjSharedEdge[1] in the Adjacent triangle 1
|
---|
| 22 |
|
---|
| 23 | public:
|
---|
| 24 | Icoor2 det; // determinant du triangle (2 fois l aire des vertices entieres)
|
---|
| 25 | union {
|
---|
| 26 | Triangle * link ;
|
---|
| 27 | long color;
|
---|
| 28 | };
|
---|
| 29 |
|
---|
| 30 | //Constructors/Destructors
|
---|
| 31 | Triangle() {}
|
---|
[5095] | 32 | Triangle(Mesh *Th,long i,long j,long k);
|
---|
[5120] | 33 | Triangle(BamgVertex *v0,BamgVertex *v1,BamgVertex *v2);
|
---|
[3913] | 34 |
|
---|
| 35 | //Operators
|
---|
[5120] | 36 | const BamgVertex & operator[](int i) const {return *TriaVertices[i];};
|
---|
| 37 | BamgVertex & operator[](int i) {return *TriaVertices[i];};
|
---|
| 38 | const BamgVertex * operator()(int i) const {return TriaVertices[i];};
|
---|
| 39 | BamgVertex * & operator()(int i) {return TriaVertices[i];};
|
---|
[3913] | 40 |
|
---|
| 41 | //Methods
|
---|
| 42 | void Echo();
|
---|
| 43 | int swap(short a1,int=0);
|
---|
| 44 | long Optim(short a,int =0);
|
---|
| 45 | int Locked(int a)const { return TriaAdjSharedEdge[a]&4;}
|
---|
| 46 | int Hidden(int a)const { return TriaAdjSharedEdge[a]&16;}
|
---|
| 47 | int GetAllflag(int a){return TriaAdjSharedEdge[a] & 1020;}
|
---|
| 48 | void SetAllFlag(int a,int f){TriaAdjSharedEdge[a] = (TriaAdjSharedEdge[a] &3) + (1020 & f);}
|
---|
| 49 | double QualityQuad(int a,int option=1) const;
|
---|
| 50 | short NuEdgeTriangleAdj(int i) const {return TriaAdjSharedEdge[i&3]&3;} // Number of the adjacent edge in adj tria
|
---|
| 51 | TriangleAdjacent FindBoundaryEdge(int i) const;
|
---|
| 52 | TriangleAdjacent Adj(int i) const {return TriangleAdjacent(TriaAdjTriangles[i],TriaAdjSharedEdge[i]&3);};
|
---|
| 53 | Triangle* TriangleAdj(int i) const {return TriaAdjTriangles[i&3];}
|
---|
[5120] | 54 | Triangle* Quadrangle(BamgVertex * & v0,BamgVertex * & v1,BamgVertex * & v2,BamgVertex * & v3) const ;
|
---|
[3913] | 55 | void ReNumbering(Triangle *tb,Triangle *te, long *renu){
|
---|
| 56 | if (link >=tb && link <te) link = tb + renu[link -tb];
|
---|
| 57 | if (TriaAdjTriangles[0] >=tb && TriaAdjTriangles[0] <te) TriaAdjTriangles[0] = tb + renu[TriaAdjTriangles[0]-tb];
|
---|
| 58 | if (TriaAdjTriangles[1] >=tb && TriaAdjTriangles[1] <te) TriaAdjTriangles[1] = tb + renu[TriaAdjTriangles[1]-tb];
|
---|
| 59 | if (TriaAdjTriangles[2] >=tb && TriaAdjTriangles[2] <te) TriaAdjTriangles[2] = tb + renu[TriaAdjTriangles[2]-tb];
|
---|
| 60 | }
|
---|
[5120] | 61 | void ReNumbering(BamgVertex *vb,BamgVertex *ve, long *renu){
|
---|
[3913] | 62 | if (TriaVertices[0] >=vb && TriaVertices[0] <ve) TriaVertices[0] = vb + renu[TriaVertices[0]-vb];
|
---|
| 63 | if (TriaVertices[1] >=vb && TriaVertices[1] <ve) TriaVertices[1] = vb + renu[TriaVertices[1]-vb];
|
---|
| 64 | if (TriaVertices[2] >=vb && TriaVertices[2] <ve) TriaVertices[2] = vb + renu[TriaVertices[2]-vb];
|
---|
| 65 | }
|
---|
| 66 | void SetAdjAdj(short a){
|
---|
| 67 | a &= 3;
|
---|
| 68 | register Triangle *tt=TriaAdjTriangles[a];
|
---|
| 69 | TriaAdjSharedEdge [a] &= 55; // remove MarkUnSwap
|
---|
| 70 | register short aatt = TriaAdjSharedEdge[a] & 3;
|
---|
| 71 | if(tt){
|
---|
| 72 | tt->TriaAdjTriangles[aatt]=this;
|
---|
| 73 | tt->TriaAdjSharedEdge[aatt]=a + (TriaAdjSharedEdge[a] & 60 ) ;}// Copy all the mark
|
---|
| 74 | }
|
---|
| 75 | void SetAdj2(short a,Triangle *t,short aat){
|
---|
| 76 | TriaAdjTriangles[a]=t; //the adjacent triangle to the edge a is t
|
---|
| 77 | TriaAdjSharedEdge[a]=aat; //position of the edge in the adjacent triangle
|
---|
| 78 | if(t) { //if t!=NULL add adjacent triangle to t (this)
|
---|
| 79 | t->TriaAdjTriangles[aat]=this;
|
---|
| 80 | t->TriaAdjSharedEdge[aat]=a;
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 | void SetTriangleContainingTheVertex() {
|
---|
| 84 | if (TriaVertices[0]) (TriaVertices[0]->t=this,TriaVertices[0]->vint=0);
|
---|
| 85 | if (TriaVertices[1]) (TriaVertices[1]->t=this,TriaVertices[1]->vint=1);
|
---|
| 86 | if (TriaVertices[2]) (TriaVertices[2]->t=this,TriaVertices[2]->vint=2);
|
---|
| 87 | }
|
---|
| 88 | void SetHidden(int a){
|
---|
| 89 | //Get Adjacent Triangle number a
|
---|
| 90 | register Triangle* t = TriaAdjTriangles[a];
|
---|
| 91 | //if it exist
|
---|
| 92 | //C|=D -> C=(C|D) bitwise inclusive OR
|
---|
| 93 | if(t) t->TriaAdjSharedEdge[TriaAdjSharedEdge[a] & 3] |=16;
|
---|
| 94 | TriaAdjSharedEdge[a] |= 16;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | void SetLocked(int a){
|
---|
| 98 | //mark the edge as on Boundary
|
---|
| 99 | register Triangle * t = TriaAdjTriangles[a];
|
---|
| 100 | t->TriaAdjSharedEdge[TriaAdjSharedEdge[a] & 3] |=4;
|
---|
| 101 | TriaAdjSharedEdge[a] |= 4;
|
---|
| 102 | }
|
---|
| 103 | void SetMarkUnSwap(int a){
|
---|
| 104 | register Triangle * t = TriaAdjTriangles[a];
|
---|
| 105 | t->TriaAdjSharedEdge[TriaAdjSharedEdge[a] & 3] |=8;
|
---|
| 106 | TriaAdjSharedEdge[a] |=8 ;
|
---|
| 107 | }
|
---|
| 108 | void SetUnMarkUnSwap(int a){
|
---|
| 109 | register Triangle * t = TriaAdjTriangles[a];
|
---|
| 110 | t->TriaAdjSharedEdge[TriaAdjSharedEdge[a] & 3] &=55; // 23 + 32
|
---|
| 111 | TriaAdjSharedEdge[a] &=55 ;
|
---|
| 112 | }
|
---|
| 113 | void SetDet() {
|
---|
| 114 | if(TriaVertices[0] && TriaVertices[1] && TriaVertices[2]) det = bamg::det(*TriaVertices[0],*TriaVertices[1],*TriaVertices[2]);
|
---|
| 115 | else det = -1; }
|
---|
| 116 |
|
---|
| 117 | //Inline methods
|
---|
| 118 | double qualite() ;
|
---|
[5095] | 119 | void Set(const Triangle &,const Mesh &,Mesh &);
|
---|
[5120] | 120 | int In(BamgVertex *v) const { return TriaVertices[0]==v || TriaVertices[1]==v || TriaVertices[2]==v ;}
|
---|
[3913] | 121 |
|
---|
| 122 | };
|
---|
| 123 |
|
---|
| 124 | }
|
---|
| 125 | #endif
|
---|