00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
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, int N=3, class V=default_env>
00017 # define TMPL template<class C, int N, class V>
00018 # define SELF point<C,N,with_idx<V> >
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
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,3,with_idx<double> > Vertex;
00042
00043 template<class SEQ, class VERTEX>
00044 static inline void point_insertor(SEQ& vertices, VERTEX *p) {
00045
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,N,with_idx<V> > : public point<C,N,V>
00057 {
00058 public:
00059 typedef C Scalar;
00060 typedef point<C,N,V> 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
00072
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 } ;
00130 } ;
00131
00132 # undef TMPL_DEF
00133 # undef TMPL
00134 # undef SELF
00135 # undef IDX
00136 # endif // shape_point_with_idx_hpp