00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __VERTEX_H__
00022 #define __VERTEX_H__
00023
00024 #include "vector3.h"
00025
00026
00027 namespace HE
00028 {
00029 class HalfEdge;
00030
00032 class Vertex
00033 {
00034 public:
00036 class edge_circulator;
00037 class const_edge_circulator;
00038 class edge_circulator
00039 {
00040 friend class const_edge_circulator;
00041 public:
00042 edge_circulator(const Vertex* v, HalfEdge* h) : _base(v), _here(h) {}
00043
00044 const Vertex* base() const { return _base; };
00045 HalfEdge* operator*() { return _here; }
00046 void operator++();
00047 void operator++(int) { ++(*this); }
00048 bool operator==(const edge_circulator& e) const { return _base==e._base && _here==e._here; }
00049 bool operator!=(const edge_circulator& e) const { return !(e == *this); }
00050 protected:
00051 const Vertex* _base;
00052 HalfEdge* _here;
00053 };
00054
00056 class const_edge_circulator
00057 {
00058 friend class edge_circulator;
00059 public:
00060 const_edge_circulator(const Vertex* v, const HalfEdge* h) : _base(v), _here(h) {}
00061 const_edge_circulator(const edge_circulator& ec) : _base(ec.base()), _here(ec._here) {}
00062
00063 const Vertex* base() const { return _base; };
00064 const HalfEdge* operator*() const { return _here; }
00065 void operator++();
00066 void operator++(int) { ++(*this); }
00067 bool operator==(const const_edge_circulator& e) const { return _base==e._base && _here==e._here; }
00068 bool operator!=(const const_edge_circulator& e) const { return !(e == *this); }
00069 protected:
00070 const Vertex* _base;
00071 const HalfEdge* _here;
00072 };
00073
00075 edge_circulator begin() { return edge_circulator(this, _edge); }
00077 const_edge_circulator begin() const { return const_edge_circulator(this, _edge); }
00078
00079 explicit Vertex(int i=-1) : _edge(0), _index(i) {}
00080 explicit Vertex(const Geometry::Vector3Df& pos, int i=-1) : _pos(pos), _edge(0), _index(i) {}
00081 explicit Vertex(const Geometry::Vector3Df& pos, HalfEdge* e, int i=-1) : _pos(pos), _edge(e), _index(i) {}
00082
00083
00084 void index(int i) { _index = i; }
00085 void position(const Geometry::Vector3Df& pos) { _pos = pos; }
00086 void edge(HalfEdge* e) { _edge = e; }
00087
00088
00089 int index() const { return _index; }
00090 const Geometry::Vector3Df& position() const { return _pos; }
00091 HalfEdge* edge() { return _edge; }
00092 const HalfEdge* edge() const { return _edge; }
00093
00094
00095 Geometry::Vector3Df normal() const;
00096 int valence() const;
00097 int degree() const { return valence(); }
00098 bool isBoundary() const;
00099
00100 bool operator==(const Vertex& v) const { return _index == v._index; }
00101
00102 HalfEdge* edgeTo(const Vertex* v) { return edgeTo(v->index()); }
00104 const HalfEdge* edgeTo(const Vertex* v) const { return edgeTo(v->index()); }
00105
00107 HalfEdge* edgeTo(int v);
00109 const HalfEdge* edgeTo(int v) const;
00110
00111 protected:
00112 Geometry::Vector3Df _pos;
00113 HalfEdge* _edge;
00114 int _index;
00115 };
00116
00118 std::ostream& operator<< (std::ostream& out, const Vertex& v);
00119 };
00120
00121 #endif // __VERTEX_H__