shape_doc 0.1
/Users/mourrain/Devel/mmx/shape/include/shape/vertex.hpp
Go to the documentation of this file.
00001 /*****************************************************************************
00002  * M a t h e m a g i x
00003  *****************************************************************************
00004  * vertex
00005  * 2008-03-21
00006  * Julien Wintz
00007  *****************************************************************************
00008  *               Copyright (C) 2006 INRIA Sophia-Antipolis
00009  *****************************************************************************
00010  * Comments :
00011  ****************************************************************************/
00012 
00013 # ifndef shape_vertex_hpp
00014 # define shape_vertex_hpp
00015 
00016 # include <shape/point.hpp>
00017 # define TMPL_DEF template<class C, class V=REF_OF(C), int N=3>
00018 # define TMPL  template<class C, class V, int N>
00019 # define TMPL1 template<class K>
00020 # define SELF  vertex<C,V,N>
00021 # undef Scalar
00022 # undef Point
00023 # define IDX -1
00024 //====================================================================
00025 namespace mmx {
00026 namespace shape {
00027   //====================================================================
00028 TMPL_DEF struct vertex;
00029 
00030 struct vertex_def {};
00031 
00032 TMPL
00033 class vertex : public point<C,V>
00034 {
00035 public:
00036   typedef C Scalar;
00037   typedef point<C,V> Point;
00038 
00039   vertex(void) ;
00040   vertex(Scalar x, Scalar y, Scalar z, int idx = IDX) ;
00041   vertex(const Point & p) ;
00042   vertex(const SELF& p) ;
00043   
00044   bool     operator == (const SELF & other) const ;
00045   bool     operator != (const SELF & other) const ;
00046   SELF & operator  = (const SELF & other) ;
00047 
00048   // Scalar   operator [] (const int & i) const ;
00049   //  Scalar & operator [] (const int & i) ;
00050 
00051   int index() const     {return m_idx;}
00052   int set_index(int i)  {m_idx=i;return m_idx;}
00053 
00054   int nface() const     {return m_nf;}
00055 private:
00056   int  m_idx ;
00057   int  m_nf ;
00058 };
00059 
00060 TMPL
00061 SELF::vertex(void) : Point(), m_idx(IDX), m_nf(-1)
00062 {
00063 }
00064 
00065 TMPL
00066 SELF::vertex(Scalar x, Scalar y, Scalar z, int idx) :Point(x,y,z), m_idx(IDX), m_nf(idx)
00067 {
00068 }
00069 
00070 TMPL
00071 SELF::vertex(const SELF & other) : Point(other), m_idx(other.index()),  m_nf(other.nface())
00072 {
00073 }
00074 
00075 TMPL
00076 SELF & SELF::operator = (const SELF & other) 
00077 {
00078   if(this == &other)
00079     return *this ;
00080   
00081   this->x() = other.x() ;
00082   this->y() = other.y() ;
00083   this->z() = other.z() ;
00084   
00085   return * this ;
00086 }
00087 
00088 TMPL bool 
00089 SELF::operator == (const SELF & other) const {
00090   return ((this->x() == other.x()) && (this->y() == other.y()) && (this->z() == other.z())) ;
00091 }
00092 
00093 TMPL bool 
00094 SELF::operator != (const SELF & other) const {
00095   return ((this->x() != other.x()) || (this->y() != other.y()) || (this->z() != other.z())) ;
00096 }
00097 
00098 // TMPL typename mmx_t<scalar_of,K>::type & 
00099 // SELF::operator [] (const int & i) {
00100 //   switch(i) {
00101 //   case 0:
00102 //     return this->x() ; 
00103 //     break ;
00104 //   case 1:
00105 //     return this->y() ;
00106 //      break ;
00107 //   case 2:
00108 //     return this->z() ;
00109 //     break ;
00110 //   default:
00111 //      break ;
00112 //   }
00113   
00114 //   return *(new Scalar(0)) ;
00115 // }
00116 
00117 // TMPL typename SELF::Scalar
00118 // SELF::operator [] (const int & i) const {
00119 //   switch(i) {
00120 //   case 0:
00121 //     return this->x() ; 
00122 //     break ;
00123 //   case 1:
00124 //     return this->y() ;
00125 //      break ;
00126 //   case 2:
00127 //     return this->z() ;
00128 //     break ;
00129 //     default:
00130 //       break ;
00131 //   }
00132   
00133 //   return (Scalar)0 ;
00134 // }
00135 
00136 TMPL inline typename SELF::Scalar read (const SELF& v, unsigned i) { return v[i]; }
00137 
00138 //====================================================================
00139 template<class V> struct use<vertex_def,V> 
00140   : public use<shape_def,V>
00141 {
00142   typedef vertex<double> Vertex;
00143   typedef vertex<double> Point;
00144   
00145   static inline void point_insertor(Seq<Vertex*>& vertices, Vertex *p) {
00146     //    std::cout<<p->x()<<" "<<p->y()<<" "<<p->z()<<" "<<p->index()<< " ";
00147     if(p->index()<0) {
00148       p->set_index(vertices.size());
00149       vertices << p; 
00150     }
00151     //      std::cout<<p->index()<<std::endl;
00152   }
00153 };
00154 
00155 //====================================================================
00156 } ; // namespace shape
00157   //--------------------------------------------------------------------
00158 
00159 template<class OSTREAM, class K> OSTREAM&
00160 operator<<(OSTREAM& os, const shape::vertex<K>& p) {
00161   os <<p.x()<<" "<<p.y()<<" "<<p.z();
00162   return os;
00163 }
00164   //====================================================================
00165 } ; // namespace mmx
00166 //====================================================================
00167 # undef TMPL_DEF
00168 # undef TMPL
00169 # undef TMPL1
00170 # undef SELF
00171 # undef IDX
00172 # endif // shape_vertex_hpp