Files Classes Functions Hierarchy
00001 #include <iostream> 00002 #include <fstream> 00003 using namespace std; 00004 00005 #include <commandline.h> 00006 #include <delaunaysimpleD2test.h> 00007 #include <graphmisc.h> 00008 #include <print.h> 00009 #include <random.h> 00010 #include <tessD2disp01.h> 00011 #include <tessD2misc.h> 00012 #include <zpr.h> 00013 00014 bool * delaunaysimpleD2test::help = 0; 00015 menusystem * delaunaysimpleD2test::messages = 0; 00016 delaunaysimpleD2<delaunaysimpleD2test::pt2,double,uint>* 00017 delaunaysimpleD2test::tessptr = 0; 00018 uint delaunaysimpleD2test::disppoints = 0; 00019 uint delaunaysimpleD2test::dispmesh = 0; 00020 uint delaunaysimpleD2test::dispsimplexindex = 0; 00021 uint delaunaysimpleD2test::dispmulticolor = 0; 00022 uint delaunaysimpleD2test::dispcircles = 0; 00023 tessD2disp02 00024 < 00025 delaunaysimpleD2<delaunaysimpleD2test::pt2,double,uint>, 00026 delaunaysimpleD2test::pt2, 00027 uint 00028 >* delaunaysimpleD2test::tessD2disp02ptr = 0; 00029 00030 00031 void delaunaysimpleD2test::test01(int argc, char** argv) 00032 { 00033 glutInit(&argc,argv); 00034 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 00035 glutInitWindowSize(800,600); 00036 glutCreateWindow(""); 00037 glutDisplayFunc(display01); 00038 glutKeyboardFunc(keyboard01); 00039 00040 OpenGLinitialisation(); 00041 00042 glEnable(GL_DEPTH_TEST); 00043 glEnable(GL_CULL_FACE); 00044 glEnable(GL_NORMALIZE); 00045 00046 xGraphics.set(); 00047 00048 commandline cmd(argc,argv); 00049 00050 string file; 00051 cmd.mapvar(file,"file"); 00052 00053 delaunaysimpleD2<pt2,double,uint> tess; 00054 00055 if (file.empty()) 00056 { 00057 uint n=5; 00058 cmd.mapvar(n,"n"); 00059 00060 random11<double> r; 00061 for (uint i=0; i<n; ++i) 00062 tess.pts.push_back( pt2(r(),r()) ); 00063 } 00064 else 00065 { 00066 ifstream targ(file.c_str()); 00067 00068 pt2 w; 00069 00070 for ( ; targ.eof()==false; ) 00071 { 00072 targ >> w.x; 00073 if (targ.eof()==true) 00074 continue; 00075 00076 targ >> w.y; 00077 tess.pts.push_back(w); 00078 } 00079 } 00080 00081 tess.eval(); 00082 00083 tessD2disp01<pt2> tessdisp(&tess.pts[0]); 00084 00085 cmd.mapvar(tessdisp.circles,"circles"); 00086 cmd.mapvar(tessdisp.multicolored,"multicolored"); 00087 00088 tessdisp.eval 00089 ( 00090 *gobj::global, 00091 &tess.vi[0], 00092 &tess.vi[tess.vi.size()-1] 00093 ); 00094 00095 glDisable(GL_DEPTH_TEST); 00096 glEnable(GL_BLEND); 00097 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00098 00099 zpr zz; 00100 glutMainLoop(); 00101 } 00102 00103 00104 void delaunaysimpleD2test::keyboard01 00105 ( 00106 unsigned char key, 00107 int x, 00108 int y 00109 ) 00110 { 00111 switch (key) 00112 { 00113 case 27: exit(0); break; 00114 } 00115 } 00116 00117 void delaunaysimpleD2test::display01() 00118 { 00119 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00120 00121 gobj::global->draw(); 00122 00123 00124 glerrordisplay(); 00125 00126 glutSwapBuffers(); 00127 } 00128 00129 00130 00131 00132 void delaunaysimpleD2test::keyboard02 00133 ( 00134 unsigned char key, 00135 int x, 00136 int y 00137 ) 00138 { 00139 assert(messages!=0); 00140 assert(tessD2disp02ptr!=0); 00141 assert(tessptr!=0); 00142 00143 switch (key) 00144 { 00145 case 27: exit(0); break; 00146 00147 case 'h': if (help!=0) *help = !*help; break; 00148 case 'u': messages->scrollup(); break; 00149 case ' ': messages->scrolldown(); break; 00150 00151 case '1': tessD2disp02ptr->gswitches[disppoints]->toggle(); break; 00152 case '2': tessD2disp02ptr->gswitches[dispmesh]->toggle(); break; 00153 case '3': tessD2disp02ptr->gswitches[dispsimplexindex]->toggle(); break; 00154 case '4': tessD2disp02ptr->gswitches[dispmulticolor]->toggle(); break; 00155 case '5': tessD2disp02ptr->gswitches[dispcircles]->toggle(); break; 00156 00157 00158 case 's': 00159 { 00160 stringstream ss; 00161 // ss << tessptr->vi.size()-1 << endl; 00162 // ss << print(tessptr->vi.begin()+1,tessptr->vi.end(),"\n") << endl; 00163 00164 for (uint i=1; i<tessptr->vi.size(); ++i) 00165 ss << i << ": " << tessptr->vi[i] << endl; 00166 00167 messages->addfont10blockstart(ss.str(),1); 00168 } 00169 break; 00170 00171 case 'p': 00172 { 00173 stringstream ss; 00174 // ss << tessptr->pts.size()-1 << endl; 00175 // ss << print(tessptr->pts.begin()+1,tessptr->pts.end(),"\n") << endl; 00176 00177 for (uint i=1; i<tessptr->pts.size(); ++i) 00178 ss << i << ": " << tessptr->pts[i] << endl; 00179 00180 messages->addfont10blockstart(ss.str(),1); 00181 } 00182 break; 00183 00184 case 'c': messages->clear(); break; 00185 00186 } 00187 00188 glutPostRedisplay(); 00189 } 00190 00191 00192 00193 void delaunaysimpleD2test::test02(int argc, char** argv) 00194 { 00195 glutInit(&argc,argv); 00196 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 00197 glutInitWindowSize(800,600); 00198 glutCreateWindow(""); 00199 glutDisplayFunc(display01); 00200 glutKeyboardFunc(keyboard02); 00201 00202 OpenGLinitialisation(); 00203 00204 glEnable(GL_DEPTH_TEST); 00205 glEnable(GL_CULL_FACE); 00206 glEnable(GL_NORMALIZE); 00207 00208 xGraphics.set(); 00209 00210 commandline cmd(argc,argv); 00211 00212 string file; 00213 cmd.mapvar(file,"file"); 00214 00215 typedef point2<double> pt2; 00216 00217 delaunaysimpleD2<pt2,double,uint> tess; 00218 tessptr = & tess; 00219 00220 if (file.empty()) 00221 { 00222 uint n=5; 00223 cmd.mapvar(n,"n"); 00224 00225 random11<double> r; 00226 for (uint i=0; i<n; ++i) 00227 tess.pts.push_back( pt2(r(),r()) ); 00228 } 00229 else 00230 { 00231 ifstream targ(file.c_str()); 00232 00233 pt2 w; 00234 00235 for ( ; targ.eof()==false; ) 00236 { 00237 targ >> w.x; 00238 if (targ.eof()==true) 00239 continue; 00240 00241 targ >> w.y; 00242 tess.pts.push_back(w); 00243 } 00244 } 00245 00246 tess.eval(); 00247 00248 tessD2misc 00249 < 00250 delaunaysimpleD2<pt2,double,uint>, 00251 pt2, 00252 uint 00253 > tm(tess); 00254 tm.windinganticlockwise(); 00255 00256 00257 tessD2disp02<delaunaysimpleD2<pt2,double,uint>,pt2,uint> 00258 tessdisp(tess); 00259 00260 tessD2disp02ptr = & tessdisp; 00261 00262 tessdisp.displaypoints(disppoints); 00263 tessdisp.displaymesh(dispmesh); 00264 tessdisp.displaysimplexindex(dispsimplexindex); 00265 tessdisp.displaymulticolor(dispmulticolor); 00266 tessdisp.displaycircles(dispcircles); 00267 00268 00269 tessdisp.update(); 00270 00271 xGraphics.push(&tessdisp); 00272 00273 gobjpush(new gobjglDisable(GL_LIGHTING)); 00274 menusystem * menu = 00275 new menusystem(0,0,true,point2<GLint>(60,30),10); 00276 menu->fontcolor = point4<float>(218.0/255.0,165.0/255.0,32.0/255.0,0.75); 00277 00278 gobjSwitch<> * menuswitch = new gobjSwitch<>(menu,true); 00279 help = & menuswitch->isdrawn; 00280 gobjpush(menuswitch); 00281 00282 menu->addfont12("Delaunay Triangulation Demo",2); 00283 00284 menu->addfont10("1 Toggle the points",1); 00285 menu->addfont10("2 Toggle the mesh",1); 00286 menu->addfont10("3 Toggle the simplexes indexes",1); 00287 menu->addfont10("4 Toggle multicolored simplexes",1); 00288 menu->addfont10("5 Toggle simplexes circles",2); 00289 00290 menu->addfont10("s Print simplexes",1); 00291 menu->addfont10("p Print points",1); 00292 menu->addfont10("space Scroll down",1); 00293 menu->addfont10("u Scroll up",1); 00294 menu->addfont10("c Clear the display",2); 00295 00296 menu->addfont10("h Toggle help menu",1); 00297 menu->addfont10("ESC Quit"); 00298 00299 /* 00300 tessD2disp02<pt2> tessdisp(tess); 00301 00302 //cmd.mapvar(tessdisp.circles,"circles"); 00303 //cmd.mapvar(tessdisp.multicolored,"multicolored"); 00304 00305 tessdisp.meshupdate(); 00306 00307 tessdisp.eval 00308 ( 00309 *gobj::global, 00310 &tess.vi[0], 00311 &tess.vi[tess.vi.size()-1] 00312 ); 00313 */ 00314 00315 messages = 00316 new menusystem(0,0,true,point2<GLint>(60,250),10); 00317 gobjpush(messages); 00318 messages->fontcolor = point4<float>(1.0,0.0,0.0,0.8); 00319 messages->lightingdisable(); 00320 00321 glDisable(GL_DEPTH_TEST); 00322 glEnable(GL_BLEND); 00323 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 00324 00325 zpr zz; 00326 glutMainLoop(); 00327 } 00328 00329
1.5.8