proj home

Files   Classes   Functions   Hierarchy  

quickhull2Dtest Class Reference

2D quickhull test and program tools. More...

#include <quickhull2Dtest.h>

Collaboration diagram for quickhull2Dtest:

List of all members.

Public Member Functions

void test02 (int argc, char **argv)
 Generate 2D points and find and display the convex hull.
void test06 (int argc, char **arg)
 Display the convex hull and points by reading in the points and hull indexes.

Static Public Member Functions

static void keyboard01 (unsigned char key, int x, int y)
 Default keyboard handler - ESC to quit.
static void display01 ()
 Displays the gobj::global with double buffering.
static void test03 ()
 Generate random 2D points and print.
static void test04 (int argc, char **argv)
 Generate random 2D points and write to file.
static void test05 (int argc, char **argv)
 Calculate the convex hull, given a file of points writes the new file hull as indexes to the points.


Detailed Description

2D quickhull test and program tools.

Definition at line 10 of file quickhull2Dtest.h.


Member Function Documentation

void quickhull2Dtest::display01 (  )  [static]

Displays the gobj::global with double buffering.

Definition at line 40 of file quickhull2Dtest.cpp.

References gobjContainer::draw(), glerrordisplay(), and gobj::global.

Referenced by test02(), and test06().

00041 { 
00042   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00043 
00044   gobj::global->draw();
00045 
00046 
00047   glerrordisplay();
00048   
00049   glutSwapBuffers();
00050 }

void quickhull2Dtest::keyboard01 ( unsigned char  key,
int  x,
int  y 
) [static]

Default keyboard handler - ESC to quit.

Definition at line 26 of file quickhull2Dtest.cpp.

Referenced by test02(), and test06().

00031 {
00032   switch (key)
00033   {
00034     case 27:
00035       exit(0);
00036       break;
00037   }
00038 }

void quickhull2Dtest::test02 ( int  argc,
char **  argv 
)

Generate 2D points and find and display the convex hull.

Definition at line 52 of file quickhull2Dtest.cpp.

References display01(), gobjContainer::displaylist(), gobj::global, gobjpush, pointsdisplay2D< T >::gq, keyboard01(), commandline::mapvar(), gobjQuadric::radius, and gobjContainer::set().

00053 {
00054   glutInit(&argc,argv);
00055   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00056   glutInitWindowSize(800,600);
00057   glutCreateWindow("");
00058   glutDisplayFunc(display01);
00059   glutKeyboardFunc(keyboard01);
00060 
00061   OpenGLinitialisation();
00062 
00063   glEnable(GL_DEPTH_TEST);
00064   glEnable(GL_CULL_FACE);
00065   glEnable(GL_NORMALIZE);
00066 
00067   xGraphics.set();
00068 
00069   commandline cmd(argc,argv);
00070 
00071   cout << "Calculate the hull of a randomly generated set of points" << endl;
00072   cout << "  inside a circle. The hull points are colored red." << endl;
00073   cout << "Options:" << endl;
00074   cout << "  numPoints=4500  varies the number of points." << endl;
00075   
00076   uint numPoints(500);
00077   cmd.mapvar(numPoints,"numPoints");
00078 
00079   bool labelpoints(false);
00080   cmd.mapvar(labelpoints,"labelpoints");
00081   bool drawpoints(true);
00082   cmd.mapvar(drawpoints,"drawpoints");
00083 
00084   typedef point2<double> pt2;
00085   vector< pt2 > v;
00086   generateRandomPointsInCircle< pt2, double, random11<double> >(v,numPoints);
00087   //vectorprint::space="\n";
00088   //cout << v << endl;
00089 
00090   quickhull2D< pt2, double > qh(v);
00091 
00092   gobjpush( new gobjglDisable(GL_LIGHTING) );
00093   gobjpush( new gobjglColor3f(0.0,1.0,0.0) );
00094   pointsdisplay2D<pt2> dp(*gobj::global,v,drawpoints,labelpoints);
00095 
00096   vector< pt2 > v2;
00097   for (uint i=0; i<qh.boundary.size(); ++i)
00098     v2.push_back( v[qh.boundary[i]] );
00099   gobjpush( new gobjglColor3f(1.0,0.0,0.0) );
00100   pointsdisplay2D<pt2> dp2(*gobj::global,v2,true,false);
00101   dp2.gq->radius=0.02;
00102 
00103   gobjpush( new gobjglBegin(GL_LINE_LOOP) );
00104   for (uint i=0; i<qh.boundary.size(); ++i)
00105     { gobjpush( new gobjglVertex2f(v[qh.boundary[i]]) ); }
00106   gobjpush( new gobjglEnd() );
00107 
00108   gobj::global->displaylist(1);
00109   zpr zz;
00110   glutMainLoop();
00111 }

