proj home

Files   Classes   Functions   Hierarchy  

pathlinesegtest Class Reference

#include <pathlinesegtest.h>

Collaboration diagram for pathlinesegtest:

List of all members.

Public Member Functions

 pathlinesegtest (int argc, char **argv)
 Default graphics setup.

Static Public Member Functions

static void display01 ()
 Redraw the scene.
static void keyboard01 (unsigned char key, int x, int y)
 ESC key to quit application.
static void test01 (int argc, char **argv)
 Display pathlineseg by reading a file.
static void test02 ()
 Read a pathlineseg from a string.
static int unittest01 (int argc, char **argv)
 Test equivalent dist01 and pathlinesegvec() function.
static int test03 (int argc, char **argv)
 Minimize a path and optionally save: file2="somefile.txt".

Static Public Attributes

static string doc []
 Brief description of each test.
static pathlinesegtestself = 0


Detailed Description

Definition at line 9 of file pathlinesegtest.h.


Constructor & Destructor Documentation

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

Default graphics setup.

Definition at line 25 of file pathlinesegtest.cpp.

References display01(), keyboard01(), and gobjContainer::set().

Referenced by test01().

00026 {
00027   glutInit(&argc,argv);
00028   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00029   glutInitWindowSize(600,600);
00030   glutCreateWindow("");
00031   glutDisplayFunc(display01);
00032   glutKeyboardFunc(keyboard01);
00033 
00034   OpenGLinitialisation();
00035 
00036   glEnable(GL_DEPTH_TEST);
00037   glEnable(GL_CULL_FACE);
00038   glEnable(GL_NORMALIZE);
00039 
00040   xGraphics.set();
00041 }


Member Function Documentation

void pathlinesegtest::display01 (  )  [static]

Redraw the scene.

Definition at line 103 of file pathlinesegtest.cpp.

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

Referenced by pathlinesegtest().

00104 {
00105   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00106 
00107   gobj::global->draw();
00108 
00109   glerrordisplay();
00110   
00111   glutSwapBuffers();
00112 }

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

ESC key to quit application.

Definition at line 114 of file pathlinesegtest.cpp.

Referenced by pathlinesegtest().

00115 {
00116   switch (key)
00117   {
00118     case 27:
00119       exit(0);
00120       break;
00121   }
00122 }

void pathlinesegtest::test01 ( int  argc,
char **  argv 
) [static]

Display pathlineseg by reading a file.

Definition at line 43 of file pathlinesegtest.cpp.

References gobjpush, commandline::mapvar(), pathlinesegtest(), filestring::serialize(), pathlineseg::serializeInverse(), and zpr::update().

Referenced by main().

00044 {
00045   cout << "Display pathlineseg. file=\"somefile.txt\"" << "\n"; 
00046   cout << "  optional: pointsdraw, pointsnumber, pointsnumber, " << "\n";
00047   cout << "  curvepointsdraw, controldraw, segdraw." << "\n";
00048 
00049   assert(self==0);
00050   self = new pathlinesegtest(argc,argv);
00051 
00052   gobjpush(new myaxes(1.0));
00053 
00054   // Read segments file in and graphically display.
00055 
00056   string cmdarg("./main prog=30 file=path001.txt");
00057 
00058   commandline cmd(argc,argv);
00059   string file="";
00060   cmd.mapvar(file,"file");
00061   if (file.empty())
00062   {
00063     cout << "error: need file eg" << endl;
00064     cout << "  " << cmdarg << endl;
00065     return;
00066   }
00067  
00068   string str;
00069   bool res=filestring::serialize(str,file);
00070   if (res==false)
00071   {
00072     cout << "error: " << cmdarg << endl; 
00073     return;
00074   }
00075   if (str.empty())
00076   { 
00077     cout << "error: empty file input." << endl; return; 
00078   }
00079 
00080   pathlineseg ps;
00081   ps.serializeInverse(str);
00082 
00083   cout << (stringc)ps << endl;
00084 
00085   pathlinesegdraw* psd = new pathlinesegdraw(&ps,false);
00086 
00087   cmd.mapvar(psd->pointsdraw,"pointsdraw");
00088   cmd.mapvar(psd->pointsnumber,"pointsnumber");
00089   cmd.mapvar(psd->curvepointsdraw,"curvepointsdraw");
00090   cmd.mapvar(psd->controldraw,"controldraw");
00091   cmd.mapvar(psd->segsdraw,"segsdraw");
00092   psd->update();
00093   gobjpush(psd);
00094 
00095 //cout << SHOW(res);
00096 // cout << "*" <<  str << "*" << endl;
00097 
00098   zpr zz;
00099   zz.update();
00100   glutMainLoop();
00101 }

void pathlinesegtest::test02 (  )  [static]

Read a pathlineseg from a string.

Definition at line 124 of file pathlinesegtest.cpp.

References pathlineseg::segments, and pathlineseg::serializeInverse().

Referenced by main().

00125 {
00126   pathlineseg ps;
00127 
00128   uint sg[] = { 1,2,2,3,3,4 };
00129   copy(sg,sg+6,back_inserter(ps.segments));
00130 
00131   cout << (stringc)ps << endl;
00132   cout << endl;
00133 
00134   cout << "serializeInverse" << endl;
00135   string s2=
00136 "<path>\
00137 <info>Path line segments</info>\
00138 <points2D>\
00139  0 0\
00140  0.0 0.0\
00141  .2 .3 .4 .7\
00142  1.2 .2\
00143  1.6 .12\
00144 </points2D>\
00145 <control>\
00146 1 2 3 4\
00147 </control>\
00148 <segments>\
00149 1 2 2 3 3 4\
00150 </segments>\
00151 </path>";
00152 
00153   pathlineseg ps2;
00154   ps2.serializeInverse(s2);
00155 
00156   cout << (stringc)ps2 << endl;
00157 }

