home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 344b.lha / plplot_v2.6 / src / plcntr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-27  |  5.6 KB  |  205 lines

  1. /* points is a pointer to a 2d array of nx by ny points. */
  2. /* iscan has nx elements. ixstor and iystor each have nstor elements. */
  3.  
  4. #include "plplot.h"
  5.  
  6. void plcntr(points,nx,ny,kx,lx,ky,ly,zlev,iscan,ixstor,iystor,nstor,pltr)
  7. PLINT nx, ny, ky, ly, kx, lx, nstor;
  8. PLFLT zlev, *points;
  9. PLINT *iscan, *ixstor, *iystor;
  10. void (*pltr)();
  11. {
  12.       PLINT kcol, krow, kstor, kscan, iwbeg, ixbeg, iybeg, izbeg;
  13.       PLINT iboun, iw, ix, iy, iz, ifirst, istep, ixgo, iygo;
  14.       PLINT l, ixg, iyg, ia, ib, ixt, iyt, jstor, next;
  15.       PLFLT dist, dx, dy, xnew, ynew, x, y;
  16.       PLFLT xlas=0., ylas=0., tpx, tpy, xt, yt;
  17.  
  18.       /* Initialize memory pointers */
  19.  
  20.       kstor = 0;
  21.       kscan = 0;
  22.  
  23.       for (krow=ky; krow<=ly; krow++) {
  24.         for (kcol=kx+1; kcol <= lx; kcol++)  {
  25.  
  26.           /* Check if a contour has been crossed */
  27.  
  28.           x = *(points + (kcol-2)*ny + krow-1);
  29.           y = *(points + (kcol-1)*ny + krow-1);
  30.           if (x < zlev && y >= zlev) {
  31.             ixbeg = kcol-1;
  32.             iwbeg = kcol;
  33.           }
  34.           else if (y < zlev && x >= zlev) {
  35.             ixbeg = kcol;
  36.             iwbeg = kcol-1;
  37.           }
  38.           else
  39.             goto lab70;
  40.  
  41.           iybeg = krow;
  42.           izbeg = krow;
  43.  
  44.           /* Yes, a contour has been crossed. Check to see if it */
  45.           /* is a new one. */
  46.  
  47.           for(l=0;l<kscan;l++)
  48.             if (ixbeg == iscan[l]) goto lab70;
  49.  
  50.           /* Here is the section which follows and draws a contour */
  51.  
  52.           for (iboun=1; iboun>= -1; iboun -= 2) {
  53.  
  54.             /* Set up starting point and initial search directions */
  55.  
  56.             ix = ixbeg;
  57.             iy = iybeg;
  58.             iw = iwbeg;
  59.             iz = izbeg;
  60.             ifirst = 1;
  61.             istep = 0;
  62.             ixgo = iw - ix;
  63.             iygo = iz - iy;
  64.  
  65. lab20:
  66.               plccal(points,nx,ny,zlev,ix,iy,ixgo,iygo,&dist);
  67.               dx = dist * ixgo;
  68.               dy = dist * iygo;
  69.               xnew = ix+dx;
  70.               ynew = iy+dy;
  71.  
  72.              /* Has a step occured in search? */
  73.  
  74.               if (istep != 0) {
  75.                 if (ixgo*iygo == 0) {
  76.  
  77.                   /* This was a diagonal step, so interpolate missed */
  78.                   /* point, rotating 45 degrees to get it */
  79.  
  80.                   ixg = ixgo;
  81.                   iyg = iygo;
  82.                   plr45(&ixg,&iyg,iboun);
  83.                   ia = iw-ixg;
  84.                   ib = iz-iyg;
  85.                   plccal(points,nx,ny,zlev,ia,ib,ixg,iyg,&dist);
  86.                   (*pltr)(xlas-1,ylas-1,&tpx,&tpy);
  87.                   drawor(tpx,tpy);
  88.                   dx = dist*ixg;
  89.                   dy = dist*iyg;
  90.                   xlas = ia+dx;
  91.                   ylas = ib+dy;
  92.                 }
  93.                 else {
  94.                   if (dist > 0.5) {
  95.                     xt = xlas;
  96.                     xlas = xnew;
  97.                     xnew = xt;
  98.                     yt = ylas;
  99.                     ylas = ynew;
  100.                     ynew = yt;
  101.                   }
  102.                 }
  103.               }
  104.               if (ifirst != 1) {
  105.                 (*pltr)(xlas-1,ylas-1,&tpx,&tpy);
  106.                 drawor(tpx,tpy);
  107.               }
  108.               else {
  109.                 (*pltr)(xnew-1,ynew-1,&tpx,&tpy);
  110.                 movwor(tpx,tpy);
  111.               }
  112.               xlas = xnew;
  113.               ylas = ynew;
  114.  
  115.               /* Check if the contour is closed */
  116.  
  117.               if (ifirst != 1 && ix == ixbeg && iy == iybeg
  118.                   && iw == iwbeg && iz == izbeg) {
  119.                 (*pltr)(xlas-1,ylas-1,&tpx,&tpy);
  120.                 drawor(tpx,tpy);
  121.                 goto lab70;
  122.               }
  123.               ifirst = 0;
  124.  
  125.               /* Now the rotation */
  126.  
  127.               istep = 0;
  128.               plr45(&ixgo,&iygo,iboun);
  129.               iw = ix+ixgo;
  130.               iz = iy+iygo;
  131.  
  132.               /* Check if out of bounds */
  133.  
  134.               if (iw<kx || iw>lx || iz<ky || iz>ly) goto  lab50;
  135.  
  136.               /* Has contact been lost with the contour? */
  137.  
  138.               if (*(points+(iw-1)*ny+iz-1) < zlev) {
  139.  
  140.                 /* Yes, lost contact => step to new centre */
  141.  
  142.                 istep = 1;
  143.                 ix = iw;
  144.                 iy = iz;
  145.                 plr135(&ixgo,&iygo,iboun);
  146.                 iw = ix+ixgo;
  147.                 iz = iy+iygo;
  148.  
  149.                 /* And do the contour memory */
  150.  
  151.                 if (iy == krow) {
  152.                   kscan = kscan+1;
  153.                   iscan[kscan-1] = ix;
  154.                 }
  155.                 else if (iy>krow) {
  156.                   kstor = kstor+1;
  157.                   if (kstor>nstor) {
  158.                     plexit("Heap exhausted in plcont.");
  159.                   }
  160.                   ixstor[kstor-1] = ix;
  161.                   iystor[kstor-1] = iy;
  162.                 }
  163.               }
  164.             goto lab20;
  165. lab50:
  166.             /* Reach here only if boundary encountered - Draw last bit */
  167.  
  168.             (*pltr)(xnew-1,ynew-1,&tpx,&tpy);
  169.             drawor(tpx,tpy);
  170.           }
  171. lab70:
  172.           ;    /* Null statement to carry label */
  173.         }
  174.  
  175.         /* Search of row complete - set up memory of next row in iscan and */
  176.         /* edit ixstor and iystor */
  177.  
  178.         if (krow<ny) {
  179.           jstor = 0;
  180.           kscan = 0;
  181.           next = krow+1;
  182.           for (l=1; l<=kstor; l++) {
  183.             ixt = ixstor[l-1];
  184.             iyt = iystor[l-1];
  185.  
  186.             /* Memory of next row into iscan */
  187.  
  188.             if (iyt == next) {
  189.               kscan = kscan+1;
  190.               iscan[kscan-1] = ixt;
  191.  
  192.             /* Retain memory of rows to come, and forget rest */
  193.  
  194.             }
  195.             else if (iyt>next) {
  196.               jstor = jstor+1;
  197.               ixstor[jstor-1] = ixt;
  198.               iystor[jstor-1] = iyt;
  199.             }
  200.           }
  201.           kstor = jstor;
  202.         }
  203.       }
  204. }
  205.