proj home

Files   Classes   Functions   Hierarchy  

polytrimon.h

Go to the documentation of this file.
00001 #ifndef POLYTRIMON_H
00002 #define POLYTRIMON_H
00003 
00004 #include <cassert>
00005 #include <deque>
00006 #include <vector>
00007 #include <iostream>
00008 using namespace std;
00009 
00010 #include <point.h>
00011 #include <typedefs.h>
00012 
00013 
00020 class polytrimon
00021 {
00023   void colorsinit();
00025   void vyinit();
00026   
00029   boolc ispointvisible() const;
00030 public:
00031 
00033   vector< point2<float> > const & pts;
00034 
00038   vector< uint > colors;
00039 
00041   vector< uint > vy;
00042 
00045   polytrimon( vector< point2<float> > const & pts_ );
00046 
00048   deque<uint> vs;
00049 
00050   template< typename T >
00051   void tessellate( T f );
00052 
00053   // Debug functions.
00054   void vsprint() const;
00055   void colorsprint() const;
00056   void vyprint() const;
00057 };
00058 
00059 
00060 //---------------------------------------------------------
00061 //  Implementation
00062 
00063 template< typename T >
00064 void polytrimon::tessellate( T f )
00065 {
00066   vs.push_front( vy[0] );
00067   vs.push_front( vy[1] );
00068 
00069   uint imax= vy.size();
00070 
00071   // The first two points from the current vs state. 
00072   uint z0;
00073   uint z1;
00074 
00075   for (uint i=2; i<imax; ++i)
00076   {
00077     vs.push_front( vy[i] );
00078 //vsprint();
00079 
00080     z0 = vs[0];
00081     z1 = vs[1];
00082 
00083     bool samecolor = 
00084       (( colors[ z0 ] & colors[ z1 ])!=0);
00085 
00086     if (samecolor==false)
00087     {
00088       // Triangle fan about z0.
00089       for (uint k=2; k<vs.size(); ++k)
00090         f(z0,vs[k-1],vs[k]);
00091 
00092       vs.clear();
00093       vs.push_front(z1);
00094       vs.push_front(z0);
00095     }
00096     else
00097     {
00098       for ( ; ispointvisible(); )
00099       {
00100         z0 = vs[0];
00101         z1 = vs[1];
00102 
00103         f(z0,z1,vs[2]);
00104 
00105         vs.pop_front();
00106         vs.pop_front();
00107         vs.push_front(z0);
00108       }
00109     }
00110   } 
00111 }
00112 
00113 #endif
00114 
00115 

Generated on Fri Mar 4 00:49:30 2011 for Chelton Evans Source by  doxygen 1.5.8