proj home

Files   Classes   Functions   Hierarchy  

main.cpp

Go to the documentation of this file.
00001 
00002 #include <vector>
00003 using namespace std;
00004 
00005 #include <GL/glut.h>
00006 
00007 
00008 #include <commandline.h>
00009 #include <cpsphere.h>
00010 #include <delaunay3D.h>
00011 #include <pointsdisplay.h>
00012 #include <gobj.h>
00013 #include <graphmisc.h>
00014 #include <point.h>
00015 #include <random.h>
00016 #include <tetrahedron.h>
00017 #include <tetrahedrondraw.h>
00018 #include <zpr.h>
00019 
00020 
00021 gobjContainer xGraphics(true);
00022 
00023 
00024 cpsphere * pcpsphere = 0;
00025 
00026 template<>
00027 double zero<double>::val = 1E-15;
00028 
00029 
00030 
00031 
00032 void test01(int argc, char** argv)
00033 {
00034   vector< point3<double> > v;
00035 
00036   uint n=5;
00037     
00038   random11<double> r;
00039   for (uint i=0; i<n; ++i)
00040     v.push_back( point3<double>(r(),r(),r()) );
00041   
00042   delaunay3D tess(v);
00043   tess.eval();
00044 
00045   for (uint i=0; i<tess.tet.size(); ++i)
00046     cout << tess.tet[i] << endl;
00047 }
00048 
00049 
00050 
00051 void keyboard
00052 (
00053   unsigned char key,
00054   int x,
00055   int y
00056 )
00057 {
00058   switch (key)
00059   {
00060     case 27:
00061       exit(0);
00062 
00063     case 'a':
00064       pcpsphere->stateinc();
00065       glutPostRedisplay();
00066       break;
00067 
00068     case 'A':
00069       pcpsphere->statedec();
00070       glutPostRedisplay();
00071       break;
00072   }
00073 }
00074 
00075 void display01()
00076 {
00077   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00078 
00079   xGraphics.draw();
00080 
00081   glerrordisplay();
00082   
00083   glutSwapBuffers();
00084 }
00085 
00086 void drawspheres01
00087 (
00088   vector< point3<double> > const & v,
00089   vector< point4<uint> > const & vi
00090 )
00091 {
00092   uintc imax = vi.size();
00093 
00094 /*
00095   double radius;
00096   uintc slices=30;
00097   uintc stacks=30;
00098 
00099   random11<double> r;
00100 
00101   xGraphics.push_back( new gobjglDisable(GL_DEPTH_TEST) );
00102   xGraphics.push_back( new gobjglEnable(GL_BLEND) );
00103   xGraphics.push_back( 
00104     new gobjglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) );
00105   xGraphics.push_back( new gobjglEnable(GL_LIGHTING) );
00106 
00107   for (uint i=0; i<imax; ++i)
00108   {
00109     point3<double> const & P1( v[ vi[i].x ] );
00110     point3<double> const & P2( v[ vi[i].y ] );
00111     point3<double> const & P3( v[ vi[i].z ] );
00112     point3<double> const & P4( v[ vi[i].a ] );
00113 
00114     tetrahedron<double> const t(P1,P2,P3,P4);
00115     point3<double> const c(t.circumcenter());
00116     radius = (c-P1).distance();
00117 
00118     xGraphics.push_back( new gobjglColor4f(r(),r(),r(),0.1) );
00119 
00120     xGraphics.push_back( new gobjglPushMatrix() );
00121     xGraphics.push_back( new gobjglTranslatef(c) );
00122     xGraphics.push_back( 
00123       new gobjglutSolidSphere(radius,slices,stacks) );
00124       //new gobjglutWireSphere(radius,slices,stacks) );
00125 
00126     xGraphics.push_back( new gobjglPopMatrix() );
00127   }
00128 
00129   xGraphics.push_back( new gobjglDisable(GL_BLEND) );
00130 
00131 */
00132 
00133 
00134   for (uint i=0; i<imax; ++i)
00135   {
00136     point3<double> const & P1( v[ vi[i].x ] );
00137     point3<double> const & P2( v[ vi[i].y ] );
00138     point3<double> const & P3( v[ vi[i].z ] );
00139     point3<double> const & P4( v[ vi[i].w ] );
00140 
00141     tetrahedrondraw<point3<double>,double> td(P1,P2,P3,P4);
00142     td.displayedges();
00143   }
00144 
00145 }
00146 
00147 
00148 void init()
00149 {
00150   GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
00151   GLfloat mat_shininess[] = { 50.0 };
00152   GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
00153   GLfloat white_light[] = { 1.0, 1.0, 1.0, 1.0 };
00154  
00155   glClearColor(0.0,0.0,0.0,0.0);
00156   glShadeModel(GL_SMOOTH);
00157  
00158   glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
00159   glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
00160   glLightfv(GL_LIGHT0, GL_POSITION, light_position);
00161   glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
00162   glLightfv(GL_LIGHT0, GL_SPECULAR, white_light);
00163 
00164   glEnable(GL_LIGHTING);
00165   glEnable(GL_LIGHT0);
00166   glEnable(GL_DEPTH_TEST);
00167   glEnable(GL_NORMALIZE);
00168   glEnable(GL_COLOR_MATERIAL); 
00169 }
00170 
00171 
00172 void test02(int argc, char** argv)
00173 {
00174   cout << "Denaulay Triangulation in 3D" << endl;
00175   cout << endl;
00176   cout << "Keyboard commands:" << endl;
00177   cout << "'a'  - iterate forwards through the tetrahedron mesh." << endl;
00178   cout << "'A'  - iterate backwards throuth the tetrahedron mesh." << endl;
00179   cout << endl;
00180 
00181   commandline cmd(argc,argv);
00182 
00183   uint n=5;
00184   cmd.mapvar(n,"n");
00185 
00186   vector< point3<double> > v;
00187 
00188   random11<double> r;
00189   for (uint i=0; i<n; ++i)
00190     v.push_back( point3<double>(r(),r(),r()) );
00191   
00192   delaunay3D tess(v);
00193   tess.eval();
00194 
00195 /*
00196   for (uint i=0; i<tess.tet.size(); ++i)
00197     cout << tess.tet[i] << endl;
00198 */
00199 
00200 
00201 
00202 
00203   xGraphics.push( new gobjglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) );
00204   //xGraphics.push( new gobjglClearColor(0.0,0.0,0.0,0.0) ); 
00205 
00206   pcpsphere = new cpsphere(v,tess.tet);
00207   xGraphics.push( pcpsphere->current );
00208   pcpsphere->update();
00209 
00210 
00211   xGraphics.push( new gobjglPushAttrib(GL_LIGHTING_BIT) );
00212   xGraphics.push( new gobjglPushAttrib(GL_CURRENT_BIT) );
00213   xGraphics.push( new gobjglDisable(GL_LIGHTING) );
00214   xGraphics.push( new gobjglColor3ub(0,255,255) );
00215 
00216   pointsdisplay3D< point3<double> > ptdisp(xGraphics,v);
00217 
00218   //xGraphics.push( new gobjglEnable(GL_LIGHTING) );
00219 
00220   drawspheres01(v,tess.tet);
00221 
00222   xGraphics.push( new gobjglPopAttrib() );
00223   xGraphics.push( new gobjglPopAttrib() );
00224 
00225 
00226   glutInit(&argc, argv);
00227   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
00228 
00229   glutInitWindowSize(600,600);
00230   glutCreateWindow("");  
00231   init();
00232   glutDisplayFunc(display01);
00233   glutKeyboardFunc(keyboard);
00234 
00235   //zprInit();
00236   //OpenGLinitialisation();
00237   //
00238 
00239 /*
00240   glDisable(GL_DEPTH_TEST);
00241   glEnable(GL_BLEND);
00242   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00243 */
00244 
00245   zpr zz;
00246   glutMainLoop();
00247 }
00248 
00249 
00250 
00251 
00252 
00253 void display02()
00254 {
00255   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00256 
00257   xGraphics.draw();
00258 
00259   glerrordisplay();
00260   
00261   glutSwapBuffers();
00262 }
00263 
00264 void test03(int argc, char** argv)
00265 {
00266   cout << "Denaulay Triangulation in 3D" << endl;
00267   cout << endl;
00268   cout << "Keyboard commands:" << endl;
00269   cout << "'a'  - iterate forwards through the tetrahedron mesh." << endl;
00270   cout << "'A'  - iterate backwards throuth the tetrahedron mesh." << endl;
00271   cout << endl;
00272 
00273   commandline cmd(argc,argv);
00274 
00275   uint n=5;
00276   cmd.mapvar(n,"n");
00277 
00278   vector< point3<double> > v;
00279 
00280   random11<double> r;
00281   for (uint i=0; i<n; ++i)
00282     v.push_back( point3<double>(r(),r(),r()) );
00283   
00284   delaunay3D tess(v);
00285   tess.eval();
00286 
00287   xGraphics.push( new gobjglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) );
00288   //xGraphics.push( new gobjglClearColor(0.0,0.0,0.0,0.0) ); 
00289 
00290   pcpsphere = new cpsphere(v,tess.tet);
00291   xGraphics.push( pcpsphere->current );
00292   pcpsphere->update();
00293 
00294 /*
00295 
00296   xGraphics.push( new gobjglPushAttrib(GL_LIGHTING_BIT) );
00297   xGraphics.push( new gobjglPushAttrib(GL_CURRENT_BIT) );
00298   xGraphics.push( new gobjglDisable(GL_LIGHTING) );
00299   xGraphics.push( new gobjglColor3ub(0,255,255) );
00300 
00301   pointsdisplay3D< point3<double> > ptdisp(xGraphics,v);
00302 
00303   xGraphics.push( new gobjglPopAttrib() );
00304   xGraphics.push( new gobjglPopAttrib() );
00305 */
00306 
00307 
00308   glutInit(&argc, argv);
00309   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00310 
00311   glutInitWindowSize(600,600);
00312   glutCreateWindow("");
00313   init();
00314   glutDisplayFunc(display02);
00315   glutKeyboardFunc(keyboard);
00316 
00317   zpr zz;
00318   glutMainLoop();
00319 }
00320 
00321 
00322 
00323 int main(int argc, char** argv)
00324 {
00325   xGraphics.set();
00326 
00327   test02(argc,argv);
00328 
00329   return 0;
00330 }
00331 
00332 
00333 
00334   

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