Subversion Repositories gelsvn

Rev

Rev 129 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 129 Rev 195
1
#ifndef __ITERS_H
1
#ifndef __ITERS_H
2
#define __ITERS_H
2
#define __ITERS_H
3
 
3
 
4
#include "CGLA/Vec3f.h"
-
 
5
#include <list>
-
 
6
 
4
 
-
 
5
#if (_MSC_VER >= 1400)
-
 
6
#ifdef _DEBUG
-
 
7
 
-
 
8
#if (_SECURE_SCL != 0)
-
 
9
#pragma message( "Warning : To use HMesh in debug mode _SECURE_SCL must be defined as 0." )
-
 
10
#endif
-
 
11
 
-
 
12
#if (_HAS_ITERATOR_DEBUGGING != 0)
-
 
13
#pragma message( "Warning : To use HMesh in debug mode _HAS_ITERATOR_DEBUGGING must be defined as 0." )
-
 
14
#endif
-
 
15
 
-
 
16
#endif
-
 
17
#endif
-
 
18
 
-
 
19
#include <list>
-
 
20
#include "CGLA/Vec3f.h"
7
 
21
 
8
namespace HMesh
22
namespace HMesh
9
{
23
{
10
		/* A nasty template trick:
24
		/* A nasty template trick:
11
 
25
 
12
		The halfedge data structure is based on pointers. Thus, for instance,
26
		The halfedge data structure is based on pointers. Thus, for instance,
13
		a halfedge contains pointers to several other halfedges, a face, and
27
		a halfedge contains pointers to several other halfedges, a face, and
14
		a vertex. However, the entities (faces, edges, vertices) are stored in
28
		a vertex. However, the entities (faces, edges, vertices) are stored in
15
		linked lists. This enables easy insertion and removal, but we would
29
		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 
30
		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
31
		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
32
		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
33
		using STL and what we need is really an iterator to the list element
20
		containing the halfedge.
34
		containing the halfedge.
21
 
35
 
22
		The solution is, of course, to store iterators instead of pointers, but
36
		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 
37
		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
38
		list of halfedges in the definition of the halfedge class. The solution
25
		is to let a template argument define the halfedge iterator type.
39
		is to let a template argument define the halfedge iterator type.
26
		 
40
		 
27
		Thus the Iters class instantiates HalfEdge_template with itself while it 
41
		Thus the Iters class instantiates HalfEdge_template with itself while it 
28
		also defines the required iterators etc. Strange but legal C++.
42
		also defines the required iterators etc. Strange but legal C++.
29
 
43
 
30
		This is the best solution I could come up with - since I really wanted 
44
		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 
45
		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. */
46
		used in CGAL and OpenMesh both of which provided inspiration. */
33
 
47
 
34
 
48
 
35
		/** Type used for the touch variables of halfedges, vertices, and faces.
49
		/** Type used for the touch variables of halfedges, vertices, and faces.
36
				The touch variables are used to contain various data such as counters,
50
				The touch variables are used to contain various data such as counters,
37
				indices, flags. In some cases it is useful to touch with the value
51
				indices, flags. In some cases it is useful to touch with the value
38
				of a pointer cast to an integer. However, this means that the 
52
				of a pointer cast to an integer. However, this means that the 
39
				integer size must be the same as the pointer size. Using "intptr_t"
53
				integer size must be the same as the pointer size. Using "intptr_t"
40
				ensures this. */
54
				ensures this. */
41
		typedef intptr_t TouchType;
55
		typedef intptr_t TouchType;
42
 
56
 
43
		/** \struct Vertex
57
		/** \struct Vertex
44
		 */
58
		 */
45
		template<class R>
59
		template<class R>
46
		struct Vertex_template
60
		struct Vertex_template
47
		{
61
		{
48
				typedef typename R::VertexIter VertexIter;
62
				typedef typename R::VertexIter VertexIter;
49
				typedef typename R::FaceIter FaceIter;
63
				typedef typename R::FaceIter FaceIter;
50
				typedef typename R::HalfEdgeIter HalfEdgeIter;
64
				typedef typename R::HalfEdgeIter HalfEdgeIter;
51
 
65
 
52
				/// Constructor, argument is vertex position
66
				/// Constructor, argument is vertex position
53
				Vertex_template(const CGLA::Vec3f&);
67
				Vertex_template(const CGLA::Vec3f&);
54
 
68
 
55
				/// Outgoing halfedge
69
				/// Outgoing halfedge
56
				HalfEdgeIter he;
70
				HalfEdgeIter he;
57
 
71
 
58
				/// Geometric vertex position
72
				/// Geometric vertex position
59
				CGLA::Vec3f pos;
73
				CGLA::Vec3f pos;
60
 
74
 
61
				/// General purpose integer. Normally used as index or flag.
75
				/// General purpose integer. Normally used as index or flag.
62
				TouchType touched;
76
				TouchType touched;
63
		};
77
		};
64
 
78
 
65
		template<class R>
79
		template<class R>
66
		struct HalfEdge_template
80
		struct HalfEdge_template
67
		{
81
		{
68
				typedef typename R::VertexIter VertexIter;
82
				typedef typename R::VertexIter VertexIter;
69
				typedef typename R::FaceIter FaceIter;
83
				typedef typename R::FaceIter FaceIter;
70
				typedef typename R::HalfEdgeIter HalfEdgeIter;
84
				typedef typename R::HalfEdgeIter HalfEdgeIter;
71
 
85
 
72
				/// Constructor
86
				/// Constructor
73
				HalfEdge_template();
87
				HalfEdge_template();
74
 
88
 
75
				/// Vertex pointed to by this halfedge.
89
				/// Vertex pointed to by this halfedge.
76
				VertexIter   vert;
90
				VertexIter   vert;
77
 
91
 
78
				/// Next halfedge in face loop.
92
				/// Next halfedge in face loop.
79
				HalfEdgeIter next;
93
				HalfEdgeIter next;
80
 
94
 
81
				/// Previous halfedge in face loop.
95
				/// Previous halfedge in face loop.
82
				HalfEdgeIter prev;
96
				HalfEdgeIter prev;
83
 
97
 
84
				/// Face owning this halfedge
98
				/// Face owning this halfedge
85
				FaceIter     face;
99
				FaceIter     face;
86
 
100
 
87
				/// Opposite halfedge
101
				/// Opposite halfedge
88
				HalfEdgeIter opp;
102
				HalfEdgeIter opp;
89
 
103
 
90
				/// General purpose integer. Normally used as index or flag.
104
				/// General purpose integer. Normally used as index or flag.
91
				TouchType touched;
105
				TouchType touched;
92
 
106
 
93
		};
107
		};
94
 
108
 
95
		template<class R>
109
		template<class R>
96
		struct Face_template
110
		struct Face_template
97
		{
111
		{
98
				typedef typename R::VertexIter VertexIter;
112
				typedef typename R::VertexIter VertexIter;
99
				typedef typename R::FaceIter FaceIter;
113
				typedef typename R::FaceIter FaceIter;
100
				typedef typename R::HalfEdgeIter HalfEdgeIter;
114
				typedef typename R::HalfEdgeIter HalfEdgeIter;
101
 
115
 
102
				/// Constructor
116
				/// Constructor
103
				Face_template();
117
				Face_template();
104
 
118
 
105
				/// Last is just some halfedge in the face loop.
119
				/// Last is just some halfedge in the face loop.
106
				HalfEdgeIter last;
120
				HalfEdgeIter last;
107
 
121
 
108
				/// General purpose integer. Normally used as index or flag.
122
				/// General purpose integer. Normally used as index or flag.
109
				TouchType touched;
123
				TouchType touched;
110
		};
124
		};
111
 
125
 
112
		struct Iters
126
		struct Iters
113
		{
127
		{
114
				typedef Vertex_template<Iters> V;
128
				typedef Vertex_template<Iters> V;
115
				typedef HalfEdge_template<Iters> HE;
129
				typedef HalfEdge_template<Iters> HE;
116
				typedef Face_template<Iters> F;
130
				typedef Face_template<Iters> F;
117
	
131
	
118
				typedef std::list<V> VertexList;
132
				typedef std::list<V> VertexList;
119
				typedef std::list<HE> HalfEdgeList;
133
				typedef std::list<HE> HalfEdgeList;
120
				typedef std::list<F> FaceList;
134
				typedef std::list<F> FaceList;
121
 
135
 
122
				typedef VertexList::iterator VertexIter;
136
				typedef VertexList::iterator VertexIter;
123
				typedef HalfEdgeList::iterator HalfEdgeIter;
137
				typedef HalfEdgeList::iterator HalfEdgeIter;
124
				typedef FaceList::iterator FaceIter;
138
				typedef FaceList::iterator FaceIter;
125
		};
139
		};
126
 
140
 
127
 
141
 
128
	typedef Face_template<Iters> Face;
142
	typedef Face_template<Iters> Face;
129
	typedef HalfEdge_template<Iters> HalfEdge;
143
	typedef HalfEdge_template<Iters> HalfEdge;
130
	typedef Vertex_template<Iters> Vertex;
144
	typedef Vertex_template<Iters> Vertex;
131
 
145
 
132
	typedef Iters::FaceList FaceList;
146
	typedef Iters::FaceList FaceList;
133
	typedef Iters::HalfEdgeList HalfEdgeList;
147
	typedef Iters::HalfEdgeList HalfEdgeList;
134
	typedef Iters::VertexList VertexList;
148
	typedef Iters::VertexList VertexList;
135
 
149
 
136
	typedef Iters::FaceIter FaceIter;
150
	typedef Iters::FaceIter FaceIter;
137
	typedef Iters::HalfEdgeIter HalfEdgeIter;
151
	typedef Iters::HalfEdgeIter HalfEdgeIter;
138
	typedef Iters::VertexIter VertexIter;
152
	typedef Iters::VertexIter VertexIter;
139
 
153
 
140
	inline FaceIter get_null_face_iter()
154
	inline FaceIter get_null_face_iter()
141
			{
155
			{
142
					static FaceList l;
156
					static FaceList l;
143
					return l.end();
157
					return l.end();
144
			}
158
			}
145
 
159
 
146
	inline VertexIter get_null_vertex_iter()
160
	inline VertexIter get_null_vertex_iter()
147
			{
161
			{
148
					static VertexList l;
162
					static VertexList l;
149
					return l.end();
163
					return l.end();
150
			}
164
			}
151
 
165
 
152
 
166
 
153
	inline HalfEdgeIter get_null_halfedge_iter()
167
	inline HalfEdgeIter get_null_halfedge_iter()
154
			{
168
			{
155
					static HalfEdgeList l;
169
					static HalfEdgeList l;
156
					return l.end();
170
					return l.end();
157
			}
171
			}
158
 
172
 
159
 
173
 
160
#define NULL_FACE_ITER HMesh::get_null_face_iter() 
174
#define NULL_FACE_ITER HMesh::get_null_face_iter() 
161
#define NULL_HALFEDGE_ITER HMesh::get_null_halfedge_iter() 
175
#define NULL_HALFEDGE_ITER HMesh::get_null_halfedge_iter() 
162
#define NULL_VERTEX_ITER HMesh::get_null_vertex_iter()
176
#define NULL_VERTEX_ITER HMesh::get_null_vertex_iter()
163
 
177
 
164
 
178
 
165
}
179
}
166
#endif
180
#endif
167
 
181