home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / software / unix / saoimage / sao1_07.tar / grphline.c < prev    next >
C/C++ Source or Header  |  1990-04-20  |  8KB  |  257 lines

  1. #ifndef lint
  2. static char SccsId[] = "%W%  %G%";
  3. #endif
  4.  
  5. /* Module:    grphline.c (Color Graph Line)
  6.  * Purpose:    Assemble lines and hash marks for the color graph
  7.  * Subroutine:    init_cgraph_lines()            returns: void
  8.  * Subroutine:    set_cgraph_line()            returns: void
  9.  * Subroutine:    init_cgraph_bars()            returns: void
  10.  * Subroutine:    set_cgraph_bar()            returns: void
  11.  * Subroutine:    init_cgraph_hash()            returns: void
  12.  * Subroutine:    set_cgraph_hash()            returns: void
  13.  * Copyright:    1989 Smithsonian Astrophysical Observatory
  14.  *        You may do anything you like with this file except remove
  15.  *        this copyright.  The Smithsonian Astrophysical Observatory
  16.  *        makes no representations about the suitability of this
  17.  *        software for any purpose.  It is provided "as is" without
  18.  *        express or implied warranty.
  19.  * Modified:    {0} Michael VanHilst    initial version         11 June 1989
  20.  *        {n} <who> -- <does what> -- <when>
  21.  */
  22.  
  23. #include <X11/Xlib.h>        /* X window stuff */
  24. #include <X11/Xutil.h>        /* X window manager stuff */
  25. #include "hfiles/color.h"    /* color structs */
  26. #include "hfiles/cgraph.h"    /* color graph structs */
  27.  
  28. extern struct cgraphRec cgraph;
  29.  
  30. /*
  31.  * Subroutine:    init_cgraph_lines
  32.  * Purpose:    Set the fixed color_linegraph coordinates (aligning segments
  33.  *        with the corresponding colorbar stripe)
  34.  */
  35. void init_cgraph_lines ( rline, gline, bline )
  36.      XPoint rline[];
  37.      XPoint gline[];
  38.      XPoint bline[];
  39. {
  40.   double inc;        /* l: ideal increment from one point to the next */
  41.   register int i;
  42.  
  43.   if( cgraph.vertical ) {
  44.     double Y;
  45.     /* vertical */
  46.     inc = cgraph.graph.Yinc;
  47.     Y = (double)cgraph.graph.yzero + (inc / 2.0);
  48.     for( i=0; i<cgraph.graph.ncolors; i++ ) {
  49.       register int y = (int)Y;
  50.       rline[i].y = y;
  51.       gline[i].y = y;
  52.       bline[i].y = y;
  53.       Y += inc;
  54.     }
  55.   } else {
  56.     double X;
  57.     /* horizontal */
  58.     inc = cgraph.graph.Xinc;
  59.     X = (double)cgraph.graph.xzero + (inc / 2.0);
  60.     for( i=0; i<cgraph.graph.ncolors; i++ ) {
  61.       register int x = (int)X;
  62.       rline[i].x = x;
  63.       gline[i].x = x;
  64.       bline[i].x = x;
  65.       X += inc;
  66.     }
  67.   }
  68. }
  69.  
  70. /*
  71.  * Subroutine:    set_cgraph_line
  72.  * Purpose:    Set the variable colorline coordinates representing intensity
  73.  * PreState:    Must be preceded by init_colorhash whenever window size or
  74.  *        color allocation is changed
  75.  */
  76. void set_cgraph_line ( cellmap, line )
  77.      double cellmap[];        /* i: values being graphed (range 0.0-1.0) */
  78.      XPoint line[];        /* i/o: line being initialized */
  79. {
  80.   int i, j;
  81.  
  82.   if( cgraph.vertical ) {
  83.     double Xwidth = cgraph.graph.Xwidth;
  84.     int xzero = cgraph.graph.xzero;
  85.     /* vertical */
  86.     for( i=cgraph.graph.ncolors-1, j=0; i>=0; i--, j++ )
  87.       line[i].x = xzero + (int)(cellmap[j] * Xwidth);
  88.   } else {
  89.     double Yheight = cgraph.graph.Yheight;
  90.     int ymax = cgraph.graph.ymax;
  91.     /* horizontal */
  92.     for( i=0; i<cgraph.graph.ncolors; i++ )
  93.       line[i].y = ymax - (int)(cellmap[i] * Yheight);
  94.   }
  95. }
  96.  
  97. #ifdef NOTNEEDED /* %% not yet needed */
  98. /*
  99.  * Subroutine:    init_cgraph_bars
  100.  * Purpose:    Set the fixed colorline coordinates (aligning segment with
  101.  *        the corresponding colorbar stripe)
  102.  * Params:    xzero, yzero, xwidth, yheight describe the graph drawing area
  103.  *        within its (possibly larger) window
  104.  * Method:    Graph starts at _zero edge, evenly spacing the segments to the
  105.  *        far edge.  (count may be less than xwidth or yheight)
  106.  */
  107. void init_cgraph_bars ( rline, bline, gline )
  108.      XPoint rline[];        /* i/o: red line being initialized */
  109.      XPoint gline[];        /* i/o: green line being initialized */
  110.      XPoint bline[];        /* i/o: blue line being initialized */
  111. {
  112.   double inc;        /* l: increment for even spacing */
  113.   int npoints;        /* l: loop end for loop by 2 */
  114.   int i;
  115.  
  116.   npoints = cgraph.graph.ncolors + cgraph.graph.ncolors;
  117.   if( cgraph.vertical ) {
  118.     double Y;        /* l: ideal position */
  119.     int y;        /* l: realizable position */
  120.     /* vertical */
  121.     inc = cgraph.graph.Yinc;
  122.     y = cgraph.graph.yzero;
  123.     Y = (double)y;
  124.     for( i=0; i<npoints; i += 2 ) {
  125.       rline[i].y = y;
  126.       gline[i].y = y;
  127.       bline[i].y = y;
  128.       Y += inc;
  129.       y = (int)Y;
  130.       rline[i+1].y = y;
  131.       gline[i+1].y = y;
  132.       bline[i+1].y = y;
  133.     }
  134.   } else {
  135.     double X;        /* l: ideal position */
  136.     int x;        /* l: realizable position */
  137.     /* horizontal */
  138.     inc = cgraph.graph.Xinc;
  139.     x = cgraph.graph.xzero;
  140.     X = (double)x;
  141.     for( i=0; i<npoints; i += 2 ) {
  142.       rline[i].x = x;
  143.       gline[i].x = x;
  144.       bline[i].x = x;
  145.       X += inc;
  146.       x = (int)X;
  147.       rline[i+1].x = x;
  148.       gline[i+1].x = x;
  149.       bline[i+1].x = x;
  150.     }
  151.   }
  152. }
  153.  
  154. /*
  155.  * Subroutine:    set_cgraph_bar
  156.  * Purpose:    Set the variable colorline coordinates representing intensity
  157.  * Params:    xzero, yzero, xwidth, yheight describe the graph drawing area
  158.  *        within its (possibly larger) window
  159.  */
  160. void set_cgraph_bar ( cellmap, line )
  161.      double cellmap[];        /* i: values being graphed (range 0.0-1.0) */
  162.      XPoint line[];        /* i/o: line being initialized */
  163. {
  164.   int i, j;
  165.  
  166.   if( cgraph.vertical ) {
  167.     double Xwidth = cgraph.graph.Xwidth;
  168.     int xzero = cgraph.graph.yzero;
  169.     register int x;
  170.     /* vertical */
  171.     for( i=cgraph.graph.ncolors-1, j=i*2; i>=0; i--, j-=2 ) {
  172.       x = xzero + (int)(cellmap[i] * Xwidth);
  173.       line[j].x = x;
  174.       line[j+1].x = x;
  175.     }
  176.   } else {
  177.     double Yheight = cgraph.graph.Yheight;
  178.     int ymax = cgraph.graph.ymax;
  179.     register int y;
  180.     /* horizontal */
  181.     for( i=0, j=0; i<cgraph.graph.ncolors; i++, j+=2 ) {
  182.       y = ymax - (int)(cellmap[i] * Yheight);
  183.       line[j].y = y;
  184.       line[j+1].y = y;
  185.     }
  186.   }
  187. }
  188. #endif
  189.  
  190. /*
  191.  * Subroutine:    init_cgraph_hash
  192.  * Purpose:    Initialize record parameters used to place the hash marks
  193.  */
  194. void init_cgraph_hash ( )
  195. {
  196.   if( cgraph.vertical ) {
  197.     cgraph.hash.Xzero = (double)(cgraph.graph.xzero - HASH_RAY);
  198.     cgraph.hash.Yzero = (double)(cgraph.graph.yzero - HASH_RAY) +
  199.       (cgraph.graph.Yinc / 2.0);
  200.     cgraph.hash.Xwidth = cgraph.graph.Xwidth;
  201.     cgraph.hash.Yheight = cgraph.graph.Yheight - cgraph.graph.Yinc;
  202.     cgraph.hash.Ymax = cgraph.hash.Yzero + cgraph.hash.Yheight;
  203.   } else {
  204.     cgraph.hash.Xzero = (double)(cgraph.graph.xzero - HASH_RAY) +
  205.       (cgraph.graph.Xinc / 2.0);
  206.     cgraph.hash.Yzero = (double)(cgraph.graph.yzero - HASH_RAY);
  207.     cgraph.hash.Xwidth = cgraph.graph.Xwidth - cgraph.graph.Xinc;
  208.     cgraph.hash.Yheight = cgraph.graph.Yheight;
  209.     cgraph.hash.Ymax = cgraph.hash.Yzero + cgraph.hash.Yheight;
  210.   }
  211. }
  212.  
  213. /*
  214.  * Subroutine:    set_cgraph_hash
  215.  * Purpose:    Set rectangle positions to mark table vertexes for one color
  216.  * PreState:    Must be preceded by init_colorhash whenever window size or
  217.  *        color allocation is changed
  218.  * Returns:    Table index of hash[0] (or where hypothetical hash[0] would be)
  219.  */
  220. int set_cgraph_hash ( table, hash, hash_cnt )
  221.      struct subtableRec *table;    /* i: pseudocolor table structure */
  222.      XRectangle hash[];        /* i/o: hash mark list */
  223.      int *hash_cnt;        /* o: number of hash mark rectangles */
  224. {
  225.   double level;
  226.   double *cell_level;        /* l: normalized cell level (range 0.0-1.0) */
  227.   double *intensity;        /* l: normalized cell intensity */
  228.   int vertex_cnt;        /* l: number of cell_level entries */
  229.   int i, k;
  230.   int hash_0 = 0;
  231.  
  232.   k = 0;
  233.   cell_level = table->cell_level;
  234.   intensity = table->intensity;
  235.   vertex_cnt = table->vertex_cnt;
  236.   for( i=0; i<vertex_cnt; i++ ) {
  237.     level = cell_level[i];
  238.     if( level < 0.0 ) {
  239.       /* advance the table index of hash[0] ahead of sub-zero vertexes */
  240.       hash_0 = i+1;
  241.     } else if( level <= 1.0 ) {
  242.       if( cgraph.vertical ) {
  243.     hash[k].y = (int)(cgraph.hash.Ymax - (level * cgraph.hash.Yheight));
  244.     hash[k].x = (int)
  245.       (cgraph.hash.Xzero + (intensity[i] * cgraph.hash.Xwidth));
  246.       } else {
  247.     hash[k].x = (int)(cgraph.hash.Xzero + (level * cgraph.hash.Xwidth));
  248.     hash[k].y = (int)
  249.       (cgraph.hash.Ymax - (intensity[i] * cgraph.hash.Yheight));
  250.       }
  251.       k++;
  252.     }
  253.   }
  254.   *hash_cnt = k;
  255.   return( hash_0 );
  256. }
  257.