home *** CD-ROM | disk | FTP | other *** search
- /* cat > headers/plot1d.h << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* plot1d.h: header for plot1d.c file */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- #define plot1d_h 1
-
- #include "all.h"
- #include "newext.h"
-
- static int last_x1,last_x2,last_y1,last_y2;
-
- /* EOF */
- /* cat > src+obj/plot1d/plot_linear.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* plot_linear: routine that does xy plot */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "plot1d.h" */
-
- void
- plot_linear ()
- {
- float a, b, xscale, yscale, gvalue, gbound, glow;
- float userx, usery, userx1, userx2, distance;
- int cval, xdim, ydim, start;
- int qx1, qx2, qy1, qy2, x, y;
- int lastw = curr_image.xdim, lasth = curr_image.ydim;
- int lastx = curr_image.startx, lasty = curr_image.starty;
- int x1 = line_rec.x1, x2 = line_rec.x2;
- int y1 = line_rec.y1, y2 = line_rec.y2;
- float uxdim = stats_xmax - stats_xmin;
- float uydim = stats_ymax - stats_ymin;
- Pixwin *plotpw;
- char label[MAXNAMELEN];
-
- if (lastw == 0 || lasth == 0)
- return;
-
- /* check line length */
- xdim = ABS (x2 - x1);
- ydim = ABS (y2 - y1);
- if (xdim == 0 && ydim == 0)
- {
- gvalue = get_gvalue ((int) pw_get (pw, x1, y1));
-
- /* apply scaling information */
- userx = (float) (stats_xmin + uxdim * (x1 - lastx) / (float) lastw);
- usery = (float) (stats_ymax - uydim * (y1 - lasty) / (float) lasth);
- sprintf (msgstr, "Note: XY plot - p = (%.2f,%.2f), gvalue = %.2f",
- userx, usery, gvalue);
- msg_write (msgstr);
- last_dir = 0;
- return;
- }
-
- plotpw = canvas_pixwin (pcanvas);
- if (linear_scaling)
- {
- gbound = stats_gmax - stats_gmin;
- glow = stats_gmin;
- }
- else
- { /* log scale */
- gminexp = (int) floor (log10 ((double) stats_gmin));
- gmaxexp = (int) ceil (log10 ((double) stats_gmax));
- process_gexp (&gminexp, &gmaxexp);
- gbound = (float) (gmaxexp - gminexp);
- glow = gminexp;
- }
- yscale = YPLENGTH / gbound;
-
- /* horizontal line: ydim=0 */
- if (ydim == 0)
- {
- if (x1 > x2)
- {
- x1--;
- x = x1;
- x1 = x2;
- x2 = x;
- }
- else
- {
- x1++;
- }
- xdim--;
- if (last_dir != 1)
- {
- clear_plot ();
- if (has_xscale)
- strncpy (label, "(X)", MAXNAMELEN - 1);
- else
- strncpy (label, "(Pixel X)", MAXNAMELEN - 1);
- userx1 = (float) (stats_xmin + uxdim * (x1 - lastx) / (float) lastw);
- userx2 = (float) (stats_xmin + uxdim * (x2 - lastx) / (float) lastw);
- plot_axes (label, userx1, userx2);
- xscale = XPLENGTH / (float) xdim;
- last_x1 = start = x1;
- last_x2 = x2;
- last_dir = 1;
- }
- else
- {
- xscale = last_xscale;
- yscale = last_yscale;
- start = last_x1;
- if (x1 < last_x1)
- x1 = last_x1;
- if (x2 > last_x2)
- x2 = last_x2;
- }
-
- cval = pw_get (pw, x1, y1);
- gvalue = get_gvalue (255 - cval);
- qy1 = (int) (YPLOT_MAX - (gvalue - glow) * yscale);
- qx1 = (int) (XPLOT_MIN + (x1 - start) * xscale);
- for (x = x1 + 1; x <= x2; x++)
- {
- cval = pw_get (pw, x, y1);
- gvalue = get_gvalue (255 - cval);
- qy2 = (int) (YPLOT_MAX - (gvalue - glow) * yscale);
- qx2 = (int) (XPLOT_MIN + xscale * (x - start));
- pwVector (plotpw, qx1, qy1, qx2, qy2, PIX_SRC, 255);
- qx1 = qx2;
- qy1 = qy2;
- }
- last_xscale = xscale;
- last_yscale = yscale;
- return;
- }
-
- /* vertical line: xdim=0 */
- if (xdim == 0)
- {
- if (y1 > y2)
- {
- y1--;
- y = y1;
- y1 = y2;
- y2 = y;
- }
- else
- {
- y1++;
- }
- ydim--;
- if (last_dir != 2)
- {
- clear_plot ();
- userx1 = (float) (uydim * (y1 - lasty) / (float) lasth);
- userx2 = (float) (uydim * (y2 - lasty) / (float) lasth);
- userx1 = (float) stats_ymax - userx1;
- userx2 = (float) stats_ymax - userx2;
- if (has_yscale)
- strncpy (label, "(Y)", MAXNAMELEN - 1);
- else
- strncpy (label, "(Pixel Y)", MAXNAMELEN - 1);
- plot_axes (label, userx2, userx1);
- xscale = XPLENGTH / (float) ydim;
- last_y2 = start = y2;
- last_y1 = y1;
- last_dir = 2;
- }
- else
- {
- xscale = last_xscale;
- yscale = last_yscale;
- start = last_y2;
- if (y1 < last_y1)
- y1 = last_y1;
- if (y2 > last_y2)
- y2 = last_y2;
- }
-
- cval = pw_get (pw, x2, y2);
- gvalue = get_gvalue (255 - cval);
- qy1 = (int) (YPLOT_MAX - (gvalue - glow) * yscale);
- qx1 = (int) (XPLOT_MIN + xscale * (start - y2));
- for (y = y2 - 1; y >= y1; y--)
- {
- cval = pw_get (pw, x2, y);
- gvalue = get_gvalue (255 - cval);
- qy2 = (int) (YPLOT_MAX - (gvalue - glow) * yscale);
- qx2 = (int) (XPLOT_MIN + xscale * (start - y));
- pwVector (plotpw, qx1, qy1, qx2, qy2, PIX_SRC, 255);
- qx1 = qx2;
- qy1 = qy2;
- }
- last_xscale = xscale;
- last_yscale = yscale;
- return;
- }
-
- /* general straight line: xdim and ydim are not zeros */
- clear_plot ();
-
- if (x1 > x2)
- {
- x1--;
- x = x1;
- x1 = x2;
- x2 = x;
- y = y1;
- y1 = y2;
- y2 = y;
- }
- else
- x1++;
- xdim--;
- ydim--;
-
- userx1 = (float) (stats_xmin + uxdim * (x1 - lastx) / (float) lastw);
- userx2 = (float) (stats_xmin + uxdim * (x2 - lastx) / (float) lastw);
- userx = ABS (userx1 - userx2);
- userx1 = (float) (stats_ymax - uydim * (y1 - lasty) / (float) lasth);
- userx2 = (float) (stats_ymax - uydim * (y2 - lasty) / (float) lasth);
- usery = ABS (userx1 - userx2);
- distance = (float) sqrt ((double) (userx * userx + usery * usery));
- if (has_xscale)
- strncpy (label, "(Scaled Distance)", MAXNAMELEN - 1);
- else
- strncpy (label, "(Scaled Pixel Distance)", MAXNAMELEN - 1);
- plot_axes (label, 0., distance);
-
- distance = (float) sqrt ((double) (xdim * xdim + ydim * ydim));
- xscale = XPLENGTH / (float) distance;
- get_eqn (x1, y1, x2, y2, &a, &b);
- y1 = a * x1 + b;
-
- plotpw = canvas_pixwin (pcanvas);
- pw_vector (pw, line_rec.x1, line_rec.y1, line_rec.x2, line_rec.y2,
- PIX_NOT (PIX_DST), 255);
- gvalue = get_gvalue ((int) pw_get (pw, x1, y1));
- pw_vector (pw, line_rec.x1, line_rec.y1, line_rec.x2, line_rec.y2,
- PIX_NOT (PIX_DST), 255);
- qy1 = (int) (YPLOT_MAX - (gvalue - glow) * yscale);
- qx1 = XPLOT_MIN;
- for (x = x1 + 1; x <= x2; x++)
- {
- y = (int) (a * x + b);
- pw_vector (pw, line_rec.x1, line_rec.y1, line_rec.x2, line_rec.y2,
- PIX_NOT (PIX_DST), 255);
- cval = pw_get (pw, x, y);
- gvalue = get_gvalue (cval);
- pw_vector (pw, line_rec.x1, line_rec.y1, line_rec.x2, line_rec.y2,
- PIX_NOT (PIX_DST), 255);
- qy2 = (int) (YPLOT_MAX - (gvalue - glow) * yscale);
- distance = (float) sqrt ((double) ((x - x1) * (x - x1) + (y - y1) * (y - y1)));
- qx2 = (int) (XPLOT_MIN + xscale * distance);
- pwVector (plotpw, qx1, qy1, qx2, qy2, PIX_SRC, 255);
- qx1 = qx2;
- qy1 = qy2;
- }
- last_dir = 3;
- last_xscale = xscale;
- last_yscale = yscale;
- return;
- }
- /* EOF */
-