Files Classes Functions Hierarchy
00001 #ifndef MENU01_H 00002 #define MENU01_H 00003 00004 #include <sstream> 00005 #include <string> 00006 00007 using namespace std; 00008 00009 00010 #include <myglutgui.h> 00011 #include <menusystem.h> 00012 #include <primitivewindow.h> 00013 00014 00015 00016 template< typename T > 00017 class menu01 : public menusystem 00018 { 00019 T & x; 00020 char state; 00021 public: 00022 00023 menu01(T & _x); 00024 00025 void draw(); 00026 00027 gobjglTranslatef meshAoffset; 00028 00029 protected: 00030 void readImmediate(char const key); 00031 void readBufferedTerminationAction(); 00032 00033 uint simplexdelete; 00034 uint simplexsplitting; 00035 uint simplexswap; 00036 uint simplexminedgelength; 00037 00038 primitiveWindow* displaywindow; 00039 }; 00040 00041 template< typename T > 00042 void menu01<T>::draw() 00043 { 00044 displaywindow->draw(); 00045 00046 menusystem::draw(); 00047 } 00048 00049 template< typename T > 00050 menu01<T>::menu01(T & _x) 00051 : menusystem(this,0,true,point2<int>(60,30),20), x(_x), meshAoffset(pt3()) 00052 { 00053 addfont12("Partitions and Miscelaneous Mesh Operations Menu"); 00054 addnewline(); 00055 addfont10(simplexdelete, 00056 "'d' Enter simplex to delete: "); 00057 addnewline(); 00058 addfont10("'c' Clip the mesh with the partition "); 00059 addnewline(); 00060 addfont10(simplexminedgelength, 00061 "'e' Minimize the simplexes edge length, enter delta: "); 00062 addnewline(); 00063 addfont10("'j' 'J' Rotate partition anti clockwise and clockwise"); 00064 addnewline(); 00065 addfont10("'k' 'K' Translate partition right and left"); 00066 addnewline(); 00067 addfont10("'l' 'L' Translate partition up and down"); 00068 addnewline(); 00069 addfont10("'m' Splitting the simplex on the boundies midpoint"); 00070 addnewline(); 00071 addfont10(simplexsplitting, 00072 " Enter s p1 for the simplex and point index: "); 00073 addnewline(); 00074 addfont10("'p' Printing the mesh (toggle to display and update)"); 00075 addnewline(); 00076 addfont10("'r' Removing null simplexes"); 00077 addnewline(); 00078 addfont10(simplexswap, 00079 "'s' Swapping two simplexes, enter i and j: "); 00080 addnewline(); 00081 addfont10("'z' 'Z' Offset mesh A forward or backwards"); 00082 00083 addnewline(); 00084 addnewline(); 00085 addfont10("ESC Quit"); 00086 00087 displaywindow = new primitiveWindow( point3<double>(6.3,7.0,0.0), 0.20 ); 00088 } 00089 00090 00091 00092 00093 template< typename T > 00094 void menu01<T>::readBufferedTerminationAction() 00095 { 00096 stringstream ss(readBufferedResult); 00097 00098 switch (state) 00099 { 00100 case 'd': 00101 { 00102 uint z; 00103 ss >> z; 00104 x.mesh->simplexdelete(z); 00105 00106 break; 00107 } 00108 00109 case 'm': 00110 { 00111 uint s; 00112 uint p0; 00113 ss >> s >> p0; 00114 00115 x.mesh->splitmidpoint1D(s,p0); 00116 00117 break; 00118 } 00119 00120 case 's': 00121 { 00122 uint i,j; 00123 ss >> i >> j; 00124 x.mesh->simplexswap(i,j); 00125 00126 break; 00127 } 00128 00129 case 'e': 00130 { 00131 double delta; 00132 ss >> delta; 00133 maxEdgeLength op(*x.mesh,delta); 00134 00135 d3meshiterrecursive<maxEdgeLength> i(x.mesh->vi,op); 00136 00137 i.evallinear(); 00138 00139 break; 00140 } 00141 } 00142 00143 x.mesh->debugcheck(); 00144 x.meshdraw->meshupdate(); 00145 glutPostRedisplay(); 00146 } 00147 00148 template< typename T > 00149 void menu01<T>::readImmediate(char const key) 00150 { 00151 switch (key) 00152 { 00153 case 27: 00154 exit(0); 00155 break; 00156 00157 case 'd': 00158 { 00159 state='d'; 00160 readBufferedSet(simplexdelete); 00161 break; 00162 } 00163 00164 case 'c': 00165 x.clip->eval(); 00166 x.meshdraw->meshupdate(); 00167 break; 00168 00169 case 'e': 00170 { 00171 state='e'; 00172 readBufferedSet(simplexminedgelength); 00173 break; 00174 } 00175 00176 case 'j': 00177 { 00178 x.hdraw->rotate(0.1); 00179 x.meshdraw->meshupdate(); 00180 break; 00181 } 00182 00183 case 'J': 00184 { 00185 x.hdraw->rotate(-0.1); 00186 x.meshdraw->meshupdate(); 00187 break; 00188 } 00189 00190 case 'k': 00191 { 00192 x.hdraw->translate( pt2(0.1,0.0) ); 00193 x.meshdraw->meshupdate(); 00194 break; 00195 } 00196 00197 case 'K': 00198 { 00199 x.hdraw->translate( pt2(-0.1,0.0) ); 00200 x.meshdraw->meshupdate(); 00201 break; 00202 } 00203 00204 case 'l': 00205 { 00206 x.hdraw->translate( pt2(0.0,0.1) ); 00207 x.meshdraw->meshupdate(); 00208 break; 00209 } 00210 00211 case 'L': 00212 { 00213 x.hdraw->translate( pt2(0.0,-0.1) ); 00214 x.meshdraw->meshupdate(); 00215 break; 00216 } 00217 00218 case 'm': 00219 { 00220 state='m'; 00221 readBufferedSet(simplexsplitting); 00222 break; 00223 } 00224 00225 case 'p': 00226 { 00227 // Toggle the print display. 00228 if (displaywindow->vg.empty()==false) 00229 displaywindow->nuke(); 00230 else 00231 { 00232 displaywindow->reset(); 00233 *displaywindow << *x.mesh; 00234 cout << *x.mesh << endl; 00235 // *displaywindow << endl; 00236 00237 // string t1; 00238 // for (uint i=1; i<x.clip->bv.size(); ++i) 00239 // { 00240 // t1=""; 00241 // t1 += i; 00242 // t1 += (" " + x.clip->bv[i]); 00243 // *displaywindow << t1; 00244 // *displaywindow << endl; 00245 // } 00246 } 00247 00248 // NOTE: I am having a lot of trouble with this code. Streams 00249 // are notorious in C++ and though I have had several discussions 00250 // over time I have not got much but trouble from C++ streams. 00251 // 00252 // Normally I would implement serialization in strings. This time I 00253 // tried yet again to create an integrated solution and use streams and 00254 // again I have been frustrated with them. At issue is their use. 00255 // I do not want to manage buffers but wish the stream to do this and 00256 // more. In short I wish to read a stream and interpret it without 00257 // crashing. Serialization is easy with text files where the data is 00258 // simply read and written too. This is all I want to do with streams 00259 // - read the data as text. I am matching them with data that writes 00260 // text and flushes with the endl. After some reading and internet 00261 // I still have not a simple answer or met any that does this. 00262 // The technology of streams seems to be in a one way direction - that 00263 // of favoring the user of a stream rather than the designed of a stream. 00264 // Why is what I am attempting to do so difficult? I am almost at 00265 // the point where I will no longer use streams but write out strings. 00266 // Then have the stream interact with the strings. This would solve this 00267 // reverse issue where I have a stream and want it back as text because 00268 // all the objects I use have an operator that can easily do this. 00269 // Further this solution is simple and generic. If all my code does this 00270 // then I will only have issues with dealing with strings and not 00271 // streams - which are much harder to deal with. Infact I have convinced 00272 // myself that this is a much more efficient path, fk the standards committee 00273 // for seeing the streams only at such a low level and not at all data 00274 // driven. I keep hearing about how wonderful streams are but I have 00275 // yet to implement them properly. I wrote a parser with streams which 00276 // failed so I rewrote with strings and it succeeded. Streams are to the 00277 // uninitiated a vial technology that is prohibative. The committee needs 00278 // a good kick up the arse. 00279 00280 00281 //cout << *x.mesh << endl; 00282 // for (uint i=1; i<x.clip->bv.size(); ++i) 00283 // cout << i << " " << x.clip->bv[i] << endl; 00284 00285 break; 00286 } 00287 00288 case 'r': 00289 { 00290 x.mesh->removenullsimplexes(); 00291 cout << *x.mesh << endl; 00292 00293 x.meshdraw->meshupdate(); 00294 break; 00295 } 00296 00297 case 's': 00298 { 00299 state='s'; 00300 readBufferedSet(simplexswap); 00301 break; 00302 } 00303 00304 00305 case 'z': 00306 { 00307 meshAoffset.z += 0.01; 00308 break; 00309 } 00310 00311 case 'Z': 00312 { 00313 meshAoffset.z -= 0.01; 00314 break; 00315 } 00316 } 00317 00318 glutPostRedisplay(); 00319 } 00320 00321 00322 00323 00324 00325 #endif 00326 00327
1.5.8