list.c

Go to the documentation of this file.
00001 /*                          L I S T . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 2004-2012 United States Government as represented by
00005  * the U.S. Army Research Laboratory.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * version 2.1 as published by the Free Software Foundation.
00010  *
00011  * This library is distributed in the hope that it will be useful, but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this file; see the file named COPYING for more
00018  * information.
00019  */
00020 /** @addtogroup plot */
00021 /** @{ */
00022 /** @file libbn/list.c
00023  *
00024  * NOTE that tp_2list() and tp_3list() are good candidates to become
00025  * intrinsic parts of plot3.c, for efficiency reasons.
00026  *
00027  * Originally written in August 04, 1978
00028  */
00029 
00030 #include "common.h"
00031 
00032 #include <stdio.h>
00033 #include "vmath.h"
00034 #include "plot3.h"
00035 
00036 /* Modes for internal flag */
00037 #define TP_MARK         1               /**< Draw marks */
00038 #define TP_LINE         2               /**< Draw lines */
00039 
00040 /**
00041  *                      T P _ I 2 L I S T
00042  *
00043  *  Take a set of x, y coordinates, and plot them as a
00044  *  polyline, ie, connect them with line segments.
00045  *  For markers, use tp_mlist(), below.
00046  *  This "C" interface expects arrays of INTs.
00047  */
00048 void
00049 tp_i2list(register FILE *fp, register int *x, register int *y, register int npoints)
00050 
00051 /* array of points */
00052 /* array of points */
00053 
00054 {
00055     if (npoints <= 0)
00056         return;
00057 
00058     pl_move(fp, *x++, *y++);
00059     while (--npoints > 0)
00060         pl_cont(fp, *x++, *y++);
00061 }
00062 
00063 
00064 /**
00065  *                      T P _ 2 L I S T
00066  *
00067  *  Take a set of x, y coordinates, and plot them as a
00068  *  polyline, ie, connect them with line segments.
00069  *  For markers, use tp_mlist(), below.
00070  *  This "C" interface expects arrays of DOUBLES.
00071  */
00072 void
00073 tp_2list(register FILE *fp, register double *x, register double *y, register int npoints)
00074 
00075 /* array of points */
00076 /* array of points */
00077 
00078 {
00079     if (npoints <= 0)
00080         return;
00081 
00082     pd_move(fp, *x++, *y++);
00083     while (--npoints > 0)
00084         pd_cont(fp, *x++, *y++);
00085 }
00086 
00087 
00088 void
00089 PL_FORTRAN(f2list, F2LIST)(FILE **fpp, float *x, float *y, int *n)
00090 {
00091     register int npoints = *n-1;        /* FORTRAN uses 1-based subscripts */
00092     register FILE       *fp = *fpp;
00093 
00094     if (npoints <= 0)
00095         return;
00096 
00097     pd_move(fp, *x++, *y++);
00098     while (--npoints > 0)
00099         pd_cont(fp, *x++, *y++);
00100 }
00101 
00102 
00103 /**
00104  *                      T P _ 3 L I S T
00105  */
00106 void
00107 tp_3list(FILE *fp, register double *x, register double *y, register double *z, register int npoints)
00108 {
00109     if (npoints <= 0)
00110         return;
00111 
00112     pd_3move(fp, *x++, *y++, *z++);
00113     while (--npoints > 0)
00114         pd_3cont(fp, *x++, *y++, *z++);
00115 }
00116 
00117 
00118 void
00119 PL_FORTRAN(f3list, F3LIST)(FILE **fpp, float *x, float *y, float *z, int *n)
00120 {
00121     register int npoints = *n-1;        /* FORTRAN uses 1-based subscripts */
00122     register FILE       *fp = *fpp;
00123 
00124     if (npoints <= 0)
00125         return;
00126 
00127     pd_3move(fp, *x++, *y++, *z++);
00128     while (--npoints > 0)
00129         pd_3cont(fp, *x++, *y++, *z++);
00130 }
00131 
00132 
00133 /**
00134  *                      T P _ 2 M L I S T
00135  *
00136  *  Take a set of x, y co-ordinates and plots them,
00137  *  with a combination of connecting lines and/or place markers.
00138  *  It is important to note that the arrays
00139  *  are arrays of doubles, and express UNIX-plot coordinates in the
00140  *  current pl_space().
00141  *
00142  *  tp_scale(TIG) may be called first to optionally re-scale the data.
00143  *
00144  *  The 'mark' character to be used for marking points off can be any
00145  *  printing ASCII character, or 001 to 005 for the special marker characters.
00146  *
00147  *  In addition, the value of the 'flag' variable determines the type
00148  *  of line to be drawn, as follows:
00149  *
00150  *@li   0       Draw nothing (rather silly)
00151  *@li   1       Marks only, no connecting lines.  Suggested interval=1.
00152  *@li   2       Draw connecting lines only.
00153  *@li   3       Draw line and marks
00154  */
00155 void
00156 tp_2mlist(FILE *fp, register double *x, register double *y, int npoints, int flag, int mark, int interval, double size)
00157 
00158 
00159 /* arrays of points */
00160 
00161 /* TP_MARK|TP_LINE */
00162 /* marker character to use */
00163 /* marker drawn every N points */
00164 /* marker size */
00165 {
00166     register int i;                     /* index variable */
00167     register int counter;               /* interval counter */
00168 
00169     if (npoints <= 0)
00170         return;
00171 
00172     if (flag & TP_LINE)
00173         tp_2list(fp, x, y, npoints);
00174     if (flag & TP_MARK) {
00175         tp_2marker(fp, mark, *x++, *y++, size);
00176         counter = 1;            /* Already plotted one */
00177         for (i=1; i<npoints; i++) {
00178             if (counter >= interval) {
00179                 tp_2marker(fp, mark, *x, *y, size);
00180                 counter = 0;    /* We made a mark */
00181             }
00182             x++; y++;
00183             counter++;          /* One more point done */
00184         }
00185     }
00186 }
00187 
00188 
00189 /**
00190  *  This FORTRAN interface expects arrays of REALs (single precision).
00191  */
00192 void
00193 PL_FORTRAN(f2mlst, F2MLST)(FILE **fp, float *x, float *y, int *np, int *flag /* indicates user's mode request */, int *mark, int *interval, float *size)
00194 {
00195     register int i;                     /* index variable */
00196     register int counter;               /* interval counter */
00197     register int npoints = *np-1;
00198 
00199     if (npoints <= 0)
00200         return;
00201 
00202     if (*flag & TP_LINE)
00203         PL_FORTRAN(f2list, F2LIST)(fp, x, y, np);
00204     if (*flag & TP_MARK) {
00205         tp_2marker(*fp, *mark, *x++, *y++, *size);
00206         counter = 1;                    /* We already plotted one */
00207         for (i=1; i<npoints; i++) {
00208             if (counter >= *interval) {
00209                 tp_2marker(*fp, *mark, *x, *y, *size);
00210                 counter = 0;    /* Made a mark */
00211             }
00212             x++; y++;
00213             counter++;          /* One more point done */
00214         }
00215     }
00216 }
00217 
00218 
00219 /** @} */
00220 /*
00221  * Local Variables:
00222  * mode: C
00223  * tab-width: 8
00224  * indent-tabs-mode: t
00225  * c-file-style: "stroustrup"
00226  * End:
00227  * ex: shiftwidth=4 tabstop=8
00228  */
Generated on Tue Dec 11 13:14:27 2012 for LIBBN by  doxygen 1.6.3