proj home

Files   Classes   Functions   Hierarchy  

d4meshpointreader.cpp

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

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