symbol.c

Go to the documentation of this file.
00001 /*                        S Y M B O L . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 2004-2006 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  * as published by the Free Software Foundation; either version 2 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 
00022 /** \addtogroup plot */
00023 /*@{*/
00024 
00025 /** @file symbol.c
00026  *      Terminal Independant Graphics Display Package.
00027  *              Mike Muuss  July 31, 1978
00028  *
00029  *      This routine is used to plot a string of ASCII symbols
00030  *  on the plot being generated, using a built-in set of fonts
00031  *  drawn as vector lists.
00032  *
00033  *      Internally, the basic font resides in a 10x10 unit square.
00034  *  Externally, each character can be thought to occupy one square
00035  *  plotting unit;  the 'scale'
00036  *  parameter allows this to be changed as desired, although scale
00037  *  factors less than 10.0 are unlikely to be legible.
00038  *
00039  *  @author
00040  *      Michael John Muuss
00041  *
00042  *  @par Source -
00043  *      The U. S. Army Research Laboratory
00044  *@n    Aberdeen Proving Ground, Maryland  21005-5068  USA
00045  *
00046  */
00047 
00048 
00049 #ifndef lint
00050 static const char RCSid[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/libbn/symbol.c,v 14.10 2006/09/05 04:19:55 lbutler Exp $ (ARL)";
00051 #endif
00052 
00053 #include "common.h"
00054 
00055 
00056 
00057 #include <stdio.h>
00058 #ifdef HAVE_STRING_H
00059 #include <string.h>
00060 #else
00061 #include <strings.h>
00062 #endif
00063 #include <math.h>
00064 
00065 #include "machine.h"
00066 #include "vmath.h"
00067 #include "plot3.h"
00068 #include "vectfont.h"
00069 
00070 /*
00071  *                      T P _ 3 S Y M B O L
00072  */
00073 void
00074 tp_3symbol(FILE *fp, char *string, fastf_t *origin, fastf_t *rot, double scale)
00075 
00076                                 /* string of chars to be plotted */
00077                                 /* lower left corner of 1st char */
00078                                 /* Transform matrix (WARNING: may xlate) */
00079                                 /* scale factor to change 1x1 char sz */
00080 {
00081         register unsigned char *cp;
00082         double  offset;                 /* offset of char from given x,y */
00083         int     ysign;                  /* sign of y motion, either +1 or -1 */
00084         vect_t  temp;
00085         vect_t  loc;
00086         mat_t   xlate_to_origin;
00087         mat_t   mat;
00088 
00089         if( string == NULL || *string == '\0' )
00090                 return;                 /* done before begun! */
00091 
00092         /*
00093          *  The point "origin" will be the center of the axis rotation.
00094          *  The text is located in a local coordinate system with the
00095          *  lower left corner of the first character at (0,0,0), with
00096          *  the text proceeding onward towards +X.
00097          *  We need to rotate the text around it's local (0,0,0),
00098          *  and then translate to the user's designated "origin".
00099          *  If the user provided translation or
00100          *  scaling in his matrix, it will *also* be applied.
00101          */
00102         MAT_IDN( xlate_to_origin );
00103         MAT_DELTAS( xlate_to_origin,    origin[X], origin[Y], origin[Z] );
00104         bn_mat_mul( mat, xlate_to_origin, rot );
00105 
00106         /* Check to see if initialization is needed */
00107         if( tp_cindex[040] == 0 )  tp_setup();
00108 
00109         /* Draw each character in the input string */
00110         offset = 0;
00111         for( cp = (unsigned char *)string ; *cp; cp++, offset += scale )  {
00112                 register TINY   *p;     /* pointer to stroke table */
00113                 register int    stroke;
00114 
00115                 VSET( temp, offset, 0, 0 );
00116                 MAT4X3PNT( loc, mat, temp );
00117                 pdv_3move( fp, loc );
00118 
00119                 for( p = tp_cindex[*cp]; (stroke= *p) != LAST; p++ )  {
00120                         int     draw;
00121 
00122                         if( stroke==NEGY )  {
00123                                 ysign = (-1);
00124                                 stroke = *++p;
00125                         } else
00126                                 ysign = 1;
00127 
00128                         /* Detect & process pen control */
00129                         if( stroke < 0 )  {
00130                                 stroke = -stroke;
00131                                 draw = 0;
00132                         } else
00133                                 draw = 1;
00134 
00135                         /* stroke co-ordinates in string coord system */
00136                         VSET( temp, (stroke/11) * 0.1 * scale + offset,
00137                                    (ysign * (stroke%11)) * 0.1 * scale, 0 );
00138                         MAT4X3PNT( loc, mat, temp );
00139                         if( draw )
00140                                 pdv_3cont( fp, loc );
00141                         else
00142                                 pdv_3move( fp, loc );
00143                 }
00144         }
00145 }
00146 
00147 
00148 /*
00149  *                      T P _ 2 S Y M B O L
00150  */
00151 void
00152 tp_2symbol(FILE *fp, char *string, double x, double y, double scale, double theta)
00153 
00154                                 /* string of chars to be plotted */
00155                                 /* x,y of lower left corner of 1st char */
00156 
00157                                 /* scale factor to change 1x1 char sz */
00158                                 /* degrees ccw from X-axis */
00159 {
00160         mat_t   mat;
00161         vect_t  p;
00162 
00163         bn_mat_angles( mat, 0.0, 0.0, theta );
00164         VSET( p, x, y, 0 );
00165         tp_3symbol( fp, string, p, mat, scale );
00166 }
00167 
00168 /*
00169  *  This FORTRAN interface expects REAL args (single precision).
00170  */
00171 void
00172 PL_FORTRAN(f2symb, F2SYMB)( fp, string, x, y, scale, theta )
00173 FILE    **fp;
00174 char    *string;
00175 float   *x;
00176 float   *y;
00177 float   *scale;
00178 float   *theta;
00179 {
00180         char buf[128];
00181 
00182         strncpy( buf, string, sizeof(buf)-1 );
00183         buf[sizeof(buf)-1] = '\0';
00184         tp_2symbol( *fp, buf, *x, *y, *scale, *theta );
00185 }
00186 /*@}*/
00187 /*
00188  * Local Variables:
00189  * mode: C
00190  * tab-width: 8
00191  * c-basic-offset: 4
00192  * indent-tabs-mode: t
00193  * End:
00194  * ex: shiftwidth=4 tabstop=8
00195  */

Generated on Mon Sep 18 01:24:47 2006 for BRL-CAD by  doxygen 1.4.6