proj home

Files   Classes   Functions   Hierarchy  

treeindexedD2test.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 #include <sstream>
00004 #include <vector>
00005 using namespace std;
00006 
00007 
00008 
00009 #include <bsptreeD2disp01.h>
00010 #include <bsptreeD2disp02.h>
00011 #include <bsptreeD2disp03.h>
00012 #include <bsptreeD2dispregions01.h>
00013 #include <commandline.h>
00014 #include <push_back.h>
00015 #include <tokenizer.h>
00016 #include <treeindexedD2iter.h>
00017 #include <treeindexedD2test.h>
00018 #include <typedefs.h>
00019 #include <zpr.h>
00020 
00021 template<>
00022 double zero<double>::val = 1E-12;
00023 
00024 point2<double> treeindexedD2test::targetprev;
00025 point2<double> treeindexedD2test::target;
00026 gobjMySphereDraw * treeindexedD2test::targetsphere = 0;
00027 gobjContainer * treeindexedD2test::targetg = 0;
00028 
00029 template<>
00030 bsptreeD2<treeindexedD2test::pt2,double,uint> treeindexedD2test::bsp;
00031 
00032 bool * treeindexedD2test::help = 0;
00033 
00034 vector< boxOBBhalfspaceD2< treeindexedD2test::pt2, double > > 
00035   treeindexedD2test::viboxes;
00036 vector< vector< uint > > treeindexedD2test::viboxesintersections;
00037 
00038 menusystem * treeindexedD2test::messages = 0;
00039 
00040 double treeindexedD2test::keyboarddelta = 0.1;
00041 
00042 template<>
00043 double bsptreeD2<treeindexedD2test::pt2,double,uint>::tmin = -10000.0;
00044 template<>
00045 double bsptreeD2<treeindexedD2test::pt2,double,uint>::tmax =  10000.0;
00046 
00047 
00048 void treeindexedD2test::test01()
00049 {
00050   cout << "Testing treeindexedD2 printing and addleft, addright." << endl;
00051 
00052   treeindexedD2<uint> t1;
00053 
00054   cout << "Created a root node." << endl;
00055   cout << (stringc)t1 << endl << endl;
00056 
00057   cout << "addleft" << endl;
00058   t1.addleft();
00059   cout << (stringc)t1 << endl << endl;
00060 
00061   cout << "Created another root node." << endl;
00062   treeindexedD2<uint> t2;
00063   cout << (stringc)t2 << endl << endl;
00064   cout << "addright" << endl;
00065   t2.addright();
00066   cout << (stringc)t2 << endl << endl;
00067 
00068 
00069 }
00070 
00071 
00072 void treeindexedD2test::test02()
00073 {
00074   cout << "Builing and printing a simple tree." << endl;
00075   treeindexedD2<uint> t1;
00076 
00077   t1.addleft();
00078   cout << "addleft" << endl;
00079   cout << (stringc)t1 << endl;
00080 
00081   t1.moveleft();
00082   t1.addleft();
00083   cout << "moveleft, addleft" << endl;
00084   cout << (stringc)t1 << endl;
00085 
00086   t1.reset();
00087   t1.moveleft();
00088   t1.addright();
00089   cout << "reset, moveleft, addright" << endl;
00090 
00091   cout << (stringc)t1 << endl;
00092 
00093 }
00094 
00095 
00096 int treeindexedD2test::unittest01(int argc, char** argv)
00097 {
00098   commandline cmd(argc,argv);
00099 
00100   string in;
00101   cmd.mapvar(in,"in");
00102   if ( in.empty() )
00103   {
00104     cout << "error: in=filename expected" << endl;
00105     return 1;
00106   }
00107 
00108   ifstream filein(in.c_str());
00109   assert(filein.good()==true);
00110   if (filein.good()==false)
00111   {
00112     cout << "error: " << in << " file can not be opened." << endl;
00113     return 1;
00114   }
00115 
00116   treeindexedD2<uint> t1;
00117   filein >> t1;
00118 
00119   cout << (stringc)t1 << endl;
00120 
00121   string s1;
00122   assertreturnOS(tokenizermisc::readfile(s1,in.c_str()));
00123 
00124   string s2( (stringc)t1 );
00125 
00126   assertreturnOS(tokenizermisc::comparewithoutspace(s1,s2));
00127 
00128   return 0;
00129 }
00130 
00131 int treeindexedD2test::unittest02()
00132 {
00133   typedef point2<double> pt2;
00134   bsptreeD2<pt2,double,uint> t1; 
00135 
00136   cout << "Building a simple 2D partition." << endl;
00137   cout << " Using manual insertion commands : move to the node before" << endl;
00138   cout << " inserting new node, then adding associated half-space to vi." << endl << endl;
00139 
00140   t1.vi.push_back( 
00141     halfspaceD2<pt2,double>(pt2(0.0,0.0),pt2(0.0,1.0)) );
00142 
00143   t1.tree.reset();
00144   t1.tree.addleft();
00145   t1.vi.push_back(
00146     halfspaceD2<pt2,double>(pt2(-1.0,1.0),pt2(0.0,1.0)) );
00147 
00148   t1.tree.reset();
00149   t1.tree.addright();
00150   t1.vi.push_back(
00151     halfspaceD2<pt2,double>(pt2(0.0,-0.5),pt2(1.0,-0.5)) );
00152 
00153   t1.tree.reset();
00154   t1.tree.moveright();
00155   t1.tree.addleft();
00156   t1.vi.push_back(
00157     halfspaceD2<pt2,double>(pt2(4.0,0.0),pt2(4.0,1.0)) );
00158 
00159   cout << (stringc)t1.tree << endl << endl;
00160 
00161   cout << "Testing if points are in correct regions." << endl;
00162 
00163   uint i[5];
00164   t1.find(i[0],pt2(1.0,1.0));
00165   assertreturnOS(i[0]==2);
00166   t1.find(i[1],pt2(-2.0,-10.0));
00167   assertreturnOS(i[1]==3);
00168   t1.find(i[2],pt2(-5.0,-5.0));
00169   assertreturnOS(i[2]==3);
00170   t1.find(i[3],pt2(1.0,-2.0));
00171   assertreturnOS(i[3]==4);
00172   t1.find(i[4],pt2(6.0,2.0));
00173   assertreturnOS(i[4]==5);
00174 
00175   return 0;
00176 }
00177 
00178 
00179 void treeindexedD2test::keyboard03
00180 (
00181   unsigned char key, 
00182   int x, 
00183   int y
00184 )
00185 {
00186   switch (key)
00187   {
00188     case 27: exit(0); break;
00189 
00190     case '+': keyboarddelta *= 10.0; if (keyboarddelta==0.0) keyboarddelta=0.1; break;
00191     case '-': keyboarddelta /= 10.0; break;
00192 
00193     case 'h': if (help!=0) *help = !*help; break;
00194   }
00195 
00196   update03();
00197 }
00198 
00199 
00200 // http://www.codeproject.com/KB/openGL/GLUT_WINDOW_TEMPLATE.aspx
00201 void treeindexedD2test::special03(int key, int x, int y)
00202 {
00203   switch (key)
00204   {
00205     case GLUT_KEY_RIGHT : target.x += keyboarddelta; break; 
00206     case GLUT_KEY_LEFT : target.x -= keyboarddelta; break; 
00207     case GLUT_KEY_UP : target.y += keyboarddelta; break; 
00208     case GLUT_KEY_DOWN : target.y -= keyboarddelta; break; 
00209   }
00210 
00211   update03();
00212 }
00213 
00214 
00215 void treeindexedD2test::update03()
00216 {
00217   assert(targetg!=0);
00218   assert(targetsphere!=0);
00219 
00220   targetg->kill(1);
00221   targetg->nuke();
00222   
00223   uint i;
00224   bsp.find(i,target);
00225   switch (i)
00226   {
00227     case 1: targetg->push(new gobjglColor3ub(220,20,60)); break;
00228     case 2: targetg->push(new gobjglColor3ub(0,206,209)); break;
00229     case 3: targetg->push(new gobjglColor3ub(255,140,0)); break;
00230     case 4: targetg->push(new gobjglColor3ub(143,188,139)); break;
00231     case 5: targetg->push(new gobjglColor3ub(184,134,11)); break;
00232 
00233     default:
00234       targetg->push(new gobjglColor3ub(255,0,0));
00235   }
00236 
00237   targetg->push(targetsphere);
00238 
00239   targetsphere->x = target.x;
00240   targetsphere->y = target.y;
00241 
00242   glutPostRedisplay();
00243 }
00244 
00245 void treeindexedD2test::display01()
00246 { 
00247   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00248 
00249   gobj::global->draw();
00250 
00251 
00252   glerrordisplay();
00253   
00254   glutSwapBuffers();
00255 }
00256 
00257 
00258 void treeindexedD2test::test03(int argc, char** argv)
00259 {
00260   glutInit(&argc,argv);
00261   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00262   glutInitWindowSize(800,600);
00263   glutCreateWindow("");
00264   glutDisplayFunc(display01);
00265 
00266 // TURNED OFF FOR TESTING.
00267   glutKeyboardFunc(keyboard03);
00268   glutSpecialFunc(special03);
00269 
00270   OpenGLinitialisation();
00271 
00272   glEnable(GL_CULL_FACE);
00273   glEnable(GL_NORMALIZE);
00274 
00275   xGraphics.set();
00276 
00277   commandline cmd(argc,argv);
00278 
00279   gobjpush(new myaxes(1.0));
00280 
00281   targetg = new gobjContainer(true);
00282 
00283   gobjpush(targetg);
00284 
00285 
00286   gobjQuadric * q2 = new gobjQuadric();
00287   q2->radius = 0.2;
00288   q2->slices=30;
00289   q2->loops=7;
00290   gobjpush(q2);
00291 
00292   targetsphere = new gobjMySphereDraw(target,q2);
00293 
00294 
00295 
00296   typedef point2<double> pt2;
00297 
00298   cout << "Building a simple 2D partition." << endl;
00299   cout << " Using manual insertion commands : move to the node before" << endl;
00300   cout << " inserting new node, then adding associated half-space to vi." << endl << endl;
00301 
00302   bsp.vi.push_back( 
00303     halfspaceD2<pt2,double>(pt2(0.0,0.0),pt2(0.0,1.0)) );
00304 
00305   bsp.tree.reset();
00306   bsp.tree.addleft();
00307   bsp.vi.push_back(
00308     halfspaceD2<pt2,double>(pt2(-1.0,1.0),pt2(0.0,1.0)) );
00309 
00310   bsp.tree.reset();
00311   bsp.tree.addright();
00312   bsp.vi.push_back(
00313     halfspaceD2<pt2,double>(pt2(0.0,-0.5),pt2(1.0,-0.5)) );
00314 
00315   bsp.tree.reset();
00316   bsp.tree.moveright();
00317   bsp.tree.addleft();
00318   bsp.vi.push_back(
00319     halfspaceD2<pt2,double>(pt2(4.0,0.0),pt2(4.0,1.0)) );
00320 
00321   
00322 
00323   bsptreeD2disp03<pt2,double,uint> * disp
00324     = new bsptreeD2disp03<pt2,double,uint>(bsp,0.02);
00325     //= new bsptreeD2disp03<pt2,double,uint>(bsp,-10000.0,10000.0,0.02);
00326   disp->update();
00327   gobjpush(disp);
00328   
00329   bsptreeD2dispregions01<pt2,double,uint> *dispregions
00330     = new bsptreeD2dispregions01<pt2,double,uint>(bsp);
00331   dispregions->delta=0.4;
00332   dispregions->update();
00333   gobjpush(dispregions);
00334   
00335   gobjpush(new gobjglDisable(GL_LIGHTING));
00336 
00337 
00338   menusystem * menu = 
00339     new menusystem(point2<GLint>(60,30),10);
00340   menu->fontcolor = point4<float>(218.0/255.0,165.0/255.0,32.0/255.0,0.75);
00341 
00342   menu->fontcolorenable();
00343 
00344   gobjSwitch<> * menuswitch = new gobjSwitch<>(menu,true);
00345   help = & menuswitch->isdrawn;
00346   gobjpush(menuswitch);
00347 
00348 
00349   gobjpush(new gobjglEnable(GL_LIGHTING));
00350 
00351   menu->addfont12("BSP Tree Demo",2);
00352 
00353   menu->addfont10("[page up] move up",1);
00354   menu->addfont10("[page down] move down",1);
00355   menu->addfont10("[< home] move left",1);
00356   menu->addfont10("[end >] move right",2);
00357 
00358 //  menu->addfont10("j J   Move ball right or left.",1);
00359 //  menu->addfont10("k K   Move ball up or down.",2);
00360 
00361   menu->addfont10("+ -   Increase or decrease change.",1);
00362   menu->addfont10("h    Toggle this help menu.",2);
00363   menu->addfont10("ESC      Quit");
00364 
00365 
00366 
00367   gobjpush(new gobjglEnable(GL_LIGHTING));
00368 
00369 //  glMatrixMode(GL_MODELVIEW);
00370 //  glLoadIdentity();
00371 
00372   zpr zz;
00373 
00374 // Unable to work out why this does not work.
00375 //  glMatrixMode(GL_MODELVIEW);
00376 //  glLoadIdentity();
00377 //  gluLookAt(
00378 //    0.0,0.0,0.0,  // COP target
00379 //    0.0,0.0,5.0,  // Reference
00380 //    0.0,1.0,0.0); // Up
00381 
00382   zz.update();
00383 
00384   update03();
00385 
00386   glutMainLoop();
00387 
00388 }
00389 
00390 int treeindexedD2test::unittest04()
00391 {
00392   treeindexedD2<uint> t1;
00393   string s(
00394 "4 \
00395 1 2 2 0 0 \
00396 2 3 4 1 0 \
00397 3 1 4 2 0 \
00398 4 3 5 2 1");
00399   stringstream ss(s);
00400   ss >> t1;
00401   
00402   cout << (stringc)t1 << endl << endl;
00403 
00404   t1.move(0*1+1*2,2);
00405   assertreturnOS(t1.current->index==4);
00406   t1.move(1*1,1);
00407   assertreturnOS(t1.current->index==2);
00408   t1.move(0*1+1*2+0*4,3);
00409   assertreturnOS(t1.current->index==3);
00410   t1.move(0*1+1*2+1*4,3);
00411   assertreturnOS(t1.current->index==5);
00412   t1.move(0*1+0*2+1*4,3);
00413   assertreturnOS(t1.current->index==4);
00414   t1.move(0*1+0*2+0*4,3);
00415   assertreturnOS(t1.current->index==1);
00416 
00417   vector< uint > v;
00418   t1.pathindex(v,0*1+0*2+0*4,3);
00419   assertreturnOS(v[0]==1);
00420   assertreturnOS(v[1]==2);
00421   assertreturnOS(v[2]==3);
00422   t1.pathindex(v,0*1+1*2+1*4,3);
00423   assertreturnOS(v[0]==1);
00424   assertreturnOS(v[1]==2);
00425   assertreturnOS(v[2]==4);
00426 
00427   return 0;
00428 }
00429 
00430 void treeindexedD2test::test04()
00431 {
00432   treeindexedD2<uint> t1;
00433   string s(
00434 "4 \
00435 1 2 2 0 0 \
00436 2 3 4 1 0 \
00437 3 1 4 2 0 \
00438 4 3 5 2 1");
00439   stringstream ss(s);
00440   ss >> t1;
00441 
00442 
00443   treeindexedD2iter<uint> i1(t1,false);
00444 
00445   cout << "Iterating over every node." << endl;
00446   for ( i1.reset(); !i1; ++i1)
00447     cout << i1()->index << " ";
00448   cout << endl << endl;
00449 
00450   cout << "Iterating over the leaves." << endl;
00451   for ( i1.reset(); !i1; ++i1)
00452     if (i1()->isleaf())
00453       cout << i1()->index << " ";
00454   cout << endl << endl;
00455   
00456   cout << "Iterating over the internal nodes." << endl;
00457   for ( i1.reset(); !i1; ++i1)
00458     if (!i1()->isleaf())
00459       cout << i1()->index << " ";
00460   cout << endl << endl;
00461 
00462 
00463   cout << "Iterating over the leaves." << endl;
00464   treeindexedD2iterleaf<uint> i2(t1);
00465   for ( i2.reset(); !i2; ++i2)
00466     cout << i2()->index << " ";
00467   cout << endl << endl;
00468 
00469   cout << "Iterating over the internal nodes." << endl;
00470   for ( treeindexedD2iterleaf<uint> i3(t1); !i3; ++i3 )
00471     cout << i3()->index << " ";  
00472   cout << endl << endl;
00473 }
00474 
00475 void treeindexedD2test::keyboard05
00476 (
00477   unsigned char key, 
00478   int x, 
00479   int y
00480 )
00481 {
00482   switch (key)
00483   {
00484     case 27: exit(0); break;
00485 
00486     case '+': keyboarddelta *= 10.0; if (keyboarddelta==0.0) keyboarddelta=0.1; break;
00487     case '-': keyboarddelta /= 10.0; break;
00488 
00489     case 't': messages->addfont12start( 
00490                 (stringc)target,1); break;
00491     case 'r': 
00492     {
00493       uint reg;
00494       bsp.find(reg,target);
00495       { 
00496         stringstream ss; 
00497         ss << reg;
00498         messages->addfont12start(ss.str(),1); 
00499       }
00500     }
00501     break;
00502 
00503     case 'h': if (help!=0) *help = !*help; break;
00504 
00505     case 'T': 
00506       messages->addfont10blockstart((stringc)bsp.tree,1); 
00507       cout << (stringc)bsp.tree << endl;
00508       break;
00509 
00510     case ' ':messages->scrolldown(); break;
00511     case 'v':
00512     {
00513       vector<uint> vis;
00514       bsp.visibility(vis,target);
00515       string str;
00516       for (uint i=0; i<vis.size(); ++i)
00517       {
00518         stringstream ss;
00519         ss << vis[i];
00520         str += ss.str();
00521         str += " ";
00522       }
00523       messages->addfont10paragraphstart(str,50);
00524     }
00525   }
00526 
00527   update05();
00528 }
00529 
00530 
00531 // http://www.codeproject.com/KB/openGL/GLUT_WINDOW_TEMPLATE.aspx
00532 void treeindexedD2test::special05(int key, int x, int y)
00533 {
00534   switch (key)
00535   {
00536     case GLUT_KEY_RIGHT : 
00537       targetprev = target; 
00538       target.x += keyboarddelta; break; 
00539     case GLUT_KEY_LEFT : 
00540       targetprev = target;
00541       target.x -= keyboarddelta; break; 
00542     case GLUT_KEY_UP : targetprev = target;
00543               target.y += keyboarddelta; break; 
00544     case GLUT_KEY_DOWN : targetprev = target;
00545               target.y -= keyboarddelta; break;
00546   }
00547 
00548   update05();
00549 }
00550 
00551 
00552 void treeindexedD2test::update05()
00553 {
00554   assert(targetsphere!=0);
00555 
00556   uint i;
00557   bsp.find(i,target);
00558 
00559   vector<uint> & v2(viboxesintersections[i]);
00560   uintc sz = v2.size();
00561   for (uint k=0; k<sz; ++k)
00562   {
00563     if (viboxes[ v2[k] ].intersects(target))
00564     {
00565       target = targetprev;
00566       break;
00567     }
00568   }
00569 
00570   targetsphere->x = target.x;
00571   targetsphere->y = target.y;
00572 
00573   glutPostRedisplay();
00574 }
00575 
00576 void treeindexedD2test::viboxesbuild()
00577 {
00578   viboxes.clear();
00579 
00580   typedef point2<double> pt2;
00581 
00582   // Some boxes in the scene. Each box is a no entry region.
00583   // Each row is a box of anti-clockwise 2D points.
00584   double boxes[] = 
00585   {
00586     0.0,0.0,  2.0,0.0,  2.0,2.0,  0.0,2.0,
00587     6.0,0.0,  7.0,0.0,  7.0,3.0,  6.0,3.0,
00588     5.0,4.0,  7.0,4.0,  7.0,6.0,  5.0,6.0,
00589     3.0,1.0,  5.0,1.0,  5.0,6.0,  3.0,6.0,
00590     1.0,3.0,  3.0,3.0,  3.0,4.0,  1.0,4.0,
00591     0.0,5.0,  2.0,5.0,  2.0,6.0,  0.0,6.0
00592   };
00593 
00594   boxOBBhalfspaceD2< pt2, double > b;
00595 
00596   // The first index is a dummy variable because
00597   //   0 is used to indicate no object.
00598   viboxes.push_back( b );
00599 
00600   for (uint i=0; i<6; ++i)
00601   {
00602     b.construct
00603     ( 
00604       pt2(boxes[i*8+0],boxes[i*8+1]),
00605       pt2(boxes[i*8+2],boxes[i*8+3]),
00606       pt2(boxes[i*8+4],boxes[i*8+5]),
00607       pt2(boxes[i*8+6],boxes[i*8+7])
00608     );
00609     viboxes.push_back(b);
00610   }
00611 
00612   // This map knowledge could have been put
00613   // into a script and read in.
00614 
00615   viboxesintersections.resize(17);
00616 
00617   push_back(viboxesintersections[1],3,6);
00618   push_back(viboxesintersections[2],3,4,5);
00619   push_back(viboxesintersections[3],3,4,5);
00620   push_back(viboxesintersections[4],2,3,4);
00621   push_back(viboxesintersections[5],2,4);
00622   push_back(viboxesintersections[6],1,5,6);
00623   push_back(viboxesintersections[7],4);
00624   push_back(viboxesintersections[8],2);
00625   push_back(viboxesintersections[9],6,5);
00626   push_back(viboxesintersections[10],1,5);
00627   push_back(viboxesintersections[11],1,4,5);
00628   push_back(viboxesintersections[12],1);
00629   push_back(viboxesintersections[13],1);
00630   push_back(viboxesintersections[14],3,4,6,5);
00631   push_back(viboxesintersections[15],5);
00632   push_back(viboxesintersections[16],3,4,5);
00633   
00634 }
00635 
00636   
00637 int treeindexedD2test::test05(int argc, char** argv)
00638 {
00639   glutInit(&argc,argv);
00640   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00641   glutInitWindowSize(800,600);
00642   glutCreateWindow("");
00643   glutDisplayFunc(display01);
00644   glutKeyboardFunc(keyboard05);
00645   glutSpecialFunc(special05);
00646 
00647   OpenGLinitialisation();
00648 
00649   glEnable(GL_DEPTH_TEST);
00650   glEnable(GL_CULL_FACE);
00651   glEnable(GL_NORMALIZE);
00652 
00653   xGraphics.set();
00654 
00655   commandline cmd(argc,argv);
00656 
00657   typedef point2<double> pt2;
00658 
00659   viboxesbuild();
00660 
00661   vector<string> ptlabels;
00662   vector<pt2> ptlist;
00663   for (uint i=1; i<viboxes.size(); ++i)
00664   {
00665     {
00666       stringstream ss;
00667       ss << i;
00668       ptlabels.push_back(ss.str());
00669       ptlist.push_back(viboxes[i].center);
00670     }
00671   }
00672   gobjpush(new gobjglPushAttrib(GL_LIGHTING));
00673   gobjpush(new gobjglPushAttrib(GL_CURRENT_BIT));
00674   gobjpush(new gobjglDisable(GL_LIGHTING));
00675 
00676   gobjpush(new gobjglColor3f(0.0,0.0,1.0));
00677   pointsdisplay2D< pt2 > pd( *gobj::global, ptlist, ptlabels );
00678 
00679   gobjpush(new gobjglPopAttrib());
00680   gobjpush(new gobjglPopAttrib());
00681 
00682   glEnable(GL_BLEND);
00683   glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
00684 
00685   gobjContainer * geom = new gobjContainer(true);
00686   //geom->push(new gobjglEnable(GL_BLEND));
00687   //geom->push(
00688   //  new gobjglBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) );
00689   geom->push(new gobjglColor4f(0.0,0.0,191.0/255.0,0.8));
00690   geom->push(new gobjglEnable(GL_LIGHTING));
00691   geom->push(new gobjglBegin(GL_QUADS));
00692 
00693   pt2 pi[4];
00694   for (uint k=1; k<viboxes.size(); ++k)
00695   {
00696     viboxes[k].cornerpoints(pi[0],pi[1],pi[2],pi[3]);
00697     for (uint i=0; i<4; ++i)
00698       geom->push(new gobjglVertex2f(pi[i].x,pi[i].y));
00699   }
00700    
00701   geom->push(new gobjglEnd());
00702   //geom->push(new gobjglDisable(GL_BLEND));
00703 
00704   gobjpush(geom);
00705 
00706   gridsquare * gs = new gridsquare(1,0xaaaa,7,6,7.0,6.0);
00707   gobjpush(gs);
00708 
00709 
00710   string in;
00711   cmd.mapvar(in,"in");
00712   if ( in.empty() )
00713   {
00714     cout << "error: in=filename expected" << endl;
00715     return 1;
00716   }
00717 
00718   ifstream filein(in.c_str());
00719   assert(filein.good()==true);
00720   if (filein.good()==false)
00721   {
00722     cout << "error: " << in << " file can not be opened." << endl;
00723     return 1;
00724   }
00725 
00726   messages = 
00727       new menusystem(0,0,true,point2<GLint>(60,250),10);
00728   gobjpush(messages);
00729   messages->fontcolor = point4<float>(1.0,0.0,0.0,0.8);
00730   messages->fontcolorenable();
00731   messages->lightingdisable();
00732 
00733   filein >> bsp;
00734   uint errorh, errorhparent;
00735   //cout << SHOW( << "  ";
00736   //cout << SHOW(errorh) << " " << SHOW(errorhparent) << endl;
00737   bool errorres = bsp.validhalfspaces(errorh,errorhparent);
00738   if (errorres==false)
00739   {
00740     string str;
00741     str += "error:  errorh=";
00742     { stringstream ss; ss << errorh; str += ss.str(); }
00743     str += " errorhparent=";
00744     { stringstream ss; ss << errorhparent; str += ss.str(); }
00745     
00746     messages->addfont12start(str,1);
00747   }
00748 
00749   gobjpush(new gobjglDisable(GL_LIGHTING));
00750   bsptreeD2disp03<pt2,double,uint> * disp
00751     = new bsptreeD2disp03<pt2,double,uint>(bsp,0.04);
00752   disp->update();
00753   gobjpush(disp);
00754   
00755   bsptreeD2dispregions01<pt2,double,uint> *dispregions
00756     = new bsptreeD2dispregions01<pt2,double,uint>(bsp);
00757   dispregions->delta=0.4;
00758   dispregions->update();
00759   gobjpush(dispregions);
00760 
00761 //cout << (stringc)bsp.tree << endl;
00762 
00763   gobjQuadric * q2 = new gobjQuadric();
00764   q2->radius = 0.1;
00765   q2->slices=30;
00766   q2->loops=7;
00767   gobjpush(q2);
00768 
00769   gobjpush(new gobjglPushAttrib(GL_CURRENT_BIT));
00770   gobjpush(new gobjglPushAttrib(GL_LIGHTING));
00771   gobjpush(new gobjglEnable(GL_LIGHTING));
00772   targetsphere = new gobjMySphereDraw(target,q2);
00773   gobjpush( new 
00774     gobjglColor4f( 153.0/255.0, 50.0/255.0, 204.0/255.0, 0.92));
00775   gobjpush(targetsphere);
00776   gobjpush( new gobjglPopAttrib() );
00777   gobjpush( new gobjglPopAttrib() );
00778 
00779   target=pt2(2.5,0.5);
00780   update05();
00781 
00782   //gobjpush(new gobjglDisable(GL_LIGHTING));
00783   menusystem * menu = 
00784     new menusystem(0,0,true,point2<GLint>(60,30),10);
00785   menu->fontcolor = point4<float>(218.0/255.0,165.0/255.0,32.0/255.0,0.75);
00786 
00787   gobjSwitch<> * menuswitch = new gobjSwitch<>(menu,true);
00788   help = & menuswitch->isdrawn;
00789   gobjpush(menuswitch);
00790   //gobjpush(new gobjglEnable(GL_LIGHTING));
00791 
00792   menu->addfont12("BSP Tree Demo",2);
00793 
00794   menu->addfont10("[page up] move up",1);
00795   menu->addfont10("[page down] move down",1);
00796   menu->addfont10("[< home] move left",1);
00797   menu->addfont10("[end >] move right",2);
00798 //  menu->addfont10("j k   Move ball left or right.",1);
00799 //  menu->addfont10("d f   Move ball down or up.",2);
00800 
00801   menu->addfont10("t     Print the targets position.",1);
00802   menu->addfont10("r     Print the targets region.",1);
00803   menu->addfont10("T     Print the tree.",1);
00804   menu->addfont10("v     Print the visibility",2);
00805 
00806   menu->addfont10("+ -   Increase or decrease change.",1);
00807   menu->addfont10("h    Toggle this help menu.",2);
00808   menu->addfont10("ESC      Quit");
00809   
00810   zpr zz;
00811 
00812   zz.update();
00813   glutMainLoop();
00814 
00815   return 0;
00816 }
00817 
00818 

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