688 |
khor |
1 |
/* ----------------------------------------------------------------------- *
|
|
|
2 |
* This file is part of GEL, http://www.imm.dtu.dk/GEL
|
|
|
3 |
* Copyright (C) the authors and DTU Informatics
|
|
|
4 |
* For license and list of authors, see ../../doc/intro.pdf
|
|
|
5 |
* ----------------------------------------------------------------------- */
|
|
|
6 |
|
|
|
7 |
/**
|
|
|
8 |
* @file ConnectivityKernel.h
|
|
|
9 |
* @brief The data structure under HMesh.
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
#ifndef __HMESH_CONNECTIVITY_KERNEL_H__
|
|
|
13 |
#define __HMESH_CONNECTIVITY_KERNEL_H__
|
|
|
14 |
|
|
|
15 |
#include <vector>
|
|
|
16 |
#include <map>
|
|
|
17 |
#include "ItemVector.h"
|
|
|
18 |
#include "ItemID.h"
|
|
|
19 |
#include "Iterators.h"
|
|
|
20 |
|
|
|
21 |
namespace HMesh
|
|
|
22 |
{
|
|
|
23 |
struct Vertex;
|
|
|
24 |
struct Face;
|
|
|
25 |
struct HalfEdge;
|
|
|
26 |
|
|
|
27 |
typedef ItemVector<Vertex>::IDType VertexID;
|
|
|
28 |
typedef ItemVector<Face>::IDType FaceID;
|
|
|
29 |
typedef ItemVector<HalfEdge>::IDType HalfEdgeID;
|
|
|
30 |
|
|
|
31 |
/// The vertex struct. This contains just a single outgoing halfedge.
|
|
|
32 |
struct Vertex
|
|
|
33 |
{
|
|
|
34 |
HalfEdgeID out;
|
|
|
35 |
};
|
|
|
36 |
|
|
|
37 |
/// The face struct. Contains a single halfedge
|
|
|
38 |
struct Face
|
|
|
39 |
{
|
|
|
40 |
HalfEdgeID last;
|
|
|
41 |
};
|
|
|
42 |
|
|
|
43 |
/// The halfedge struct. Contains IDs of next, previous, and opposite edges as well as incident face and vertex.
|
|
|
44 |
struct HalfEdge
|
|
|
45 |
{
|
|
|
46 |
HalfEdgeID next;
|
|
|
47 |
HalfEdgeID prev;
|
|
|
48 |
HalfEdgeID opp;
|
|
|
49 |
VertexID vert;
|
|
|
50 |
FaceID face;
|
|
|
51 |
};
|
|
|
52 |
|
|
|
53 |
|
|
|
54 |
typedef IDIterator<Vertex> VertexIDIterator;
|
|
|
55 |
typedef IDIterator<Face> FaceIDIterator;
|
|
|
56 |
typedef IDIterator<HalfEdge> HalfEdgeIDIterator;
|
|
|
57 |
|
|
|
58 |
static const VertexID InvalidVertexID;
|
|
|
59 |
static const FaceID InvalidFaceID;
|
|
|
60 |
static const HalfEdgeID InvalidHalfEdgeID;
|
|
|
61 |
|
|
|
62 |
typedef std::map<VertexID, VertexID> VertexIDRemap;
|
|
|
63 |
typedef std::map<FaceID, FaceID> FaceIDRemap;
|
|
|
64 |
typedef std::map<HalfEdgeID, HalfEdgeID> HalfEdgeIDRemap;
|
|
|
65 |
|
|
|
66 |
/// The IDRemap struct is just used for garbage collection.
|
|
|
67 |
struct IDRemap
|
|
|
68 |
{
|
|
|
69 |
VertexIDRemap vmap;
|
|
|
70 |
FaceIDRemap fmap;
|
|
|
71 |
HalfEdgeIDRemap hmap;
|
|
|
72 |
};
|
|
|
73 |
|
|
|
74 |
/** The connectivity kernel is basically an aggregate of ItemVectors for vertices, faces, and halfedges.
|
|
|
75 |
This class contains no geometry information - only information about connectivitiy. Arguably it abstracts
|
|
|
76 |
away the implementation from the ConnectivityKernel class making it possible, for instance, to use a different kernel. */
|
|
|
77 |
class ConnectivityKernel
|
|
|
78 |
{
|
|
|
79 |
public:
|
|
|
80 |
|
|
|
81 |
/// number of active vertices in kernel
|
|
|
82 |
size_t no_vertices() const;
|
|
|
83 |
/// number of active faces in kernel
|
|
|
84 |
size_t no_faces() const;
|
|
|
85 |
/// number of active halfedges in kernel
|
|
|
86 |
size_t no_halfedges() const;
|
|
|
87 |
|
|
|
88 |
/// number of total vertices in kernel
|
|
|
89 |
size_t allocated_vertices() const;
|
|
|
90 |
/// number of total faces in kernel
|
|
|
91 |
size_t allocated_faces() const;
|
|
|
92 |
/// number of total halfedges in kernel
|
|
|
93 |
size_t allocated_halfedges() const;
|
|
|
94 |
|
|
|
95 |
/// check if ID of vertex is in use
|
|
|
96 |
bool in_use(VertexID id) const;
|
|
|
97 |
/// check if ID of face is in use
|
|
|
98 |
bool in_use(FaceID id) const;
|
|
|
99 |
/// check if ID of halfedge is in use
|
|
|
100 |
bool in_use(HalfEdgeID id) const;
|
|
|
101 |
|
|
|
102 |
/// Iterator to first VertexID, optional argument defines if unused items should be skipped
|
|
|
103 |
VertexIDIterator vertices_begin(bool skip = true) const;
|
|
|
104 |
/// Iterator to first FaceID, optional argument defines if unused items should be skipped
|
|
|
105 |
FaceIDIterator faces_begin(bool skip = true) const;
|
|
|
106 |
/// Iterator to first HalfEdgeID, optional argument defines if unused items should be skipped
|
|
|
107 |
HalfEdgeIDIterator halfedges_begin(bool skip = true) const;
|
|
|
108 |
|
|
|
109 |
/// Iterator to past the end VertexID
|
|
|
110 |
VertexIDIterator vertices_end() const;
|
|
|
111 |
/// Iterator topast the end FaceID
|
|
|
112 |
FaceIDIterator faces_end() const;
|
|
|
113 |
/// Iterator to past the end HalfEdgeID
|
|
|
114 |
HalfEdgeIDIterator halfedges_end() const;
|
|
|
115 |
|
|
|
116 |
/// get the ID of next halfedge, given by current halfedge ID
|
|
|
117 |
HalfEdgeID next(HalfEdgeID current) const;
|
|
|
118 |
/// get the ID of previous halfedge, given by current halfedge ID
|
|
|
119 |
HalfEdgeID prev(HalfEdgeID current) const;
|
|
|
120 |
/// get the ID of opposite halfedge, given by current halfedge ID
|
|
|
121 |
HalfEdgeID opp(HalfEdgeID current) const;
|
|
|
122 |
/// get the ID of outgoing halfedge, given by current vertex ID
|
|
|
123 |
HalfEdgeID out(VertexID current) const;
|
|
|
124 |
/// get the ID of last halfedge of current face ID
|
|
|
125 |
HalfEdgeID last(FaceID current) const;
|
|
|
126 |
/// get the ID of vertex pointed to by current halfedge ID
|
|
|
127 |
VertexID vert(HalfEdgeID id) const;
|
|
|
128 |
/// get the ID of face owning current halfedge ID
|
|
|
129 |
FaceID face(HalfEdgeID id) const;
|
|
|
130 |
|
|
|
131 |
/// add vertex to kernel
|
|
|
132 |
VertexID add_vertex();
|
|
|
133 |
/// add face to kernel
|
|
|
134 |
FaceID add_face();
|
|
|
135 |
/// add halfedge to kernel
|
|
|
136 |
HalfEdgeID add_halfedge();
|
|
|
137 |
|
|
|
138 |
/// remove vertex from kernel, given by ID
|
|
|
139 |
void remove_vertex(VertexID id);
|
|
|
140 |
/// remove face from kernel, given by ID
|
|
|
141 |
void remove_face(FaceID id);
|
|
|
142 |
/// remove halfedge from kernel, given by ID
|
|
|
143 |
void remove_halfedge(HalfEdgeID id);
|
|
|
144 |
|
|
|
145 |
/// set the ID of next halfedge of current halfedge to next
|
|
|
146 |
void set_next(HalfEdgeID current, HalfEdgeID next);
|
|
|
147 |
/// set the ID of previous halfedge of current halfedge to prev
|
|
|
148 |
void set_prev(HalfEdgeID current, HalfEdgeID prev);
|
|
|
149 |
/// set the ID of opposite halfedge of current halfedge to opp
|
|
|
150 |
void set_opp(HalfEdgeID current, HalfEdgeID opp);
|
|
|
151 |
/// set the ID of outgoing halfedge of current vertex to out
|
|
|
152 |
void set_out(VertexID current, HalfEdgeID out);
|
|
|
153 |
/// set the ID of last halfedge of current face to last
|
|
|
154 |
void set_last(FaceID current, HalfEdgeID last);
|
|
|
155 |
/// set the ID of vertex pointed to by current halfedge to vert
|
|
|
156 |
void set_vert(HalfEdgeID current, VertexID vert);
|
|
|
157 |
/// set the ID of face owning current halfedge to face
|
|
|
158 |
void set_face(HalfEdgeID current, FaceID face);
|
|
|
159 |
|
|
|
160 |
/// Clean up unused space in vectors - WARNING! Invalidates existing handles!
|
|
|
161 |
void cleanup(IDRemap& map);
|
|
|
162 |
|
|
|
163 |
/// clear the kernel
|
|
|
164 |
void clear();
|
|
|
165 |
|
|
|
166 |
private:
|
|
|
167 |
|
|
|
168 |
ItemVector<Vertex> vertices;
|
|
|
169 |
ItemVector<Face> faces;
|
|
|
170 |
ItemVector<HalfEdge> halfedges;
|
|
|
171 |
};
|
|
|
172 |
|
|
|
173 |
inline VertexID ConnectivityKernel::add_vertex()
|
|
|
174 |
{ return vertices.add(Vertex()); }
|
|
|
175 |
|
|
|
176 |
inline FaceID ConnectivityKernel::add_face()
|
|
|
177 |
{ return faces.add(Face()); }
|
|
|
178 |
|
|
|
179 |
inline HalfEdgeID ConnectivityKernel::add_halfedge()
|
|
|
180 |
{ return halfedges.add(HalfEdge()); }
|
|
|
181 |
|
|
|
182 |
inline void ConnectivityKernel::remove_vertex(VertexID id)
|
|
|
183 |
{ vertices.remove(id); }
|
|
|
184 |
|
|
|
185 |
inline void ConnectivityKernel::remove_face(FaceID id)
|
|
|
186 |
{ faces.remove(id); }
|
|
|
187 |
|
|
|
188 |
inline void ConnectivityKernel::remove_halfedge(HalfEdgeID id)
|
|
|
189 |
{ halfedges.remove(id); }
|
|
|
190 |
|
|
|
191 |
|
|
|
192 |
inline HalfEdgeID ConnectivityKernel::next(HalfEdgeID id) const
|
|
|
193 |
{ return halfedges[id].next; }
|
|
|
194 |
|
|
|
195 |
inline HalfEdgeID ConnectivityKernel::prev(HalfEdgeID id) const
|
|
|
196 |
{ return halfedges[id].prev; }
|
|
|
197 |
|
|
|
198 |
inline HalfEdgeID ConnectivityKernel::opp(HalfEdgeID id) const
|
|
|
199 |
{ return halfedges[id].opp; }
|
|
|
200 |
|
|
|
201 |
inline HalfEdgeID ConnectivityKernel::out(VertexID id) const
|
|
|
202 |
{ return vertices[id].out; }
|
|
|
203 |
|
|
|
204 |
inline HalfEdgeID ConnectivityKernel::last(FaceID id) const
|
|
|
205 |
{ return faces[id].last; }
|
|
|
206 |
|
|
|
207 |
inline VertexID ConnectivityKernel::vert(HalfEdgeID id) const
|
|
|
208 |
{ return halfedges[id].vert; }
|
|
|
209 |
|
|
|
210 |
inline FaceID ConnectivityKernel::face(HalfEdgeID id) const
|
|
|
211 |
{ return halfedges[id].face; }
|
|
|
212 |
|
|
|
213 |
inline void ConnectivityKernel::set_next(HalfEdgeID id, HalfEdgeID next)
|
|
|
214 |
{ halfedges[id].next = next; }
|
|
|
215 |
|
|
|
216 |
inline void ConnectivityKernel::set_prev(HalfEdgeID id, HalfEdgeID prev)
|
|
|
217 |
{ halfedges[id].prev = prev; }
|
|
|
218 |
|
|
|
219 |
inline void ConnectivityKernel::set_opp(HalfEdgeID id, HalfEdgeID opp)
|
|
|
220 |
{halfedges[id].opp = opp; }
|
|
|
221 |
|
|
|
222 |
inline void ConnectivityKernel::set_out(VertexID id, HalfEdgeID out)
|
|
|
223 |
{ vertices[id].out = out; }
|
|
|
224 |
|
|
|
225 |
inline void ConnectivityKernel::set_last(FaceID id, HalfEdgeID last)
|
|
|
226 |
{ faces[id].last = last; }
|
|
|
227 |
|
|
|
228 |
inline void ConnectivityKernel::set_vert(HalfEdgeID id, VertexID vert)
|
|
|
229 |
{ halfedges[id].vert = vert; }
|
|
|
230 |
|
|
|
231 |
inline void ConnectivityKernel::set_face(HalfEdgeID id, FaceID face)
|
|
|
232 |
{ halfedges[id].face = face; }
|
|
|
233 |
|
|
|
234 |
|
|
|
235 |
|
|
|
236 |
inline size_t ConnectivityKernel::no_vertices() const
|
|
|
237 |
{ return vertices.size(); }
|
|
|
238 |
|
|
|
239 |
inline size_t ConnectivityKernel::no_faces() const
|
|
|
240 |
{ return faces.size(); }
|
|
|
241 |
|
|
|
242 |
inline size_t ConnectivityKernel::no_halfedges() const
|
|
|
243 |
{ return halfedges.size(); }
|
|
|
244 |
|
|
|
245 |
|
|
|
246 |
|
|
|
247 |
inline size_t ConnectivityKernel::allocated_vertices() const
|
|
|
248 |
{ return vertices.allocated_size(); }
|
|
|
249 |
|
|
|
250 |
inline size_t ConnectivityKernel::allocated_faces() const
|
|
|
251 |
{ return faces.allocated_size(); }
|
|
|
252 |
|
|
|
253 |
inline size_t ConnectivityKernel::allocated_halfedges() const
|
|
|
254 |
{ return halfedges.allocated_size(); }
|
|
|
255 |
|
|
|
256 |
|
|
|
257 |
|
|
|
258 |
inline bool ConnectivityKernel::in_use(VertexID id) const
|
|
|
259 |
{ return vertices.in_use(id); }
|
|
|
260 |
|
|
|
261 |
inline bool ConnectivityKernel::in_use(FaceID id) const
|
|
|
262 |
{ return faces.in_use(id); }
|
|
|
263 |
|
|
|
264 |
inline bool ConnectivityKernel::in_use(HalfEdgeID id) const
|
|
|
265 |
{ return halfedges.in_use(id); }
|
|
|
266 |
|
|
|
267 |
inline VertexIDIterator ConnectivityKernel::vertices_begin(bool skip) const
|
|
|
268 |
{ return VertexIDIterator(vertices, vertices.index_begin(skip), skip); }
|
|
|
269 |
inline FaceIDIterator ConnectivityKernel::faces_begin(bool skip) const
|
|
|
270 |
{ return FaceIDIterator(faces, faces.index_begin(skip), skip); }
|
|
|
271 |
inline HalfEdgeIDIterator ConnectivityKernel:: halfedges_begin(bool skip) const
|
|
|
272 |
{ return HalfEdgeIDIterator(halfedges, halfedges.index_begin(skip), skip); }
|
|
|
273 |
|
|
|
274 |
|
|
|
275 |
inline VertexIDIterator ConnectivityKernel::vertices_end() const
|
|
|
276 |
{ return VertexIDIterator(vertices, vertices.index_end()); }
|
|
|
277 |
inline FaceIDIterator ConnectivityKernel::faces_end() const
|
|
|
278 |
{ return FaceIDIterator(faces, faces.index_end()); }
|
|
|
279 |
inline HalfEdgeIDIterator ConnectivityKernel::halfedges_end() const
|
|
|
280 |
{ return HalfEdgeIDIterator(halfedges, halfedges.index_end()); }
|
|
|
281 |
|
|
|
282 |
|
|
|
283 |
inline void ConnectivityKernel::clear()
|
|
|
284 |
{
|
|
|
285 |
vertices.clear();
|
|
|
286 |
faces.clear();
|
|
|
287 |
halfedges.clear();
|
|
|
288 |
}
|
|
|
289 |
}
|
|
|
290 |
|
|
|
291 |
#endif
|