source: issm/trunk/src/c/Bamgx/objects/Triangle.h@ 3263

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

Big reorg

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