Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

tri_strips_texture.H

Go to the documentation of this file.
00001 /**********************************************************************
00002  * tri_strips_texture.H:
00003  **********************************************************************/
00004 #ifndef TRI_STRIPS_TEXTURE_H_IS_INCLUDED
00005 #define TRI_STRIPS_TEXTURE_H_IS_INCLUDED
00006 
00007 #include "flat_shade.H"
00008 
00009 /**********************************************************************
00010  * TriStripsTexture:
00011  *
00012  *      Used to visualize the pattern of triangle and edge
00013  *      strips. Draws each triangle strip and edge strip in a
00014  *      randomly chosen color.  But not too random -- the same
00015  *      strip will have the same color each time it is drawn.
00016  *
00017  *      TriStripsTexture is really just a FlatShadeTexture,
00018  *      except it uses a specialized strip callback, StripColorCB,
00019  *      to set distinct colors when starting each strip.
00020  **********************************************************************/
00021 class StripColorCB : public GLStripCB {
00022  protected:
00023 
00024    bool _starting;    // set to true in begin_edges(EdgeStrip* e)
00025 
00026    // _starting is used within an edge strip to set a color
00027    // randomly on the first edge drawn after starting a new
00028    // piece of the strip. this is needed because a single
00029    // edge strip can consist of multiple distinct pieces. to
00030    // get a consistent, distinct color per *piece* we need
00031    // to seed the random number generator not with the
00032    // address of the strip itself, but with the address of
00033    // the leading edge of each piece in turn.
00034 
00035  public:
00036    StripColorCB() : _starting(0) {}
00037 
00038    //******** TRI STRIPS ********
00039    virtual void begin_faces(TriStrip* t) {
00040       // set a random color per strip
00041       // choose same color next time for this strip
00042       srand48((long) t);        
00043       glColor4d(drand48(), drand48(), drand48(), alpha);
00044       GLStripCB::begin_faces(t);    // glBegin(GL_TRIANGLE_STRIP);
00045    }
00046    virtual void faceCB(CBvert* v, CBface* f) {
00047       // no colors or texture coordinates
00048       glNormal3dv(f->norm().data());    // face normals (for flat shading)
00049       glVertex3dv(v->loc().data());     // vertex coordinates
00050    }
00051 
00052    //******** EDGE STRIPS ********
00053    virtual void begin_edges(EdgeStrip* e) {
00054       // get ready to set a random color per
00055       // each new piece of the edge strip
00056       _starting = 1;
00057       GLStripCB::begin_edges(e);    // glBegin(GL_LINE_STRIP); 
00058    }
00059    virtual void edgeCB(CBvert* v, CBedge* e) {
00060       // if this is the beginning of a new piece
00061       // of the edge strip, set a color
00062       if (_starting) {
00063          _starting = 0;         // use it up
00064          srand48((long) e);     // set the color
00065          glColor4d(drand48(), drand48(), drand48(), alpha);
00066       }
00067       GLStripCB::edgeCB(v,e);
00068    }
00069 
00070    //******** VERT STRIPS ********
00071    virtual void begin_verts(VertStrip* v) {
00072       // set a random color per strip
00073       // choose same color next time for this strip
00074       srand48((long) v);        
00075       glColor4d(drand48(), drand48(), drand48(), alpha);
00076       GLStripCB::begin_verts(v);    // glBegin(GL_POINTS);
00077    }
00078 };
00079 
00080 /**********************************************************************
00081  * TriStripsTexture:
00082  *
00083  *      It's really just a FlatShadeTexture with a different
00084  *      triangle strip callback implementation.
00085  **********************************************************************/
00086 class TriStripsTexture : public FlatShadeTexture {
00087  public:
00088    TriStripsTexture(Patch* patch = 0) :
00089       FlatShadeTexture(patch, new StripColorCB) {}
00090 
00091    //******** RUN-TIME TYPE ID ********
00092    DEFINE_RTTI_METHODS2("Show tri-strips", BasicTexture, CDATA_ITEM *);
00093 
00094    //******** GTexture VIRTUAL METHODS ********
00095  
00096   // A new color is set inside the display list when each
00097    // triangle strip is drawn. That's why the display list
00098    // needs to be invalidated when alpha changes.
00099    virtual void push_alpha(double a)  {
00100       FlatShadeTexture::push_alpha(a);
00101       changed();
00102    }
00103    virtual void pop_alpha() {
00104       FlatShadeTexture::pop_alpha();
00105       changed();
00106    }
00107 
00108    // show the crease And border strips in addition to
00109    // triangle strips:
00110    virtual int draw(CVIEWptr& v) {
00111       glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_LINE_BIT);
00112       glDisable(GL_LIGHTING);                   // GL_ENABLE_BIT
00113       glLineWidth(5);                           // GL_LINE_BIT
00114       if (_patch && _patch->cur_creases())
00115          _patch->cur_creases()->draw(_cb);      // GL_CURRENT_BIT
00116       if (_patch && _patch->cur_borders())
00117          _patch->cur_borders()->draw(_cb);      // GL_CURRENT_BIT
00118       glPopAttrib();
00119       return FlatShadeTexture::draw(v);
00120    }
00121 
00122    //******** DATA_ITEM VIRTUAL METHODS ********
00123    virtual DATA_ITEM  *dup() const { return new TriStripsTexture; }
00124 };
00125 
00126 #endif // TRI_STRIPS_TEXTURE_H_IS_INCLUDED
00127 
00128 /* end of file tri_strips_texture.H */

Generated on Mon Sep 18 11:39:34 2006 for jot by  doxygen 1.4.4