next up previous contents
Next: Contruction du tableau Up: LEÇON Les classes Triangulation Previous: Protection contre les dépassements

Deuxième amélioration

La classe triangulation devient

const nbholesmax=100;
class Vertex;
class Triangle;
class Edge;

/***************************************************/
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(){nt=nv=ne=0;nbholes=nbholesmax;}// default constructor
Grid(const char *path );     // reads a triangulation
void save(const char* path) const; //save mesh in Gfem format
int no(Triangle* tt) const { return t.no(tt);}
int no(Vertex* tt) const { return v.no(tt);}
int no(Edge* tt) const { return e.no(tt);}//place in e of  tt
};

Grid::Grid(const char *path ):v(),t(),e()
{// reads a triangulation in MacGfem format
  int i,j, ii;
  float x,y;
  ifstream file(path);

  assert(!file.fail());
  file >> nv >> nt;
  nbholes =nbholesmax;  // not in macgfem format
  v.init(nv);
  t.init(nt);
  e.init(nv+nt+nbholes-1);
  for( i=0; i<nv; i++ ) 
  	file >> v[i].x >> v[i].y >> v[i].where;
  for( i=0; i<nt; i++ ) 
  {
    for(j=0;j<3;j++){ file >> ii; t[i].v[j] = &v[ii-1];}
    file >> t[i].where;
    t[i].area = ((t[i].v[1]->x - t[i].v[0]->x) 
                  * (t[i].v[2]->y - t[i].v[0]->y)
                  - (t[i].v[2]->x - t[i].v[0]->x) 
                  * (t[i].v[1]->y - t[i].v[0]->y))/2;
  }
  file.close();
}

//---------------------------------------------------------
void Grid::save(const char *path ) const
{// write a triangulation in MacGfem format
  int i,j=0;
  ofstream file(path);

  file << nv <<"	"<< nt<<endl;
  for( i=0; i<nv; i++ ) 
  	file << v[i].x <<"	"<< v[i].y <<"	"<< v[i].where<<endl;
  for( i=0; i<nt; i++ ) 
	file << no(t[i].v[0])+1 <<"	"<< no(t[i].v[1])+1 
	<<"	"<< no(t[i].v[2])+1<<"	"<< j<<endl;
  file.close();
}



Pironneau Olivier
Jeudi 12 mars 1998 16:24:39