plot3.c

Go to the documentation of this file.
00001 /*                         P L O T 3 . 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/plot3.c
00023  *
00024  * @brief A public-domain UNIX plot library, for 2-D and 3-D plotting
00025  * in 16-bit VAX signed integer spaces, or 64-bit IEEE floating point.
00026  *
00027  * These routines generate "UNIX plot" output (with the addition of
00028  * 3-D commands).  They behave almost exactly like the regular libplot
00029  * routines, except:
00030  *
00031  * -# These all take a stdio file pointer, and can thus be used to
00032  *    create multiple plot files simultaneously.
00033  * -# There are 3-D versions of most commands.
00034  * -# There are IEEE floating point versions of the commands.
00035  * -# The names have been changed.
00036  *
00037  * The 3-D extensions are those of Doug Gwyn, from his System V
00038  * extensions.
00039  *
00040  * These are the ascii command letters allocated to various actions.
00041  * Care has been taken to consistently match lowercase and uppercase
00042  * letters.
00043  *
00044  * @code
00045                 2d      3d      2df     3df
00046 space           s       S       w       W
00047 move            m       M       o       O
00048 cont            n       N       q       Q
00049 point           p       P       x       X
00050 line            l       L       v       V
00051 circle          c               i
00052 arc             a               r
00053 linmod          f
00054 label           t
00055 erase           e
00056 color           C
00057 flush           F
00058 
00059  bd gh jk  uyz
00060 ABDEGHIJKRTUYZ
00061 
00062 @endcode
00063  *
00064  */
00065 
00066 #include "common.h"
00067 
00068 #include <stdio.h>
00069 
00070 #include "vmath.h"
00071 #include "plot3.h"
00072 
00073 
00074 static int pl_outputMode = PL_OUTPUT_MODE_BINARY;
00075 
00076 /** For the sake of efficiency, we trust putc() to write only one byte */
00077 /*#define putsi(a)      putc(a&0377, plotfp); putc((a>>8)&0377, plotfp)*/
00078 #define putsi(a)        putc(a, plotfp); putc((a>>8), plotfp)
00079 
00080 
00081 /*
00082  * These interfaces provide the standard UNIX-Plot functionality
00083  */
00084 
00085 int
00086 pl_getOutputMode() {
00087     return pl_outputMode;
00088 }
00089 
00090 void
00091 pl_setOutputMode(int mode) {
00092     pl_outputMode = mode;
00093 }
00094 
00095 /**
00096  * @brief
00097  * plot a point
00098  */
00099 void
00100 pl_point(register FILE *plotfp, int x, int y)
00101 {
00102     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00103         putc('p', plotfp);
00104         putsi(x);
00105         putsi(y);
00106     } else {
00107         fprintf(plotfp, "p %d %d\n", x, y);
00108     }
00109 }
00110 
00111 void
00112 pl_line(register FILE *plotfp, int px1, int py1, int px2, int py2)
00113 {
00114     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00115         putc('l', plotfp);
00116         putsi(px1);
00117         putsi(py1);
00118         putsi(px2);
00119         putsi(py2);
00120     } else {
00121         fprintf(plotfp, "l %d %d %d %d\n", px1, py1, px2, py2);
00122     }
00123 }
00124 
00125 void
00126 pl_linmod(register FILE *plotfp, register char *s)
00127 {
00128     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00129         putc('f', plotfp);
00130         while (*s)
00131             putc(*s++, plotfp);
00132         putc('\n', plotfp);
00133     } else {
00134         fprintf(plotfp, "f %s\n", s);
00135     }
00136 }
00137 
00138 void
00139 pl_move(register FILE *plotfp, int x, int y)
00140 {
00141     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00142         putc('m', plotfp);
00143         putsi(x);
00144         putsi(y);
00145     } else {
00146         fprintf(plotfp, "m %d %d\n", x, y);
00147     }
00148 }
00149 
00150 void
00151 pl_cont(register FILE *plotfp, int x, int y)
00152 {
00153     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00154         putc('n', plotfp);
00155         putsi(x);
00156         putsi(y);
00157     } else {
00158         fprintf(plotfp, "n %d %d\n", x, y);
00159     }
00160 }
00161 
00162 void
00163 pl_label(register FILE *plotfp, register char *s)
00164 {
00165     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00166         putc('t', plotfp);
00167         while (*s)
00168             putc(*s++, plotfp);
00169         putc('\n', plotfp);
00170     } else {
00171         fprintf(plotfp, "t %s\n", s);
00172     }
00173 }
00174 
00175 void
00176 pl_space(register FILE *plotfp, int px1, int py1, int px2, int py2)
00177 {
00178     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00179         putc('s', plotfp);
00180         putsi(px1);
00181         putsi(py1);
00182         putsi(px2);
00183         putsi(py2);
00184     } else {
00185         fprintf(plotfp, "s %d %d %d %d\n", px1, py1, px2, py2);
00186     }
00187 }
00188 
00189 void
00190 pl_erase(register FILE *plotfp)
00191 {
00192     if (pl_outputMode == PL_OUTPUT_MODE_BINARY)
00193         putc('e', plotfp);
00194     else
00195         fprintf(plotfp, "e\n");
00196 }
00197 
00198 void
00199 pl_circle(register FILE *plotfp, int x, int y, int r)
00200 {
00201     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00202         putc('c', plotfp);
00203         putsi(x);
00204         putsi(y);
00205         putsi(r);
00206     } else {
00207         fprintf(plotfp, "c %d %d %d\n", x, y, r);
00208     }
00209 }
00210 
00211 void
00212 pl_arc(register FILE *plotfp, int xc, int yc, int px1, int py1, int px2, int py2)
00213 {
00214     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00215         putc('a', plotfp);
00216         putsi(xc);
00217         putsi(yc);
00218         putsi(px1);
00219         putsi(py1);
00220         putsi(px2);
00221         putsi(py2);
00222     } else {
00223         fprintf(plotfp, "a %d %d %d %d %d %d\n", xc, yc, px1, py1, px2, py2);
00224     }
00225 }
00226 
00227 void
00228 pl_box(register FILE *plotfp, int px1, int py1, int px2, int py2)
00229 {
00230     pl_move(plotfp, px1, py1);
00231     pl_cont(plotfp, px1, py2);
00232     pl_cont(plotfp, px2, py2);
00233     pl_cont(plotfp, px2, py1);
00234     pl_cont(plotfp, px1, py1);
00235     pl_move(plotfp, px2, py2);
00236 }
00237 
00238 /*
00239  * Here lie the BRL 3-D extensions.
00240  */
00241 
00242 /** Warning: r, g, b are ints.  The output is chars. */
00243 void
00244 pl_color(register FILE *plotfp, int r, int g, int b)
00245 {
00246     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00247         putc('C', plotfp);
00248         putc(r, plotfp);
00249         putc(g, plotfp);
00250         putc(b, plotfp);
00251     } else {
00252         fprintf(plotfp, "C %d %d %d\n", r, g, b);
00253     }
00254 }
00255 
00256 void
00257 pl_flush(register FILE *plotfp)
00258 {
00259     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00260         putc('F', plotfp);
00261     } else {
00262         fprintf(plotfp, "F\n");
00263     }
00264 
00265     fflush(plotfp);
00266 }
00267 
00268 void
00269 pl_3space(register FILE *plotfp, int px1, int py1, int pz1, int px2, int py2, int pz2)
00270 {
00271     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00272         putc('S', plotfp);
00273         putsi(px1);
00274         putsi(py1);
00275         putsi(pz1);
00276         putsi(px2);
00277         putsi(py2);
00278         putsi(pz2);
00279     } else {
00280         fprintf(plotfp, "S %d %d %d %d %d %d\n", px1, py1, pz1, px2, py2, pz2);
00281     }
00282 }
00283 
00284 void
00285 pl_3point(register FILE *plotfp, int x, int y, int z)
00286 {
00287     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00288         putc('P', plotfp);
00289         putsi(x);
00290         putsi(y);
00291         putsi(z);
00292     } else {
00293         fprintf(plotfp, "P %d %d %d\n", x, y, z);
00294     }
00295 }
00296 
00297 void
00298 pl_3move(register FILE *plotfp, int x, int y, int z)
00299 {
00300     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00301         putc('M', plotfp);
00302         putsi(x);
00303         putsi(y);
00304         putsi(z);
00305     } else {
00306         fprintf(plotfp, "M %d %d %d\n", x, y, z);
00307     }
00308 }
00309 
00310 void
00311 pl_3cont(register FILE *plotfp, int x, int y, int z)
00312 {
00313     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00314         putc('N', plotfp);
00315         putsi(x);
00316         putsi(y);
00317         putsi(z);
00318     } else {
00319         fprintf(plotfp, "N %d %d %d\n", x, y, z);
00320     }
00321 }
00322 
00323 void
00324 pl_3line(register FILE *plotfp, int px1, int py1, int pz1, int px2, int py2, int pz2)
00325 {
00326     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00327         putc('L', plotfp);
00328         putsi(px1);
00329         putsi(py1);
00330         putsi(pz1);
00331         putsi(px2);
00332         putsi(py2);
00333         putsi(pz2);
00334     } else {
00335         fprintf(plotfp, "L %d %d %d %d %d %d\n", px1, py1, pz1, px2, py2, pz2);
00336     }
00337 }
00338 
00339 void
00340 pl_3box(register FILE *plotfp, int px1, int py1, int pz1, int px2, int py2, int pz2)
00341 {
00342     pl_3move(plotfp, px1, py1, pz1);
00343     /* first side */
00344     pl_3cont(plotfp, px1, py2, pz1);
00345     pl_3cont(plotfp, px1, py2, pz2);
00346     pl_3cont(plotfp, px1, py1, pz2);
00347     pl_3cont(plotfp, px1, py1, pz1);
00348     /* across */
00349     pl_3cont(plotfp, px2, py1, pz1);
00350     /* second side */
00351     pl_3cont(plotfp, px2, py2, pz1);
00352     pl_3cont(plotfp, px2, py2, pz2);
00353     pl_3cont(plotfp, px2, py1, pz2);
00354     pl_3cont(plotfp, px2, py1, pz1);
00355     /* front edge */
00356     pl_3move(plotfp, px1, py2, pz1);
00357     pl_3cont(plotfp, px2, py2, pz1);
00358     /* bottom back */
00359     pl_3move(plotfp, px1, py1, pz2);
00360     pl_3cont(plotfp, px2, py1, pz2);
00361     /* top back */
00362     pl_3move(plotfp, px1, py2, pz2);
00363     pl_3cont(plotfp, px2, py2, pz2);
00364 }
00365 
00366 /*
00367  * Double floating point versions
00368  */
00369 
00370 void
00371 pd_point(register FILE *plotfp, double x, double y)
00372 {
00373     size_t ret;
00374     double in[2];
00375     unsigned char out[2*8+1];
00376 
00377     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00378         in[0] = x;
00379         in[1] = y;
00380         htond(&out[1], (unsigned char *)in, 2);
00381 
00382         out[0] = 'x';
00383         ret = fwrite(out, 1, 2*8+1, plotfp);
00384         if (ret != 2*8+1) {
00385             perror("fwrite");
00386         }
00387     } else {
00388         fprintf(plotfp, "x %g %g\n", x, y);
00389     }
00390 }
00391 
00392 void
00393 pd_line(register FILE *plotfp, double px1, double py1, double px2, double py2)
00394 {
00395     size_t ret;
00396     double in[4];
00397     unsigned char out[4*8+1];
00398 
00399     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00400         in[0] = px1;
00401         in[1] = py1;
00402         in[2] = px2;
00403         in[3] = py2;
00404         htond(&out[1], (unsigned char *)in, 4);
00405 
00406         out[0] = 'v';
00407         ret = fwrite(out, 1, 4*8+1, plotfp);
00408         if (ret != 4*8+1) {
00409             perror("fwrite");
00410         }
00411     } else {
00412         fprintf(plotfp, "v %g %g %g %g\n", px1, py1, px2, py2);
00413     }
00414 }
00415 
00416 /** Note: no pd_linmod(), just use pl_linmod() */
00417 
00418 void
00419 pd_move(register FILE *plotfp, double x, double y)
00420 {
00421     size_t ret;
00422     double in[2];
00423     unsigned char out[2*8+1];
00424 
00425     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00426         in[0] = x;
00427         in[1] = y;
00428         htond(&out[1], (unsigned char *)in, 2);
00429 
00430         out[0] = 'o';
00431         ret = fwrite(out, 1, 2*8+1, plotfp);
00432         if (ret != 2*8+1) {
00433             perror("fwrite");
00434         }
00435     } else {
00436         fprintf(plotfp, "o %g %g\n", x, y);
00437     }
00438 }
00439 
00440 void
00441 pd_cont(register FILE *plotfp, double x, double y)
00442 {
00443     size_t ret;
00444     double in[2];
00445     unsigned char out[2*8+1];
00446 
00447     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00448         in[0] = x;
00449         in[1] = y;
00450         htond(&out[1], (unsigned char *)in, 2);
00451 
00452         out[0] = 'q';
00453         ret = fwrite(out, 1, 2*8+1, plotfp);
00454         if (ret != 2*8+1) {
00455             perror("fwrite");
00456         }
00457     } else {
00458         fprintf(plotfp, "q %g %g\n", x, y);
00459     }
00460 }
00461 
00462 void
00463 pd_space(register FILE *plotfp, double px1, double py1, double px2, double py2)
00464 {
00465     size_t ret;
00466     double in[4];
00467     unsigned char out[4*8+1];
00468 
00469     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00470         in[0] = px1;
00471         in[1] = py1;
00472         in[2] = px2;
00473         in[3] = py2;
00474         htond(&out[1], (unsigned char *)in, 4);
00475 
00476         out[0] = 'w';
00477         ret = fwrite(out, 1, 4*8+1, plotfp);
00478         if (ret != 4*8+1) {
00479             perror("fwrite");
00480         }
00481     } else {
00482         fprintf(plotfp, "w %g %g %g %g\n", px1, py1, px2, py2);
00483     }
00484 }
00485 
00486 void
00487 pd_circle(register FILE *plotfp, double x, double y, double r)
00488 {
00489     size_t ret;
00490     double in[3];
00491     unsigned char out[3*8+1];
00492 
00493     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00494         in[0] = x;
00495         in[1] = y;
00496         in[2] = r;
00497         htond(&out[1], (unsigned char *)in, 3);
00498 
00499         out[0] = 'i';
00500         ret = fwrite(out, 1, 3*8+1, plotfp);
00501         if (ret != 3*8+1) {
00502             perror("fwrite");
00503         }
00504     } else {
00505         fprintf(plotfp, "i %g %g %g\n", x, y, r);
00506     }
00507 }
00508 
00509 void
00510 pd_arc(register FILE *plotfp, double xc, double yc, double px1, double py1, double px2, double py2)
00511 {
00512     size_t ret;
00513     double in[6];
00514     unsigned char out[6*8+1];
00515 
00516     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00517         in[0] = xc;
00518         in[1] = yc;
00519         in[2] = px1;
00520         in[3] = py1;
00521         in[4] = px2;
00522         in[5] = py2;
00523         htond(&out[1], (unsigned char *)in, 6);
00524 
00525         out[0] = 'r';
00526         ret = fwrite(out, 1, 6*8+1, plotfp);
00527         if (ret != 6*8+1) {
00528             perror("fwrite");
00529         }
00530     } else {
00531         fprintf(plotfp, "r %g %g %g %g %g %g\n", xc, yc, px1, py1, px2, py2);
00532     }
00533 }
00534 
00535 void
00536 pd_box(register FILE *plotfp, double px1, double py1, double px2, double py2)
00537 {
00538     pd_move(plotfp, px1, py1);
00539     pd_cont(plotfp, px1, py2);
00540     pd_cont(plotfp, px2, py2);
00541     pd_cont(plotfp, px2, py1);
00542     pd_cont(plotfp, px1, py1);
00543     pd_move(plotfp, px2, py2);
00544 }
00545 
00546 /* Double 3-D, both in vector and enumerated versions */
00547 void
00548 pdv_3space(register FILE *plotfp, const fastf_t *min, const fastf_t *max)
00549 {
00550     size_t ret;
00551     unsigned char out[6*8+1];
00552 
00553     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00554         htond(&out[1], (unsigned char *)min, 3);
00555         htond(&out[3*8+1], (unsigned char *)max, 3);
00556 
00557         out[0] = 'W';
00558         ret = fwrite(out, 1, 6*8+1, plotfp);
00559         if (ret != 6*8+1) {
00560             perror("fwrite");
00561         }
00562     } else {
00563         fprintf(plotfp, "W %g %g %g %g %g %g\n", V3ARGS(min), V3ARGS(max));
00564     }
00565 }
00566 
00567 void
00568 pd_3space(register FILE *plotfp, double px1, double py1, double pz1, double px2, double py2, double pz2)
00569 {
00570     size_t ret;
00571     double in[6];
00572     unsigned char out[6*8+1];
00573 
00574     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00575         in[0] = px1;
00576         in[1] = py1;
00577         in[2] = pz1;
00578         in[3] = px2;
00579         in[4] = py2;
00580         in[5] = pz2;
00581         htond(&out[1], (unsigned char *)in, 6);
00582 
00583         out[0] = 'W';
00584         ret = fwrite(out, 1, 6*8+1, plotfp);
00585         if (ret != 6*8+1) {
00586             perror("fwrite");
00587         }
00588     } else {
00589         fprintf(plotfp, "W %g %g %g %g %g %g\n", px1, py1, pz1, px2, py2, pz2);
00590     }
00591 }
00592 
00593 void
00594 pdv_3point(register FILE *plotfp, const fastf_t *pt)
00595 {
00596     size_t ret;
00597     unsigned char out[3*8+1];
00598 
00599     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00600         htond(&out[1], (unsigned char *)pt, 3);
00601 
00602         out[0] = 'X';
00603         ret = fwrite(out, 1, 3*8+1, plotfp);
00604         if (ret != 3*8+1) {
00605             perror("fwrite");
00606         }
00607     } else {
00608         fprintf(plotfp, "X %g %g %g\n", V3ARGS(pt));
00609     }
00610 }
00611 
00612 void
00613 pd_3point(register FILE *plotfp, double x, double y, double z)
00614 {
00615     size_t ret;
00616     double in[3];
00617     unsigned char out[3*8+1];
00618 
00619     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00620         in[0] = x;
00621         in[1] = y;
00622         in[2] = z;
00623         htond(&out[1], (unsigned char *)in, 3);
00624 
00625         out[0] = 'X';
00626         ret = fwrite(out, 1, 3*8+1, plotfp);
00627         if (ret != 3*8+1) {
00628             perror("fwrite");
00629         }
00630     } else {
00631         fprintf(plotfp, "X %g %g %g\n", x, y, z);
00632     }
00633 }
00634 
00635 void
00636 pdv_3move(register FILE *plotfp, const fastf_t *pt)
00637 {
00638     size_t ret;
00639     unsigned char out[3*8+1];
00640 
00641     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00642         htond(&out[1], (unsigned char *)pt, 3);
00643 
00644         out[0] = 'O';
00645         ret = fwrite(out, 1, 3*8+1, plotfp);
00646         if (ret != 3*8+1) {
00647             perror("fwrite");
00648         }
00649     } else {
00650         fprintf(plotfp, "O %g %g %g\n", V3ARGS(pt));
00651     }
00652 }
00653 
00654 void
00655 pd_3move(register FILE *plotfp, double x, double y, double z)
00656 {
00657     size_t ret;
00658     double in[3];
00659     unsigned char out[3*8+1];
00660 
00661     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00662         in[0] = x;
00663         in[1] = y;
00664         in[2] = z;
00665         htond(&out[1], (unsigned char *)in, 3);
00666 
00667         out[0] = 'O';
00668         ret = fwrite(out, 1, 3*8+1, plotfp);
00669         if (ret != 3*8+1) {
00670             perror("fwrite");
00671         }
00672     } else {
00673         fprintf(plotfp, "O %g %g %g\n", x, y, z);
00674     }
00675 }
00676 
00677 void
00678 pdv_3cont(register FILE *plotfp, const fastf_t *pt)
00679 {
00680     size_t ret;
00681     unsigned char out[3*8+1];
00682 
00683     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00684         htond(&out[1], (unsigned char *)pt, 3);
00685 
00686         out[0] = 'Q';
00687         ret = fwrite(out, 1, 3*8+1, plotfp);
00688         if (ret != 3*8+1) {
00689             perror("fwrite");
00690         }
00691     } else {
00692         fprintf(plotfp, "Q %g %g %g\n", V3ARGS(pt));
00693     }
00694 }
00695 
00696 void
00697 pd_3cont(register FILE *plotfp, double x, double y, double z)
00698 {
00699     size_t ret;
00700     double in[3];
00701     unsigned char out[3*8+1];
00702 
00703     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00704         in[0] = x;
00705         in[1] = y;
00706         in[2] = z;
00707         htond(&out[1], (unsigned char *)in, 3);
00708 
00709         out[0] = 'Q';
00710         ret = fwrite(out, 1, 3*8+1, plotfp);
00711         if (ret != 3*8+1) {
00712             perror("fwrite");
00713         }
00714     } else {
00715         fprintf(plotfp, "Q %g %g %g\n", x, y, z);
00716     }
00717 }
00718 
00719 void
00720 pdv_3line(register FILE *plotfp, const fastf_t *a, const fastf_t *b)
00721 {
00722     size_t ret;
00723     unsigned char out[6*8+1];
00724 
00725     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00726         htond(&out[1], (unsigned char *)a, 3);
00727         htond(&out[3*8+1], (unsigned char *)b, 3);
00728 
00729         out[0] = 'V';
00730         ret = fwrite(out, 1, 6*8+1, plotfp);
00731         if (ret != 6*8+1) {
00732             perror("fwrite");
00733         }
00734     } else {
00735         fprintf(plotfp, "V %g %g %g %g %g %g\n", V3ARGS(a), V3ARGS(b));
00736     }
00737 }
00738 
00739 void
00740 pd_3line(register FILE *plotfp, double px1, double py1, double pz1, double px2, double py2, double pz2)
00741 {
00742     size_t ret;
00743     double in[6];
00744     unsigned char out[6*8+1];
00745 
00746     if (pl_outputMode == PL_OUTPUT_MODE_BINARY) {
00747         in[0] = px1;
00748         in[1] = py1;
00749         in[2] = pz1;
00750         in[3] = px2;
00751         in[4] = py2;
00752         in[5] = pz2;
00753         htond(&out[1], (unsigned char *)in, 6);
00754 
00755         out[0] = 'V';
00756         ret = fwrite(out, 1, 6*8+1, plotfp);
00757         if (ret != 6*8+1) {
00758             perror("fwrite");
00759         }
00760     } else {
00761         fprintf(plotfp, "V %g %g %g %g %g %g\n", px1, py1, pz1, px2, py2, pz2);
00762     }
00763 }
00764 
00765 void
00766 pdv_3box(register FILE *plotfp, const fastf_t *a, const fastf_t *b)
00767 {
00768     pd_3move(plotfp, a[X], a[Y], a[Z]);
00769     /* first side */
00770     pd_3cont(plotfp, a[X], b[Y], a[Z]);
00771     pd_3cont(plotfp, a[X], b[Y], b[Z]);
00772     pd_3cont(plotfp, a[X], a[Y], b[Z]);
00773     pd_3cont(plotfp, a[X], a[Y], a[Z]);
00774     /* across */
00775     pd_3cont(plotfp, b[X], a[Y], a[Z]);
00776     /* second side */
00777     pd_3cont(plotfp, b[X], b[Y], a[Z]);
00778     pd_3cont(plotfp, b[X], b[Y], b[Z]);
00779     pd_3cont(plotfp, b[X], a[Y], b[Z]);
00780     pd_3cont(plotfp, b[X], a[Y], a[Z]);
00781     /* front edge */
00782     pd_3move(plotfp, a[X], b[Y], a[Z]);
00783     pd_3cont(plotfp, b[X], b[Y], a[Z]);
00784     /* bottom back */
00785     pd_3move(plotfp, a[X], a[Y], b[Z]);
00786     pd_3cont(plotfp, b[X], a[Y], b[Z]);
00787     /* top back */
00788     pd_3move(plotfp, a[X], b[Y], b[Z]);
00789     pd_3cont(plotfp, b[X], b[Y], b[Z]);
00790 }
00791 
00792 void
00793 pd_3box(register FILE *plotfp, double px1, double py1, double pz1, double px2, double py2, double pz2)
00794 {
00795     pd_3move(plotfp, px1, py1, pz1);
00796     /* first side */
00797     pd_3cont(plotfp, px1, py2, pz1);
00798     pd_3cont(plotfp, px1, py2, pz2);
00799     pd_3cont(plotfp, px1, py1, pz2);
00800     pd_3cont(plotfp, px1, py1, pz1);
00801     /* across */
00802     pd_3cont(plotfp, px2, py1, pz1);
00803     /* second side */
00804     pd_3cont(plotfp, px2, py2, pz1);
00805     pd_3cont(plotfp, px2, py2, pz2);
00806     pd_3cont(plotfp, px2, py1, pz2);
00807     pd_3cont(plotfp, px2, py1, pz1);
00808     /* front edge */
00809     pd_3move(plotfp, px1, py2, pz1);
00810     pd_3cont(plotfp, px2, py2, pz1);
00811     /* bottom back */
00812     pd_3move(plotfp, px1, py1, pz2);
00813     pd_3cont(plotfp, px2, py1, pz2);
00814     /* top back */
00815     pd_3move(plotfp, px1, py2, pz2);
00816     pd_3cont(plotfp, px2, py2, pz2);
00817 }
00818 
00819 /**
00820  * Draw a ray
00821  */
00822 void
00823 pdv_3ray(FILE *fp, const fastf_t *pt, const fastf_t *dir, double t)
00824 {
00825     point_t tip;
00826 
00827     VJOIN1(tip, pt, t, dir);
00828     pdv_3move(fp, pt);
00829     pdv_3cont(fp, tip);
00830 }
00831 
00832 /** @} */
00833 /*
00834  * Local Variables:
00835  * mode: C
00836  * tab-width: 8
00837  * indent-tabs-mode: t
00838  * c-file-style: "stroustrup"
00839  * End:
00840  * ex: shiftwidth=4 tabstop=8
00841  */
Generated on Tue Dec 11 13:14:27 2012 for LIBBN by  doxygen 1.6.3