Files Classes Functions Hierarchy
00001 #include <cassert> 00002 #include <iostream> 00003 #include <fstream> 00004 using namespace std; 00005 00006 // TODO clean this up! 00007 00008 #include <GL/glut.h> 00009 #include <GL/gl.h> 00010 00011 #include <arc.h> 00012 #include <arcdraw.h> 00013 #include <arcsconnected.h> 00014 #include <arcsdef.h> 00015 #include <arcprob.h> 00016 #include <commandline.h> 00017 #include <farcmin01.h> 00018 #include <gobj.h> 00019 #include <graphmisc.h> 00020 #include <openwindowresource.h> 00021 #include <pathlinesegtest.h> 00022 #include <zpr.h> 00023 00024 // Instanciated in main as pathlineseg.cpp needs it but cannot instantiate it. 00025 template<> 00026 double zero<double>::val = 1E-10; 00027 00028 00029 void print(vector<arc> const & v) 00030 { 00031 cout << endl << endl; 00032 cout << "Printing the arcs" << endl; 00033 for (uint i=0; i<v.size(); ++i) 00034 v[i].print(); 00035 } 00036 00037 00038 void writearcgeometry(int argc, char** & argv) 00039 { 00040 commandline cmd(argc,argv); 00041 string filearcs = "pa03.txt"; 00042 cmd.mapvar(filearcs,"filearcs"); 00043 00044 if (filearcs.empty()) 00045 { 00046 cout << "error: no filearcs=<filename> command"; 00047 cout << " line argument" << endl; 00048 return; 00049 } 00050 00051 vector<arc> vi; 00052 arc::arcreader(vi,filearcs.c_str()); 00053 00054 for (uint i=0; i<vi.size(); ++i) 00055 { 00056 arcdraw *ad = new arcdraw(vi[i]); 00057 gobj::global->push(ad); 00058 } 00059 00060 print(vi); 00061 00062 } 00063 00064 00065 00066 00067 00068 void prog01(int argc, char** & argv) 00069 { 00070 00071 openwindowresource window(argc,argv); 00072 00073 writearcgeometry(argc,argv); 00074 00075 00076 } 00077 00078 void test01() 00079 { 00080 cout << "Looking at the atan2 function" << endl; 00081 cout << "Really asking the question that given a point" << endl; 00082 cout << "on a unit circle what is its angle." << endl; 00083 cout << endl; 00084 double phi; 00085 cout << "Enter phi(degrees): "; 00086 cin >> phi; 00087 phi *= PI/180.0; 00088 00089 pt2 p0(cos(phi),sin(phi)); 00090 p0.normalize(); 00091 cout << p0 << endl; 00092 double theta; 00093 theta = atan2(p0.y,p0.x); 00094 cout << theta << endl; 00095 cout << theta*180.0/PI << endl; 00096 } 00097 00098 00099 void test02() 00100 { 00101 arc a(1.0,pt2(0.0,1.0),pt2(1.0,0.0)); 00102 cout << "center=" << a.center << endl; 00103 } 00104 00105 void test03() 00106 { 00107 vector<arc> v; 00108 00109 arc::arcreader(v,"pa03.txt"); 00110 00111 for (uint i=0; i<v.size(); ++i) 00112 { 00113 cout << v[i].p0 << " " << v[i].p1 << " "; 00114 cout << v[i].radius << endl; 00115 } 00116 00117 } 00118 00119 void test04() 00120 { 00121 vector<pt2> pts; 00122 pts.push_back( pt2(0.0,0.0) ); 00123 pts.push_back( pt2(1.0,1.1) ); 00124 pts.push_back( pt2(1.5,2.8) ); 00125 00126 00127 arc a1(2.5,pts[0],pts[1]); 00128 00129 cout << "a1" << endl; 00130 a1.print(); 00131 00132 double theta0 = a1.phi1 + PI; 00133 if (theta0 > 2.0*PI) 00134 theta0 -= 2.0*PI; 00135 00136 cout << SHOW(a1.phi1*radtodeg) << endl; 00137 cout << SHOW(theta0*radtodeg) << endl; 00138 00139 arc a2; 00140 a2.constructPhi0TwoPoints(theta0,pts[1],pts[2]); 00141 00142 //cout << "a2" << endl; 00143 //a2.print(); 00144 00145 } 00146 00147 void test05(int argc, char** & argv) 00148 { 00149 cout << "Constructing connected arcs" << endl; 00150 openwindowresource window(argc,argv); 00151 00152 vector<pt2> pts; 00153 pts.push_back( pt2(0.0,0.0) ); 00154 pts.push_back( pt2(1.0,1.1) ); 00155 pts.push_back( pt2(1.5,2.8) ); 00156 pts.push_back( pt2(2.8,4.2) ); 00157 00158 pts.push_back( pt2(4.8,4.0) ); 00159 pts.push_back( pt2(6.8,4.2) ); 00160 pts.push_back( pt2(8.1,5.5) ); 00161 00162 00163 arcsconnected ac(3,pts.size()-1); 00164 00165 ac.constructR0(2.5,pts); 00166 00167 uintc N = ac.vi.size(); 00168 vector<arc> & vi(ac.vi); 00169 00170 00171 for (uint i=0; i<N; ++i) 00172 { 00173 arcdraw *ad = new arcdraw(vi[i]); 00174 gobj::global->push(ad); 00175 } 00176 00177 //print(vi); 00178 } 00179 00180 00181 void test06() 00182 { 00183 cout << "Testing the distance from any point to an arc" << endl; 00184 00185 pt2 p0(1.0,0.0); 00186 pt2 p1(0.0,1.0); 00187 00188 arc a1(1.0,p0,p1); 00189 a1.print(); 00190 00191 cout << "Enter a point" << endl; 00192 pt2 p2(0.0,1.0); 00193 cin >> p2; 00194 double dist(0.0); 00195 a1.distance(dist,p2); 00196 cout << SHOW(dist) << endl; 00197 00198 } 00199 00200 void test07(int argc, char** & argv) 00201 { 00202 string fileprob="pb01.txt"; 00203 arcprob a1(fileprob); 00204 00205 string filearcs="pa04.txt"; 00206 00207 //cout << "arcprob constructed???" << endl; 00208 00209 assert(a1.ac!=0); 00210 00211 a1.ac->arcwriter("pa04.txt"); 00212 00213 cout << endl << endl; 00214 cout << "Look at the arc produced" << endl; 00215 00216 vector<arc> & vi(a1.ac->vi); 00217 for (uint i=0; i<vi.size(); ++i) 00218 vi[i].print(); 00219 } 00220 00221 void displayarcsfileformat() 00222 { 00223 cout << "Displaying the Arcs File Format" << endl; 00224 cout << endl; 00225 cout << " Format for filearcs: This is a text file containing a list" << endl; 00226 cout << " of points and arcs. An arc is described by three parameters" << endl; 00227 cout << " i j radius where i and j are indexes into the list of points." << endl; 00228 cout << " The arc is on the right of line ij if the radius is +ve, " << endl; 00229 cout << " left if the radius is -ve." << endl; 00230 cout << endl; 00231 cout << " Here is an example of the filearc file." << endl; 00232 cout << endl; 00233 00234 cout << "3" << endl; 00235 cout << "0.0 0.0" << endl; 00236 cout << "1.0 1.1" << endl; 00237 cout << "1.5 2.8" << endl; 00238 cout << "2" << endl; 00239 cout << "0 1 2.5" << endl; 00240 cout << "1 2 -2.5" << endl; 00241 cout << endl; 00242 00243 cout << " The first number is the number of points to be read in." << endl; 00244 cout << " After the 2D points comes the number of arcs to be read" << endl; 00245 cout << " Each arc indexes to two points and has a signed radius" << endl; 00246 cout << endl; 00247 } 00248 00249 void test08() 00250 { 00251 pt2 p0(0.0,0.0); 00252 //pt2 p1(1.5,2.8); 00253 pt2 p1(1.5,0.8); 00254 double theta=315.0*degtorad; 00255 00256 arc a1; 00257 a1.constructPhi0TwoPoints(theta,p0,p1); 00258 a1.print(); 00259 00260 00261 } 00262 00263 int main(int argc, char** argv) 00264 { 00265 commandline cmd(argc,argv); 00266 uint prog(0); 00267 cmd.mapvar(prog,"prog"); 00268 00269 bool help(false); 00270 cmd.mapvar(help,"help"); 00271 if (help==true) 00272 { 00273 displayarcsfileformat(); 00274 } 00275 00276 switch (prog) 00277 { 00278 case 0: 00279 cout << "Test programs for arc workspace" << endl << endl; 00280 00281 cout << "$./main prog=1 filearcs=<pa03.txt> " << endl; 00282 cout << " Display 2D arcs in file filearcs." << endl; 00283 00284 cout << "$./main prog=5" << endl; 00285 cout << " Constructing connected arcs" << endl; 00286 cout << "$./main prog=6" << endl; 00287 cout << " Testing the distance from a point to an arc." << endl; 00288 cout << "$/.main prog=7 fileprob=<pb01.txt> filearcs=<pa04.txt>" << endl; 00289 cout << " Testing initial condition solution" << endl; 00290 cout << "$./main prog=8" << endl; 00291 cout << " Looking at initial angle and 2 points construction." << endl; 00292 cout << "$./main prog=30 " << pathlinesegtest::doc[1] << endl; 00293 cout << "$./main prog=31 " << pathlinesegtest::doc[2] << endl; 00294 cout << "$./main prog=32 " << pathlinesegtest::doc[3] << endl; 00295 cout << "$./main prog=33 " << pathlinesegtest::doc[4] << endl; 00296 00297 00298 cout << "./main help=true" << endl; 00299 cout << " Display info such as the arc file formats." << endl; 00300 00301 break; 00302 00303 case 1: prog01(argc,argv); break; 00304 00305 case 4: test04(); break; 00306 case 5: test05(argc,argv); break; 00307 case 6: test06(); break; 00308 case 7: test07(argc,argv); break; 00309 case 8: test08(); break; 00310 00311 case 30: pathlinesegtest::test01(argc,argv); break; 00312 case 31: pathlinesegtest::test02(); break; 00313 case 32: return pathlinesegtest::unittest01(argc,argv); 00314 case 33: pathlinesegtest::test03(argc,argv); break; 00315 00316 default: cout << "error: No case handled." << endl; return 1; 00317 } 00318 00319 00320 return 0; 00321 } 00322 00323 00324 00325
1.5.8