Subversion Repositories gelsvn

Rev

Rev 512 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
511 s042372 1
/*
2
* Written by Christian Thode Larsen 2009-2010
3
* Contact: thode2d@gmail.com
4
* Based on original work by J. Andreas Baerentzen
5
* Inspired by OpenMesh (www.openmesh.org)
6
*/
7
 
8
#ifndef __HMESH_CONNECTIVITY_KERNEL_H__
9
#define __HMESH_CONNECTIVITY_KERNEL_H__
10
 
11
#include <vector>
12
#include "ItemVector.h"
13
#include "Items.h"
14
 
15
namespace HMesh
16
{
17
	class ConnectivityKernel
18
	{
19
	public:
20
		VertexID add_vertex();
21
		FaceID add_face();
22
		HalfEdgeID add_halfedge();
23
 
24
		void remove_vertex(VertexID id);
25
        void remove_face(FaceID id);
26
        void remove_halfedge(HalfEdgeID id);
27
 
28
		void resize_vertices(IndexType size);
29
		void resize_faces(IndexType size);
30
		void resize_halfedges(IndexType size);
31
 
32
		HalfEdgeID next(HalfEdgeID id) const;
33
		HalfEdgeID prev(HalfEdgeID id) const;
34
		HalfEdgeID opp(HalfEdgeID id) const;
35
		HalfEdgeID out(VertexID id) const;
36
		HalfEdgeID last(FaceID id) const;
37
		VertexID vert(HalfEdgeID id) const;
38
		FaceID face(HalfEdgeID id) const;
39
 
40
		void set_next(HalfEdgeID id, HalfEdgeID next);
41
		void set_prev(HalfEdgeID id, HalfEdgeID prev);
42
		void set_opp(HalfEdgeID id, HalfEdgeID opp);
43
		void set_out(VertexID id, HalfEdgeID out);
44
		void set_last(FaceID id, HalfEdgeID last);
45
		void set_vert(HalfEdgeID id, VertexID vert);
46
		void set_face(HalfEdgeID id, FaceID face);
47
 
48
		IndexType no_vertices(bool active = true) const;
49
		IndexType no_faces(bool active = true) const;
50
		IndexType no_halfedges(bool active = true) const;
51
 
52
		bool in_use(VertexID id) const;
53
		bool in_use(FaceID id) const;
54
		bool in_use(HalfEdgeID id) const;
55
 
56
		VertexID vertices_next(VertexID id, bool skip = true) const;
57
		HalfEdgeID halfedges_next(HalfEdgeID id, bool skip = true) const;
58
		FaceID faces_next(FaceID id, bool skip = true) const;
59
 
60
		VertexID vertices_prev(VertexID id, bool skip = true) const;
61
		HalfEdgeID halfedges_prev(HalfEdgeID id, bool skip = true) const;
62
		FaceID faces_prev(FaceID id, bool skip = true) const;
63
 
64
		VertexID vertices_begin(bool skip = true) const;
65
        HalfEdgeID halfedges_begin(bool skip = true) const;
66
        FaceID faces_begin(bool skip = true) const;
67
 
68
        VertexID vertices_end() const;
69
        HalfEdgeID halfedges_end() const;
70
        FaceID faces_end() const;
71
 
72
		void cleanup();
73
		void clear();
74
 
75
	private:
76
		ItemVector<Vertex> vertices;
77
		ItemVector<Face> faces;
78
		ItemVector<HalfEdge> halfedges;
79
	};
80
 
81
	inline VertexID ConnectivityKernel::add_vertex()
82
	{
83
		vertices.add(Vertex());
84
		return VertexID(vertices.size());
85
	}
86
 
87
	inline FaceID ConnectivityKernel::add_face()
88
	{
89
		faces.add(Face());
90
		return FaceID(faces.size());
91
	}
92
 
93
	inline HalfEdgeID ConnectivityKernel::add_halfedge()
94
	{
95
		halfedges.add(HalfEdge());
96
		return HalfEdgeID(halfedges.size());
97
	}
98
 
99
 
100
 
101
	inline void ConnectivityKernel::remove_vertex(VertexID id)
102
	{ vertices.remove(id.idx()); }
103
 
104
	inline void ConnectivityKernel::remove_face(FaceID id)
105
	{ faces.remove(id.idx()); }
106
 
107
	inline void ConnectivityKernel::remove_halfedge(HalfEdgeID id)
108
	{ halfedges.remove(id.idx()); }
109
 
110
 
111
 
112
	inline void ConnectivityKernel::resize_vertices(IndexType size)
113
	{  vertices.resize(size); }
114
 
115
	inline void ConnectivityKernel::resize_faces(IndexType size)
116
	{  faces.resize(size); }
117
 
118
	inline void ConnectivityKernel::resize_halfedges(IndexType size)
119
	{  halfedges.resize(size); }
120
 
121
 
122
	inline HalfEdgeID ConnectivityKernel::next(HalfEdgeID id) const
123
	{ return HalfEdgeID(halfedges[id.idx()].next); }
124
 
125
	inline HalfEdgeID ConnectivityKernel::prev(HalfEdgeID id) const
126
	{ return HalfEdgeID(halfedges[id.idx()].prev); }
127
 
128
	inline HalfEdgeID ConnectivityKernel::opp(HalfEdgeID id) const
129
	{ return HalfEdgeID(halfedges[id.idx()].opp); }
130
 
131
	inline HalfEdgeID ConnectivityKernel::out(VertexID id) const
132
	{ return HalfEdgeID(vertices[id.idx()].out); }
133
 
134
	inline HalfEdgeID ConnectivityKernel::last(FaceID id) const
135
	{ return HalfEdgeID(faces[id.idx()].last); }
136
 
137
	inline VertexID ConnectivityKernel::vert(HalfEdgeID id) const
138
	{ return VertexID(halfedges[id.idx()].vert); }
139
 
140
	inline FaceID ConnectivityKernel::face(HalfEdgeID id) const
141
	{ return FaceID(halfedges[id.idx()].face); }
142
 
143
	inline void ConnectivityKernel::set_next(HalfEdgeID id, HalfEdgeID next)
144
	{ halfedges[id.idx()].next = next; }
145
 
146
	inline void ConnectivityKernel::set_prev(HalfEdgeID id, HalfEdgeID prev)
147
	{ halfedges[id.idx()].prev = prev; }
148
 
149
	inline void ConnectivityKernel::set_opp(HalfEdgeID id, HalfEdgeID opp)
150
	{halfedges[id.idx()].opp = opp; }
151
 
152
	inline void ConnectivityKernel::set_out(VertexID id, HalfEdgeID out)
153
	{ vertices[id.idx()].out = out; }
154
 
155
	inline void ConnectivityKernel::set_last(FaceID id, HalfEdgeID last)
156
	{ faces[id.idx()].last = last; }
157
 
158
	inline void ConnectivityKernel::set_vert(HalfEdgeID id, VertexID vert)
159
	{ halfedges[id.idx()].vert = vert; }
160
 
161
	inline void ConnectivityKernel::set_face(HalfEdgeID id, FaceID face)
162
	{ halfedges[id.idx()].face = face; }
163
 
164
	inline IndexType ConnectivityKernel::no_vertices(bool active) const
165
	{ return vertices.size(active); }
166
 
167
	inline IndexType ConnectivityKernel::no_faces(bool active) const
168
	{ return faces.size(active); }
169
 
170
	inline IndexType ConnectivityKernel::no_halfedges(bool active) const
171
	{ return halfedges.size(active); }
172
 
173
	inline bool ConnectivityKernel::in_use(VertexID id) const
174
	{ return vertices.in_use(id.idx()); }
175
 
176
	inline bool ConnectivityKernel::in_use(FaceID id) const
177
	{ return faces.in_use(id.idx()); }
178
 
179
	inline bool ConnectivityKernel::in_use(HalfEdgeID id) const
180
	{ return halfedges.in_use(id.idx()); }
181
 
182
	inline VertexID ConnectivityKernel::vertices_next(VertexID id, bool skip) const
183
	{ return vertices.index_next(id.idx(), skip); }
184
 
185
	inline HalfEdgeID ConnectivityKernel::halfedges_next(HalfEdgeID id, bool skip) const
186
	{ return halfedges.index_next(id.idx(), skip); }
187
 
188
	inline FaceID ConnectivityKernel::faces_next(FaceID id, bool skip) const
189
	{ return faces.index_next(id.idx(), skip); }
190
 
191
	inline VertexID ConnectivityKernel::vertices_prev(VertexID id, bool skip) const
192
	{ return vertices.index_prev(id.idx(), skip); }
193
 
194
	inline HalfEdgeID ConnectivityKernel::halfedges_prev(HalfEdgeID id, bool skip) const
195
	{ return halfedges.index_prev(id.idx(), skip); }
196
 
197
	inline FaceID ConnectivityKernel::faces_prev(FaceID id, bool skip) const
198
	{ return faces.index_prev(id.idx(), skip); }
199
 
200
	inline VertexID ConnectivityKernel::vertices_begin(bool skip) const
201
	{ return vertices.index_begin(skip); }
202
 
203
    inline HalfEdgeID ConnectivityKernel::halfedges_begin(bool skip) const
204
	{ return halfedges.index_begin(skip); }
205
 
206
    inline FaceID ConnectivityKernel::faces_begin(bool skip) const
207
	{ return faces.index_begin(skip); }
208
 
209
    inline VertexID ConnectivityKernel::vertices_end() const
210
	{ return vertices.index_end(); }
211
 
212
    inline HalfEdgeID ConnectivityKernel::halfedges_end() const
213
	{ return halfedges.index_end(); }
214
 
215
    inline FaceID ConnectivityKernel::faces_end() const
216
	{ return faces.index_end(); }
217
 
218
	inline void ConnectivityKernel::clear()
219
	{
220
		vertices.clear();
221
		faces.clear();
222
		halfedges.clear();
223
	}
224
 
225
	inline void ConnectivityKernel::cleanup()
226
	{
227
		vertices.cleanup();
228
		faces.cleanup();
229
		halfedges.cleanup();
230
	}
231
}
232
 
233
#endif