int pathlinesegtest::test03 ( int  argc,
char **  argv 
) [static]

Minimize a path and optionally save: file2="somefile.txt".

Definition at line 224 of file pathlinesegtest.cpp.

References assertreturnOS, filestring::deserialize(), funcstate< X >::dim, pathlinesegvec::distfn, commandline::mapvar(), printvecfunc(), pathlinesegvec::read(), minexpdim< X >::reset(), filestring::serialize(), pathlineseg::serializeInverse(), pathlinesegvec::write(), minexpdim< X >::xi, and funcstate< X >::xi.

Referenced by main().

00225 {
00226   commandline cmd(argc,argv);
00227   string file="path002.txt";
00228   cmd.mapvar(file,"file");
00229   if (file.empty())
00230   {
00231     cout << "error: need file in command line eg file=path002.txt" << endl;
00232     return 1;
00233   }
00234 
00235   string str;
00236   assertreturnOS(filestring::serialize(str,file));
00237   assertreturnOS(str.empty()==false);
00238 
00239   // Aim: display original and minimized paths.
00240 
00241   // Original 
00242   pathlineseg ps0;
00243   ps0.serializeInverse(str);
00244 
00245   // Path to be minimized.
00246   pathlineseg ps;
00247   ps.serializeInverse(str);
00248 
00249   pathlinesegvec* psf = new pathlinesegvec(ps);
00250   psf->read();
00251 
00252   double h0=0.3;
00253   cmd.mapvar(h0,"h0");
00254   minexpdimN<double> mn(*psf,h0);
00255 
00256   // Change the distance function.
00257   cmd.mapvar(psf->distfn,"distfn");
00258 
00259   mn.reset();
00260 
00261   cout << printvecfunc(psf->xi,psf->dim+1) << endl;
00262 
00263   uint i=0;
00264   uint imax=4;
00265   cmd.mapvar(imax,"imax");
00266   do
00267   {
00268     ++mn;
00269     cout << setw(3) << i << " " << printvecfunc(mn.xi,psf->dim+1) << endl;
00270     //cout << " " << mn.fn->counter << " " << mn.himax() << endl;
00271     ++i;
00272 
00273 
00274   } while ( (i<imax) );
00275 
00276   psf->write();
00277 
00278 
00279   string file2("");
00280   cmd.mapvar(file2,"file2");
00281   if (file2.empty())
00282   { 
00283     cout << (stringc)ps << endl;
00284   }
00285   else
00286   {
00287     assertreturnOS(filestring::deserialize(file2,(stringc)ps));
00288   }
00289 
00290   return 0;
00291 }

int pathlinesegtest::unittest01 ( int  argc,
char **  argv 
) [static]

Test equivalent dist01 and pathlinesegvec() function.

Definition at line 159 of file pathlinesegtest.cpp.

References assertreturnOS, funcstate< X >::dim, pathlinesegvec::distfn, funcstate< X >::fnvalue(), commandline::mapvar(), printvecfunc(), pathlinesegvec::read(), filestring::serialize(), SHOW, pathlinesegvec::write(), and funcstate< X >::xi.

Referenced by main().

00160 {
00161   commandline cmd(argc,argv);
00162   string file="path002.txt";
00163   cmd.mapvar(file,"file");
00164   if (file.empty())
00165   {
00166     cout << "error: need file in command line eg file=path002.txt" << endl;
00167     return 1;
00168   }
00169 
00170   string str;
00171   assertreturnOS(filestring::serialize(str,file));
00172   assertreturnOS(str.empty()==false);
00173 
00174   pathlineseg ps;
00175   ps.serializeInverse(str);
00176 
00177 cout << (stringc)ps << endl;
00178   double psdist01=ps.dist01();
00179 cout << SHOW(psdist01) << endl;
00180 //cout << SHOW(ps.dist01()) << endl;
00181 
00182 cout << endl;
00183 
00184   pathlinesegvec psf(ps);
00185 
00186   psf.read();
00187   psf.distfn=1;
00188   psf();
00189   cout << printvecfunc(psf.xi,psf.dim+1) << endl;
00190 
00191   // TODO - read a pathlineseg file in
00192   // and print out.
00193   
00194 
00195   double psfdist = psf.fnvalue();
00196   cout << SHOW(psfdist) << endl;
00197 
00198   // Testing that the two distance functions are the same.
00199   assertreturnOS(zero<double>::test(psdist01-psfdist));
00200 
00201   double psdist02=ps.dist02();
00202   psf.distfn=2;
00203   cout << SHOW(psdist02) << endl;
00204   psf();
00205   psfdist=psf.fnvalue();
00206   cout << SHOW(psfdist) << endl;
00207   assertreturnOS(zero<double>::test(psdist02-psfdist));
00208 
00209   // Testing writing back to instance.
00210   for (uint i=0; i<=psf.dim; ++i)
00211   {
00212     psf.xi[i] = 0.5 + i;
00213   }
00214   cout << printvecfunc(psf.xi,psf.dim+1) << endl;
00215   psf.write();
00216 
00217   cout << (stringc)ps << endl;
00218 
00219 
00220   return 0;
00221 }


Member Data Documentation

string pathlinesegtest::doc [static]

Initial value:

 
{
  "",
  "Display pathlineseg by reading a file.",
  "Read a pathlineseg from a string.",
  "Test equivalent dist01 and pathlinesegvec() function.",
  "Minimize a path and optionally save: file2=\"somefile.txt\"."
}
Brief description of each test.

Definition at line 16 of file pathlinesegtest.h.

Referenced by main().

Definition at line 18 of file pathlinesegtest.h.


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