Building a Mesh

To build a triangular mesh use handle operators. Below there is a simple algorithm building a tetrahedron.

int i, j;
bool is_manifold;

/*first create point references*/
Point* p[4];
p[0] = new Point(vec3(0,0,0), vec3(0,0,0), 0);
p[1] = new Point(vec3(1,0,0), vec3(0,0,0), 1);
p[2] = new Point(vec3(0,1,0), vec3(0,0,0), 2);
p[3] = new Point(vec3(0,0,1), vec3(0,0,0), 3);

/*next, create an empty surface*/
Surf *s = new Surf();

/*now attach the faces to the surface. */
Face* f[4];
f[0] = s->create(p[0], p[2], p[1]);
f[1] = s->create(p[0], p[2], p[3]);
f[2] = s->create(p[1], p[2], p[3]);
f[3] = s->create(p[0], p[3], p[2]);

/*in this stage perform glue operations at edges for each face*/
for(i=1; i<4; i++)
{
  Hedge* he[3], *mhe[3];
  Point *p[3];

  
  for(j=0; j<3;j++){
    he[j] = f[i]->hedge(j);
    p[j]  = f[i]->vertex(j);
  }
  
  /*look for existing mate hedges*/  
  mhe[0] = p[0]->lookup_hedge(p[1]);
  mhe[1] = p[1]->lookup_hedge(p[2]);
  mhe[2] = p[2]->lookup_hedge(p[0]);
  
  is_manifold = true;

  /*verify manifoldness*/
  for(j =0;j<3; j++)
   if (mhe[j]!=NULL && !mhe[j]->edge()->is_bdry())
        is_manifold = false;

  /*glueing each edge of the new face*/
  if(is_manifold){
  
    if(mhe[0]!=NULL)
      s->glue(mhe[0], he[0])

    if(mhe[1]!=NULL)
      s->glue(mhe[1], he[1])

    if(mhe[2]!=NULL)
      s->glue(mhe[2], he[2])
  }

}

Generated on Fri Feb 24 12:23:23 2006 for TOPs by  doxygen 1.4.6-NO