La classe triangulation devient la classe Grid ci-dessous. On a remplacé Vertex* par A<Vertex> et de même pour Triangle*.
Par ailleurs la classe est enrichie de
class Vertex;
class Triangle;
class Edge;
class Grid;
/***************************************************/
class Vertex {
public:
float x, y; // cordinates
int where; // on which boundary
int nsupp; // nb of triangles which contains this vertex
A<Triangle*> supp; // all triangles which contain the vertex
int nmate; // number of neighbor vertices
A<Vertex*> mate; // all neighbors
};
/***************************************************/
class Triangle {
public:
Vertex* v[3]; // the 3 vertices of the triangle
Edge* e[3]; // pointer to the edges opposite each vertex
int where; // in which region
float area;
};
/***************************************************/
class Edge { public:
Vertex *in, *out; // oriented by first to last vertex
Triangle *left, *right;// triangles on each side of edge
int where; // on which curve (or boundary)
float length;
};
/***************************************************/
class Grid {
public:
int nt, nv, ne; // nb of triangles, vertices and edges
int nbholes; // nb of holes in the domain
int bdth; // bandwidth
A<Vertex> v; // all vertices
A<Triangle> t; // all triangles
A<Edge> e; // all edges
Grid(const char *path ); // reads a triangulation
void square(int nx, int ny); // triangulate a square
void save(const char* path); // save the mesh in Gfem format
};
L'implémentation des 2 fonctions se trouve dans le fichier grid.cpp
//---------------------------------------------------------
Grid::Grid(const char *path )
{// reads a triangulation in Gfem format
int i,ii[3],j;
ifstream file(path);
assert(!file.fail());
file >> nv >> nt;
v.init(nv);
t.init(nt);
for( i=0; i<nv; i++ )
file >> v[i].x >> v[i].y >> v[i].where;
for( i=0; i<nt; i++ )
{
file >> ii[0] >> ii[1] >> ii[2] >> t[i].where;
for(j=0;j<3;j++) t[i].v[j] = &v[ii[j]-1];
}
nbholes =100; // not in macgfem format
file.close();
}
//---------------------------------------------------------
void Grid::save(const char *path )
{// write a triangulation in MacGfem format
int i,junk=0;
ofstream file(path);
file << nv <<'\t'<< nt<<endl;
for( i=0; i<nv; i++ )
file << v[i].x <<'\t'<< v[i].y <<'\t'<< v[i].where << endl;
for( i=0; i<nt; i++ )
file << no(&t[i].v[0])+1 <<'\t'<< no(&t[i].v[1])+1 <<'\t'
<< no(&t[i].v[2])+1<<'\t'<< junk<<endl;
file.close();
}