39 |
bj |
1 |
#ifndef __ITERS_H
|
|
|
2 |
#define __ITERS_H
|
|
|
3 |
|
|
|
4 |
#include "CGLA/Vec3f.h"
|
|
|
5 |
#include <list>
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
namespace HMesh
|
|
|
9 |
{
|
|
|
10 |
/* A nasty template trick:
|
|
|
11 |
|
|
|
12 |
The halfedge data structure is based on pointers. Thus, for instance,
|
|
|
13 |
a halfedge contains pointers to several other halfedges, a face, and
|
|
|
14 |
a vertex. However, the entities (faces, edges, vertices) are stored in
|
|
|
15 |
linked lists. This enables easy insertion and removal, but we would
|
|
|
16 |
like to be able to take the halfedge pointer stored in, say, a
|
|
|
17 |
halfedge and find the position in the linked list in order to remove the
|
|
|
18 |
halfedge from the list. This is not possible since the list is implemented
|
|
|
19 |
using STL and what we need is really an iterator to the list element
|
|
|
20 |
containing the halfedge.
|
|
|
21 |
|
|
|
22 |
The solution is, of course, to store iterators instead of pointers, but
|
|
|
23 |
that solution is problematic because we cannot define an iterator to a
|
|
|
24 |
list of halfedges in the definition of the halfedge class. The solution
|
|
|
25 |
is to let a template argument define the halfedge iterator type.
|
|
|
26 |
|
|
|
27 |
Thus the Iters class instantiates HalfEdge_template with itself while it
|
|
|
28 |
also defines the required iterators etc. Strange but legal C++.
|
|
|
29 |
|
|
|
30 |
This is the best solution I could come up with - since I really wanted
|
|
|
31 |
to use STL to store the elements. The solution is similar to what is
|
|
|
32 |
used in CGAL and OpenMesh both of which provided inspiration. */
|
|
|
33 |
|
|
|
34 |
template<class R>
|
|
|
35 |
struct Vertex_template
|
|
|
36 |
{
|
|
|
37 |
typedef typename R::VertexIter VertexIter;
|
|
|
38 |
typedef typename R::FaceIter FaceIter;
|
|
|
39 |
typedef typename R::HalfEdgeIter HalfEdgeIter;
|
|
|
40 |
|
|
|
41 |
HalfEdgeIter he;
|
|
|
42 |
CGLA::Vec3f pos;
|
|
|
43 |
|
|
|
44 |
Vertex_template(const CGLA::Vec3f&);
|
|
|
45 |
|
|
|
46 |
bool is_boundary();
|
|
|
47 |
void check_boundary_consistency();
|
|
|
48 |
|
|
|
49 |
const CGLA::Vec3f& get_pos() const {return pos;}
|
|
|
50 |
void set_pos(const CGLA::Vec3f& _pos) {pos=_pos;}
|
|
|
51 |
|
|
|
52 |
int touched;
|
|
|
53 |
};
|
|
|
54 |
|
|
|
55 |
template<class R>
|
|
|
56 |
struct HalfEdge_template
|
|
|
57 |
{
|
|
|
58 |
typedef typename R::VertexIter VertexIter;
|
|
|
59 |
typedef typename R::FaceIter FaceIter;
|
|
|
60 |
typedef typename R::HalfEdgeIter HalfEdgeIter;
|
|
|
61 |
|
|
|
62 |
VertexIter vert;
|
|
|
63 |
HalfEdgeIter next;
|
|
|
64 |
HalfEdgeIter prev;
|
|
|
65 |
|
|
|
66 |
FaceIter face;
|
|
|
67 |
HalfEdgeIter opp;
|
|
|
68 |
|
|
|
69 |
bool is_boundary();
|
|
|
70 |
int touched;
|
|
|
71 |
|
|
|
72 |
HalfEdge_template();
|
|
|
73 |
};
|
|
|
74 |
|
|
|
75 |
template<class R>
|
|
|
76 |
struct Face_template
|
|
|
77 |
{
|
|
|
78 |
typedef typename R::VertexIter VertexIter;
|
|
|
79 |
typedef typename R::FaceIter FaceIter;
|
|
|
80 |
typedef typename R::HalfEdgeIter HalfEdgeIter;
|
|
|
81 |
|
|
|
82 |
HalfEdgeIter last;
|
|
|
83 |
int touched;
|
|
|
84 |
|
|
|
85 |
Face_template();
|
|
|
86 |
};
|
|
|
87 |
|
|
|
88 |
struct Iters
|
|
|
89 |
{
|
|
|
90 |
typedef Vertex_template<Iters> V;
|
|
|
91 |
typedef HalfEdge_template<Iters> HE;
|
|
|
92 |
typedef Face_template<Iters> F;
|
|
|
93 |
|
|
|
94 |
typedef std::list<V> VertexList;
|
|
|
95 |
typedef std::list<HE> HalfEdgeList;
|
|
|
96 |
typedef std::list<F> FaceList;
|
|
|
97 |
|
|
|
98 |
typedef VertexList::iterator VertexIter;
|
|
|
99 |
typedef HalfEdgeList::iterator HalfEdgeIter;
|
|
|
100 |
typedef FaceList::iterator FaceIter;
|
|
|
101 |
};
|
|
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
}
|
|
|
106 |
#endif
|