proj home

Files   Classes   Functions   Hierarchy  

tessD2draw02.h

Go to the documentation of this file.
00001 #ifndef TESSD2DRAW02_H
00002 #define TESSD2DRAW02_H
00003 
00004 #include <gobj.h>
00005 #include <graphmisc.h>
00006 #include <pointsdisplay.h>
00007 #include <random.h>
00008 #include <triangle.h>
00009 
00015 template< typename TESS, typename PT >
00016 class tessD2draw02points : public gobjContainer
00017 {
00018   TESS & tess;
00019 public:
00020 
00022   gobjglColor3ub col;
00023 
00025   bool & isdrawn;
00026 
00027   tessD2draw02points(TESS & tess_, bool & isdrawn_)
00028     : tess(tess_), col(255,255,0), isdrawn(isdrawn_) {}
00029 
00031   void draw();
00032 };
00033 
00037 template< typename TESS, typename PT, typename INDX >
00038 class tessD2draw02mesh : public gobj
00039 {
00040   TESS & tess;
00041 public:
00042 
00044   gobjglColor3f col;
00045 
00047   tessD2draw02mesh(TESS & tess_)
00048     : tess(tess_), col(0.0,0.0,1.0) {}
00049 
00051   void draw();
00052 
00053 private:
00054   template< typename TR, typename PTS >
00055   void drawtriangle(TR const & t, PTS const & pts);
00056 };
00057 
00061 template< typename TESS, typename PT, typename INDX >
00062 class tessD2draw02simplexindex : public gobj
00063 {
00064   TESS & tess;
00065 public:
00066 
00068   gobjglColor3f col;
00069 
00071   bool & isdrawn;
00072 
00074   tessD2draw02simplexindex(TESS & tess_, bool & isdrawn_)
00075     : tess(tess_), col(1.0,0.0,0.0), isdrawn(isdrawn_) {}
00076 
00078   void draw();
00079 
00080 private:
00081   template< typename TR, typename PTS >
00082   void processtriangle
00083   (
00084     point2<double> & q,
00085     TR const & t, 
00086     PTS const & pts
00087   ) const;
00088 };
00089 
00095 template< typename TESS, typename PT, typename INDX >
00096 class tessD2draw02multicolor : public gobj
00097 {
00098   TESS & tess;
00099 public:
00100 
00102   bool & isdrawn;
00103 
00105   double blend;
00106 
00108   tessD2draw02multicolor(TESS & tess_, bool & isdrawn_)
00109     : tess(tess_), isdrawn(isdrawn_), blend(0.5) {}
00110 
00112   void draw();
00113 
00114 private:
00115   template< typename TR, typename PTS >
00116   void drawtriangle(TR const & t, PTS const & pts);
00117 
00118   random11<double> r;
00119 };
00120 
00124 template< typename TESS, typename PT, typename INDX >
00125 class tessD2draw02circles: public gobj
00126 {
00127   TESS & tess;
00128 public:
00129 
00131   bool & isdrawn;
00132 
00134   double blend;
00135 
00137   tessD2draw02circles(TESS & tess_, bool & isdrawn_)
00138     : tess(tess_), isdrawn(isdrawn_), blend(0.5) {}
00139 
00141   void draw();
00142 
00143 private:
00144   typedef point2<double> pt2;
00145 
00146   template< typename PTS, typename S >
00147   void get
00148   (   
00149     triangle<pt2,double> & t,
00150     PTS const & pts,
00151     S & s
00152   ) const
00153     { t.constructUnordered( pts[s.pi[0]], pts[s.pi[1]], pts[s.pi[2]] ); }
00154 
00155 };
00156 
00157 
00158 //---------------------------------------------------------
00159 // Implementation
00160 
00161 
00162 template< typename TESS, typename PT, typename INDX >
00163 void tessD2draw02circles<TESS,PT,INDX>::draw()
00164 {
00165   gobjContainer & y = * new gobjContainer(true);
00166 
00167   y.push( new gobjglPushAttrib(GL_CURRENT_BIT));
00168   y.push( new gobjglPushAttrib(GL_LIGHTING_BIT));
00169 
00170   y.push(new gobjglDisable(GL_LIGHTING));
00171   y.push( new gobjglEnable(GL_BLEND));
00172   y.push( new gobjglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
00173 
00174   gobjMyCircle * cir = new gobjMyCircle();
00175   y.push(cir);
00176 
00177   triangle<pt2,double> t;
00178   pt2 p0;
00179   double radius;
00180   typedef point3<double> pt3;
00181 
00182   random11<double> r;
00183 
00184   INDX const imax = tess.vi.size();
00185   for (INDX i=1; i<imax; ++i)
00186   {
00187     if (tess.vi[i].isnull())
00188       continue;
00189 
00190     y.push(new gobjglColor4f(r(),r(),r(),blend));
00191 
00192     get(t,tess.pts,tess.vi[i]);
00193 
00194     t.outercircle(radius,p0);
00195 
00196 //cout << SHOW(radius) << " " << SHOW(p0) << endl;
00197 
00198     y.push( new gobjMyCircleDraw(radius, pt3(p0), *cir) );
00199   }
00200 
00201   //y.push( new gobjglEnd());
00202 
00203   y.push( new gobjglPopAttrib());
00204   y.push( new gobjglPopAttrib());
00205 
00206 //cout << SHOW(y.vg.size()) << endl;
00207 //cout << SHOW(isdrawn) << endl;
00208 
00209   gobjSwitch<bool&> * s = 
00210     new gobjSwitch<bool&>(&y,isdrawn);
00211 
00212   gobjpush(s);
00213 }
00214 
00215 
00216 template< typename TESS, typename PT, typename INDX >
00217 template< typename TR, typename PTS >
00218 void tessD2draw02multicolor<TESS,PT,INDX>::drawtriangle
00219 (
00220   TR const & t,
00221   PTS const & pts
00222 )
00223 {
00224   if (t.isnull())
00225     return;
00226 
00227   PT const & P0(pts[t.pi[0]]); 
00228   PT const & P1(pts[t.pi[1]]); 
00229   PT const & P2(pts[t.pi[2]]); 
00230 
00231   gobjpush(new gobjglColor4f(r(),r(),r(),blend));
00232 
00233   gobjpush(new gobjglVertex2f(P0.x,P0.y));
00234   gobjpush(new gobjglVertex2f(P1.x,P1.y));
00235   gobjpush(new gobjglVertex2f(P2.x,P2.y));
00236 }
00237 
00238 template< typename TESS, typename PT, typename INDX >
00239 void tessD2draw02multicolor<TESS,PT,INDX>::draw()
00240 {
00241   gobjContainer * preserve = gobjContainer::global;
00242   
00243   gobjContainer & y = * new gobjContainer(true);
00244   y.set();
00245 
00246   y.push( new gobjglPushAttrib(GL_CURRENT_BIT));
00247   y.push( new gobjglPushAttrib(GL_LIGHTING_BIT));
00248 
00249   y.push(new gobjglDisable(GL_LIGHTING));
00250   y.push( new gobjglEnable(GL_BLEND));
00251   y.push( new gobjglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
00252 
00253   y.push( new gobjglBegin(GL_TRIANGLES));
00254 
00255   INDX const imax = tess.vi.size();
00256   for (INDX i=1; i<imax; ++i)
00257     drawtriangle(tess.vi[i],tess.pts);
00258 
00259   y.push( new gobjglEnd());
00260 
00261   y.push( new gobjglPopAttrib());
00262   y.push( new gobjglPopAttrib());
00263 
00264   gobjSwitch<bool&> * s = 
00265     new gobjSwitch<bool&>(&y,isdrawn);
00266 
00267   // Restore
00268   gobjContainer::global = preserve;
00269   
00270   gobjpush(s);
00271 }
00272 
00273 
00274 
00275 template< typename TESS, typename PT, typename INDX >
00276 template< typename TR, typename PTS >
00277 void tessD2draw02mesh<TESS,PT,INDX>::drawtriangle
00278 (
00279   TR const & t,
00280   PTS const & pts
00281 )
00282 {
00283   if (t.isnull())
00284     return;
00285 
00286   PT const & P0(pts[t.pi[0]]); 
00287   PT const & P1(pts[t.pi[1]]); 
00288   PT const & P2(pts[t.pi[2]]); 
00289 
00290   glVertex2f(P0.x,P0.y);
00291   glVertex2f(P1.x,P1.y);
00292   glVertex2f(P0.x,P0.y);
00293   glVertex2f(P2.x,P2.y);
00294   glVertex2f(P1.x,P1.y);
00295   glVertex2f(P2.x,P2.y);
00296 }
00297 
00298 template< typename TESS, typename PT, typename INDX >
00299 void tessD2draw02mesh<TESS,PT,INDX>::draw()
00300 {
00301   glPushAttrib(GL_CURRENT_BIT);
00302   glPushAttrib(GL_LIGHTING_BIT);
00303 
00304   glDisable(GL_LIGHTING);
00305 
00306   col.draw();
00307 
00308   glBegin(GL_LINES);
00309 
00310   INDX const imax = tess.vi.size();
00311   for (INDX i=1; i<imax; ++i)
00312     drawtriangle(tess.vi[i],tess.pts);
00313 
00314   glEnd();
00315 
00316   glPopAttrib();
00317   glPopAttrib();
00318 }
00319 
00320 template< typename TESS, typename PT >
00321 void tessD2draw02points<TESS,PT>::draw()
00322 {
00323   gobjContainer & y = * new gobjContainer(true);
00324 
00325   y.push( new gobjglPushAttrib(GL_CURRENT_BIT) );
00326   y.push( new gobjglPushAttrib(GL_LIGHTING_BIT) );
00327 
00328   y.push( new gobjglDisable(GL_LIGHTING) );
00329 
00330   y.push( new gobjglColor3ub(col) );
00331     
00332   pointsdisplay2D< PT > dp(y,tess.pts);
00333 
00334   y.push( new gobjglPopAttrib() );
00335   y.push( new gobjglPopAttrib() );
00336 
00337   gobjSwitch<bool&> * s = 
00338     new gobjSwitch<bool&>(&y,isdrawn);
00339 
00340   gobjpush(s);
00341 }
00342 
00343 template< typename TESS, typename PT, typename INDX >
00344 void tessD2draw02simplexindex<TESS,PT,INDX>::draw()
00345 {
00346   gobjContainer & y = * new gobjContainer(true);
00347 
00348   y.push( new gobjglPushAttrib(GL_CURRENT_BIT) );
00349   y.push( new gobjglPushAttrib(GL_LIGHTING_BIT) );
00350 
00351   y.push( new gobjglDisable(GL_LIGHTING) );
00352 
00353   y.push( new gobjglColor3f(col) );
00354 
00355   vector< point2<double> > pts;
00356   INDX sz=tess.vi.size();
00357   pts.resize(sz);
00358   for (INDX i=1; i<sz; ++i)
00359     processtriangle(pts[i],tess.vi[i],tess.pts);
00360     
00361   pointsdisplay2D< PT > dp(y,pts);
00362 
00363   y.push( new gobjglPopAttrib() );
00364   y.push( new gobjglPopAttrib() );
00365 
00366   gobjSwitch<bool&> * s = 
00367     new gobjSwitch<bool&>(&y,isdrawn);
00368 
00369   gobjpush(s);
00370 }
00371 
00372 template< typename TESS, typename PT, typename INDX >
00373 template< typename TR, typename PTS >
00374 void tessD2draw02simplexindex<TESS,PT,INDX>::processtriangle
00375 (
00376   point2<double> & q,
00377   TR const & t,
00378   PTS const & pts
00379 ) const
00380 {
00381   typedef point2<double> pt2;
00382   if (t.isnull())
00383   {
00384     q = pt2();
00385     return;
00386   }
00387 
00388   PT const & P0(pts[t.pi[0]]); 
00389   PT const & P1(pts[t.pi[1]]); 
00390   PT const & P2(pts[t.pi[2]]); 
00391 
00392   q.x = (P0.x+P1.x+P2.x)*((double)1.0)/((double)3.0);
00393   q.y = (P0.y+P1.y+P2.y)*((double)1.0)/((double)3.0);
00394 }
00395 
00396 
00397 #endif
00398 

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