proj home

Files   Classes   Functions   Hierarchy  

snakesorttest.cpp

Go to the documentation of this file.
00001 
00002 #include <vector>
00003 using namespace std;
00004 
00005 #include <pointsdisplay.h>
00006 #include <functionalobjectoperators.h>
00007 #include <gobj.h>
00008 #include <graphmisc.h>
00009 #include <random.h>
00010 #include <snakesort.h>
00011 #include <snakesorttest.h>
00012 #include <zpr.h>
00013 
00014 void snakesorttest::keyboard01
00015 (
00016   unsigned char key, 
00017   int x, 
00018   int y
00019 )
00020 {
00021   switch (key)
00022   {
00023     case 27:
00024       exit(0);
00025       break;
00026   }
00027 }
00028 
00029 void snakesorttest::display01()
00030 { 
00031   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00032 
00033   gobj::global->draw();
00034 
00035 
00036   glerrordisplay();
00037   
00038   glutSwapBuffers();
00039 }
00040 
00041 void snakesorttest::test01(int argc, char** argv)
00042 {
00043   int a1[]=
00044   {
00045     93,2,95,-2,5, 
00046     84,23,58,-10,50,
00047     100,120,-73 
00048   };
00049 
00050   snakesort::d1(&a1[0],13,5,less<int>());
00051   cout << print(a1,a1+13) << endl;
00052 }
00053 
00054 
00055 void snakesorttest::test02(int argc, char** argv)
00056 {
00057   glutInit(&argc,argv);
00058   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00059   glutInitWindowSize(800,600);
00060   glutCreateWindow("");
00061   glutDisplayFunc(display01);
00062   glutKeyboardFunc(keyboard01);
00063 
00064   OpenGLinitialisation();
00065 
00066   glEnable(GL_DEPTH_TEST);
00067   glEnable(GL_CULL_FACE);
00068   glEnable(GL_NORMALIZE);
00069 
00070   xGraphics.set();
00071 
00072   uint N(125);
00073   vector< point2<double> > v;
00074   fillvec(v,N);
00075 
00076   snakesort::d2(&v[0],v.size(),less<double>());
00077 
00078   drawlinethroughpoints(v);
00079 
00080   typedef point3<double> pt3;
00081 
00082   vector<pt3> v2;
00083   for (uint i=0; i<N; ++i)
00084     v2.push_back( pt3(v[i].x,v[i].y,0.0) );
00085   drawpoints(v2);
00086 
00087   gobjpush( new myaxes(1.0) );
00088   
00089 
00090   gobj::global->displaylist(1);
00091   zpr zz;
00092   glutMainLoop();
00093 }
00094 
00095 void snakesorttest::drawlinethroughpoints
00096 ( 
00097   vector<pt2> const & v 
00098 )
00099 {
00100   gobjpush(new gobjglDisable(GL_LIGHTING));
00101   gobjpush( new gobjglColor3f(1.0,0.0,0.0) );
00102   gobjpush( new gobjglBegin(GL_LINE_STRIP) ); 
00103 
00104   for (uint i=0; i<v.size(); ++i)
00105     { gobjpush( new gobjglVertex2f(v[i]) ); }
00106 
00107   gobjpush( new gobjglEnd() );
00108 }
00109 
00110 void snakesorttest::drawlinethroughpoints
00111 (
00112   vector<pt3> const & v
00113 ) 
00114 {
00115   gobjpush(new gobjglDisable(GL_LIGHTING));
00116   gobjpush( new gobjglColor3f(1.0,0.0,0.0) );
00117   gobjpush( new gobjglBegin(GL_LINE_STRIP) ); 
00118 
00119   for (uint i=0; i<v.size(); ++i)
00120     { gobjpush( new gobjglVertex3f(v[i]) ); }
00121 
00122   gobjpush( new gobjglEnd() );
00123 }
00124 
00125 void snakesorttest::fillvec
00126 ( 
00127   vector<pt2> & v, 
00128   uintc n 
00129 ) 
00130 {
00131   random11<> r; 
00132  
00133   for (uint i=0; i<n; ++i)
00134     v.push_back( pt2(r(),r()) );
00135 }
00136 
00137 void snakesorttest::fillvec
00138 ( 
00139   vector<pt3> & v, 
00140   uintc n 
00141 ) 
00142 {
00143   random11<> r; 
00144  
00145   for (uint i=0; i<n; ++i)
00146     v.push_back( pt3(r(),r(),r()) );
00147 }
00148 
00149 void snakesorttest::drawpoints(vector<pt3> const & v)
00150 {
00151   gobjpush( new gobjglPushAttrib(GL_CURRENT_BIT) );
00152   gobjpush( new gobjglPushAttrib(GL_LIGHTING_BIT) );
00153   gobjpush( new gobjglDisable(GL_LIGHTING) );
00154   gobjpush( new gobjglColor3f(1.0,1.0,0.0) );
00155     
00156   pointsdisplay3D<pt3> dp(v,true,false);
00157 
00158   gobjpush( new gobjglPopAttrib() );
00159   gobjpush( new gobjglPopAttrib() );
00160 }
00161 
00162 
00163 
00164 
00165 
00166 void snakesorttest::test03(int argc, char** argv)
00167 {
00168   glutInit(&argc,argv);
00169   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00170   glutInitWindowSize(800,600);
00171   glutCreateWindow("");
00172   glutDisplayFunc(display01);
00173   glutKeyboardFunc(keyboard01);
00174 
00175   OpenGLinitialisation();
00176 
00177   glEnable(GL_DEPTH_TEST);
00178   glEnable(GL_CULL_FACE);
00179   glEnable(GL_NORMALIZE);
00180 
00181   xGraphics.set();
00182 
00183   uint N(100);
00184   vector< pt3 > v;
00185   fillvec(v,N);
00186 
00187   snakesort::d3(&v[0],N,less<double>());
00188 
00189   drawlinethroughpoints(v);
00190   drawpoints(v);
00191 
00192   gobjpush( new myaxes(1.0) );
00193 
00194   gobj::global->displaylist(1);
00195   zpr zz;
00196   glutMainLoop();
00197 }
00198 

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