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