Algorithm Alley
by Thomas E. Janzen


Listing One
for (i = 1; i < (gw - 1); ++i) {
  for (j = 1; j < (gh - 1); ++j) {
    suma = 0.0; sumb = 0;
    for (io = -1; io <= 1; ++io) {
      for (jo = -1; jo <= 1; ++jo) {
        suma  += sobelaM[io+1][jo+1] * pixels[i + io][j + jo];
        sumb += sobelbM[io+1][jo+1] * pixels[i + io][j + jo];
      }
    }
    diffpixels[i][j] = (fabs(suma) + fabs(sumb)) / 8.0;
  }
}

Listing Two
for (i = 1; i < (gw - 1); ++i) {
  for (j = 1; j < (gh - 1); ++j) {
    sumo = 0.0;
    for (io = -1; io <= 1; ++io)
      for (jo = -1; jo <= 1; ++jo)
        sumo  += laplaceline[io+1][jo+1] * pixels[i + io][j + jo];
    diffpixels[i][j] = sumo / 3;
  }
}


Listing Three 
sumo += (-pixels[i-1][j-1] - pixels[i-1][j] - pixels[i-1][j+1] 
      - pixels[i][j-1] + 8*pixels[i][j] - pixels[i][j+1] 
      - pixels[i+1][j-1] - pixels[i+1][j] - pixels[i+1][j+1])/8;


Listing Four
glBegin(GL_LINES);
 ...
for (u_ctr = 0; u_ctr < PARM_STEP_QTY; ++u_ctr) {
  for (v_ctr = 0; v_ctr < PARM_STEP_QTY; ++v_ctr) {
    if (isoparm) {
      if (!(u_ctr % 4) || (u_ctr == (PARM_STEP_QTY - 1))) {
        glVertex3dv(vertices[u_ctr][v_ctr]);
        glVertex3dv(vertices[u_ctr][v_ctr + 1]);
      }
    }else {
      ... // draw either silhouettes or patches
    }
  }
}
glEnd();
 ...


Listing Five 
void Bezier(Bezier_type points, const dbl_vec_type LookAtEye)...
for (u = 0; u <= PARM_STEP_QTY; ++u) {
  for (v = 0; v <= PARM_STEP_QTY; ++v) { ...
  cross(vert[u][v + 1], vert[u][v], vert[u + 1][v], n);
  if (silhouette) {
    ... // draw borders on edge vert
    if ((v + 2) <= PARM_STEP_QTY) { // for inner patches
      cross(vert[u][v + 2], vert[u][v + 1], vert[u + 1][v + 1], n2);
      eyevect[0..2] = vert[u][v + 1][0..2] - Eye[0..2];
      if (oppositesigns(dot(eyevect, n), dot(eyevect, n2))) { 
        glVertex3dv(vert[u][v+1]);
        glVertex3dv(vert[u + 1][v + 1]);
      }
    }
    if ((u + 2) <= PARM_STEP_QTY) {
      //... similar code along changing u counter
    }
  }else {
   //  draw normal patches.
    ...

Listing Six
for (k = 0; k < DIM_QTY; ++k) {
  for (i = 0; i < DIM_QTY; ++i) {
    for (j = 0; j < DIM_QTY; ++j)
      p[k] += bu[i] * bv[j] * p_control[i][j][k];
  }
}





2


