Files Classes Functions Hierarchy
00001 00002 #include <cassert> 00003 #include <iostream> 00004 #include <fstream> 00005 00006 using namespace std; 00007 00008 #include <GL/glut.h> 00009 #include <GL/gl.h> 00010 00011 #include <zpr.h> 00012 #include <graphmisc.h> 00013 #include <commandline.h> 00014 #include <gobj.h> 00015 #include <pointsdisplay.h> 00016 #include <random.h> 00017 #include <print.h> 00018 #include <point.h> 00019 00020 #include <d3tess.h> 00021 #include <d3tessdraw.h> 00022 #include <d2func.h> 00023 #include <d2circle.h> 00024 #include <halfspaceD2.h> 00025 #include <aclock.h> 00026 #include <d3meshpointreader.h> 00027 00028 #include <d3minboundary.h> 00029 #include <d3minrecursive.h> 00030 #include <d3mincircle.h> 00031 #include <d3mincentroid.h> 00032 #include <d3mincentroid2.h> 00033 #include <message.h> 00034 #include <typedefs.h> 00035 00036 00037 00038 // Tempory 00039 #include <trianglespace.h> 00040 00041 #define SHOW(x) #x << '=' << (x) 00042 typedef point2<double> pt2; 00043 typedef point2<double> const pt2c; 00044 00045 template<> 00046 double zero<double>::val = 1E-15; 00047 00048 d3tess * mesh; 00049 d3tessdraw *meshdraw; 00050 00051 pt2 targetcenter; 00052 doublec targetradius = 0.6; 00053 d2func * p2dfunc = new d2circle(targetcenter,targetradius); 00054 00055 bool enabletargetcurve(false); 00056 00057 gobjMyCircle targetcircle; 00058 gobjMyCircleDraw targetcurve 00059 ( 00060 targetradius, 00061 pt3(targetcenter.x,targetcenter.y,0.0), 00062 targetcircle 00063 ); 00064 00065 gobjContainer xGraphics; 00066 00067 messagefile error("error.txt",true); 00068 00069 random11<double> r; 00070 00071 void init02(); 00072 00073 00074 // Superior to using cin for string input as a null string can be entered! 00075 string getInputString() 00076 { 00077 string s; 00078 cin >> s; 00079 return s; 00080 /* 00081 string s; 00082 char ch; 00083 for ( ; ; ) 00084 { 00085 ch = cin.peek(); 00086 cin.ignore(); 00087 00088 if (ch=='\n') 00089 return s; 00090 00091 s += ch; 00092 } 00093 00094 assert(false); 00095 return s; 00096 */ 00097 } 00098 00099 00100 // Add a point to the mesh only if it is inside. 00101 boolc addpointinsidemesh() 00102 { 00103 00104 00105 static gobjQuadric q4; 00106 q4.radius=0.005; 00107 00108 xGraphics.push( new gobjglColor3f(1.0,0.0,0.0) ); 00109 00110 uint k= mesh->pt.size(); 00111 00112 pt2 x(-1.0+2.0*r(),-1.0+2.0*r()); 00113 mesh->pt.push_back(pt3(x.x,x.y,p2dfunc->eval(x))); 00114 xGraphics.push( new gobjMySphereDraw( x, &q4 ) ); 00115 00116 if (mesh->searchminimizetowardspoint(k)) 00117 { 00118 00119 00120 messageglobal() << "addpointinsidemesh()" << "\n"; 00121 messageglobal() << *mesh << "\n\n"; 00122 00123 messageglobal() << "k=" << k << "\n"; 00124 00125 mesh->addpoint(k); 00126 messageglobal() << *mesh << "\n\n"; 00127 return true; 00128 } 00129 00130 return false; 00131 } 00132 00133 void addrandompointtomeshptvector(pt2 & x) 00134 { 00135 x = pt2(-1.0+2.0*r(),-1.0+2.0*r()); 00136 mesh->pt.push_back(pt3(x.x,x.y,p2dfunc->eval(x))); 00137 } 00138 00139 00140 void addrandompointtomesh() 00141 { 00142 static gobjQuadric q3; 00143 q3.radius=0.005; 00144 00145 xGraphics.push( new gobjglColor3f(1.0,0.0,0.0) ); 00146 00147 uint k= mesh->pt.size(); 00148 00149 pt2 x; 00150 addrandompointtomeshptvector(x); 00151 //pt2 x(-1.0+2.0*r(),-1.0+2.0*r()); 00152 //mesh->pt.push_back(pt3(x.x,x.y,p2dfunc->eval(x))); 00153 xGraphics.push( new gobjMySphereDraw( x, &q3 ) ); 00154 00155 mesh->addpoint(k); 00156 } 00157 00158 void timmingexperiment04() 00159 { 00160 cout << "Creating a 3D Data Set" << endl; 00161 cout << "Writing Points to a File" << endl; 00162 cout << " Enter the filename: "; 00163 string fname; 00164 cin >> fname; 00165 cout << " Enter the number of points: "; 00166 uint n; 00167 cin >> n; 00168 00169 ofstream targ(fname.c_str()); 00170 00171 for (uint i=0; i<n; ++i) 00172 { 00173 pt2 x(-1.0+2.0*r(),-1.0+2.0*r()); 00174 targ << x.x << " " << x.y << " " << p2dfunc->eval(x) << endl; 00175 } 00176 00177 cout << "Finished writing file: " << fname << endl << endl; 00178 } 00179 00180 void timmingexperiment03() 00181 { 00182 cout << "Creating a 2D Data Set" << endl; 00183 cout << "Writing Points to a File" << endl; 00184 cout << " Enter the filename: "; 00185 string fname; 00186 cin >> fname; 00187 cout << " Enter the number of points: "; 00188 uint n; 00189 cin >> n; 00190 00191 ofstream targ(fname.c_str()); 00192 00193 for (uint i=0; i<n; ++i) 00194 targ << -1.0+2.0*r() << " " << -1.0+2.0*r() << endl; 00195 00196 cout << "Finished writing file: " << fname << endl << endl; 00197 } 00198 00199 void filereadingmesh 00200 ( 00201 d3meshpointreader & mr 00202 ) 00203 { 00204 00205 cout << "Starting insertion of points into the mesh" << endl; 00206 00207 aclock c; 00208 c.measure(); 00209 mr.eval(); 00210 c.measure(); 00211 00212 cout << "Finished insertion of points into the mesh" << endl << endl; 00213 cout << "Time without graphics: "; 00214 cout << c.diff_s() << "s" << endl; 00215 } 00216 00217 void timmingexperiment02() 00218 { 00219 cout << "Reading Points from a File" << endl; 00220 cout << "Expecting the file to have 2 or 3 columns of numbers." << endl; 00221 cout << endl; 00222 cout << " Enter the filename: "; 00223 string fname; 00224 00225 //fname = "dataset2D08.txt"; 00226 //cout << fname << endl; 00227 cin >> fname; 00228 00229 bool res; 00230 d3meshpointreader mr(res,*mesh,fname); 00231 00232 if (res==false) 00233 return; 00234 00235 filereadingmesh(mr); 00236 } 00237 00238 00239 00240 void timmingexperiment01() 00241 { 00242 cout << "Multiple timing experiments" << endl; 00243 cout << endl; 00244 cout << "Enter the filename: "; 00245 string fname; 00246 cin >> fname; 00247 00248 ofstream fil(fname.c_str()); 00249 00250 cout << "Enter number of measurements M: "; 00251 uint M; 00252 cin >> M; 00253 00254 uint n=100; 00255 00256 aclock c; 00257 00258 for (uint k=0; k<M; ++k) 00259 { 00260 cout << SHOW(k) << endl; 00261 cout << SHOW(n) << endl; 00262 mesh->vi.reserve(n); 00263 00264 c.measure(); 00265 for (uint i=0; i<n; ++i) 00266 addrandompointtomesh(); 00267 c.measure(); 00268 fil << n << " " << c.diff_s() << endl; 00269 00270 mesh->reset(); 00271 00272 init02(); 00273 00274 n *= 2; 00275 } 00276 cout << "out of loop" << endl; 00277 exit(0); 00278 00279 } 00280 00281 void timmingexperiment05() 00282 { 00283 cout << "Multiple Timing Experiments." << endl; 00284 cout << "The results are stored in timings.txt" << endl; 00285 00286 cout << "Enter the filename with a list of 2D data files to be timed: "; 00287 string filenames; 00288 //cin >> filenames; 00289 filenames="dataset2Dlist.txt"; 00290 cout << filenames << endl; 00291 00292 ifstream filelist(filenames.c_str()); 00293 00294 ofstream filtim("timings.txt"); 00295 00296 if (filelist.good()==false) 00297 { 00298 cout << "error: can not open file: " << filenames << endl; 00299 return; 00300 } 00301 00302 while (filelist.eof()==false) 00303 { 00304 string f1; 00305 filelist >> f1; 00306 00307 if (f1.empty()) 00308 continue; 00309 00310 cout << "Started reading file: " << f1 << endl; 00311 bool res; 00312 d3meshpointreader mr(res,*mesh,f1); 00313 if (res==false) 00314 { 00315 cout << "error: could not read file:" << f1 << "." << endl; 00316 continue; 00317 } 00318 cout << "Finished reading file: " << f1 << endl; 00319 cout << "Timing file:" << f1 << "." << endl; 00320 00321 cout << "Starting insertion of points into the mesh" << endl; 00322 mr.eval(filtim); 00323 cout << "Finished insertion of points into the mesh" << endl << endl; 00324 } 00325 } 00326 00327 00328 00329 00330 void timmingexperiment06() 00331 { 00332 cout << "Simulating Multiple Timing Experiments." << endl; 00333 cout << "The results are stored in timings.txt" << endl; 00334 cout << "This is testing an algorithm not yet build." << endl; 00335 cout << " It has the same complexity as this one." << endl; 00336 cout << " A O(n) operation is applied after this step." << endl; 00337 cout << endl; 00338 cout << "A bounding box is first inserted. All the points " << endl; 00339 cout << " should lie well within the bounding box." << endl; 00340 cout << endl; 00341 cout << "For a preordered data set I am expecting linear results" << endl; 00342 00343 00344 cout << "Enter the filename with a list of 2D data files to be timed: "; 00345 string filenames; 00346 //cin >> filenames; 00347 filenames="datasetlist.txt"; 00348 cout << filenames << endl; 00349 00350 ifstream filelist(filenames.c_str()); 00351 00352 ofstream filtim("timings.txt"); 00353 00354 if (filelist.good()==false) 00355 { 00356 cout << "error: can not open file: " << filenames << endl; 00357 return; 00358 } 00359 00360 // Points defining the bounding box. 00361 vector< pt3 > vbox; 00362 vbox.push_back( pt3(-2.0,-2.0,0.0) ); 00363 vbox.push_back( pt3(2.0,-2.0,0.0) ); 00364 vbox.push_back( pt3(2.0,2.0,0.0) ); 00365 vbox.push_back( pt3(-2.0,2.0,0.0) ); 00366 00367 00368 while (filelist.eof()==false) 00369 { 00370 string f1; 00371 filelist >> f1; 00372 00373 if (f1.empty()) 00374 continue; 00375 00376 cout << "Started reading file: " << f1 << endl; 00377 bool res; 00378 d3meshpointreader mr(res,*mesh,vbox,f1); 00379 if (res==false) 00380 { 00381 cout << "error: could not read file:" << f1 << "." << endl; 00382 continue; 00383 } 00384 cout << "Finished reading file: " << f1 << endl; 00385 cout << "Timing file:" << f1 << "." << endl; 00386 00387 cout << "Starting insertion of points into the mesh" << endl; 00388 mr.eval(filtim); 00389 cout << "Finished insertion of points into the mesh" << endl << endl; 00390 } 00391 } 00392 00393 00394 00395 00396 00397 00398 00399 void timmingexperiment00() 00400 { 00401 cout << "Timing experiment." << endl; 00402 cout << "Enter the number of points n: "; 00403 uint n; 00404 cin >> n; 00405 mesh->vi.reserve(n); 00406 00407 aclock c; 00408 c.measure(); 00409 for (uint i=0; i<n; ++i) 00410 addrandompointtomesh(); 00411 c.measure(); 00412 cout << "Time without graphics: "; 00413 cout << c.diff_s() << "s" << endl; 00414 00415 meshdraw->meshupdate(); 00416 } 00417 00418 void minimizermenu() 00419 { 00420 cout << endl; 00421 cout << "Minimizer Menu" << endl; 00422 cout << endl; 00423 cout << "The tessellator has a minimizer." << endl; 00424 cout << "Setting the minimizer affects all future mesh insertions." << endl; 00425 cout << endl; 00426 cout << " 0: No minimizer" << endl; 00427 cout << " 1: minb - minimize the boundary on insertion" << endl; 00428 cout << " 2: minbr" << endl; 00429 cout << " 3: minc" << endl; 00430 cout << " 4: minDT - Delaunay Triangulation" << endl; 00431 cout << " 5: mincentroid" << endl; 00432 cout << " 6: mincentroidr" << endl; 00433 00434 cout << " Enter a choice "; 00435 00436 string const s = getInputString(); 00437 if (s.empty()) 00438 { 00439 cout << "No Choice Executed" << endl; 00440 cout << "End of Minimizer Menu" << endl; 00441 return; 00442 } 00443 00444 if (s=="0") 00445 mesh->minimizerSet( new d3minoperator(*mesh) ); 00446 00447 if (s=="1") 00448 mesh->minimizerSet( new d3minboundary(*mesh) ); 00449 00450 if (s=="2") 00451 mesh->minimizerSet 00452 ( 00453 new d3minrecursiveoperator(*mesh,new d3minboundary(*mesh)) 00454 ); 00455 00456 if (s=="3") 00457 mesh->minimizerSet( new d3mincircle(*mesh) ); 00458 00459 if (s=="4") 00460 mesh->minimizerSet 00461 ( 00462 new d3minrecursiveoperator(*mesh,new d3mincircle(*mesh)) 00463 ); 00464 00465 if (s=="5") 00466 mesh->minimizerSet( new d3mincentroid(*mesh) ); 00467 00468 if (s=="6") 00469 mesh->minimizerSet 00470 ( 00471 new d3minrecursiveoperator(*mesh,new d3mincentroid2(*mesh)) 00472 ); 00473 00474 cout << "End of Choice Menu" << endl; 00475 } 00476 00477 00478 void searchStats 00479 ( 00480 double & searchlongest, 00481 double & searchaverage, 00482 uintc n 00483 ) 00484 { 00485 // Create the mesh first. 00486 mesh->reset(); 00487 init02(); 00488 00489 for (uint i=3; i<n; ++i) 00490 addrandompointtomesh(); 00491 00492 // Create a vector of points inside the mesh 00493 vector<uint> v; 00494 00495 pt2 x; 00496 uint k; 00497 for ( ; v.size()<n; ) 00498 { 00499 k = mesh->pt.size(); 00500 addrandompointtomeshptvector(x); 00501 if (mesh->searchminimizetowardspoint(k)) 00502 v.push_back(k); 00503 } 00504 00505 // Set the cp to some random point inside the mesh 00506 mesh->cp = (rand()% n)+1; 00507 00508 mesh->searchminimizetowardspoint(v[0]); 00509 double c = mesh->movecounter; 00510 searchlongest = c; 00511 searchaverage = c; 00512 00513 for (uint i=1, sz=v.size(); i<sz; ++i) 00514 { 00515 #ifndef NDEBUG 00516 assert( mesh->searchminimizetowardspoint(v[i]) ); 00517 #else 00518 mesh->searchminimizetowardspoint(v[i]); 00519 #endif 00520 00521 c = mesh->movecounter; 00522 if (c>searchlongest) 00523 searchlongest = c; 00524 00525 searchaverage += c; 00526 } 00527 00528 searchaverage *= 1.0/n; 00529 } 00530 00531 00532 00533 void searchexp01() 00534 { 00535 cout << "Enter the number of points: "; 00536 uint n; 00537 cin >> n; 00538 00539 double searchlongest; 00540 double searchaverage; 00541 00542 searchStats(searchlongest,searchaverage,n); 00543 00544 cout << SHOW(searchlongest) << endl; 00545 cout << SHOW(searchaverage) << endl; 00546 00547 meshdraw->meshupdate(); 00548 } 00549 00550 void searchexp02() 00551 { 00552 uint nmax = 1000000; 00553 00554 cout << "Writing search results to search.txt" << endl; 00555 cout << "The number of points is capped at " << nmax << endl; 00556 00557 string fname("search.txt"); 00558 ofstream f(fname.c_str()); 00559 00560 if (f.good()==false) 00561 { 00562 cout << "error: can not open file: " << fname << endl; 00563 return; 00564 } 00565 00566 uint n = 8; 00567 uint N = 3; 00568 00569 cout << "Enter the initial number of points u and the number of times" << endl; 00570 cout << " this is doubled." << endl; 00571 cin >> n; 00572 cin >> N; 00573 00574 double searchlongest; 00575 double searchaverage; 00576 00577 for (uint i=0; i<N; ++i) 00578 { 00579 searchStats(searchlongest,searchaverage,n); 00580 f << n << " " << searchaverage << endl; 00581 n *= 2; 00582 } 00583 } 00584 00585 void filewritingmesh() 00586 { 00587 cout << endl; 00588 cout << " Writing the mesh out." << endl; 00589 cout << endl; 00590 cout << " Enter the filename: "; 00591 00592 string fname(getInputString()); 00593 00594 if (fname.empty()) 00595 return; 00596 00597 ofstream targ(fname.c_str()); 00598 00599 if (targ.good()==false) 00600 { 00601 cout << "error: could not write the file out." << endl; 00602 return; 00603 } 00604 00605 targ << *mesh; 00606 } 00607 00608 void filereadingmesh() 00609 { 00610 cout << endl; 00611 cout << " Reading a mesh in." << endl; 00612 cout << endl; 00613 cout << " Enter the filename: "; 00614 00615 string fname(getInputString()); 00616 00617 if (fname.empty()) 00618 return; 00619 00620 ifstream targ(fname.c_str()); 00621 00622 if (targ.good()==false) 00623 { 00624 cout << "error: could not read the file." << endl; 00625 return; 00626 } 00627 00628 targ >> *mesh; 00629 } 00630 00631 00632 void filemenu() 00633 { 00634 cout << endl; 00635 cout << "File Menu" << endl; 00636 cout << endl; 00637 cout << " 0: Read a tessellation in from a file." << endl; 00638 cout << " 1: Write a tessellation out to a file." << endl; 00639 cout << " 2: Read points from file." << endl; 00640 cout << " 3: Create a new data set by writing 2D random data points to a file." << endl; 00641 cout << " 4: Create a new data set by writing 3D random data points to a file." << endl; 00642 00643 cout << " Enter a choice "; 00644 00645 string const s = getInputString(); 00646 if (s.empty()) 00647 { 00648 cout << "No Choice Executed" << endl; 00649 cout << "End of File Menu" << endl; 00650 return; 00651 } 00652 00653 if (s=="0") 00654 filereadingmesh(); 00655 00656 if (s=="1") 00657 filewritingmesh(); 00658 00659 if (s=="2") 00660 timmingexperiment02(); 00661 00662 if (s=="3") 00663 timmingexperiment03(); 00664 00665 if (s=="4") 00666 timmingexperiment04(); 00667 00668 } 00669 00670 00671 void searchmenu() 00672 { 00673 cout << endl; 00674 cout << "Search Menu" << endl; 00675 cout << endl; 00676 cout << " 0: Calculate the shortes, longest and average lengths" << endl; 00677 cout << " of a n point data set with n random inside searches." << endl; 00678 cout << " 1: Write the average search lengths to a file search.txt ." << endl; 00679 00680 cout << " Enter a choice "; 00681 00682 string const s = getInputString(); 00683 if (s.empty()) 00684 { 00685 cout << "No Choice Executed" << endl; 00686 cout << "End of Search Menu" << endl; 00687 return; 00688 } 00689 00690 if (s=="0") 00691 searchexp01(); 00692 00693 if (s=="1") 00694 searchexp02(); 00695 00696 cout << "End of Search Menu" << endl; 00697 } 00698 00699 void timmingsmenu() 00700 { 00701 cout << endl; 00702 cout << "Timmings Menu" << endl; 00703 cout << endl; 00704 cout << " 0: One tessellation with n points measured." << endl; 00705 cout << " 1: Multiple timing measurements to file." << endl; 00706 cout << " 2: Multiple timmings on 2D data files" << endl; 00707 cout << " 3: Simulating Multiple timmings on my Bounded Algorithm" << endl; 00708 cout << " Enter a choice "; 00709 00710 00711 string const s = getInputString(); 00712 if (s.empty()) 00713 { 00714 cout << "No Choice Executed" << endl; 00715 cout << "End of Timmings Menu" << endl; 00716 return; 00717 } 00718 00719 if (s=="0") 00720 timmingexperiment00(); 00721 00722 if (s=="1") 00723 timmingexperiment01(); 00724 00725 if (s=="2") 00726 timmingexperiment05(); 00727 00728 if (s=="3") 00729 timmingexperiment06(); 00730 00731 cout << "End of Timmings Menu" << endl; 00732 } 00733 00734 00735 00736 00737 void displaymenu() 00738 { 00739 cout << endl; 00740 cout << "Display Menu" << endl; 00741 cout << endl; 00742 cout << " 0: points numbering toggle" << endl; 00743 cout << " 1: triangles numbering toggle" << endl; 00744 cout << " 2: winding toggle" << endl; 00745 cout << " 3: grid toggle" << endl; 00746 cout << " 4: cp toggle" << endl; 00747 cout << " 5: surface toggle" << endl; 00748 cout << " 6: cp circle toggle" << endl; 00749 cout << " 7: circles through triangles" << endl; 00750 cout << " 8: cp voronoi local polygons about base vertices" << endl; 00751 cout << " 9: multicolored triangles" << endl; 00752 cout << " 10: voronoi diagram" << endl; 00753 00754 cout << " Enter a choice "; 00755 00756 string const s = getInputString(); 00757 if (s.empty()) 00758 { 00759 cout << "No Choice Executed" << endl; 00760 cout << "End of Display Menu" << endl; 00761 return; 00762 } 00763 00764 if (s=="0") 00765 { 00766 meshdraw->graphicsDeffered.gswitch[0]->toggle(); 00767 meshdraw->meshupdate(); 00768 } 00769 00770 if (s=="1") 00771 { 00772 meshdraw->graphicsDeffered.gswitch[1]->toggle(); 00773 meshdraw->meshupdate(); 00774 } 00775 00776 if (s=="9") 00777 { 00778 meshdraw->graphicsDeffered.gswitch[2]->toggle(); 00779 meshdraw->meshupdate(); 00780 } 00781 00782 if (s=="10") 00783 { 00784 meshdraw->graphicsDeffered.gswitch[3]->toggle(); 00785 meshdraw->meshupdate(); 00786 } 00787 00788 if (s=="2") 00789 meshdraw->graphicsImmediate.gswitch[0]->toggle(); 00790 00791 if (s=="3") 00792 meshdraw->graphicsImmediate.gswitch[1]->toggle(); 00793 00794 if (s=="4") 00795 meshdraw->graphicsImmediate.gswitch[2]->toggle(); 00796 00797 if (s=="5") 00798 meshdraw->graphicsImmediate.gswitch[3]->toggle(); 00799 00800 if (s=="6") 00801 meshdraw->graphicsImmediate.gswitch[4]->toggle(); 00802 00803 if (s=="7") 00804 meshdraw->graphicsImmediate.gswitch[5]->toggle(); 00805 00806 if (s=="8") 00807 meshdraw->graphicsImmediate.gswitch[6]->toggle(); 00808 00809 00810 00811 cout << "End of Display Menu" << endl; 00812 } 00813 00814 00815 void mainmenu() 00816 { 00817 for (; ; ) 00818 { 00819 00820 cout << endl; 00821 cout << "Main Menu" << endl; 00822 cout << endl; 00823 cout << " 0: Timmings Menu" << endl; 00824 cout << " 1: Display Menu" << endl; 00825 cout << " 2: File Menu" << endl; 00826 00827 cout << " 5: Change the Minimizer." << endl; 00828 cout << " 6: Reset the mesh." << endl; 00829 cout << " 9: Search Menu" << endl; 00830 00831 cout << " Enter a choice "; 00832 00833 00834 string const s = getInputString(); 00835 if (s.empty()) 00836 { 00837 cout << "No Choice Executed" << endl; 00838 cout << "End of Main Menu" << endl; 00839 return; 00840 } 00841 00842 if (s=="0") 00843 timmingsmenu(); 00844 00845 if (s=="1") 00846 displaymenu(); 00847 00848 if (s=="2") 00849 filemenu(); 00850 00851 if (s=="5") 00852 minimizermenu(); 00853 00854 if (s=="6") 00855 { 00856 mesh->reset(); 00857 init02(); 00858 meshdraw->meshupdate(); 00859 } 00860 00861 if (s=="9") 00862 searchmenu(); 00863 00864 } 00865 } 00866 00867 00868 void keyboard(unsigned char key, int x, int y) 00869 { 00870 switch (key) 00871 { 00872 case 27: 00873 delete mesh; 00874 mesh=0; 00875 delete meshdraw; 00876 meshdraw=0; 00877 delete p2dfunc; 00878 p2dfunc=0; 00879 00880 exit(0); 00881 break; 00882 00883 case 'a': 00884 mesh->vs.anticlockwise(); 00885 break; 00886 00887 case 'A': 00888 mesh->vs.clockwise(); 00889 break; 00890 00891 case 'j': 00892 mesh->moveleft(); 00893 break; 00894 00895 case 'k': 00896 mesh->moveright(); 00897 break; 00898 00899 case 'm': 00900 mesh->movedown(); 00901 break; 00902 00903 case 'b': 00904 mesh->boundaryorient(); 00905 break; 00906 00907 case 'w': 00908 mesh->surfaceleft(); 00909 break; 00910 case 'e': 00911 mesh->surfaceright(); 00912 break; 00913 00914 case 'R': 00915 { 00916 for (; !addpointinsidemesh(); ); 00917 00918 meshdraw->meshupdate(); 00919 } 00920 break; 00921 00922 00923 case 'r': 00924 addrandompointtomesh(); 00925 meshdraw->meshupdate(); 00926 break; 00927 00928 case 't': 00929 for (uint i=0; i<100; ++i) 00930 addrandompointtomesh(); 00931 meshdraw->meshupdate(); 00932 break; 00933 00934 case 'T': 00935 mainmenu(); 00936 break; 00937 00938 case 'p': 00939 cout << endl; 00940 cout << *mesh; 00941 break; 00942 00943 case 'z': 00944 mesh->flip(); 00945 meshdraw->meshupdate(); 00946 break; 00947 00948 case 'l': 00949 cout << "l=" << mesh->cpbasemeasure() << endl; 00950 break; 00951 00952 } 00953 00954 glutPostRedisplay(); 00955 } 00956 00957 void display() 00958 { 00959 //glMatrix temp; 00960 myglPushMatrix temp; 00961 00962 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00963 00964 //axes(0.5); 00965 00966 meshdraw->draw(); 00967 00968 xGraphics.draw(); 00969 00970 glerrordisplay(); 00971 00972 { 00973 glPushMatrix(); 00974 00975 glPushAttrib(GL_CURRENT_BIT); 00976 glPushAttrib(GL_LIGHTING_BIT); 00977 00978 glColor3f(1.0,1.0,0.0); 00979 glEnable(GL_LIGHTING); 00980 00981 if (enabletargetcurve) 00982 targetcurve.draw(); 00983 00984 glPopAttrib(); 00985 glPopAttrib(); 00986 00987 glPopMatrix(); 00988 } 00989 glerrordisplay(); 00990 00991 glutSwapBuffers(); 00992 } 00993 00994 void addpoint(pt2 const & x) 00995 { 00996 mesh->pt.push_back(p2dfunc->make(x.x,x.y)); 00997 } 00998 00999 void addpoint(doublec x, doublec y) 01000 { 01001 mesh->pt.push_back(p2dfunc->make(x,y)); 01002 } 01003 01004 void init00() 01005 { 01006 cout << endl; 01007 cout << "Test Mesh" << endl; 01008 01009 mesh->pt.push_back(p2dfunc->make(0.0,0.0)); 01010 mesh->pt.push_back(p2dfunc->make(1.0,0.0)); 01011 mesh->pt.push_back(p2dfunc->make(1.0,1.0)); 01012 01013 mesh->vi.push_back( simplexD2linked(1,2,3, 0,0,0) ); 01014 } 01015 01016 void init02() 01017 { 01018 cout << endl; 01019 cout << "Test Mesh" << endl; 01020 cout << "Adding three random points to make the first" << endl; 01021 cout << " simplex or triangle in the mesh." << endl; 01022 01023 for (uint i=0; i<3; ++i) 01024 mesh->pt.push_back( 01025 p2dfunc->make(-1.0+2.0*r(),-1.0+2.0*r()) ); 01026 01027 mesh->initialize(); 01028 } 01029 01030 01031 01032 void help() 01033 { 01034 cout << "Command Line Options" << endl; 01035 cout << "For boolean values true and 1, false and 0 are equivalent" << endl; 01036 cout << "file=filename - read in points from a file" << endl; 01037 cout << "cp=true - current pointer" << endl; 01038 cout << "winding=true - display the triangle windings" << endl; 01039 cout << "surface=true - draw the surface" << endl; 01040 cout << "grid=true - draw the triangles as blue grid" << endl; 01041 cout << "points=true - number each point with its integer index" << endl; 01042 cout << "debug=0 - only use when NDEBUG is undefined so checkdebug() is not excecuted" << endl; 01043 cout << "triangles=1 - number each triangle with its integer index" << endl; 01044 cout << "cpcircle=1 - draw a circle through the cp's simplex." << endl; 01045 cout << "circles=1 - draw circles through every simplex." << endl; 01046 cout << "cpvoronoi=1 - display voronoi polygons about the cp." << endl; 01047 cout << "multcolor=1 - display the triangles with random colorings" << endl; 01048 cout << "voronoi=1 - display strict voronoi polygons" << endl; 01049 01050 01051 cout << endl; 01052 cout << "Keyboard Commands" << endl; 01053 cout << "'T' enters you into the main menu which is displayed at the" << endl; 01054 cout << " command line rather than the application." << endl << endl; 01055 cout << "'a' 'A' - rotate anticlockwise or clockwise the cp triangle." << endl; 01056 cout << "'j' 'k' - move left, right and down on current triangle" << endl; 01057 cout << " 'm'" << endl; 01058 cout << "'b' - orient the current triangle to the boundary if possible" << endl; 01059 cout << "'w' 'e' - First orient the cp to the boundary with 'b'. Then move" << endl; 01060 cout << " on the surface left and right respectively." << endl; 01061 cout << "'z' - the flip operator" << endl; 01062 01063 cout << endl; 01064 cout << "Minimizers" << endl; 01065 cout << " Explore mesh balancing." << endl; 01066 cout << " By default no mesh balancing is performed." << endl; 01067 cout << "minb=1 - boundary minimization on insertion" << endl; 01068 cout << "minbr=1 - boundary minimization with recursion" << endl; 01069 cout << "minc=1 - circle minimization on insertion" << endl; 01070 cout << "minDT=1 - Delauny Triangulation - recursive circle minimization" << endl; 01071 cout << "mincentroid=1 - circle by average points and radius, insertion" << endl; 01072 cout << "mincentroid2r=1 - circle by average points and min radius, recursive" << endl; 01073 //cout << "greedy=true - very bad mesh generated." << endl; 01074 //cout << "greedy2=true - very experimental, do I know what I am doing?" << endl; 01075 01076 } 01077 01078 01079 int main(int argc, char** argv ) 01080 { 01081 glutInit(&argc,argv); 01082 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 01083 uintc wx=800; 01084 uintc wy=800; 01085 01086 glutInitWindowSize(wx,wy); 01087 01088 glutCreateWindow(""); 01089 01090 glutDisplayFunc(display); 01091 glutKeyboardFunc(keyboard); 01092 01093 OpenGLinitialisation(); 01094 01095 glEnable(GL_DEPTH_TEST); 01096 01097 //glDisable(GL_CULL_FACE); 01098 glEnable(GL_CULL_FACE); 01099 01100 glEnable(GL_NORMALIZE); 01101 01102 xGraphics.set(); 01103 01104 //error.setMessageGlobal(); 01105 error.globalset(); 01106 01107 help(); 01108 01109 commandline cmd(argc,argv); 01110 01111 uint N(1000); 01112 cmd.mapvar(N,"N"); 01113 01114 mesh = new d3tess(N); 01115 01116 cmd.mapvar(mesh->debugenable,"debug"); 01117 01118 meshdraw = new d3tessdraw(*mesh); 01119 01120 cmd.mapvar(meshdraw->graphicsDeffered.gswitch[d3tessdraw::points]->isdrawn,"points"); 01121 cmd.mapvar(meshdraw->graphicsDeffered.gswitch[d3tessdraw::simplexes]->isdrawn,"triangles"); 01122 cmd.mapvar(meshdraw->graphicsDeffered.gswitch[d3tessdraw::multicolor]->isdrawn,"multicolor"); 01123 cmd.mapvar(meshdraw->graphicsDeffered.gswitch[d3tessdraw::voronoi]->isdrawn,"voronoi"); 01124 01125 01126 cmd.mapvar(meshdraw->graphicsImmediate.gswitch[d3tessdraw::winding]->isdrawn,"winding"); 01127 cmd.mapvar(meshdraw->graphicsImmediate.gswitch[d3tessdraw::grid]->isdrawn,"grid",true); 01128 cmd.mapvar(meshdraw->graphicsImmediate.gswitch[d3tessdraw::cp]->isdrawn,"cp",true); 01129 cmd.mapvar(meshdraw->graphicsImmediate.gswitch[d3tessdraw::surface]->isdrawn,"surface"); 01130 cmd.mapvar(meshdraw->graphicsImmediate.gswitch[d3tessdraw::circle]->isdrawn,"cpcircle"); 01131 cmd.mapvar(meshdraw->graphicsImmediate.gswitch[d3tessdraw::circles]->isdrawn,"circles"); 01132 cmd.mapvar(meshdraw->graphicsImmediate.gswitch[d3tessdraw::voronoip]->isdrawn,"cpvoronoi"); 01133 01134 01135 01136 bool enableminb(false); 01137 cmd.mapvar(enableminb,"minb"); 01138 if (enableminb) 01139 mesh->minimizerSet( new d3minboundary(*mesh) ); 01140 01141 bool enableminbr(false); 01142 cmd.mapvar(enableminbr,"minbr"); 01143 if (enableminbr) 01144 mesh->minimizerSet 01145 ( 01146 new d3minrecursiveoperator(*mesh,new d3minboundary(*mesh)) 01147 ); 01148 01149 bool enableminc(false); 01150 cmd.mapvar(enableminc,"minc"); 01151 if (enableminc) 01152 mesh->minimizerSet( new d3mincircle(*mesh) ); 01153 01154 bool enableminDT(false); 01155 cmd.mapvar(enableminDT,"minDT"); 01156 if (enableminDT) 01157 mesh->minimizerSet 01158 ( 01159 new d3minrecursiveoperator(*mesh,new d3mincircle(*mesh)) 01160 ); 01161 01162 bool enablemincentroid(false); 01163 cmd.mapvar(enablemincentroid,"mincentroid"); 01164 if (enablemincentroid) 01165 mesh->minimizerSet( new d3mincentroid(*mesh) ); 01166 01167 bool enablemincentroid2r(false); 01168 cmd.mapvar(enablemincentroid2r,"mincentroid2r"); 01169 if (enablemincentroid2r) 01170 mesh->minimizerSet 01171 ( 01172 new d3minrecursiveoperator(*mesh,new d3mincentroid2(*mesh)) 01173 ); 01174 01175 cmd.mapvar(enabletargetcurve,"targetcurve"); 01176 01177 //test01(); 01178 01179 r.rg.seed(17); 01180 01181 string fname; 01182 cmd.mapvar(fname,"file"); 01183 bool fileread(false); 01184 01185 if (fname.empty()==false) 01186 { 01187 d3meshpointreader mr(fileread,*mesh,fname); 01188 01189 if (fileread) 01190 filereadingmesh(mr); 01191 else 01192 cout << "error: could not read file " << fname << endl; 01193 } 01194 01195 if (fileread==false) 01196 init02(); 01197 01198 meshdraw->meshupdate(); 01199 01200 zpr zz; 01201 01202 glutPostRedisplay(); 01203 01204 glutMainLoop(); 01205 01206 return 0; 01207 } 01208 01209 01210 01211
1.5.8