ucdriver.h

00001 //
00002 //###########################################################################
00003 //                              UCDRIVER.H
00004 //###########################################################################
00005 // 
00006 //                  HEADER FILE FOR CLASS UCdriver          
00007 //
00008 //###########################################################################
00009 //
00010 //            Initial Version             : David Sansot
00011 //            Additions and Modifications : Chris Anderson 
00012 //
00013 //                            (C) UCLA 1994, 1995, 2004
00014 //###########################################################################
00015 //
00016 
00017 #ifndef _UCDRIVER_
00018 #define _UCDRIVER_  
00019 
00020 #include <string>
00021 #include <cstring>
00022 #include <iostream>
00023 #include <cstdlib>
00024 using namespace std;
00025 
00026 #define DEFAULT_INSTANCE  "graph.out"
00027 
00028 /**
00029    \class UCdriver
00030    \brief A virtual base class for two dimensional graphics.
00031 
00032     This class is extended to support different output devices
00033     (e.g. to a display window or PostScript file). Creating higher
00034     level graphics classes that utilize UCdriver methods enables the
00035     graphics output to be rendered on multiple output devices. 
00036     <p>
00037     The input coordinates to the graphics routines are assumed to be
00038     in the "normalized" drawing range [0,1]x[0,1].<p>
00039     
00040 <i>Source</i>: 
00041 <A HREF="../UCdriver.h">UCdriver.h</A><p>
00042 
00043 @author David Sansot, Chris Anderson (C) UCLA 1994-2009
00044 @version 1/31/09 
00045 */
00046 class UCdriver
00047 {
00048 
00049 public:
00050 
00051 //
00052 //###########################################################################
00053 //                      CONSTRUCTOR       
00054 //###########################################################################
00055 
00056 /** 
00057     Constructor, implements appropriate low level initialization for 
00058     the graphics system.
00059 
00060     The character string argument allows one to pass a name 
00061     (such as a file name) to the initialization routines.
00062     There is a default definition for this constructor 
00063     i.e. it is not a virtual function.
00064 
00065     
00066     @param s A character string to be 
00067     passed to initialization routine (e.g. a file name). 
00068 */
00069 UCdriver(const char *s = 0)
00070 {
00071     if (s)
00072     {
00073       instance = new(char[strlen(s) + 1]);
00074       strcpy(instance,s);
00075     }
00076     else
00077     {
00078       instance = new(char[strlen(DEFAULT_INSTANCE) + 1]);
00079       strcpy(instance,DEFAULT_INSTANCE);
00080     }
00081     dTypeName = 0;
00082     setDriverTypeName("UCdriver");
00083 };
00084 //
00085 //###########################################################################
00086 //                          DESTRUCTOR       
00087 //###########################################################################
00088 //
00089 /**
00090     Destructor, shuts down, or cleans up, the graphics system. 
00091 */ 
00092 virtual ~UCdriver(){delete [] instance; delete [] dTypeName;};
00093     
00094 //
00095 //###########################################################################
00096 //                          SETDRIVERTYPENAME
00097 //###########################################################################
00098 //
00099 /**
00100     Sets the name of the graphics driver. The default driver name is "UCdriver". 
00101     @param dName Character string specifying the driver name. 
00102 */ 
00103 virtual void setDriverTypeName(const char* dName)
00104 {
00105     if(dTypeName != 0) delete [] dTypeName;
00106     if((dName != 0)&&(strlen(dName) != 0))
00107     {
00108     dTypeName = new(char[strlen(dName) + 1]);
00109     }
00110     strcpy(dTypeName,dName);
00111 }
00112 /**
00113     Returns the name of the graphics driver. 
00114 */ 
00115 virtual const char* getDriverTypeName()
00116 {
00117  return dTypeName;
00118 }
00119  
00120 //
00121 //###########################################################################
00122 //                          LINE       
00123 //###########################################################################
00124 //
00125 /**
00126     Draws a line between the points (x1, y1) and (x2,y2).  
00127     
00128     <p>
00129     @param x1 The x-coordinate of 1st point (a value in [0,1])
00130 
00131     @param y1 The y-coordinate of 1st point (a value in [0,1])
00132 
00133     @param x2 The x-coordinate of 2nd point (a value in [0,1])
00134 
00135     @param y2 The y-coordinate of 2nd point (a value in [0,1])
00136 
00137     @param dash_pattern One of the enumerated dash constants. 
00138     A value of 0 (default) for dash_pattern corresponds to a solid line. 
00139     If equal to USER_DASH then the parameter user_pattern sets the dash pattern.
00140 
00141     @param user_pattern The last two bytes of this parameter are used to 
00142     represent the dash pattern if dash_pattern = USER_DASH.
00143 
00144     @param width  The width of the line as a fraction of the drawing window
00145     width.  For example, in the PostScript representation the
00146     default is 0.001.  Passing a value of 0 for width causes the
00147     default to be used.
00148 
00149     @param color One of the enumerated color constants values 
00150     specifying the color of the line. 
00151     If color == 0 the default color is used. 
00152     If color == USER_RGB then the parameter RGB is used to set the color.  
00153     
00154     @param RGB a three element double array with values between
00155     0 and 255 specifying the red, green and blue components of the color. 
00156     This parameter is only used if color == USER_RGB. 
00157 
00158 */
00159 virtual void line(double x1, double y1, double x2, double y2,
00160                   int dash_pattern, unsigned user_pattern, double width,
00161                   int color, double *RGB) = 0; 
00162 
00163 //
00164 //###########################################################################
00165 //                          LINES       
00166 //###########################################################################
00167 //
00168 /**
00169     Draws a connected set of line segments. The segment endpoints 
00170     are specified by (X[0],Y[0]), (X[1],Y[1]), ..., (X[npoints-1],Y[npoint-1]). 
00171   
00172     <p>
00173     @param X A double array of the x-coordinates of the segment endpoints (values in [0,1])
00174 
00175     @param Y A double array of the y-coordinates of the segment endpoints (values in [0,1])
00176 
00177     @param npoints The number of segment endpoints (typically the size of the X and Y arrays).
00178 
00179     @param dash_pattern One of the enumerated dash constants. 
00180     A value of 0 (default) for dash_pattern corresponds to a solid line. 
00181     If equal to USER_DASH then the parameter user_pattern sets the dash pattern.
00182 
00183     @param user_pattern The last two bytes of this parameter are used to 
00184     represent the dash pattern if dash_pattern = USER_DASH.
00185 
00186     @param width  The width of the line as a fraction of the drawing window
00187     width.  For example, in the PostScript representation the
00188     default is 0.001.  Passing a value of 0 for width causes the
00189     default to be used.
00190 
00191     @param color One of the enumerated color constants values 
00192     specifying the color of the line. 
00193     If color == 0 the default color is used. 
00194     If color == USER_RGB then the parameter RGB is used to set the color.  
00195     
00196     @param RGB A three element double array with values between
00197     0 and 255 specifying the red, green and blue components of the color.  
00198 */
00199 virtual void lines(double *X, double *Y, long npoints,
00200                   int dash_pattern, unsigned user_pattern, double width,
00201                   int color, double *RGB) = 0;
00202 
00203 //
00204 //###########################################################################
00205 //                          POINT       
00206 //###########################################################################
00207 //
00208 /**
00209     Draws the character c at a point.  
00210 
00211     <p>
00212     @param x  The x-coordinate of the point (a value in [0,1])
00213 
00214     @param y  The y-coordinate of the point (a value in [0,1])
00215 
00216     @param c  The character to be drawn
00217 
00218     @param font A character string specifying the font to be used. 
00219     If font == 0 the default font is used. 
00220 
00221     @param size  The relative size of the character with respect to 
00222     the drawing window. If size == 0, the default size value is used. 
00223 
00224     @param color One of the enumerated color constants values 
00225     specifying the color of the line. 
00226     If color == 0 the default color is used. 
00227     If color == USER_RGB then the parameter RGB is used to set the color.  
00228     
00229     @param RGB A three element double array with values between
00230     0 and 255 specifying the red, green and blue components of the color.  
00231  
00232 */
00233 virtual void point(double x, double y, char c, const char *font,
00234                      double size, int color, double *RGB) = 0;
00235 //
00236 //###########################################################################
00237 //                          POINTS       
00238 //###########################################################################
00239 //  
00240 /**
00241   Draws the character c at a collection of points. The coordinates of the points
00242   are specfied by the values in the X and Y arrays; e.g. 
00243   (X[0],y[0]), (X[1],Y[1]), ..., (X[npoint-1],Y[npoints-1]).
00244 
00245     <p>
00246     @param X A double array of the x-coordinates of point locations (values in [0,1])
00247 
00248     @param Y A double array of the y-coordinates of point locations (values in [0,1])
00249 
00250     @param npoints The number of points (typically the size of the X and Y arrays).
00251 
00252     @param c The character to be drawn
00253 
00254     @param font A character string specifying the font to be used. 
00255     If font == 0 the default font is used. 
00256 
00257     @param size  The relative size of the character with respect to 
00258     the drawing window. If size == 0, the default size value is used. 
00259 
00260     @param color One of the enumerated color constants values 
00261     specifying the color of the line. 
00262     If color == 0 the default color is used. 
00263     If color == USER_RGB then the parameter RGB is used to set the color.  
00264     
00265     @param RGB a three element double array with values between
00266     0 and 255 specifying the red, green and blue components of the color.  
00267  
00268 
00269 */
00270   
00271 virtual void points(double *X, double *Y, long npoints, char c,
00272                       const char *font, double size, int color,
00273                       double *RGB) = 0;
00274 
00275 //
00276 //###########################################################################
00277 //                          TEXT       
00278 //###########################################################################
00279 //
00280 /**
00281     Draws the string s at the reference point (x,y). 
00282     
00283     <p>
00284     @param x  The x-coordinate of the point (a value in [0,1])
00285 
00286     @param y  The y-coordinate of the point (a value in [0,1])
00287 
00288     @param s  A character string containing the characters to be drawn. 
00289 
00290     @param font A character string specifying the font to be used. 
00291     If font == 0 the default font is used. 
00292 
00293     @param size  The relative size of the characters with respect to 
00294     the drawing window. If size == 0, the default size value is used. 
00295 
00296     @param rotation The rotation of the string about the
00297     reference point in a counterclockwise direction. The angle is 
00298     specified in degrees.
00299 
00300     @param horiz_just The horizontal alignment of the string about the
00301     reference point. A values of 0 causes the string to be horizontally 
00302     centered about the reference point. A value of -1 causes the left 
00303     edge of the string to be lined up with the reference point, a 
00304     value of 1 lines up the right edge, and any other value the
00305     interpolation of these.  For example,  -0.5 causes the reference point
00306     to be located a forth of the string from the left edge of the
00307     string. Alignment is performed before any rotation.
00308 
00309     @param vert_just The vertical alignment of the string about the
00310     reference point. A values of 0 causes the
00311     string to be vertically centered about the reference point.
00312     A value of -1 causes the top  edge of the string to be lined up with 
00313     the reference point, a value of 1 lines up the bottom edge, 
00314     and any other value the interpolation of these.  
00315     For example,  -0.5 causes the reference point to be located a forth of 
00316     the string from the top edge of the string. 
00317     Alignment is performed before any rotation.
00318     
00319     @param color One of the enumerated color constants values 
00320     specifying the color of the line. 
00321     If color == 0 the default color is used. 
00322     If color == USER_RGB then the parameter RGB is used to set the color.  
00323     
00324     @param RGB A three element double array with values between
00325     0 and 255 specifying the red, green and blue components of the color.  
00326 
00327 */
00328 virtual void text(double x, double y, const char *s, const char *font,
00329                     double size, double rotation, double horiz_just,
00330                     double vert_just, int color, double *RGB) = 0;
00331 /**
00332     Draws a filled polygonal region whose vertices are 
00333     are specified by (X[0],Y[0]), (X[1],Y[1]), ..., (X[npoints-1],Y[npoint-1]),(X[0],Y[0]) 
00334 
00335     Note : The first point is not repeated in the polygonal list. 
00336   
00337     <p>
00338     @param X A double array of the x-coordinates of the polygon vertices (values in [0,1])
00339 
00340     @param Y A double array of the y-coordinates of the polygon vertices (values in [0,1])
00341 
00342     @param npoints The number of segment endpoints (typically the size of the X and Y arrays).
00343     
00344     @param RGB A three element double array with values between
00345     0 and 255 specifying the red, green and blue components of the color.  
00346 */
00347 virtual void region(double *X, double *Y, long npoints, double *RGB) = 0;
00348 
00349 
00350 //
00351 //###########################################################################
00352 //                          FRAME()      
00353 //###########################################################################
00354 //
00355 /**
00356    Clears the screen or advances the page.
00357 */
00358 virtual void frame() = 0; 
00359 //
00360 //###########################################################################
00361 //                      ENUMERATED CONSTANTS       
00362 //###########################################################################
00363 //
00364 //                        Dash patterns 
00365 //
00366 /**
00367 SOLID, DASH, DOUBLE_DASH, DASH_DOT,DASH_DOUBLE_DOT,DOTS, USER_DASH
00368 */
00369   enum dashConstants{SOLID, DASH, 
00370   DOUBLE_DASH, DASH_DOT,DASH_DOUBLE_DOT,DOTS, USER_DASH};
00371 
00372 //                           Colors 
00373 /** 
00374 BLACK, DARK_GREY, LIGHT_GREY, BLUE, LIGHT_BLUE, GREEN,
00375 LIGHT_GREEN, CYAN, LIGHT_CYAN,  RED, LIGHT_RED, MAGENTA,LIGHT_MAGENTA, ORANGE,
00376 YELLOW, WHITE, USER_RGB.
00377 */
00378   enum colorConstants{BLACK, DARK_GREY, LIGHT_GREY, BLUE, LIGHT_BLUE, GREEN,
00379         LIGHT_GREEN, CYAN, LIGHT_CYAN, RED, LIGHT_RED, MAGENTA,
00380         LIGHT_MAGENTA, ORANGE, YELLOW, WHITE, USER_RGB};
00381 
00382 protected :
00383 
00384   char *instance;          //  The name of the instance.  In the case of the
00385                            //  PostScript driver, this is used as the file
00386                            //  name.
00387 
00388   char *dTypeName;         //   Name of the driver class
00389 
00390 };
00391 #endif 
00392 
00393 

Generated on Tue Feb 17 11:57:13 2009 for QtGLgraphics by  doxygen 1.5.1-p1