home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / GCC / GERLIB_DEV08B.LHA / gerlib / libg++ / etc / PlotFile3D / PlotFile3D.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  6.7 KB  |  224 lines

  1. // Header file for PlotFile3D class -*- C++ -*-
  2. /* 
  3. Copyright (C) 1990 Free Software Foundation
  4.     written by J. Thomas Ngo, Harvard University
  5.  
  6. This file is part of the GNU C++ Library.
  7.  
  8. The GNU C++ Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY.  No author or distributor accepts
  10. responsibility to anyone for the consequences of using it or for
  11. whether it serves any particular purpose or works at all, unless he
  12. says so in writing.  Refer to the GNU General Public License for full
  13. details.
  14.  
  15. Everyone is granted permission to copy, modify and redistribute The
  16. GNU C++ Library, but only under the conditions described in the GNU
  17. General Public License.  A copy of this license is supposed to have
  18. been given to you along with The GNU C++ Library so you can know your
  19. rights and responsibilities.  It should be in a file named COPYING.
  20. Among other things, the copyright notice and this notice must be
  21. preserved on all copies.  
  22. */
  23.  
  24.  
  25. #ifndef _PlotFile3D_h
  26. #ifdef __GNUG__
  27. #pragma interface
  28. #endif
  29. #define _PlotFile3D_h 1
  30.  
  31. //===========================================================================
  32. // Top-level declarations
  33. //===========================================================================
  34.  
  35. #include <builtin.h>
  36. #include <bool.h>
  37. #include <assert.h>
  38. #include <PlotFile.h>
  39. #include "Vec3D.h"
  40.  
  41. // constant implementation parameters
  42.  
  43. const int    umini = 0;        // Plot limits to send to 2D package
  44. const int    vmini = 0;
  45. const int    umaxi = 3120;
  46. const int    vmaxi = 3120;
  47.  
  48. const double margin = 0.9;     // How much leeway to give on edge of pic
  49.  
  50. class PlotFile3D : private PlotFile 
  51. {
  52. protected:
  53.  
  54.   // internal state
  55.  
  56.   Vec3D        intp;             // Internal idea of where cursor is in 3D
  57.   bool         valid3D;          // true if 3D cursor valid
  58.  
  59.   bool         stereo;           // true for stereo images
  60.   int          stereo_offset;    // Stereo separation in pixels (computed)
  61.   
  62.   Vec3D        ul,vl,wl;         // Basis vectors for the left or main image
  63.   Vec3D        ur,vr,wr;         // Basis for alternate image, if stereo
  64.   
  65.   double       scale;            // Amount by which to stretch u,v to fit
  66.   double       uorig, vorig;     // Offset for scaled u, v
  67.   
  68.   double*      sintab;           // tables, needed by circle, sphere
  69.   double*      costab;
  70.   int          ppq;              // points per quadrant in current table
  71.   
  72.   // helper functions
  73.  
  74.   // project 3D into 2D
  75.  
  76.   void         project(int&, int&, const Vec3D&, const Vec3D&,
  77.                        const Vec3D& rel) const;
  78.   
  79.   // All clipping handled here
  80.   
  81.   void         line2D(int u0, int v0, int u1, int v1);
  82.   
  83.   // Methods to handle state of 3D cursor:  defined or undefined
  84.   
  85.   void         define3D();
  86.   void         undefine3D();
  87.   void         must_be_valid3D();
  88.  
  89.   void initialize(bool stereo, double th, double ph);
  90.   
  91. public:
  92.   
  93.   PlotFile3D(bool st=FALSE, double th=M_PI/12, double ph=M_PI/3)
  94.       : PlotFile() { initialize(st, th, ph); }
  95.   PlotFile3D(int fd, bool st=FALSE, double th=M_PI/12,double ph=M_PI/3)
  96.       : PlotFile(fd) { initialize(st, th, ph); }
  97.   PlotFile3D(const char *name,
  98.          bool st=FALSE, double th=M_PI/12,double ph=M_PI/3)
  99.       : PlotFile(name) { initialize(st, th, ph); }
  100. #ifdef _OLD_STREAMS
  101.   PlotFile3D(FILE* fp, bool st=FALSE, double th=M_PI/12,double ph=M_PI/3)
  102.       : PlotFile(fp) { initialize(st, th, ph); }
  103. #endif
  104.                ~PlotFile3D();
  105.  
  106.    // plot commands taking Vec3D args
  107.  
  108.    PlotFile3D&  space (const Vec3D& p0, const Vec3D& p1);
  109.  
  110.    PlotFile3D&  move  (const Vec3D& p);
  111.    PlotFile3D&  cont  (const Vec3D& p);
  112.    PlotFile3D&  line  (const Vec3D& p0, const Vec3D& p1);
  113.    PlotFile3D&  point (const Vec3D& p);
  114.  
  115.    PlotFile3D&  box   (const Vec3D& p0, const Vec3D& p1);
  116.    PlotFile3D&  circle(const Vec3D& center, const Vec3D& radius,
  117.                        const int points_per_quadrant =10 );
  118.  
  119.    // This one has no PlotFile analog
  120.    PlotFile3D&  sphere(const Vec3D& center, const Vec3D& radius,
  121.                        const int points_per_quadrant =10 );
  122.  
  123.    // versions taking raw coordinates
  124.  
  125.    PlotFile3D&  space (const double x0, const double y0, const double z0,
  126.                        const double x1, const double y1, const double z1);
  127.    PlotFile3D&  move  (const double xi, const double yi, const double zi);
  128.    PlotFile3D&  cont  (const double xi, const double yi, const double zi);
  129.    PlotFile3D&  line  (const double x0, const double y0, const double z0,
  130.                        const double x1, const double y1, const double z1);
  131.    PlotFile3D&  point (const double xi, const double yi, const double zi);
  132.    PlotFile3D&  box   (const double x0, const double y0, const double z0,
  133.                        const double x1, const double y1, const double z1);
  134.    PlotFile3D&  circle(const double cx, const double cy, const double cz,
  135.                        const double rx, const double ry, const double rz,
  136.                        const int points_per_quadrant =10 );
  137.    PlotFile3D&  sphere(const double cx, const double cy, const double cz,
  138.                        const double rx, const double ry, const double rz,
  139.                        const int points_per_quadrant =10 );
  140.  
  141.   // For convenience
  142.  
  143.   PlotFile3D&  home(); // Move cursor to upper left, out of the way
  144.   
  145.   // These plot commands get passed right to PlotFile
  146.   
  147.   PlotFile3D&  erase();
  148.   PlotFile3D&  label(const char* s);
  149.   PlotFile3D&  linemod(const char* s);
  150.   
  151.   // Error handling
  152.   void error(const char* s) const;
  153. };
  154.  
  155. // Handling of valid3D
  156.  
  157. inline void PlotFile3D::define3D() 
  158.   valid3D = TRUE;
  159. }
  160.  
  161. inline void PlotFile3D::undefine3D() 
  162.   valid3D = FALSE;
  163. }
  164.  
  165. inline void PlotFile3D::must_be_valid3D() 
  166. {
  167.   assert(valid3D);
  168. }
  169.  
  170. // Versions of routines that take coordinates as Vec3D
  171.  
  172. inline PlotFile3D& PlotFile3D::line(const Vec3D& p0, const Vec3D& p1)
  173.   move(p0); return cont(p1);
  174. }
  175.  
  176. inline PlotFile3D& PlotFile3D::point(const Vec3D& p)
  177.   return line(p, p);
  178. }
  179.  
  180. // Versions of routines that take coordinates as doubles
  181.  
  182. inline PlotFile3D& PlotFile3D::line(const double x0, const double y0, 
  183.                                     const double z0,
  184.                                     const double x1, const double y1, 
  185.                                     const double z1)
  186.   Vec3D p0(x0, y0, z0);
  187.   Vec3D p1(x1, y1, z1);
  188.   move(p0);
  189.   return cont(p1);
  190. }
  191.  
  192. inline PlotFile3D& PlotFile3D::point(const double xi, const double yi, 
  193.                                      const double zi)
  194.   Vec3D p(xi, yi, zi);
  195.   return line(p, p);
  196. }
  197.  
  198. // Versions of routines that take no coordinates
  199.  
  200. inline PlotFile3D& PlotFile3D::erase() 
  201.   PlotFile::erase(); return home(); 
  202. }
  203.  
  204. inline PlotFile3D& PlotFile3D::label(const char* s) 
  205.   PlotFile::label(s); return home(); 
  206.  
  207. }
  208.  
  209. inline PlotFile3D& PlotFile3D::linemod(const char* s) 
  210.   PlotFile::linemod(s); return *this; 
  211. }
  212.  
  213.  
  214. #endif              // _PlotFile3D_h
  215.