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

Last change on this file since 3391 was 3391, checked in by Eric.Larour, 15 years ago

Renamed Vertex to BamgVertex, to avoid conflicts with ISSM Vertex object in Makefile.am

File size: 5.1 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 "BamgVertex.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 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
102 void SetLocked(int a){
103 //mark the edge as on Boundary
104 register Triangle * t = TriaAdjTriangles[a];
105 t->TriaAdjSharedEdge[TriaAdjSharedEdge[a] & 3] |=4;
106 TriaAdjSharedEdge[a] |= 4;
107 }
108 void SetMarkUnSwap(int a){
109 register Triangle * t = TriaAdjTriangles[a];
110 t->TriaAdjSharedEdge[TriaAdjSharedEdge[a] & 3] |=8;
111 TriaAdjSharedEdge[a] |=8 ;
112 }
113 void SetUnMarkUnSwap(int a){
114 register Triangle * t = TriaAdjTriangles[a];
115 t->TriaAdjSharedEdge[TriaAdjSharedEdge[a] & 3] &=55; // 23 + 32
116 TriaAdjSharedEdge[a] &=55 ;
117 }
118 void SetDet() {
119 if(TriaVertices[0] && TriaVertices[1] && TriaVertices[2]) det = bamg::det(*TriaVertices[0],*TriaVertices[1],*TriaVertices[2]);
120 else det = -1; }
121
122 //Inline methods
123 double qualite() ;
124 void Set(const Triangle &,const Triangles &,Triangles &);
125 int In(Vertex *v) const { return TriaVertices[0]==v || TriaVertices[1]==v || TriaVertices[2]==v ;}
126
127 };
128
129}
130#endif
Note: See TracBrowser for help on using the repository browser.