next up previous contents
Next: Implementation Up: Hidden Line Removal using Previous: Hidden Line Removal using

Algorithm

Here, the BSP Tree routine and Polygon Clipping routine are used in succession to perform hidden line removal. A C++ pseudo-code illustrating the algorithm is given below.

void HiddenLineRemoval ()
{
  OFFObject *obj;
  Point3d viewpoint;
  Poly2d subject,clip;
  Poly2d *insidelist,*outsidelist;
  Poly2d *subjectlist,*new_subjectlist;
  int i,j,k,l;

  ReadOFFObject (obj);
  Read (viewpioint);

  Sort_using_BSP (obj,viewpoint);

  Transform2d (obj,viewpoint);

  for (i = obj->nf-1; i >= 0; i--)
     {
      subject = obj->faces[i];

      subjectlist[0] = subject;
      subjectlist->n = 1;

      for (j = i+1; j <= obj->nf; j++)
         {
          clip = obj->faces[j];

          new_subjectlist->n = 0;
          for (k = 0; k < subjectlist->n; k++)
             {
              Clip2polygons(clip,subjectlist[k],insidelist,outsidelist);
              new_subjectlist += outsidelist;
              new_subjectlist->n += outsidelist->n;
             		// Append 'outsidelist' to 'new_subjectlist'
             }

          subjectlist = new_subjectlist;
         }

      Output (subjectlist);
             	// Print 'subjectlist' as output
     }
}

The input here are the set of convex polygons in 3D space in OFF format and the view point, and the output is a set of non-overlapping polygons in 2D space which when drawn in any order, give the desired hidden line removal effect with respect to the given view point.



Anirudh Modi
4/15/1998