shape_doc 0.1
/Users/mourrain/Devel/mmx/shape/include/shape/point_set.hpp
Go to the documentation of this file.
00001 /*****************************************************************************
00002  * M a t h e m a g i x
00003  *****************************************************************************
00004  * point set
00005  * 2009-05-08
00006  * Bernard Mourrain
00007  *****************************************************************************
00008  *               Copyright (C) 2006 INRIA Sophia-Antipolis
00009  *****************************************************************************
00010  * Comments :
00011  ****************************************************************************/
00012 # ifndef shape_point_set_hpp
00013 # define shape_point_set_hpp
00014 //====================================================================
00015 # include <realroot/Seq.hpp>
00016 # include <shape/point.hpp>
00017 # include <shape/vertex.hpp>
00018 
00019 # define TMPL   template<class C, class V>
00020 # define TMPL1  template<class V>
00021 //# define Shape  geometric<V>
00022 # define SELF   point_set<C,V>
00023 # define Viewer viewer<axel,W>
00024 //====================================================================
00025 namespace mmx {
00026 namespace shape {
00027 
00028 // TMPL struct  point_set;
00029 
00030 // TMPL struct  use<point_set_def,V>
00031 // {
00032 //   typedef typename point_def<K>::Point Point;
00033 //   typedef typename Seq< Point >::iterator PointIterator;
00034 //   typedef typename Seq< Point >::const_iterator PointConstIterator;
00035 // };
00036 
00037 
00038 template<class C, class V=default_env>
00039 class point_set : public SHAPE_OF(V)
00040 {
00041 public:
00042   typedef typename SHAPE_OF(V)                  Shape;
00043   typedef point<C,REF_OF(V)>                    Point;
00044   typedef typename Seq< Point >::iterator       PointIterator;
00045   typedef typename Seq< Point >::const_iterator PointConstIterator;
00046 
00047   point_set(void) ;
00048   point_set(unsigned n) ;
00049  ~point_set(void) ;
00050 
00051   void push_back(const Point & p) ;
00052   
00053   void pop(Point * vertex) ;
00054 
00055   void clear(void) ;
00056 
00057   inline Seq<Point>& vertices(void) { return m_vertices ; }
00058 
00059   PointConstIterator begin() const { return m_vertices.begin() ; }
00060   PointIterator begin()       { return m_vertices.begin() ; }
00061   PointConstIterator end()   const { return m_vertices.end(); }
00062   PointIterator end()         { return m_vertices.end(); }
00063 
00064   const Point& vertex(unsigned i) const {
00065     return m_vertices[i] ;
00066   }
00067 
00068   Point& vertex(unsigned i) {
00069     return m_vertices[i] ;
00070   }
00071 
00072   unsigned nbv(void)  const { return m_vertices.size() ; }
00073   unsigned size(void) const { return m_vertices.size() ; }
00074 
00075   SELF& operator<<(const Point&p) { push_back(p); return *this; }
00076   SELF& push(const Point&p)       { push_back(p); return *this; }
00077 private:
00078   Seq<Point> m_vertices ;
00079 } ;
00080 
00081 TMPL SELF::point_set(void) : Shape() {}
00082 
00083 TMPL SELF::point_set(unsigned n) : Shape(), m_vertices(n) {}
00084 
00085 TMPL SELF::~point_set(void) {}
00086 
00087 TMPL void 
00088 SELF::push_back(const Point& p) {
00089   m_vertices.push_back(p) ;
00090 }
00091 
00092 TMPL void 
00093 SELF::pop(Point * vertex) {
00094   //    remove(m_vertices, vertex) ;
00095 }
00096 
00097 TMPL void SELF::clear(void) {
00098      m_vertices.resize(0) ;
00099 }
00100 //--------------------------------------------------------------------  
00101   template<class O, class V> struct viewer; struct axel;
00102 
00103 template<class W, class C, class V> Viewer&
00104 operator<<(Viewer& out, const SELF& ps) {
00105   using namespace shape;
00106   
00107   typedef typename SELF::Point Point;
00108   typedef typename SELF::PointConstIterator PointIterator;
00109   
00110   if(ps.nbv()>0) {
00111     out<<"<pointset size=\""<<ps.nbv()<<"\" color=\"rgb\">\n";
00112     for(PointIterator p= ps.begin();  p != ps.end(); p++) {
00113       use<point_def,V>::print_with_color(out, *p);
00114       out <<"\n";
00115     }
00116     out<<" </pointset>\n ";
00117   }
00118   return out;
00119 }
00120 //--------------------------------------------------------------------
00121 } ; // namespace shape
00122 } ; // namespace mmx
00123 //====================================================================
00124 # undef TMPL
00125 # undef TMPL1
00126 # undef Shape
00127 # undef SELF
00128 # undef Viewer
00129 # endif // shape_point_set_hpp