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

gugr_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 GUGR_IO_H
00021 #define GUGR_IO_H
00022 
00023 #include <iostream>
00024 #include <iomanip>
00025 
00026 namespace gugr {
00027 
00028 using gul::Assert;
00029 using gul::Ptr;
00030 using gul::rtr;
00031 using gul::uint64;
00032 using gul::point2;
00033 using gul::line2;
00034 using gul::triangle2;
00035 using gul::dump_point;
00036 
00037 /*------------------------------------------------------------------------
00038   output functions for debugging
00039 ------------------------------------------------------------------------*/
00040 template< class T >
00041 class Dump
00042 {
00043 public:
00044   static T orgx,orgy,scalex,scaley; 
00045 public:
00046   static void set_transformation( T aorgx, T aorgy, T ascalex, T ascaley )
00047   {
00048     orgx = aorgx; 
00049     orgy = aorgy;
00050     scalex = ascalex;
00051     scaley = ascaley;
00052   }
00053   static void dump_vertice( graph_vertex *v )
00054   {
00055     double dx1,dy1;
00056     T x1,y1;
00057   
00058     if( v != NULL )
00059     {
00060       v->v.v().m_x.Dump(dx1);
00061       v->v.v().m_y.Dump(dy1);
00062       x1 = (T)dx1;
00063       y1 = (T)dy1; 
00064 
00065       x1 = cnv2coord<T>(x1)*scalex + orgx; 
00066       y1 = cnv2coord<T>(y1)*scaley + orgy;  
00067       std::cout << (void *)v << ": (" <<
00068                 std::setprecision(8) << x1 << ", " << y1 << 
00069                 "), " << (void *)v->e << "\n";
00070     }
00071     std::cout.flush();
00072   }
00073   static void dump_vert( const vertex& v )
00074   {
00075     double dx1,dy1;
00076     T x1,y1;
00077   
00078     v.v().m_x.Dump(dx1);
00079     v.v().m_y.Dump(dy1);
00080     x1 = (T)dx1;
00081     y1 = (T)dy1; 
00082 
00083     x1 = cnv2coord<T>(x1)*scalex + orgx; 
00084     y1 = cnv2coord<T>(y1)*scaley + orgy;  
00085     std::cout << "(" << x1 << ", " << y1 <<  ")\n";
00086     std::cout.flush();
00087   }
00088   static void dump_vertices( graph_vertex *V )
00089   {
00090     graph_vertex *v;
00091     double dx1,dy1;
00092     T x1,y1;
00093   
00094     v = V;
00095     std::cout << "VERTICES\n";
00096     while( v != NULL )
00097     {
00098       v->v.v().m_x.Dump(dx1);
00099       v->v.v().m_y.Dump(dy1);
00100       x1 = (T)dx1;
00101       y1 = (T)dy1; 
00102 
00103       x1 = cnv2coord<T>(x1)*scalex + orgx; 
00104       y1 = cnv2coord<T>(y1)*scaley + orgy;  
00105       std::cout << (void *)v << ": (" <<
00106                 std::setprecision(8) << x1 << ", " << y1 << 
00107                 "), " << (void *)v->e << "\n";
00108       v = v->next;
00109     }
00110     std::cout.flush();
00111   }
00112   static void dump_edges( graph_edge *E )
00113   {
00114     graph_edge *e;
00115     double dx1,dx2,dy1,dy2;
00116     T x1,x2,y1,y2;
00117     
00118     e = E;
00119     std::cout << "EDGES\n";    
00120     while( e != NULL )
00121     {
00122       e->v[0]->v.v().m_x.Dump(dx1);
00123       e->v[0]->v.v().m_y.Dump(dy1);
00124       e->v[1]->v.v().m_x.Dump(dx2);
00125       e->v[1]->v.v().m_y.Dump(dy2);
00126 
00127       x1 = (T)dx1; x2 = (T)dx2; y1 = (T)dy1; y2 = (T)dy2;
00128       
00129       x1 = cnv2coord<T>(x1)*scalex + orgx; 
00130       x2 = cnv2coord<T>(x2)*scalex + orgx; 
00131       y1 = cnv2coord<T>(y1)*scaley + orgy; 
00132       y2 = cnv2coord<T>(y2)*scaley + orgy; 
00133 
00134       std::cout << (void *)e << ": [" << e->f[0] << "," << e->f[1] << "] [" <<
00135                 (void *)e->v[0] << "=(" << std::setprecision(8) <<
00136                 x1 << ", " << y1 << "), " << (void *)e->e[0] <<
00137                 "]  [" << (void *)e->v[1] << "=(" <<
00138                 x2 << ", " << y2 << "), " << (void *)e->e[1];
00139       if( e->l.IsNULL() )
00140         std::cout << "]\n";
00141       else
00142       {
00143         e->l.v().m_x.Dump(dx1);
00144         e->l.v().m_y.Dump(dy1);
00145         x1 = (T)dx1; y1 = (T)dy1;
00146         x1 = cnv2coord<T>(x1)*scalex + orgx; 
00147         y1 = cnv2coord<T>(y1)*scaley + orgy; 
00148  
00149         e->l.dx().Dump(dx2);
00150         e->l.dy().Dump(dy2);
00151         x2 = (T)dx2; y2 = (T)dy2;
00152 
00153         std::cout << "]  L: (" << x1 << ", " << y1 << "), dx=" <<
00154                   x2 << ", dy=" << y2 << "\n";
00155       }
00156       e = e->next;
00157     }
00158     std::cout.flush();
00159   }
00160 };
00161 
00162 /*---------------------------------------------------------------------
00163   same as above, but without the transformation hazzle
00164 ----------------------------------------------------------------------*/
00165 class dump_graph
00166 {
00167 public:
00168   gul::poolmap<graph_vertex*,int> m_V;
00169   int                             m_nV;
00170   gul::poolmap<graph_edge*,int>   m_E;
00171   int                             m_nE;
00172   graph_vertex_list              *m_VL;
00173   graph_edge_list                *m_EL;
00174 
00175 
00176 public:
00177   dump_graph( graph_vertex_list *V, graph_edge_list *E )
00178   {
00179     int i;
00180     graph_vertex *v = V->First();
00181     graph_edge   *e = E->First();
00182 
00183     m_VL = V;
00184     m_EL = E;
00185 
00186     // initialize pointer lookup tables
00187     i = 1;    
00188     while( v != NULL )
00189     {
00190       m_V[v] = i;
00191       i++;
00192       v = v->next;
00193     }
00194     m_nV = i;
00195 
00196     i = 1;    
00197     while( e != NULL )
00198     {
00199       m_E[e] = i;
00200       i++;
00201       e = e->next;
00202     }
00203     m_nE = i;
00204   };
00205   
00206   void dump_vertice( graph_vertex *v, std::ostream& s )
00207   {
00208     if( v )
00209       s << "V" << m_V[v] << ": [(" << v->v.v() << "), " 
00210         << "E" << m_E[v->e] << "]\n";
00211     else
00212       s << "<NULL>\n";
00213   }
00214 
00215   void dump_vertices( graph_vertex *V, std::ostream& s )
00216   {
00217     graph_vertex *v = V;
00218 
00219     s << "VERTICES\n";
00220     while( v != NULL )
00221     {
00222       s << "V" << m_V[v] << ": [(" << v->v.v() << "), " 
00223         << "E" << m_E[v->e] << "]\n";
00224       v = v->next;
00225     }
00226   }
00227 
00228   void dump_edges( graph_edge *E, std::ostream& s )
00229   {
00230     graph_edge *e = E; 
00231 
00232     s << "EDGES\n";    
00233     while( e != NULL )
00234     {
00235       s << "E" << m_E[e] << ": [" << e->f[0].i << "," << e->f[1].i << "] ["
00236         << "V" << m_V[e->v[0]] << "=(" << e->v[0]->v.v() << "), " 
00237         << "E" << m_E[e->e[0]] << "]  ["
00238         << "V" << m_V[e->v[1]] << "=(" << e->v[1]->v.v() << "), " 
00239         << "E" << m_E[e->e[1]] << "]";                
00240       s << "\n";
00241       e = e->next;
00242     }
00243   }
00244 };
00245 
00246 inline std::ostream& operator<<( std::ostream& s, gugr::dump_graph& g )
00247 {
00248   g.dump_vertices(g.m_VL->First(),s);
00249   g.dump_edges(g.m_EL->First(),s);
00250 
00251   return s << "\n";
00252 } 
00253 
00254 
00255 inline void dump_segment( segment *S, std::ostream& s )
00256 {
00257    s << "[" << S->f[0].i << ", " << S->f[1].i << "] B=(" 
00258      << S->B << "), (" << S->E << ")\n";
00259 }
00260 
00261 
00262 class dump_segs
00263 {
00264 public:
00265   segment_list *m_S;
00266 
00267 public:
00268   dump_segs( segment_list *S )
00269   {
00270     m_S = S;
00271   }
00272 
00273   void dump( ListNode<segment> *S, std::ostream& s )
00274   {
00275     for( ; S; S = S->next )
00276     {
00277       s << "[" << S->el.f[0].i << ", " << S->el.f[1].i << "] B=(" 
00278         << S->el.B << "), (" << S->el.E << ")\n";
00279     }
00280   }
00281 };
00282 
00283 inline std::ostream& operator<<( std::ostream& s, gugr::dump_segs& S )
00284 {
00285   S.dump(S.m_S->First(),s);
00286   return s;
00287 } 
00288 
00289 }
00290 
00291 
00292 
00293 #endif

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