proj home

Files   Classes   Functions   Hierarchy  

partitionstest Class Reference

Testing 2D partitions. More...

#include <partitionstest.h>

Collaboration diagram for partitionstest:

List of all members.

Public Types

typedef point2< double > pt2
typedef point3< double > pt3

Public Member Functions

void set ()
 Set the global pointer to this class.
 partitionstest (int argc, char **argv)
 Initialize for 2D.
 partitionstest ()
 Initialize for 3D.
void addpoint (intc x, intc y)
 Paint a pixel.
void addstar (intc k, intc x, intc y)
 Paint a few pixels.
void addstarbig (intc x, intc y)
 Paint a snowflake.
void test01 ()
 Test a straight line partition.
void test02 ()
 Test a triangle partition.
void test03 ()
 Test a boomerang partition compiled from an equation.
void test04 ()
 Inverted square from compiled equation.
void test05 ()
 Subtract a circle from a square.
void test06 (int argc, char **argv)
 Test a tetrahedron partition.

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 display02 ()
static void reshape (GLsizei w1, GLsizei h1)
 Needing rework, the screen size can be reshaped.
static void mousefunc01 (int button, int state, int x, int y)
 Clicking the mouse adds points to the screen.

Public Attributes

vector< pt2vec
 The points in space.
vector< uintred
 The points in the red partition.
vector< uintblue
 The points in the blue partition.
partitionspace< pt2 > * ps
 The current partition.
uint width
 Screen width.
uint height
 Screen height.
gobjContainer xGraphics
 Container used for 3D graphics.

Static Public Attributes

static partitionstestglobal = 0
 Global pointer to this class.


Detailed Description

Testing 2D partitions.

Definition at line 15 of file partitionstest.h.


Member Typedef Documentation

typedef point2<double> partitionstest::pt2

Definition at line 19 of file partitionstest.h.

typedef point3<double> partitionstest::pt3

Definition at line 20 of file partitionstest.h.


Constructor & Destructor Documentation

partitionstest::partitionstest ( int  argc,
char **  argv 
)

Initialize for 2D.

Definition at line 79 of file partitionstest.cpp.

References display01(), height, keyboard01(), mousefunc01(), reshape(), and width.

00080 {
00081   glutInit(&argc, argv);
00082   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
00083 
00084   width=600;
00085   height=600;
00086   glutInitWindowSize(width,height);
00087   glutCreateWindow("");
00088 
00089   glutDisplayFunc(display01);
00090   glutMouseFunc(mousefunc01);
00091   glutReshapeFunc(reshape);
00092   glutKeyboardFunc(keyboard01);
00093 
00094   glClearColor(1.0,1.0,1.0,0.0);
00095 
00096   glColor3d(0.0,0.0,0.0);
00097   glPointSize(3.0);
00098 
00099   glMatrixMode(GL_PROJECTION);
00100   glLoadIdentity();
00101   gluOrtho2D(0.0,1.0,0.0,1.0);
00102 
00103   set();
00104 }

partitionstest::partitionstest (  ) 

Initialize for 3D.

Definition at line 255 of file partitionstest.cpp.

00256 {
00257 }


Member Function Documentation

void partitionstest::addpoint ( intc  x,
intc  y 
)

Paint a pixel.

Definition at line 106 of file partitionstest.cpp.

References blue, height, partitionspace< PT >::isInside(), ps, red, width, point2< T >::x, and point2< T >::y.

00107 {
00108   pt2 pos;
00109   pos.x = x/(double)width;
00110   pos.y = 1.0-y/(double)height;
00111 
00112   uintc k=vec.size();
00113   vec.push_back( pos );
00114 
00115   assert(ps!=0);
00116 
00117   if (ps->isInside(pos))
00118     red.push_back(k);
00119   else
00120     blue.push_back(k);
00121 
00122   glutPostRedisplay();
00123 }

void partitionstest::addstar ( intc  k,
intc  x,
intc  y 
)

Paint a few pixels.

Definition at line 126 of file partitionstest.cpp.

References addpoint().

00131 {
00132   addpoint(x,y);
00133   addpoint(x+k,y);
00134   addpoint(x-k,y);
00135   addpoint(x,y+k);
00136   addpoint(x+k,y+k);
00137   addpoint(x-k,y+k);
00138   addpoint(x,y-k);
00139   addpoint(x+k,y-k);
00140   addpoint(x-k,y-k);
00141 }

