00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 #ifndef lint
00051 static const char RCSid[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/libbn/axis.c,v 14.10 2006/09/02 14:02:14 lbutler Exp $ (BRL)";
00052 #endif
00053 
00054 #include "common.h"
00055 
00056 
00057 
00058 #include <stdio.h>
00059 #include <math.h>
00060 #ifdef HAVE_STRING_H
00061 #include <string.h>
00062 #else
00063 #include <strings.h>
00064 #endif
00065 
00066 #include "machine.h"
00067 #include "vmath.h"
00068 #include "plot3.h"
00069 
00070 #define TICK_YLEN       (char_width)    
00071 #define NUM_YOFF        (3*char_width)  
00072 #define TITLE_YOFF      (5*char_width)  
00073 
00074 void
00075 
00076 
00077 
00078 tp_3axis(FILE *fp,
00079          char *string,          
00080          fastf_t *origin,
00081          fastf_t *rot,
00082          double length,         
00083          int ccw,               
00084          int ndigits,           
00085          double label_start,    
00086          double label_incr,     
00087          double tick_separation,
00088          double char_width)     
00089 {
00090         register int i;
00091         int     nticks;
00092         point_t tick_bottom;                    
00093         vect_t  axis_incr;                      
00094         vect_t  axis_dir;
00095         point_t title_left;                     
00096         point_t cur_point;
00097         point_t num_start;
00098         point_t num_center;                     
00099         point_t num_last_end;                   
00100         vect_t  temp;
00101         vect_t  diff;
00102         mat_t   xlate_to_0;
00103         mat_t   mat;                            
00104         char    fmt[32];
00105         char    str[64];
00106 
00107         
00108         if( ccw )
00109                 ccw = -1;                       
00110         else
00111                 ccw = 1;                        
00112 
00113         if( NEAR_ZERO(tick_separation, SMALL) )  tick_separation = 1;
00114 
00115         
00116 
00117 
00118 
00119 
00120 
00121 
00122 
00123         MAT_IDN( xlate_to_0 );
00124         MAT_DELTAS( xlate_to_0,  origin[X],  origin[Y],  origin[Z] );
00125         bn_mat_mul( mat, rot, xlate_to_0 );
00126         VMOVE( cur_point, origin );
00127 
00128         
00129         VSET( temp, 0, -TICK_YLEN * ccw, 0 );
00130         MAT4X3PNT( tick_bottom, mat, temp );
00131 
00132         
00133         VSET( temp, 0, -NUM_YOFF * ccw, 0 );
00134         MAT4X3PNT( num_center, mat, temp );
00135         temp[X] = -char_width*ndigits;
00136         MAT4X3PNT( num_last_end, mat, temp );
00137 
00138         
00139         VSET( temp, 1, 0, 0 );
00140         MAT4X3VEC( axis_dir, mat, temp );
00141         VSCALE( axis_incr, axis_dir, tick_separation );
00142 
00143         
00144         VSET( temp, 0.5*(length - strlen(string)*char_width), -TITLE_YOFF*ccw, 0 );
00145         MAT4X3PNT( title_left, mat, temp );
00146         tp_3symbol(fp, string, title_left, rot, char_width );
00147 
00148         nticks = length/tick_separation+0.5;
00149         pdv_3move( fp, cur_point );
00150         for( i=0; i<=nticks; i++) {
00151                 
00152 
00153 
00154 
00155 
00156 
00157                 pdv_3cont( fp, tick_bottom );
00158 
00159                 if( ndigits > 0 )  {
00160                         double f;
00161                         sprintf( fmt, "%%%dg", ndigits);
00162                         sprintf( str, fmt, label_start );
00163                         f = strlen(str) * char_width * 0.5;
00164                         VJOIN1( num_start, num_center, -f, axis_dir );
00165 
00166                         
00167 
00168 
00169                         VSUB2( diff, num_start, num_last_end );
00170                         if( VDOT( diff, axis_dir ) >= 0 )  {
00171                                 tp_3symbol( fp, str, num_start, rot, char_width );
00172                                 VJOIN1( num_last_end, num_center, f, axis_dir );
00173                         }
00174                 }
00175 
00176                 if( i == nticks )  break;
00177 
00178                 
00179                 pdv_3move( fp, cur_point );
00180                 VADD2( cur_point, cur_point, axis_incr );
00181                 VADD2( tick_bottom, tick_bottom, axis_incr );
00182                 VADD2( num_center, num_center, axis_incr );
00183 
00184                 label_start += label_incr;
00185 
00186                 pdv_3cont( fp, cur_point);              
00187         }
00188 }
00189 
00190 void
00191 PL_FORTRAN(f3axis, F3AXIS)(fp, string, x, y, z, length, theta, ccw,
00192         ndigits, label_start, label_incr, tick_separation, char_width )
00193 FILE            **fp;
00194 char            *string;        
00195 float           *x,*y,*z;               
00196 float           *length;        
00197 float           *theta;         
00198 int             *ccw;
00199 int             *ndigits;       
00200 float           *label_start;   
00201 float           *label_incr;            
00202 float           *tick_separation;               
00203 float           *char_width;    
00204 {
00205         char buf[128];
00206         mat_t   mat;
00207         vect_t  pnt;
00208 
00209         VSET( pnt, *x, *y, *z );
00210         MAT_IDN(mat);
00211         bn_mat_angles( mat, 0.0, 0.0, *theta );
00212         strncpy( buf, string, sizeof(buf)-1 );
00213         buf[sizeof(buf)-1] = '\0';
00214         tp_3axis( *fp, buf, pnt, mat, *length, *ccw,
00215                 *ndigits, *label_start, *label_incr,
00216                 *tick_separation, *char_width );
00217 }
00218 
00219 
00220 
00221 
00222 
00223 
00224 
00225 
00226 
00227