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

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

some reorganization in BAMG

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