void partitionstest::addstarbig ( intc  x,
intc  y 
)

Paint a snowflake.

Definition at line 144 of file partitionstest.cpp.

00148 {
00149   // Incrementing in Fibonacci pattern, no particular reason.
00150   // eg 6 = 3 + F[2], 11 = 6 + F[3], 
00151   //   19 = 11 + F[4], 32 = 19 + F[5], ...
00152   addstar(1,x,y);
00153   addstar(3,x,y);
00154   addstar(6,x,y);
00155   addstar(11,x,y);
00156   addstar(19,x,y);
00157   addstar(32,x,y);
00158   addstar(53,x,y);
00159 }

void partitionstest::display01 (  )  [static]

Displays the gobj::global with double buffering.

Definition at line 35 of file partitionstest.cpp.

References blue, glerrordisplay(), global, red, and vec.

Referenced by partitionstest().

00036 { 
00037   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00038 
00039   assert(global!=0);
00040 
00041   glColor3f(1.0,0.0,0.0);
00042   glBegin(GL_POINTS);
00043   uint sz=global->red.size();
00044   for (uint i=0; i<sz; ++i)
00045     glVertex2f(global->vec[global->red[i]].x,global->vec[global->red[i]].y);
00046   glEnd();
00047 
00048   glColor3f(0.0,0.0,1.0);
00049   glBegin(GL_POINTS);
00050   sz=global->blue.size();
00051   for (uint i=0; i<sz; ++i)
00052     glVertex2f(global->vec[global->blue[i]].x,global->vec[global->blue[i]].y);
00053   glEnd();
00054 
00055   glerrordisplay();
00056   
00057   glutSwapBuffers();
00058 }

void partitionstest::display02 (  )  [static]

Definition at line 259 of file partitionstest.cpp.

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

Referenced by test06().

00260 {
00261   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00262 
00263   gobj::global->draw();
00264 
00265   glerrordisplay();
00266   
00267   glutSwapBuffers();
00268 }

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

Default keyboard handler - ESC to quit.

Definition at line 23 of file partitionstest.cpp.

Referenced by partitionstest(), and test06().

00028 {
00029   switch (key)
00030   {
00031     case 27: exit(0); break;
00032   }
00033 }

void partitionstest::mousefunc01 ( int  button,
int  state,
int  x,
int  y 
) [static]

Clicking the mouse adds points to the screen.

Definition at line 165 of file partitionstest.cpp.

Referenced by partitionstest().

