proj home

Files   Classes   Functions   Hierarchy  

simplexD2tessapp01.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 using namespace std;
00004 
00005 #include <commandline.h>
00006 #include <graphmisc.h>
00007 #include <print.h>
00008 #include <simplexD2tessapp01.h>
00009 #include <tessD2disp01.h>
00010 #include <tessD2misc.h>
00011 #include <zpr.h>
00012 
00013 bool * simplexD2tessapp01::help = 0;
00014 menusystem * simplexD2tessapp01::messages = 0;
00015 simplexD2tessindexed<simplexD2tessapp01::pt2,double,uint>* 
00016   simplexD2tessapp01::tessptr = 0;
00017 uint simplexD2tessapp01::displaypoints = 0;
00018 uint simplexD2tessapp01::dispmesh = 0;
00019 uint simplexD2tessapp01::dispsimplexindex = 0;
00020 uint simplexD2tessapp01::dispmulticolor = 0;
00021 uint simplexD2tessapp01::dispcircles = 0;
00022 tessD2disp02
00023 <
00024   simplexD2tessindexed<simplexD2tessapp01::pt2,double,uint>,
00025   simplexD2tessapp01::pt2,
00026   uint
00027 >* simplexD2tessapp01::tessD2disp02ptr = 0;
00028 
00029 
00030 
00031 void simplexD2tessapp01::keyboard01
00032 (
00033   unsigned char key, 
00034   int x, 
00035   int y
00036 )
00037 {
00038   switch (key)
00039   {
00040     case 27: exit(0); break;
00041   }
00042 }
00043 
00044 void simplexD2tessapp01::display01()
00045 { 
00046   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00047 
00048   gobj::global->draw();
00049 
00050 
00051   glerrordisplay();
00052   
00053   glutSwapBuffers();
00054 }
00055 
00056 
00057 
00058 
00059 void simplexD2tessapp01::keyboard02
00060 (
00061   unsigned char key, 
00062   int x, 
00063   int y
00064 )
00065 {
00066   assert(messages!=0);
00067   assert(tessD2disp02ptr!=0);
00068   assert(tessptr!=0);
00069 
00070   switch (key)
00071   {
00072     case 27: exit(0); break;
00073 
00074     case 'h': if (help!=0) *help = !*help; break;
00075     case 'u': messages->scrollup(); break;
00076     case ' ': messages->scrolldown(); break;
00077 
00078     case '1': tessD2disp02ptr->gswitches[displaypoints]->toggle(); break;
00079     case '2': tessD2disp02ptr->gswitches[dispmesh]->toggle(); break;
00080     case '3': tessD2disp02ptr->gswitches[dispsimplexindex]->toggle(); break;
00081     case '4': tessD2disp02ptr->gswitches[dispmulticolor]->toggle(); break;
00082     case '5': tessD2disp02ptr->gswitches[dispcircles]->toggle(); break;
00083 
00084     case 's': 
00085     {
00086       stringstream ss;
00087       for (uint i=1; i<tessptr->vi.size(); ++i)
00088         ss << i << ":   " << tessptr->vi[i] << endl;
00089 
00090       messages->addfont10blockstart(ss.str(),1); 
00091     }
00092     break;
00093 
00094     case 'p':
00095     {
00096       stringstream ss;
00097       for (uint i=1; i<tessptr->pts.size(); ++i)
00098         ss << i << ":   " << tessptr->pts[i] << endl;
00099 
00100       messages->addfont10blockstart(ss.str(),1); 
00101     }
00102     break;
00103 
00104     case 'c':  messages->clear(); break;
00105 
00106   }
00107 
00108   glutPostRedisplay();
00109 }
00110 
00111 
00112 
00113 void simplexD2tessapp01::test02(int argc, char** argv)
00114 {
00115   glutInit(&argc,argv);
00116   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00117   glutInitWindowSize(800,600);
00118   glutCreateWindow("");
00119   glutDisplayFunc(display01);
00120   glutKeyboardFunc(keyboard02);
00121 
00122   OpenGLinitialisation();
00123 
00124   glEnable(GL_DEPTH_TEST);
00125   glEnable(GL_CULL_FACE);
00126   glEnable(GL_NORMALIZE);
00127 
00128   xGraphics.set();
00129 
00130   commandline cmd(argc,argv);
00131 
00132   string file;
00133   cmd.mapvar(file,"file");
00134 
00135   typedef point2<double> pt2;
00136 
00137   simplexD2tessindexed<point2<double>,double,uint> tess;
00138   tessptr = & tess;
00139 
00140   if (file.empty())
00141   {
00142     cout << "error:  filename of an indexed 2D tessellation expected." << endl;
00143     cout << "  eg ./main prog=4 file=tessD2002.txt" << endl;
00144     return;
00145   }
00146 
00147   string s;
00148   bool res = tokenizermisc::readfile(s,file);
00149   if (res==false)
00150   {
00151     cout << "error:  could not read file " << file << endl;
00152     return;
00153   }
00154   tess.serializeInverse(s);
00155   tess.windinganticlockwise();
00156 
00157 
00158   tessD2disp02<simplexD2tessindexed<pt2,double,uint>,pt2,uint> 
00159     tessdisp(tess);
00160 
00161   tessD2disp02ptr = & tessdisp;
00162 
00163   tessdisp.displaypoints(displaypoints);
00164   tessdisp.displaymesh(dispmesh);
00165   tessdisp.displaysimplexindex(dispsimplexindex);
00166   tessdisp.displaymulticolor(dispmulticolor);
00167   tessdisp.displaycircles(dispcircles);
00168   
00169   tessdisp.update();
00170 
00171   tessdisp.gswitches[dispcircles]->isdrawn=false;
00172 
00173   xGraphics.push(&tessdisp);
00174 
00175   gobjpush(new gobjglDisable(GL_LIGHTING));
00176   menusystem * menu = 
00177     new menusystem(0,0,true,point2<GLint>(60,30),10);
00178   menu->fontcolor = point4<float>(218.0/255.0,165.0/255.0,32.0/255.0,0.75);
00179 
00180   gobjSwitch<> * menuswitch = new gobjSwitch<>(menu,true);
00181   help = & menuswitch->isdrawn;
00182   gobjpush(menuswitch);
00183 
00184   menu->addfont12("Indexed Triangles Tessellation",2);
00185 
00186   menu->addfont10("1        Toggle the points",1);
00187   menu->addfont10("2        Toggle the mesh",1);
00188   menu->addfont10("3        Toggle the simplexes indexes",1);
00189   menu->addfont10("4        Toggle multicolored simplexes",1);
00190   menu->addfont10("5        Toggle simplexes circles",2);
00191 
00192   menu->addfont10("s        Print simplexes",1);
00193   menu->addfont10("p        Print points",1);
00194   menu->addfont10("space Scroll down",1);
00195   menu->addfont10("u        Scroll up",1); 
00196   menu->addfont10("c        Clear the display",2); 
00197 
00198   menu->addfont10("h        Toggle help menu",1);
00199   menu->addfont10("ESC      Quit");
00200 
00201 /*
00202   tessD2disp02<pt2> tessdisp(tess);
00203 
00204   //cmd.mapvar(tessdisp.circles,"circles");
00205   //cmd.mapvar(tessdisp.multicolored,"multicolored");
00206 
00207   tessdisp.meshupdate();
00208 
00209   tessdisp.eval
00210   (
00211     *gobj::global,
00212     &tess.vi[0],
00213     &tess.vi[tess.vi.size()-1]
00214   );
00215 */
00216 
00217   messages = 
00218     new menusystem(0,0,true,point2<GLint>(60,250),10);
00219   gobjpush(messages);
00220   messages->fontcolor = point4<float>(1.0,0.0,0.0,0.8);
00221   messages->lightingdisable();
00222 
00223   glDisable(GL_DEPTH_TEST);
00224   glEnable(GL_BLEND);
00225   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00226 
00227   zpr zz;
00228   glutMainLoop();
00229 }
00230 
00231 

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