synaps/topology/point_complex.h

00001 /*********************************************************************
00002 *      This file is part of the source code of SYNAPS library          *
00003 *   Author(s): G. Gatellier                                          *
00004 *              B. Mourrain, GALAAD, INRIA                            *
00005 **********************************************************************/
00006 #ifndef synaps_topology_point_complex_H
00007 #define synaps_topology_point_complex_H
00008 /*********************************************************************/
00009 #include <vector>
00010 #include <map>
00011 #include <synaps/base/Seq.h>
00012 #include <synaps/topology/point_graph.h>
00013 #include <synaps/base/io/geomview.h>
00014 /*********************************************************************/
00015 __BEGIN_NAMESPACE_SYNAPS
00016 //--------------------------------------------------------------------
00017 namespace topology
00018 {
00019 
00021 
00032   template<class C, 
00033            class R = Seq<topology::point<C> >, 
00034            class E = Seq<std::vector<int> >,
00035            class F = Seq<std::vector<int> >
00036           >
00037   struct point_complex: point_graph<C,R,E>  {
00039     typedef E Vect;
00041     typedef R VectPt;
00043     typedef typename R::value_type point_t;
00045     typedef C coeff_t;
00047     typedef F faces_t;
00049     F Faces;
00051     point_complex():point_graph<C,R,E>(),Faces() {}
00052 
00054     point_complex(const point_complex<C,R,E> & G)
00055       : point_graph<C,R,E>(G),Faces(G.Faces) {}
00056 
00066     void insert_face(int  idx_pt0, 
00067                      int  idx_pt1,
00068                      int  idx_pt2)
00069       {
00070         std::vector<int> t(3);
00071         t[0]=idx_pt0;
00072         t[1]=idx_pt1;
00073         t[2]=idx_pt2;
00074         Faces.push_back(t);
00075       }
00076   };
00077   //--------------------------------------------------------------------
00078   template <class C, class R, class E, class F>
00079   void print( geomview::ostream & out, 
00080               const point_complex<C,R,E,F> & G,
00081               float r = 0.0, float g = 0.0,
00082               float b = 0.9, float a = 1.,
00083               float sz= 0.01)
00084     {
00085       std::vector< std::pair<unsigned,unsigned> > lines;
00086       for( unsigned  i = 0;  i <  G.Edges.size(); i++ )
00087         for( unsigned j = 0; j < G.Edges[i].size(); j++ )
00088           lines.push_back( std::pair<unsigned,unsigned>(i,G.Edges[i][j]) );
00089       std::ofstream f;
00090       f.open (out.file, std::ofstream::out | std::ofstream::app);
00091       f << "{=SKEL\n";
00092       f << G.Vertices.size()  << " " << lines.size() << std::endl;
00093       for ( unsigned i = 0; i < G.Vertices.size(); i ++ )
00094         {
00095           unsigned m = std::min((unsigned)3,G.Vertices[i].size());
00096           for ( unsigned d = 0; d < m; d++ )
00097             f << G.Vertices[i][d] << " ";
00098           for ( unsigned d = m; d < 3; d++ )
00099             f << "0 ";
00100           f << std::endl;
00101         };
00102       
00103       if(lines.size())
00104         f << 2 << " " << lines[0].first << " " << lines[0].second //<< std::endl;
00105           << " "<< r << " " << g << " " << b << " " << a << std::endl;
00106       for ( unsigned i = 1; i < lines.size(); i ++)
00107         f << 2 << " " << lines[i].first << " " << lines[i].second
00108           << " "<< r << " " << g << " " << b << " " << a << std::endl;
00109       f <<"}\n";
00110 
00111 
00112 
00113       f << "{=COFF\n";
00114       // Number of points.
00115       f << G.Vertices.size() <<  " ";
00116 
00117       // Number of triangles.
00118       f << G.Faces.size() << std::endl;
00119 
00120       // Edge numbers.
00121       f << "0"  << std::endl;
00122       
00123       // List of points.
00124       for ( int i = 0 ; i < G.Vertices.size() ; i++ )
00125         f <<  G.Vertices[i][0] << " "
00126           <<  G.Vertices[i][1] << " "
00127           <<  G.Vertices[i][2] << " "
00128           << r << " " << g << " " << b << " " << a  <<"\n";
00129 
00130     // The triangles and their indices.
00131       for ( int j = 0 ; j < G.Faces.size() ; j++ )
00132         f <<  "3" << " "
00133           << G.Faces[j][0] << " "
00134           << G.Faces[j][1] << " "
00135           << G.Faces[j][2] << std::endl;
00136       
00137       f <<"}\n";
00138 
00139       /*
00140         for(unsigned i=0; i< G.Vertices.size(); i++) 
00141         { 
00142         print(f,G.Vertices[i],r,g,b,a,sz);
00143         }
00144       */
00145       f.close(); 
00146     }
00147 
00148   template <class C, class R, class E, class F>
00149   geomview::ostream & operator<< (geomview::ostream & os, 
00150                                   const point_complex<C,R,E,F> & G)
00151   {
00152     print(os,G,os.color.r,os.color.g,os.color.b,1,os.width.sz); 
00153     return os;
00154   }
00155 
00156 }
00157 
00158 //--------------------------------------------------------------------
00159 __END_NAMESPACE_SYNAPS
00160 /*********************************************************************/
00161 #endif // synaps_topology_point_complex_H

SYNAPS DOCUMENTATION
logo