proj home

Files   Classes   Functions   Hierarchy  

d3meshpointreader.cpp

Go to the documentation of this file.
00001 
00002 #include <iostream>
00003 #include <fstream>
00004 using namespace std;
00005 
00006 #include <point.h>
00007 #include <d3tess.h>
00008 
00009 #include <aclock.h>
00010 
00011 #include <d3meshpointreader.h>
00012 
00013 typedef unsigned int uint;
00014 
00015 
00016 d3meshpointreader::d3meshpointreader
00017 (
00018   bool & res,
00019   d3tess & tess_, 
00020   string const & filename
00021 )
00022   : tess(tess_)
00023 {
00024   res=false;
00025 
00026   uint columns(0);
00027   if (isfilegood(columns,filename)==false)
00028     return;
00029 
00030   ifstream targ(filename.c_str());
00031 
00032   tess.reset();
00033 
00034   if (columns==2)
00035     readtwocolumns(targ);
00036 
00037   if (columns==3)
00038     readthreecolumns(targ);
00039 
00040   cout << "Finished reading file: " << filename << endl << endl;
00041 
00042   res=true;
00043 }
00044 
00045 
00046 d3meshpointreader::d3meshpointreader
00047 (
00048   bool & res,
00049   d3tess & tess_, 
00050   vector< pt3 > const & vbox,
00051   string const & filename
00052 )
00053   : tess(tess_)
00054 {
00055   res=false;
00056 
00057   uint columns(0);
00058   if (isfilegood(columns,filename)==false)
00059     return;
00060 
00061   ifstream targ(filename.c_str());
00062 
00063   tess.reset();
00064 
00065   for (uint i=0; i<vbox.size(); ++i)
00066     tess.pt.push_back(vbox[i]);
00067 
00068   if (columns==2)
00069     readtwocolumns(targ);
00070 
00071   if (columns==3)
00072     readthreecolumns(targ);
00073 
00074   res=true;
00075 }
00076 
00077 void d3meshpointreader::eval()
00078 {
00079   tess.initialize();
00080 
00081   uint sz=tess.pt.size();
00082   for (uint i=4; i<sz; ++i)
00083   {
00084 //cout << "Inserting point " << i << endl;
00085     tess.addpoint(i);
00086   }
00087 }
00088 
00089 
00090 void d3meshpointreader::eval(ostream & os)
00091 {
00092   aclock c;
00093   c.measure();
00094   eval();
00095   c.measure();
00096 
00097   os << tess.pt.size()-1 << " " << c.diff_s() << endl;
00098 }
00099 
00100 
00101 bool const d3meshpointreader::isfilegood
00102 (
00103   uint & columns,
00104   string const & filename
00105 ) const
00106 {
00107   ifstream targ(filename.c_str());
00108 
00109   if (targ.good()==false)
00110   {
00111     cout << "error:  targ.good() failed" << endl;
00112     cout << "        can not open file: " << filename << endl;
00113 
00114     return false;
00115   }
00116 
00117   if (targ.eof()==true)
00118   {
00119     cout << "error:  empty file: " << filename << endl;
00120     return false;
00121   }
00122     
00123   string s;
00124   getline(targ,s);
00125 
00126   uint sz=s.size();
00127   if (sz<=1)
00128   {
00129     cout << "error:  can not read first line of file: " << filename << endl;
00130     return false;
00131   }
00132 
00133   char const space(' ');
00134 
00135   // Iterate along the string.  The current position is either pointing to
00136   //   an element that is a space or not.  This is used to count the number
00137   //   of arguments or columns in the line.
00138   bool statespace=true;
00139    
00140   uint counter(0);
00141 
00142   if (s[0]!=space)
00143   {
00144     statespace=false;
00145     counter=1;
00146   }
00147    
00148   for (uint i=1; i<sz; ++i)
00149   {
00150     if (statespace)
00151     {
00152       if (s[i]!=space)
00153       {
00154         statespace=false;
00155         ++counter;
00156       }
00157 
00158       continue;
00159     }
00160 
00161     if (s[i]==space)
00162       statespace=true;
00163 
00164   }
00165 
00166   columns=counter;
00167 
00168   return true;
00169 }
00170 
00171 
00172 void d3meshpointreader::readtwocolumns(ifstream & targ)
00173 {
00174   pt3 x;
00175 
00176   for ( ; targ.eof()==false; )
00177   {
00178     targ >> x.x;
00179     if (targ.eof()==true)
00180       continue;
00181 
00182     targ >> x.y;
00183     tess.pt.push_back(x);
00184   }
00185 
00186 }
00187 
00188 void d3meshpointreader::readthreecolumns(ifstream & targ)
00189 {
00190   pt3 x;
00191 
00192   for ( ; targ.eof()==false; )
00193   {
00194     targ >> x.x;
00195     if (targ.eof()==true)
00196       continue;
00197     targ >> x.y;
00198     if (targ.eof()==true)
00199       continue;
00200     targ >> x.z;
00201 
00202     tess.pt.push_back(x);
00203   }
00204 
00205 }
00206 
00207 

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