void quickhull2Dtest::test03 (  )  [static]

Generate random 2D points and print.

Definition at line 114 of file quickhull2Dtest.cpp.

References print().

Referenced by main().

00115 {
00116   uintc n=6;
00117   vector< point2<float> > v;
00118   generateRandomPointsInCircle< point2<float>, float, random11<float> >(v,n);
00119   cout << print(v,"\n") << endl;
00120 
00121   // <TODO>
00122   //quickhull2D<point2<float>,float> q1(v);
00123   //cout << q1.boundary << endl;
00124 }

void quickhull2Dtest::test04 ( int  argc,
char **  argv 
) [static]

Generate random 2D points and write to file.

$./main prog=4 numPoints=10 pointsfile=data01.txt

Definition at line 126 of file quickhull2Dtest.cpp.

References commandline::mapvar(), pts, and vectorfile::serialize().

Referenced by main().

00127 {
00128   commandline cmd(argc,argv);
00129   
00130   uint numPoints(10);
00131   cmd.mapvar(numPoints,"numPoints");
00132   string pointsfile;
00133   cmd.mapvar(pointsfile,"pointsfile");
00134   if (pointsfile.empty())
00135   {
00136     cout << "error:  A filename was not given. eg pointsfile=data.txt" << endl;
00137     return;
00138   }
00139   
00140   vector< point2<double> > pts;
00141   generateRandomPointsInCircle< point2<double>, double, random11<float> >
00142     (pts,numPoints);
00143 
00144   if (vectorfile::serialize(pointsfile,pts)==false)
00145   {
00146     cout << "error:  Failed to write file" << pointsfile << "." << endl;
00147     return;
00148   }
00149  
00150   cout << "success:  Written out the points to file " << pointsfile << "." << endl;
00151   cout << endl;
00152 
00153 }

void quickhull2Dtest::test05 ( int  argc,
char **  argv 
) [static]

Calculate the convex hull, given a file of points writes the new file hull as indexes to the points.

$./main prog=5 pointsfile=data.txt hullfile=hull.txt

Definition at line 155 of file quickhull2Dtest.cpp.

References quickhull2D< PT, D >::boundary, quickhull2Drandomized< PT, D >::boundary, vectorfile::deserialize(), commandline::hastoken(), commandline::mapvar(), pts, and vectorfile::serialize().

Referenced by main().

00156 {
00157   commandline cmd(argc,argv);
00158 
00159   string pointsfile;
00160   cmd.mapvar(pointsfile,"pointsfile");
00161   string hullfile;
00162   cmd.mapvar(hullfile,"hullfile");
00163 
00164   boolc pointsfileinvalid(pointsfile.empty());
00165   if (pointsfileinvalid)
00166     cout << "error:  A pointsfile was not given. eg pointsfile=data.txt" << endl;
00167   boolc hullfileinvalid(hullfile.empty());
00168   if (hullfileinvalid)
00169     cout << "error:  A hullfile not given. eg hullfile=index.txt" << endl;
00170 
00171   if (hullfileinvalid||pointsfileinvalid)
00172     return;
00173 
00174   typedef point2<double> pt2;
00175   vector< pt2 > pts;
00176   if (!vectorfile::deserialize(pts,pointsfile))
00177   {
00178     cout << "error:  Failed to read a file of 2D points from file.";
00179     cout << pointsfile << endl;
00180     return;
00181   }
00182 
00183   bool randomize(cmd.hastoken("randomize"));
00184   if (randomize)
00185   {
00186     cout << "Randomizing the input points." << endl;
00187 
00188 
00189     quickhull2Drandomized<pt2,double> qh(pts);
00190 
00191     if (qh.boundary.size()==0)
00192     {
00193       cout << "error:  No points on hull found by the quickhull algorithm." << endl;
00194       return;
00195     }
00196 
00197     if (!vectorfile::serialize(hullfile,qh.boundary))
00198     {
00199       cout << "error:  Failed to write the hull." << endl;
00200       return;
00201     }
00202   }
00203   else
00204   {
00205     quickhull2D<pt2,double> qh(pts);
00206 
00207     if (qh.boundary.size()==0)
00208     {
00209       cout << "error:  No points on hull found by the quickhull algorithm." << endl;
00210       return;
00211     }
00212 
00213     if (!vectorfile::serialize(hullfile,qh.boundary))
00214     {
00215       cout << "error:  Failed to write the hull." << endl;
00216       return;
00217     }
00218   }
00219 
00220   cout << "Successfully ran the quick hull algorithm." << endl;
00221   cout << endl;
00222 }

