shape_doc 0.1
/Users/mourrain/Devel/mmx/shape/include/shape/point_with_idx.hpp
Go to the documentation of this file.
00001 /*****************************************************************************
00002  * M a t h e m a g i x
00003  *****************************************************************************
00004  * vertex
00005  * 2010-08-18
00006  * Bernard Mourrain & Julien Wintz
00007  *****************************************************************************
00008  *               Copyright (C) 2006 INRIA Sophia-Antipolis
00009  *****************************************************************************
00010  * Comments :
00011  ****************************************************************************/
00012 # ifndef shape_point_with_idx_hpp
00013 # define shape_point_with_idx_hpp
00014 
00015 # include <shape/point.hpp>
00016 # define TMPL_DEF template<class C, class V=default_env, int N=3>
00017 # define TMPL  template<class C, class V, int N>
00018 # define SELF point<C,with_idx<V>,N>
00019 # undef Scalar
00020 # undef Point
00021 # define IDX -1
00022 /*********************************************************************/
00023 namespace mmx {
00024   namespace shape {
00025 //====================================================================
00026 template<class K> struct with_idx: public K {
00027   //  typedef typename use<point_with_idx_def,K>::Vertex Point;
00028 };
00029 template<class FF, class K> struct use<FF,with_idx<K> > 
00030   : public use<FF,K> {};
00031 
00032   template<class V> struct use<ref_def,with_idx<V> > {
00033     typedef with_idx<REF_OF(V)> Ref;
00034 };
00035 //--------------------------------------------------------------------
00036 struct point_with_idx_def {};
00037 
00038 template<> struct use<point_with_idx_def>
00039    : public use<point_def> {
00040 
00041   typedef point<double,with_idx<double> > Vertex;
00042 
00043   template<class SEQ, class VERTEX>
00044   static inline void point_insertor(SEQ& vertices, VERTEX *p) {
00045     //   std::cout<<p->x()<<" "<<p->y()<<" "<<p->z()<<" "<<p->index()<< " ";
00046     if(p->index()<0) {
00047       p->set_index(vertices.size());
00048       vertices << p; 
00049     }
00050     std::cout<<p->index()<<std::endl;
00051   }
00052 
00053 };
00054 //--------------------------------------------------------------------
00055 TMPL
00056 class point<C,with_idx<V>,N> : public point<C,V,N>
00057 {
00058 public:
00059   typedef C Scalar;
00060   typedef point<C,V,N> Point;
00061 
00062   point(void) ;
00063   point(Scalar x, Scalar y, Scalar z, int idx = IDX) ;
00064   point(const Point & p) ;
00065   point(const SELF& p) ;
00066   
00067   bool     operator == (const SELF & other) const ;
00068   bool     operator != (const SELF & other) const ;
00069   SELF & operator  = (const SELF & other) ;
00070 
00071   // Scalar   operator [] (const int & i) const ;
00072   //  Scalar & operator [] (const int & i) ;
00073 
00074   int index() const     {return m_idx;}
00075   int set_index(int i)  {m_idx=i;return m_idx;}
00076 
00077   int nface() const     {return m_nf;}
00078 private:
00079   int  m_idx ;
00080   int  m_nf ;
00081 };
00082 
00083 TMPL
00084 SELF::point(void) : Point(), m_idx(IDX), m_nf(IDX)
00085 {
00086 }
00087 
00088 TMPL
00089 SELF::point(Scalar x, Scalar y, Scalar z, int idx) :Point(x,y,z), m_idx(IDX), m_nf(idx)
00090 {
00091 }
00092 
00093 TMPL
00094 SELF::point(const Point& p) :Point(p), m_idx(IDX), m_nf(p.n_face())
00095 {
00096 }
00097 
00098 TMPL
00099 SELF::point(const SELF & other) : Point(other), m_idx(other.index()),  m_nf(other.nface())
00100 {
00101 }
00102 
00103 TMPL
00104 SELF & SELF::operator = (const SELF & other) 
00105 {
00106   if(this == &other)
00107     return *this ;
00108   
00109   this->x() = other.x() ;
00110   this->y() = other.y() ;
00111   this->z() = other.z() ;
00112   
00113   return * this ;
00114 }
00115 
00116 TMPL bool 
00117 SELF::operator == (const SELF & other) const {
00118   return ((this->x() == other.x()) && (this->y() == other.y()) && (this->z() == other.z())) ;
00119 }
00120 
00121 TMPL bool 
00122 SELF::operator != (const SELF & other) const {
00123   return ((this->x() != other.x()) || (this->y() != other.y()) || (this->z() != other.z())) ;
00124 }
00125 
00126 TMPL inline typename SELF::Scalar read (const SELF& v, unsigned i) { return v[i]; }
00127 
00128 //====================================================================
00129   } ; // namespace shape
00130 } ; // namespace mmx
00131 /*********************************************************************/
00132 # undef TMPL_DEF
00133 # undef TMPL
00134 # undef SELF
00135 # undef IDX
00136 # endif // shape_point_with_idx_hpp