00171 {
00172   assert(global!=0);
00173 
00174   if (button==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
00175   {
00176     global->addstarbig(x,y);
00177   }
00178 }

void partitionstest::reshape ( GLsizei  w1,
GLsizei  h1 
) [static]

Needing rework, the screen size can be reshaped.

Definition at line 60 of file partitionstest.cpp.

References global, height, vec, and width.

Referenced by partitionstest().

00061 {
00062   glViewport(0,0,w1,h1);
00063 
00064   assert(global!=0);
00065 
00066   double rx = (double)(global->width) / (double)w1;
00067   double ry = (double)(global->height) / (double)h1;
00068 
00069   for (uint i=0; i<global->vec.size(); ++i)
00070   {
00071     global->vec[i].x *= rx;
00072     global->vec[i].y *= ry;
00073   }
00074 
00075   global->width = w1; 
00076   global->height = h1;
00077 }

void partitionstest::set (  )  [inline]

Set the global pointer to this class.

Definition at line 28 of file partitionstest.h.

References global.

00029     { partitionstest::global=this; }

void partitionstest::test01 (  ) 

Test a straight line partition.

Definition at line 180 of file partitionstest.cpp.

References ps.

00181 {
00182   pt2 a(0.0,0.0);
00183   pt2 b(0.5,1.0);
00184   ps = new halfspaceD2<pt2,double>(a,b);
00185 
00186   glutPostRedisplay();
00187   glutMainLoop();
00188 }

void partitionstest::test02 (  ) 

Test a triangle partition.

Definition at line 191 of file partitionstest.cpp.

References ps.

00192 {
00193   pt2 a(0.3,0.3);
00194   pt2 b(0.4,0.8);
00195   pt2 c(0.7,0.2);
00196   ps = new trianglepartition< pt2, double >(a,c,b);
00197 
00198   glutPostRedisplay();
00199   glutMainLoop();
00200 }

void partitionstest::test03 (  ) 

Test a boomerang partition compiled from an equation.

Definition at line 202 of file partitionstest.cpp.

References Peq(), PeqCapture(), ps, and halfspaceD2< PT, PD >::set().

00203 {
00204   halfspaceD2< pt2, double > L[4];
00205 
00206   L[0].set( pt2(0.4,0.8), pt2(0.3,0.3) );
00207   L[1].set( pt2(0.3,0.3), pt2(0.7,0.2) );
00208   L[2].set( pt2(0.7,0.2), pt2(0.4,0.5) );
00209   L[3].set( pt2(0.4,0.5), pt2(0.4,0.8) );
00210 
00211   PeqCapture(ps,Peq(L[0])*Peq(L[1])*(Peq(L[2])+Peq(L[3])));
00212 
00213   glutPostRedisplay();
00214   glutMainLoop();
00215 }

void partitionstest::test04 (  ) 

Inverted square from compiled equation.

Definition at line 217 of file partitionstest.cpp.

References Peq(), PeqCapture(), ps, and halfspaceD2< PT, PD >::set().

00218 {
00219   halfspaceD2< pt2, double > L[4];
00220 
00221   pt2 A(0.4,0.8);
00222   pt2 B(0.4,0.2);
00223   pt2 C(0.9,0.2);
00224   pt2 D(0.9,0.8);
00225 
00226   L[0].set(A,B);
00227   L[1].set(B,C);
00228   L[2].set(C,D);
00229   L[3].set(D,A);
00230 
00231   PeqCapture(ps,!(Peq(L[0])*Peq(L[1])*Peq(L[2])*Peq(L[3])));
00232 
00233   glutPostRedisplay();
00234   glutMainLoop();
00235 }

void partitionstest::test05 (  ) 

Subtract a circle from a square.

Definition at line 271 of file partitionstest.cpp.

References Peq(), PeqCapture(), ps, and halfspaceD2< PT, PD >::set().

00272 {
00273 
00274   halfspaceD2< pt2, double > L[4];
00275 
00276   pt2 A(0.4,0.8);
00277   pt2 B(0.4,0.2);
00278   pt2 C(0.9,0.2);
00279   pt2 D(0.9,0.8);
00280 
00281   L[0].set(A,B);
00282   L[1].set(B,C);
00283   L[2].set(C,D);
00284   L[3].set(D,A);
00285 
00286   circlepartition cir( pt2(0.5,0.4), 0.3 );
00287   PeqCapture(ps,Peq(L[0])*Peq(L[1])*Peq(L[2])*Peq(L[3])-Peq(cir));
00288 
00289   glutPostRedisplay();
00290   glutMainLoop();
00291 }

void partitionstest::test06 ( int  argc,
char **  argv 
)

Test a tetrahedron partition.

Definition at line 294 of file partitionstest.cpp.

References display02(), height, tetrahedronpartition< T, D >::isInside(), keyboard01(), commandline::mapvar(), gobjContainer::push(), r, gobjContainer::set(), zpr::update(), width, point3< T >::x, xGraphics, point3< T >::y, and point3< T >::z.

00295 {
00296   glutInit(&argc, argv);
00297   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
00298 
00299   width=600;
00300   height=600;
00301   glutInitWindowSize(width,height);
00302   glutCreateWindow("");
00303   glutDisplayFunc(display02);
00304   glutKeyboardFunc(keyboard01);
00305 
00306   zpr zz;
00307   OpenGLinitialisation();
00308 
00309   xGraphics.set();
00310 
00311 
00312   unsigned int numPoints=100000;
00313 
00314   cout << "Testing tetrahedron" << endl;
00315   cout << "You can define the tetrhedron" << endl;
00316   cout << "eg" << endl;
00317   cout << "$./main a0=0.5 a1=0.0 a2=0.866 b0=-0.5 b1=0.0 b2=0.866 c0=-1.0 c1=1.0 c2=0.0 d0=0.0 d1=1.0 d2=0.0" << endl;
00318   cout << "Points are scattered about a unit cube at the origin." << endl;
00319   cout << "scale=2.5         Scale the cube." << endl;
00320   cout << "numPoints=" << numPoints << "   Change the number of points." << endl;
00321   cout << "green=false       Turn of green points." << endl;
00322   cout << endl;
00323 
00324   commandline cmd(argc,argv);
00325   double a0=-0.5;
00326   double a1=0.0;
00327   double a2=0.866;
00328 
00329   double b0=-0.5;
00330   double b1=0.0;
00331   double b2=-0.866;
00332 
00333   double c0=1.0;
00334   double c1=0.0;
00335   double c2=0.0;
00336 
00337   double d0=0.0;
00338   double d1=0.85556;
00339   double d2=0.0;
00340 
00341   cmd.mapvar(numPoints,"numPoints");
00342 
00343   cmd.mapvar(a0,"a0");
00344   cmd.mapvar(a1,"a1");
00345   cmd.mapvar(a2,"a2");
00346   cmd.mapvar(b0,"b0");
00347   cmd.mapvar(b1,"b1");
00348   cmd.mapvar(b2,"b2");
00349   cmd.mapvar(c0,"c0");
00350   cmd.mapvar(c1,"c1");
00351   cmd.mapvar(c2,"c2");
00352   cmd.mapvar(d0,"d0");
00353   cmd.mapvar(d1,"d1");
00354   cmd.mapvar(d2,"d2");
00355 
00356   bool green = false;
00357   cmd.mapvar(green,"green");
00358 
00359   double scale=2.0;
00360   cmd.mapvar(scale,"scale");
00361 
00362   pt3 p0(a0,a1,a2);
00363   pt3 p1(b0,b1,b2);
00364   pt3 p2(c0,c1,c2);
00365   pt3 p3(d0,d1,d2);
00366 
00367   tetrahedronpartition< pt3, double > tet(p0,p2,p1,p3);
00368 
00369   pt3 colr1(1.0,0.0,0.0);
00370   pt3 colr2(0.0,1.0,0.0);
00371 
00372   random11<double> r;
00373 
00374   pt3 X;
00375 
00376   xGraphics.push( new gobjglDisable(GL_LIGHTING) );
00377 
00378   xGraphics.push( new gobjglBegin(GL_POINTS) );
00379 
00380   for (uint i=0; i<numPoints; ++i)
00381   {
00382     X = pt3(scale*(r()-0.5),scale*(r()-0.5),scale*(r()-0.5));
00383 
00384     if (tet.isInside(X))
00385     {
00386       xGraphics.push( new gobjglColor3f(colr1.x,colr1.y,colr1.z) );
00387       xGraphics.push( new gobjglVertex3f(X.x,X.y,X.z) );
00388     }
00389     else
00390     {  
00391       if (green)
00392       {
00393         xGraphics.push( new gobjglColor3f(colr2.x,colr2.y,colr2.z) );
00394         xGraphics.push( new gobjglVertex3f(X.x,X.y,X.z) );
00395       }
00396     }
00397     
00398   }
00399 
00400   xGraphics.push( new gobjglEnd() );
00401 
00402   zz.update();
00403 
00404   glutMainLoop();
00405 }


Member Data Documentation

The points in the blue partition.

Definition at line 34 of file partitionstest.h.

Referenced by addpoint(), and display01().

Global pointer to this class.

Definition at line 26 of file partitionstest.h.

Referenced by display01(), reshape(), and set().

Screen height.

Definition at line 48 of file partitionstest.h.

Referenced by addpoint(), partitionstest(), reshape(), and test06().

The current partition.

Definition at line 37 of file partitionstest.h.

Referenced by addpoint(), test01(), test02(), test03(), test04(), and test05().

The points in the red partition.

Definition at line 32 of file partitionstest.h.

Referenced by addpoint(), and display01().

The points in space.

Definition at line 23 of file partitionstest.h.

Referenced by display01(), and reshape().

Screen width.

Definition at line 46 of file partitionstest.h.

Referenced by addpoint(), partitionstest(), reshape(), and test06().

Container used for 3D graphics.

Definition at line 87 of file partitionstest.h.

Referenced by test06().


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

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