proj home

Files   Classes   Functions   Hierarchy  

simplexD2tessindexed.h

Go to the documentation of this file.
00001 #ifndef SIMPLEXD2TESSINDEXED_H
00002 #define SIMPLEXD2TESSINDEXED_H
00003 
00004 #include <vector>
00005 #include <sstream>
00006 using namespace std;
00007 
00008 #include <simplexD2indexed.h>
00009 #include <tessD2misc.h>
00010 #include <tokenizer.h>
00011 #include <typedefs.h>
00012 #include <vectorreadin.h>
00013 
00014 /*
00015 \brief A 2D tessellation of indexed triangles.
00016 
00017 \par Serialization
00018 \verbatim
00019 number of points+1
00020 0.0 0.0
00021 x y 
00022 ...
00023 number of triangles+1 
00024 0 0
00025 a b c
00026 ...
00027 \endverbatim
00028 
00029 */
00030 template< typename PT, typename PD, typename INDX >
00031 class simplexD2tessindexed
00032 {
00033 public:
00034 
00036   vector< PT > pts;
00038   vector< simplexD2indexed<INDX> > vi;
00039 
00041   simplexD2tessindexed();
00042 
00043 
00045   void construct
00046   ( 
00047     PD const * points,
00048     INDX const pointsize,
00049     INDX const * triangles,
00050     INDX const trianglessize
00051   );
00052     
00054   void windinganticlockwise();
00055 
00057   operator stringc () const;
00058 
00060   void serializeInverse(stringc & s);
00061 
00062 
00063 };
00064 
00065 //---------------------------------------------------------
00066 // Implementation
00067 
00068 template< typename PT, typename PD, typename INDX >
00069 void simplexD2tessindexed<PT,PD,INDX>::serializeInverse(stringc & s)
00070 {
00071   pts.clear();
00072   vi.clear();
00073 
00074   tokenizer tokenstream;
00075   tokenstream.readaslinesgeneral(s);
00076 
00077 /*
00078   tokenstream.readaslines(s);
00079   tokenstream.subtract(",");
00080   tokenstream.subtract(" ");
00081 
00082 //  tokenstream.printdelimiter="*";
00083 //  cout << tokenstream << endl;
00084 
00085 //  cout << endl << endl;
00086 
00087   // Remove leading and trailing space.
00088   tokenstream.trim();
00089   // Delete empty tokens.
00090   tokenstream.remove_if();
00091 
00092 //cout << tokenstream << endl;
00093 */
00094 
00095 
00096 
00097   tokenstream.reset();
00098   uint ptssize;
00099   stringstream(tokenstream()) >> ptssize;
00100   ++tokenstream;
00101 //cout << "ptssize=" << ptssize << endl;
00102 
00103   PD x,y;
00104   for (uint i=0; i<ptssize; ++i)
00105   {
00106     
00107     stringstream(tokenstream()) >> x;
00108     ++tokenstream;
00109     stringstream(tokenstream()) >> y;
00110     ++tokenstream;
00111 //cout << "x=" << x << " y=" << y << endl;
00112     pts.push_back( PT(x,y) );
00113   }
00114 
00115   uint visize;
00116   stringstream(tokenstream()) >> visize;
00117   ++tokenstream;
00118 //cout << "visize=" << visize << endl;
00119   INDX a,b,c;
00120   for (uint i=0; i<visize; ++i)
00121   {
00122     stringstream(tokenstream()) >> a;
00123     ++tokenstream;
00124     stringstream(tokenstream()) >> b;
00125     ++tokenstream;
00126     stringstream(tokenstream()) >> c;
00127     ++tokenstream;
00128 //cout << "a=" << a << " b=" << b << " c=" << c << endl;
00129 
00130     vi.push_back( simplexD2indexed<INDX>(a,b,c) );
00131   }
00132 
00133 }
00134 
00135 
00136 
00137 template< typename PT, typename PD, typename INDX >
00138 simplexD2tessindexed<PT,PD,INDX>::simplexD2tessindexed()
00139 {
00140   pts.push_back(PT());
00141   vi.push_back( simplexD2indexed<INDX>() );
00142 }
00143 
00144 template< typename PT, typename PD, typename INDX >
00145 simplexD2tessindexed<PT,PD,INDX>::operator stringc () const
00146 {
00147   stringstream ss;
00148   
00149   uint imax = pts.size();
00150   ss << imax << "\n";
00151   for (uint i=0; i<imax; ++i)
00152     ss << pts[i] << "\n";
00153   imax = vi.size();
00154   ss << imax << "\n";
00155   for (uint i=0; i<imax; ++i)
00156     ss << vi[i] << "\n";
00157 
00158   return ss.str();
00159 }
00160 
00161 template< typename PT, typename PD, typename INDX >
00162 void simplexD2tessindexed<PT,PD,INDX>::construct
00163 ( 
00164   PD const * points,
00165   INDX const pointsize,
00166   INDX const * triangles,
00167   INDX const trianglessize
00168 )
00169 {
00170   vectorreadingD2(pts,points,pointsize);
00171   vectorreadingD3(vi,triangles,trianglessize);
00172 }
00173 
00174 
00175 template< typename PT, typename PD, typename INDX >
00176 void simplexD2tessindexed<PT,PD,INDX>::windinganticlockwise()
00177 {
00178   tessD2misc
00179   <
00180     simplexD2tessindexed<PT,PD,INDX>,
00181     PT,
00182     INDX 
00183   > tm(*this);
00184   tm.windinganticlockwise();
00185 }
00186 
00187 
00188 #endif
00189 
00190 

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