Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

gul_io.h

Go to the documentation of this file.
00001 /* LIBGUL - Geometry Utility Library
00002  * Copyright (C) 1998-1999 Norbert Irmer
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */
00019  
00020 #ifndef GUL_IO_H
00021 #define GUL_IO_H
00022 
00023 namespace gul {
00024 
00025 using std::ostream;
00026 
00027 enum dump_format
00028 {
00029   human_readable = 0,
00030   gul_format
00031 };
00032 
00033 enum dump_point_format
00034 {
00035   homogeneous = 0,
00036   euclidian,
00037   mixed
00038 };
00039 
00040 class dump_defaults
00041 {
00042 public:
00043   GULAPI static dump_format       m_format;       // default: human_readable;
00044   GULAPI static dump_point_format m_point_format; // default: homogeneous;
00045 
00046   static void set_format( dump_format f ) { m_format = f; }
00047   static void set_point_format( dump_point_format f ) { m_point_format = f; }
00048 };
00049 
00050 template< class EP >
00051 class dump_point
00052 {
00053 public:
00054   EP                m_P;
00055   dump_format       m_f; 
00056   dump_point_format m_e;
00057 
00058   dump_point( const EP& P, dump_format f, dump_point_format e )
00059   {
00060     m_P = P;
00061     m_f = f;
00062     m_e = e;
00063   }
00064   dump_point( const EP& P )
00065   {
00066     m_P = P;
00067     m_f = dump_defaults::m_format;
00068     m_e = dump_defaults::m_point_format;
00069   }
00070 
00071   std::ostream& out_human( std::ostream& s ) const
00072   {
00073     int i;
00074 
00075     if( (!EP::hom()) || (m_e == homogeneous) )
00076     {
00077       s << m_P[0];
00078       for( i = 1; i < EP::dim(); i++ )
00079       {
00080         s << " ";
00081         s << m_P[i];   
00082       }
00083     }
00084     else if( m_e == euclidian )
00085     {
00086       s << m_P[0]/m_P.weight();
00087       for( i = 1; i < EP::dim()-1; i++ )
00088       {
00089         s << " ";
00090         s << m_P[i]/m_P.weight();   
00091       }
00092     }
00093     else if( m_e == mixed )
00094     {
00095       s << m_P[0]/m_P.weight();
00096       for( i = 1; i < EP::dim()-1; i++ )
00097       {
00098         s << " ";
00099         s << m_P[i]/m_P.weight();   
00100       }
00101       s << " ";
00102       s << m_P.weight();   
00103     }
00104     return s;
00105   }
00106 
00107   std::ostream& out_gul( std::ostream& s ) const
00108   {
00109     int i;
00110 
00111     if( (!EP::hom()) || (m_e == homogeneous) )
00112     {
00113       s << "(" << m_P[0];
00114       for( i = 1; i < EP::dim(); i++ )
00115       {
00116         s << ", ";
00117         s << m_P[i];   
00118       }
00119       s << ")";
00120     }
00121     else if( m_e == euclidian )
00122     {
00123       s << "(" << m_P[0]/m_P.weight();
00124       for( i = 1; i < EP::dim()-1; i++ )
00125       {
00126         s << ", ";
00127         s << m_P[i]/m_P.weight();   
00128       }
00129       s << ")";
00130     }
00131    else if( m_e == mixed )
00132     {
00133       s << "(" << m_P[0]/m_P.weight();
00134       for( i = 1; i < EP::dim()-1; i++ )
00135       {
00136         s << ", ";
00137         s << m_P[i]/m_P.weight();   
00138       }
00139       s << ", ";
00140       s << m_P.weight();   
00141       s << ")";
00142     }
00143     return s;
00144   }
00145 };
00146 
00147 template< class EP >
00148 inline std::ostream& operator<<( std::ostream& os, const gul::dump_point<EP>& P )
00149 {
00150   if( P.m_f == human_readable )
00151     P.out_human(os);
00152   else if( P.m_f == gul_format )
00153     P.out_gul(os);
00154 
00155   return os;
00156 }
00157 
00158 
00159 template< class T >
00160 inline ostream& operator<<( ostream& s, const point1<T>& p )
00161 {
00162   return s << gul::dump_point<gul::point1<T> >(p);
00163 } 
00164 template< class T>
00165 inline ostream& operator<<( ostream& s, const hpoint1<T>& p )
00166 {
00167   return s << gul::dump_point<gul::hpoint1<T> >(p);
00168 } 
00169 
00170 template< class T >
00171 inline ostream& operator<<( ostream& s, const point2<T>& p )
00172 {
00173   return s << gul::dump_point<gul::point2<T> >(p);
00174 } 
00175 template< class T>
00176 inline ostream& operator<<( ostream& s, const hpoint2<T>& p )
00177 {
00178   return s << gul::dump_point<gul::hpoint2<T> >(p);
00179 } 
00180 
00181 template< class T >
00182 inline ostream& operator<<( ostream& s, const point<T>& p )
00183 {
00184   return s << gul::dump_point<gul::point<T> >(p);
00185 } 
00186 template< class T>
00187 inline ostream& operator<<( ostream& s, const hpoint<T>& p )
00188 {
00189   return s << gul::dump_point<gul::hpoint<T> >(p);
00190 } 
00191 
00192 template< class EP, class L >
00193 class dump_line
00194 {
00195 public:
00196   L m_line;
00197   dump_format       m_f;
00198   dump_point_format m_e;
00199 
00200   dump_line( const L& l, dump_format f, dump_point_format e )
00201   {
00202     m_line = l;
00203     m_f = f;
00204     m_e = e;
00205   }
00206   dump_line( const L& l )
00207   {
00208     m_line = l;
00209     m_f = dump_defaults::m_format;
00210     m_e = dump_defaults::m_point_format;
00211   }
00212   ostream& out_human( ostream& os ) const
00213   {
00214     os << "(" << dump_point<EP>(m_line[0],m_f,m_e) << " "
00215        << dump_point<EP>(m_line[1],m_f,m_e) << ")";
00216 
00217     return os;
00218   }
00219   ostream& out_gul( ostream& os ) const
00220   {
00221     os << "(" << dump_point<EP>(m_line[0],m_f,m_e) << ", "
00222        << dump_point<EP>(m_line[1],m_f,m_e) << ")";
00223 
00224     return os;
00225   }
00226 };
00227 
00228 template< class EP, class L >
00229 inline ostream& operator<<( ostream& os, const dump_line<EP,L>& l )
00230 {
00231   if( l.m_f == human_readable )
00232     l.out_human(os);
00233   else if( l.m_f == gul_format )
00234     l.out_gul(os);
00235 
00236   return os;
00237 }
00238 
00239 template< class T >
00240 inline ostream& operator<<( ostream& os, const line<T>& l )
00241 {
00242   os << dump_line<point<T>,line<T> >(l);
00243   return os;
00244 }
00245 
00246 template< class T >
00247 inline ostream& operator<<( ostream& os, const line2<T>& l )
00248 {
00249   os << dump_line<point2<T>,line2<T> >(l);
00250   return os;
00251 }
00252 
00253 template< class T >
00254 class dump_list
00255 {
00256 public:
00257   List<ListNode<T> > *m_L;
00258 
00259   dump_list( List<ListNode<T> > *L )
00260   {
00261     m_L = L;
00262   }
00263   ostream& out_gul( ostream& os ) const
00264   {
00265     ListNode<T> *n;
00266 
00267     os << "(\n";
00268 
00269     n = m_L->First();
00270     if( n )
00271       os << "  " << n->el;
00272 
00273     for( ; n; n = n->next )
00274     {
00275       os << ",\n";
00276       os << "  " << n->el;
00277     }
00278 
00279     os << "\n";
00280     os << ")";
00281 
00282     return os;
00283   }
00284 };
00285 
00286 template< class T >
00287 inline ostream& operator<<( ostream& os, const dump_list<T>& L )
00288 {
00289   L.out_gul(os);
00290 
00291   return os;
00292 }
00293 
00294 
00295 template< class T, class HP >
00296 class dump_surf
00297 {
00298 public:
00299   int               m_nu;
00300   int               m_pu;
00301   Ptr<T>            m_U;
00302   int               m_nv;
00303   int               m_pv;
00304   Ptr<T>            m_V;
00305   Ptr< Ptr< HP > >  m_Pw;
00306   dump_format       m_f;
00307   dump_point_format m_e;
00308 
00309   dump_surf( int nu, int pu, Ptr<T>& U, int nv, int pv, Ptr<T>& V,
00310              Ptr< Ptr< HP > >& Pw, dump_format f, dump_point_format e )
00311   {
00312     m_nu = nu;
00313     m_pu = pu;
00314     m_U = U;
00315     m_nv = nv;
00316     m_pv = pv;
00317     m_V = V;
00318     m_Pw = Pw;
00319     m_f = f;
00320     m_e = e;
00321   }
00322   dump_surf( int nu, int pu, Ptr<T>& U, int nv, int pv, Ptr<T>& V,
00323              Ptr< Ptr< HP > >& Pw )
00324   {
00325     m_nu = nu;
00326     m_pu = pu;
00327     m_U = U;
00328     m_nv = nv;
00329     m_pv = pv;
00330     m_V = V;
00331     m_Pw = Pw;
00332     m_f = dump_defaults::m_format;
00333     m_e = dump_defaults::m_point_format;
00334   }
00335 
00336   std::ostream& out_human( std::ostream& os ) const
00337   {
00338    int i,j;
00339 
00340     os << "Knot Vector V\n";
00341     for( i = 0; i < m_nv+m_pv+2; i++ )
00342       os << m_V[i] << " ";
00343     os << "\n";
00344 
00345     os << "Knot Vector U\n";
00346     for( i = 0; i < m_nu+m_pu+2; i++ )
00347       cout << m_U[i] << " ";
00348     os << "\n";
00349     os.flush();
00350 
00351     os << "Control Points:\n";
00352     for( i = 0; i < m_nv+1; i++ )
00353     {
00354       for( j = 0; j < m_nu+1; j++ )
00355         os << "(" << dump_point<HP>(m_Pw[i][j],m_f,m_e) << ") ";
00356       os << "\n";
00357     }
00358     os.flush();
00359 
00360     return os;
00361   }
00362   std::ostream& out_gul( std::ostream& os ) const
00363   {
00364     int i,j;
00365 
00366     os << "(\n";
00367     // u knot vector
00368     os << "  (\n";
00369     os << "    " << m_U[0];
00370     for( i = 1; i < m_nu + m_pu + 2; i++ )
00371     {
00372       os << ",\n";
00373       os << "    " << m_U[i];        
00374     }
00375     os << "\n";
00376     os << "  ),\n";
00377 
00378     // v knot vector
00379     os << "  (\n";
00380     os << "    " << m_V[0];
00381     for( i = 1; i < m_nv + m_pv + 2; i++ )
00382     {
00383       os << ",\n";
00384       os << "    " << m_V[i];        
00385     }
00386     os << "\n  ),\n";
00387 
00388     // control point matrix
00389     os << "  (\n";
00390 
00391     // first row
00392     os << "    (\n";
00393     os << "      " << dump_point<HP>(m_Pw[0][0],m_f,m_e);
00394     for( i = 1; i <= m_nu; i++ )
00395     {
00396       os << ",\n";
00397       os << "      " << dump_point<HP>(m_Pw[0][i],m_f,m_e);
00398     }
00399     os << "\n    )";
00400 
00401     // remaining rows
00402     for( j = 1; j <= m_nv; j++ )
00403     {
00404       os << ",\n";
00405       os << "    (\n";
00406       os << "      " << dump_point<HP>(m_Pw[j][0],m_f,m_e);
00407       for( i = 1; i <= m_nu; i++ )
00408       {
00409         os << ",\n";
00410         os << "      " << dump_point<HP>(m_Pw[j][i],m_f,m_e);
00411       }
00412       os << "\n    )";
00413     }
00414 
00415     os << "\n  )\n";
00416     os << ")";
00417 
00418     return os;
00419   }
00420 };
00421 
00422 template< class T, class HP >
00423 inline ostream& operator<<( ostream& os, const dump_surf<T,HP>& s )
00424 {
00425   if( s.m_f == human_readable )
00426     s.out_human(os);
00427   else if( s.m_f == gul_format )
00428     s.out_gul(os);
00429 
00430   return os;
00431 }
00432 
00433 
00434 
00435 template< class T, class HP >
00436 class dump_curve
00437 {
00438 public:
00439   int              m_n;
00440   int              m_p;
00441   Ptr<T>           m_U;
00442   Ptr< HP >        m_Pw;
00443 
00444   dump_curve( int n, int p, Ptr<T>& U, Ptr< HP >& Pw )
00445   {
00446     m_n = n;
00447     m_p = p;
00448     m_U = U;
00449     m_Pw = Pw;
00450   }
00451 };
00452 
00453 template< class T, class HP >
00454 inline ostream& operator<<( ostream& os, const dump_curve<T,HP>& c )
00455 {
00456   int i;
00457 
00458   os << "Knot Vector U\n";
00459   for( i = 0; i < c.m_n+c.m_p+2; i++ )
00460     cout << c.m_U[i] << " ";
00461   os << "\n";
00462   os.flush();
00463 
00464   os << "Control Points:\n";
00465   for( i = 0; i < c.m_n+1; i++ )
00466   {
00467     os << "(" << c.m_Pw[i] << ") ";
00468   }
00469   os.flush();
00470 
00471   return os;
00472 }
00473 
00474 template< class HP >
00475 class dump_matrix
00476 {
00477 public:
00478   int                     m_nRows;
00479   int                     m_nCols;
00480   const Ptr< Ptr< HP > >& m_M;
00481 
00482   dump_matrix( int nRows, int nCols, const Ptr< Ptr< HP > >& M ) : m_M(M)
00483   {
00484     m_nRows = nRows;
00485     m_nCols = nCols;
00486   }
00487 };
00488 
00489 template< class HP >
00490 inline ostream& operator<<( ostream& os, const dump_matrix<HP>& m )
00491 {
00492   int i,j;
00493 
00494   os << "Matrix:\n";
00495   for( i = 0; i < m.m_nRows; i++ )
00496   {
00497     for( j = 0; j < m.m_nCols; j++ )
00498       os << "(" << m.m_M[i][j] << ") ";
00499     os << "\n";
00500   }
00501   os.flush();
00502 
00503   return os;
00504 }
00505 
00506 template< class HP >
00507 class dump_vector
00508 {
00509 public:
00510   int            m_nV;
00511   const Ptr<HP>& m_V;
00512 
00513   dump_vector( int nV, const Ptr<HP>& V ) : m_V(V)
00514   {
00515     m_nV = nV;
00516   }
00517 };
00518 
00519 template< class HP >
00520 inline ostream& operator<<( ostream& os, const dump_vector<HP>& m )
00521 {
00522   int i;
00523 
00524   os << "Vector:\n";
00525   for( i = 0; i < m.m_nV; i++ )
00526   {
00527     os << "(" << m.m_V[i] << ") ";
00528     os << "\n";
00529   }
00530   os.flush();
00531 
00532   return os;
00533 }
00534 
00535 
00536 
00537 
00538 
00539 
00540 
00541 
00542 
00543 
00544 
00545 
00546 
00547 
00548 
00549 
00550 
00551 
00552 
00553 
00554 
00555 }
00556 
00557 #endif
00558 

Generated on Mon Jan 21 04:17:32 2002 for GUL 0.6 - Geometry Utility Library by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001