Overture  Version 25
Face.h
Go to the documentation of this file.
1 #ifndef __KKC_FACE__
2 #define __KKC_FACE__
3 
4 #include "ArraySimple.h"
5 
6 //
7 // Face is a small helper class used by the Advancing Front mesh generator.
8 // Its purpose is to make the bookkeeping of newly generated faces and elements
9 // a little easier to perform and read.
10 //
11 
12 class Face
13 {
14 public:
15  //inline Face(const IntegerArray &vertices_, int z1_, int z2_, int id_)
16  inline Face(const ArraySimple<int> &vertices_, int z1_, int z2_, int id_)
17  {
18  vertices[0] = vertices[1] = vertices[2] = vertices[3] = -1;
19 
20  nVerts = vertices_.size(0);
21 
22  // should check to make sure nVerts<=4 ?
23  for ( int v=0; v<nVerts; v++ )
24  vertices[v] = vertices_[v];
25 
26  z1 = z1_;
27  z2 = z2_;
28  id = id_;
29  }
30 
31  inline Face(const ArraySimpleFixed<int,3,1,1,1> &vertices_, int z1_, int z2_, int id_)
32  {
33  vertices[0] = vertices[1] = vertices[2] = vertices[3] = -1;
34 
35  nVerts = 3;
36 
37  // should check to make sure nVerts<=4 ?
38  for ( int v=0; v<nVerts; v++ )
39  vertices[v] = vertices_[v];
40 
41  z1 = z1_;
42  z2 = z2_;
43  id = id_;
44  }
45 
46  inline virtual ~Face() { }
47  inline int getID() const { return id; }
48  inline int getVertex(const int &v) const { return vertices[v]; }
49  inline int getZ1ID() const { return z1; }
50  inline int getZ2ID() const { return z2; }
51  inline int getNumberOfVertices() const { return nVerts; }
52  inline void setZ1ID( const int &z ) { z1 = z; }
53  inline void setZ2ID( const int &z ) { z2 = z; }
54  inline void setVertex( int v, int vid ) { vertices[v]=vid; }
55 
56  inline void reverseVertices()
57  {
58  int vold[4];
59  int v;
60  for ( v=0; v<nVerts; v++ ) vold[v] = vertices[v];
61 
62  for ( v=0; v<nVerts; v++ ) vertices[v] = vold[nVerts-v-1];
63  }
64 
65 protected:
66  Face() { }
67  int nVerts;
68  int id;
69  int vertices[4];
70  int z1;
71  int z2;
72 };
73 
74 inline bool faceVerticesAreSame( const Face & face1, const Face & face2 )
75 {
76  // this function checks to see if two faces are the same by examining the vertex lists
77  // two faces are considered identicle if they both have the same vertices.
78  // the ordering of the vertices can be the same as or the reverse of each other.
79 
80  // first make sure the two faces have the same number of vertices
81  bool result = face1.getNumberOfVertices() == face2.getNumberOfVertices();
82 
83  // if the number of vertices are the same, check the id's of each vertex
84  if (result)
85  {
86  int nVertices = face1.getNumberOfVertices();
87  int minVID1 = face1.getVertex(0);
88  int minVIDX1 = 0;
89  int minVID2 = face2.getVertex(0);
90  int minVIDX2 = 0;
91  // first find the starting point for each vertex
92  // the starting point is the lowest value of a vertex id in a face
93  for ( int v=1; v<nVertices; v++ )
94  {
95  if (face1.getVertex(v)<minVID1)
96  {
97  minVID1 = face1.getVertex(v);
98  minVIDX1 = v;
99  }
100 
101  if (face2.getVertex(v)<minVID2)
102  {
103  minVID2 = face2.getVertex(v);
104  minVIDX2 = v;
105  }
106  }
107 
108  result = minVID1 == minVID2;
109  // if the starting vertices are not the same then the faces cannot be identicle
110  if (result)
111  {
112  // the starting vertices are the same and we now need to compare them
113  // check in the order given in each of the faces
114  for (int v=0; v<nVertices && result ; v++)
115  {
116  int if1 = (minVIDX1 + v)%nVertices;
117  int if2 = (minVIDX2 + v)%nVertices;
118  result = face1.getVertex(if1)==face2.getVertex(if2);
119  }
120  // if the check failed with the current ordering of each face, check with face2's ordering reversed
121  if (!result)
122  {
123  result = true;
124  for (int v=0; v<nVertices ; v++ )//&& result ; v++)
125  {
126  int if1 = (minVIDX1 + v)%nVertices;
127  int if2 = (nVertices+minVIDX2 - v)%nVertices;
128  result = result && face1.getVertex(if1)==face2.getVertex(if2);
129  //result = face1.getVertex(if1)==face2.getVertex(if2);
130  }
131  }
132  }
133  }
134 
135  return result;
136 }
137 
138 
139 #endif