void quickhull2Dtest::test06 ( int  argc,
char **  arg 
)

Display the convex hull and points by reading in the points and hull indexes.

$./main prog=6 pointfile=data.txt hullfile=hull.txt

Definition at line 224 of file quickhull2Dtest.cpp.

References vectorfile::deserialize(), display01(), gobj::global, gobjpush, pointsdisplay2D< T >::gq, keyboard01(), commandline::mapvar(), pts, gobjQuadric::radius, gobjContainer::set(), and SHOW.

00225 {
00226   glutInit(&argc,arg);
00227   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00228   glutInitWindowSize(800,600);
00229   glutCreateWindow("");
00230   glutDisplayFunc(display01);
00231   glutKeyboardFunc(keyboard01);
00232 
00233   OpenGLinitialisation();
00234 
00235   glEnable(GL_DEPTH_TEST);
00236   glEnable(GL_CULL_FACE);
00237   glEnable(GL_NORMALIZE);
00238 
00239   xGraphics.set();
00240 
00241   commandline cmd(argc,arg);
00242 
00243   string pointsfile;
00244   cmd.mapvar(pointsfile,"pointsfile");
00245   string hullfile;
00246   cmd.mapvar(hullfile,"hullfile");
00247 
00248   boolc pointsfileinvalid(pointsfile.empty());
00249   if (pointsfileinvalid)
00250     cout << "error:  A pointsfile was not given. eg pointsfile=data.txt" << endl;
00251   boolc hullfileinvalid(hullfile.empty());
00252   if (hullfileinvalid)
00253     cout << "error:  A hullfile not given. eg hullfile=index.txt" << endl;
00254 
00255   if (hullfileinvalid||pointsfileinvalid)
00256     return;
00257 
00258   typedef point2<double> pt2;
00259   vector< pt2 > pts;
00260   boolc pointsfilereadinvalid=
00261     !vectorfile::deserialize(pts,pointsfile);
00262 
00263   if (pointsfilereadinvalid)
00264     cout << "error:  Failed to read a file of 2D points from file. " << endl;
00265 
00266   vector<uint> boundary;
00267   boolc hullfilereadinvalid=
00268     !vectorfile::deserialize(boundary,hullfile);
00269 
00270 cout << SHOW(boundary.size()) << endl;
00271 
00272   if (hullfilereadinvalid)
00273     cout << "error:  Failed to read hull file as indexes." << endl;
00274 
00275   if (pointsfilereadinvalid||hullfilereadinvalid)
00276     return;
00277 
00278   cout << "success: Read the points and hull indexes." << endl;
00279   cout << endl;
00280 
00281   bool labelpoints(false);
00282   cmd.mapvar(labelpoints,"labelpoints");
00283   bool drawpoints(true);
00284   cmd.mapvar(drawpoints,"drawpoints");
00285 
00286   gobjpush( new gobjglDisable(GL_LIGHTING) );
00287   gobjpush( new gobjglColor3f(0.0,1.0,0.0) );
00288   pointsdisplay2D<pt2> dp(*gobj::global,pts,drawpoints,labelpoints);
00289 
00290   vector< pt2 > v2;
00291   for (uint i=0; i<boundary.size(); ++i)
00292     v2.push_back( pts[boundary[i]] );
00293   gobjpush( new gobjglColor3f(1.0,0.0,0.0) );
00294   pointsdisplay2D<pt2> dp2(*gobj::global,v2,true,false,false);
00295   dp2.gq->radius=0.02;
00296   
00297   zpr zz;
00298 
00299   glutMainLoop();
00300 
00301 }


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:50:11 2011 for Chelton Evans Source by  doxygen 1.5.8