GLDriverQt.h

00001 //
00002 //###########################################################################
00003 //                            GLDriverQt.h
00004 //###########################################################################
00005 // 
00006 //                  HEADER FILE FOR CLASS GLDriverQt        
00007 //
00008 //###########################################################################
00009 //
00010 //###########################################################################
00011 //
00012 // 
00013 #include <QtOpenGL>
00014 
00015 #include "ucdriverex.h"
00016 
00017 class GLDisplayListWidget;
00018 
00019 #ifndef __GLDriverQtQt__
00020 #define __GLDriverQtQt__
00021 
00022 
00023 #define ENSUREMINMAX(A,B,MIN,MAX) MIN = (A < B) ? A : B;MAX = (A < B) ? B : A
00024 #define SETSCALE(MIN,MAX,SCALEVAR) SCALEVAR = MAX-MIN
00025 
00026 /*! 
00027     \class GLDriverQt
00028         \brief This class is implements a UCdriver (and UCdriverEx) 
00029     interface to a GLDisplayListWidget class instance. It manages an openGL
00030     display list (this is a GL thing) that is then displayed on 
00031     each repaint pass by the associated GLDisplayListWidget.
00032     <p>
00033     A GLDriverQt class instance is contained within an 
00034     GLDisplayListWidget and  therefore access to the UCdriver (UCdriverEx) 
00035     interface is made through a pointer to this instance. Since GLdriverQt is 
00036     derived from UCdriverEx (and hence UCdriver) the pointer to the contained
00037     GLDriverQt can be passed to any routines written in terms of UCdriverEx 
00038     (or UCdriver) and the results of those routines will be displayed in 
00039     the GLDisplayListWidget child window. 
00040 
00041     Sample Code Fragment:
00042 \code
00043 //   Instantiate a GLDisplayListWidget in the containing window constructor 
00044 
00045      glWidget = new GLDisplayListWidget;     
00046 
00047 //
00048 //   Elsewhere in containing window class (typically in a response function)
00049 //   capture the GLDriverQt pointer. 
00050 //
00051      GLDriverQt* Gldriver = glWidget->getGLDriverQtPtr(); 
00052 
00053 //   Use the  start() to open up a GL display list and then create
00054 //   graphics by calling UCdriver or UCdriverEx methods. Close
00055 //   the list and induce a repaint of glWidget by calling frame(). 
00056 
00057      Gldriver->start();
00058      
00059      Gldriver->point(...);          //           
00060      Gldriver->lines(...);          // UCdriver or UCdriverEx calls
00061      Gldriver->pointEx(...);        //
00062 
00063      Gldriver->frame();
00064  
00065 \endcode
00066     
00067 <i>Source</i>: 
00068 <A HREF="../GLDriverQt.h">GLDriverQt.h</A>, 
00069 <A HREF="../GLDriverQt.cpp">GLDriverQt.cpp</A><p>
00070 
00071 @author Chris Anderson (C) UCLA 2007-09 
00072 @version 2/16/09 
00073 */
00074 
00075 class GLDriverQt : public UCdriverEx  
00076 {
00077 
00078 public:
00079 
00080         GLDriverQt(int DisplayList);
00081         GLDriverQt();
00082 
00083     GLuint getDisplayList(){return displayListIndex;};
00084         virtual ~GLDriverQt();
00085 
00086 
00087 /** 
00088 Starts a new frame (or plot). 
00089 */
00090     void start();
00091 /** 
00092 Clears the current plot. 
00093 */
00094     void clearFrame();
00095     
00096 private :
00097 
00098         /// the associated GLDisplayListWidget
00099         
00100     GLDisplayListWidget* m_glWnd;
00101     
00102     /// the display list index 
00103     
00104     GLuint displayListIndex;
00105         
00106     /// currently not used. originally destined for use with the text output functions
00107         unsigned int textBase;
00108         
00109         ///define the current alpha level
00110         double m_dAlpha;
00111 
00112         ///define the range of the X axis
00113         double m_dXMin,m_dXMax;double m_dXScale;
00114 
00115         ///define the range of the Y axis
00116         double m_dYMin,m_dYMax;double m_dYScale;
00117 
00118         ///define the range of the Z axis
00119         double m_dZMin,m_dZMax;double m_dZScale;
00120 
00121         ///normalize an x coordinate
00122         inline double NORMX(double x) { return (x*m_dXScale)+m_dXMin; }
00123 
00124         ///normalize a y coordinate
00125         inline double NORMY(double y) { return (y*m_dYScale)+m_dYMin; }
00126 
00127         ///normalize a z coordinate
00128         inline double NORMZ(double z) { return (z*m_dZScale)+m_dZMin; }
00129 
00130         /** Set the color according to the rules defined by UCdriver.
00131                 WARNING: There is no sanity checking for the value of the RGB
00132                 array if the USER_RGB option is used.
00133 
00134                 @param color the UCdriver defined color
00135                 @param RGB      an array of 3 double values that define an RGB color.
00136         */
00137         inline void SetColor(unsigned int color,double* RGB);
00138         /** Set the line stippling to correspond with the values in UCdriver.
00139                 User defined patterns are currently unsupported.
00140 
00141                 @param stipple the stipple pattern to use
00142                 @param user_pattern the user defined stipple pattern. Currently not supported
00143         */
00144         inline void SetStipple(unsigned int stipple,unsigned int user_pattern);
00145 
00146 /** 
00147 Opens up a new GL list for capturing plotting commands.. 
00148 */
00149         void OpenList();
00150 /** 
00151 Closes the current GL list. 
00152 */
00153         void CloseList();
00154 /**
00155 Deletes the elements of the input display list. 
00156 */
00157     void DeleteList();
00158 
00159 
00160 //UCdriver
00161 public:
00162         
00163         virtual void line(double x1,double y1, double x2,double y2, int dash_pattern,
00164                       unsigned int user_pattern, double width, int color,double *RGB);
00165         
00166         
00167         virtual void lines(double* X,double* Y,long npoints, int dash_pattern,
00168                        unsigned int user_pattern,double width,int color,double* RGB);
00169         
00170     
00171         virtual void point(double x,double y, char chr,const char *font,double size, int color,
00172     double *RGB);
00173 
00174         virtual void points(double *X,double *Y,long npoints, char chr,const char* font,double dsize,
00175                                 int color,double *RGB);
00176 
00177         virtual void text(
00178                 double x,double y,const char* s,const char* font,double size,double rotation,
00179                 double horiz_just,double vert_just,
00180                 int color,double *RGB);
00181 
00182 /**  Not implemented for GLDriverQt */
00183 
00184     virtual void region(double *X, double *Y, long npoints, double *RGB) 
00185         {
00186         return;
00187         // Currently ignored parameters //
00188         X       = 0;
00189         Y       = 0;
00190         npoints = 0;
00191         RGB     = 0;
00192         //////////////////////////////////
00193         };
00194 
00195         virtual void frame(); 
00196 
00197 //UCdriverEx
00198 
00199 public:
00200 
00201         virtual double alphaEx(double alpha=1.0)
00202         {
00203                 double old = m_dAlpha;
00204                 m_dAlpha = alpha;
00205                 return old;
00206         }
00207 
00208         virtual void lineEx(
00209                 double x1,double y1,
00210                 double x2,double y2,
00211                 int dash_pattern,unsigned int user_pattern,
00212                 double width,
00213                 int color,double *RGB);
00214 
00215         virtual void lineEx(
00216                 double x1,double y1,double z1,
00217                 double x2,double y2,double z2,
00218                 int dash_pattern,unsigned int user_pattern,
00219                 double width,
00220                 int color,double *RGB);
00221 
00222         virtual void linesEx(
00223                 double* X,double* Y,long npoints,
00224                 int dash_pattern,unsigned int user_pattern,
00225                 double width,int color,double* RGB);
00226 
00227         virtual void linesEx(
00228                 double* X,double* Y,double* Z,long npoints,
00229                 int dash_pattern,unsigned int user_pattern,
00230                 double width,int color,double* RGB);
00231 
00232         virtual void textEx(double x,double y,double z, double nx, double ny, double nz, 
00233                 const char* s,const char* font, double size, double rotation, double horiz_just, 
00234         double vert_just, int color,double *RGB);
00235 
00236         virtual void pointEx(
00237                 double x,double y,
00238                 char chr,const char* font,double size,
00239                 int color,double* RGB);
00240 
00241         virtual void pointEx(double x,double y,double z,char chr,const char* font,
00242     double size, int color,double* RGB);
00243 
00244     protected : 
00245 
00246     void plotHText(double x, double y, const char *s, const char *font, double size, 
00247     double rotation, double horiz_just, double vert_just, int color, double *rgb);
00248 
00249     void plotHText(double x, double y, double z,
00250     double nx, double ny, double nz, const char *s, const char *font, double size, 
00251     double rotation, double horiz_just, double vert_just, int color, double *rgb);
00252     
00253     public :
00254     
00255 // GLDisplayListWidget  helper 
00256 
00257 /** 
00258 Associates a GLDisplayListWidget parent object with the driver. 
00259 */
00260         void SetGLDisplayListWidget(GLDisplayListWidget* a);
00261 };
00262 
00263 #endif 
00264 
00265 

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