Subversion Repositories gelsvn

Rev

Rev 578 | Rev 588 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 578 Rev 586
Line 17... Line 17...
17
#include "ItemVector.h"
17
#include "ItemVector.h"
18
#include "ItemID.h"
18
#include "ItemID.h"
19
 
19
 
20
namespace HMesh
20
namespace HMesh
21
{
21
{
22
    typedef std::map<VertexID, VertexID> VertexIDRemap;
22
    struct Vertex;
23
    typedef std::map<FaceID, FaceID> FaceIDRemap;
23
    struct Face;
24
    typedef std::map<HalfEdgeID, HalfEdgeID> HalfEdgeIDRemap;
-
 
25
 
-
 
26
    struct IDRemap
24
    struct HalfEdge;
27
    {
25
    
28
        VertexIDRemap vmap;
26
    typedef ItemVector<Vertex>::IDType VertexID;
29
        FaceIDRemap fmap;
27
    typedef ItemVector<Face>::IDType FaceID;
30
        HalfEdgeIDRemap hmap;
28
    typedef ItemVector<HalfEdge>::IDType HalfEdgeID;
31
    };
-
 
32
 
29
 
-
 
30
    /// The vertex struct. This contains just a single outgoing halfedge.
33
    struct Vertex
31
    struct Vertex
34
    { 
32
    { 
35
        HalfEdgeID out; 
33
        HalfEdgeID out; 
36
    };
34
    };
37
 
35
 
-
 
36
    /// The face struct. Contains a single halfedge
38
    struct Face
37
    struct Face
39
    { 
38
    { 
40
        HalfEdgeID last; 
39
        HalfEdgeID last; 
41
    };
40
    };
42
 
41
 
-
 
42
    /// The halfedge struct. Contains IDs of next, previous, and opposite edges as well as incident face and vertex.
43
    struct HalfEdge
43
    struct HalfEdge
44
    {
44
    {
45
        HalfEdgeID next;
45
        HalfEdgeID next;
46
        HalfEdgeID prev;
46
        HalfEdgeID prev;
47
        HalfEdgeID opp;
47
        HalfEdgeID opp;
48
        VertexID vert;
48
        VertexID vert;
49
        FaceID face;
49
        FaceID face;
50
    };
50
    };
-
 
51
    
-
 
52
    static const VertexID InvalidVertexID;
-
 
53
    static const FaceID InvalidFaceID;
-
 
54
    static const HalfEdgeID InvalidHalfEdgeID;
-
 
55
    
-
 
56
    typedef std::map<VertexID, VertexID> VertexIDRemap;
-
 
57
    typedef std::map<FaceID, FaceID> FaceIDRemap;
-
 
58
    typedef std::map<HalfEdgeID, HalfEdgeID> HalfEdgeIDRemap;
-
 
59
  
-
 
60
    /// The IDRemap struct is just used for garbage collection.
-
 
61
    struct IDRemap
-
 
62
    {
-
 
63
        VertexIDRemap vmap;
-
 
64
        FaceIDRemap fmap;
-
 
65
        HalfEdgeIDRemap hmap;
-
 
66
    };
51
 
67
 
-
 
68
    /** The connectivity kernel is basically an aggregate of ItemVectors for vertices, faces, and halfedges.
-
 
69
     This class contains no geometry information - only information about connectivitiy. Arguably it abstracts
-
 
70
     away the implementation from the Manifold class making it possible, for instance, to use a different kernel. */
52
    class ConnectivityKernel
71
    class ConnectivityKernel
53
    {
72
    {
54
    public:
73
    public:
55
        /// add vertex to kernel
74
        /// add vertex to kernel
56
        VertexID add_vertex();
75
        VertexID add_vertex();
Line 102... Line 121...
102
        void set_vert(HalfEdgeID current, VertexID vert);
121
        void set_vert(HalfEdgeID current, VertexID vert);
103
        /// set the ID of face owning current halfedge to face
122
        /// set the ID of face owning current halfedge to face
104
        void set_face(HalfEdgeID current, FaceID face);
123
        void set_face(HalfEdgeID current, FaceID face);
105
 
124
 
106
        /// number of active vertices in kernel
125
        /// number of active vertices in kernel
107
        size_t active_vertices() const;
126
        size_t no_vertices() const;
108
        /// number of active faces in kernel
127
        /// number of active faces in kernel
109
        size_t active_faces() const;
128
        size_t no_faces() const;
110
        /// number of active halfedges in kernel
129
        /// number of active halfedges in kernel
111
        size_t active_halfedges() const;
130
        size_t no_halfedges() const;
112
 
131
 
113
        /// number of total vertices in kernel
132
        /// number of total vertices in kernel
114
        size_t total_vertices() const;
133
        size_t allocated_vertices() const;
115
        /// number of total faces in kernel
134
        /// number of total faces in kernel
116
        size_t total_faces() const;
135
        size_t allocated_faces() const;
117
        /// number of total halfedges in kernel
136
        /// number of total halfedges in kernel
118
        size_t total_halfedges() const;
137
        size_t allocated_halfedges() const;
119
 
138
 
120
        /// check if ID of vertex is in use
139
        /// check if ID of vertex is in use
121
        bool in_use(VertexID id) const;
140
        bool in_use(VertexID id) const;
122
        /// check if ID of face is in use
141
        /// check if ID of face is in use
123
        bool in_use(FaceID id) const;
142
        bool in_use(FaceID id) const;
Line 163... Line 182...
163
        ItemVector<Face> faces;
182
        ItemVector<Face> faces;
164
        ItemVector<HalfEdge> halfedges;
183
        ItemVector<HalfEdge> halfedges;
165
    };
184
    };
166
 
185
 
167
    inline VertexID ConnectivityKernel::add_vertex()
186
    inline VertexID ConnectivityKernel::add_vertex()
168
    {
-
 
169
        vertices.add(Vertex());
187
    { return vertices.add(Vertex()); }
170
        return VertexID(vertices.total_size() - 1);
-
 
171
    }
-
 
172
 
188
 
173
    inline FaceID ConnectivityKernel::add_face()
189
    inline FaceID ConnectivityKernel::add_face()
174
    {
-
 
175
        faces.add(Face());
190
    { return faces.add(Face()); }
176
        return FaceID(faces.total_size() - 1);
-
 
177
    }
-
 
178
 
191
 
179
    inline HalfEdgeID ConnectivityKernel::add_halfedge()
192
    inline HalfEdgeID ConnectivityKernel::add_halfedge()
180
    {
-
 
181
        halfedges.add(HalfEdge());
193
    { return halfedges.add(HalfEdge()); }
182
        return HalfEdgeID(halfedges.total_size() - 1);
-
 
183
    }
-
 
184
 
-
 
185
 
-
 
186
 
-
 
187
 
194
 
188
    inline void ConnectivityKernel::remove_vertex(VertexID id)
195
    inline void ConnectivityKernel::remove_vertex(VertexID id)
189
    { vertices.remove(id.index); }
196
    { vertices.remove(id); }
190
 
197
 
191
    inline void ConnectivityKernel::remove_face(FaceID id)
198
    inline void ConnectivityKernel::remove_face(FaceID id)
192
    { faces.remove(id.index); }
199
    { faces.remove(id); }
193
 
200
 
194
    inline void ConnectivityKernel::remove_halfedge(HalfEdgeID id)
201
    inline void ConnectivityKernel::remove_halfedge(HalfEdgeID id)
195
    { halfedges.remove(id.index); }
202
    { halfedges.remove(id); }
196
 
-
 
197
 
-
 
198
 
203
 
199
    inline void ConnectivityKernel::resize_vertices(size_t size)
204
    inline void ConnectivityKernel::resize_vertices(size_t size)
200
    {  vertices.resize(size); }
205
    {  vertices.resize(size); }
201
 
206
 
202
    inline void ConnectivityKernel::resize_faces(size_t size)
207
    inline void ConnectivityKernel::resize_faces(size_t size)
Line 205... Line 210...
205
    inline void ConnectivityKernel::resize_halfedges(size_t size)
210
    inline void ConnectivityKernel::resize_halfedges(size_t size)
206
    {  halfedges.resize(size); }
211
    {  halfedges.resize(size); }
207
 
212
 
208
 
213
 
209
    inline HalfEdgeID ConnectivityKernel::next(HalfEdgeID id) const
214
    inline HalfEdgeID ConnectivityKernel::next(HalfEdgeID id) const
210
    { return HalfEdgeID(halfedges[id.index].next); }
215
    { return halfedges[id].next; }
211
 
216
 
212
    inline HalfEdgeID ConnectivityKernel::prev(HalfEdgeID id) const
217
    inline HalfEdgeID ConnectivityKernel::prev(HalfEdgeID id) const
213
    { return HalfEdgeID(halfedges[id.index].prev); }
218
    { return halfedges[id].prev; }
214
 
219
 
215
    inline HalfEdgeID ConnectivityKernel::opp(HalfEdgeID id) const
220
    inline HalfEdgeID ConnectivityKernel::opp(HalfEdgeID id) const
216
    { return HalfEdgeID(halfedges[id.index].opp); }
221
    { return halfedges[id].opp; }
217
 
222
 
218
    inline HalfEdgeID ConnectivityKernel::out(VertexID id) const
223
    inline HalfEdgeID ConnectivityKernel::out(VertexID id) const
219
    { return HalfEdgeID(vertices[id.index].out); }
224
    { return vertices[id].out; }
220
 
225
 
221
    inline HalfEdgeID ConnectivityKernel::last(FaceID id) const
226
    inline HalfEdgeID ConnectivityKernel::last(FaceID id) const
222
    { return HalfEdgeID(faces[id.index].last); }
227
    { return faces[id].last; }
223
 
228
 
224
    inline VertexID ConnectivityKernel::vert(HalfEdgeID id) const
229
    inline VertexID ConnectivityKernel::vert(HalfEdgeID id) const
225
    { return VertexID(halfedges[id.index].vert); }
230
    { return halfedges[id].vert; }
226
 
231
 
227
    inline FaceID ConnectivityKernel::face(HalfEdgeID id) const
232
    inline FaceID ConnectivityKernel::face(HalfEdgeID id) const
228
    { return FaceID(halfedges[id.index].face); }
233
    { return halfedges[id].face; }
229
 
234
 
230
    inline void ConnectivityKernel::set_next(HalfEdgeID id, HalfEdgeID next)
235
    inline void ConnectivityKernel::set_next(HalfEdgeID id, HalfEdgeID next)
231
    { halfedges[id.index].next = next; }
236
    { halfedges[id].next = next; }
232
 
237
 
233
    inline void ConnectivityKernel::set_prev(HalfEdgeID id, HalfEdgeID prev)
238
    inline void ConnectivityKernel::set_prev(HalfEdgeID id, HalfEdgeID prev)
234
    { halfedges[id.index].prev = prev; }
239
    { halfedges[id].prev = prev; }
235
 
240
 
236
    inline void ConnectivityKernel::set_opp(HalfEdgeID id, HalfEdgeID opp)
241
    inline void ConnectivityKernel::set_opp(HalfEdgeID id, HalfEdgeID opp)
237
    {halfedges[id.index].opp = opp; }
242
    {halfedges[id].opp = opp; }
238
 
243
 
239
    inline void ConnectivityKernel::set_out(VertexID id, HalfEdgeID out)
244
    inline void ConnectivityKernel::set_out(VertexID id, HalfEdgeID out)
240
    { vertices[id.index].out = out; }
245
    { vertices[id].out = out; }
241
 
246
 
242
    inline void ConnectivityKernel::set_last(FaceID id, HalfEdgeID last)
247
    inline void ConnectivityKernel::set_last(FaceID id, HalfEdgeID last)
243
    { faces[id.index].last = last; }
248
    { faces[id].last = last; }
244
 
249
 
245
    inline void ConnectivityKernel::set_vert(HalfEdgeID id, VertexID vert)
250
    inline void ConnectivityKernel::set_vert(HalfEdgeID id, VertexID vert)
246
    { halfedges[id.index].vert = vert; }
251
    { halfedges[id].vert = vert; }
247
 
252
 
248
    inline void ConnectivityKernel::set_face(HalfEdgeID id, FaceID face)
253
    inline void ConnectivityKernel::set_face(HalfEdgeID id, FaceID face)
249
    { halfedges[id.index].face = face; }
254
    { halfedges[id].face = face; }
250
 
255
 
251
 
256
 
252
 
257
 
253
    inline size_t ConnectivityKernel::active_vertices() const
258
    inline size_t ConnectivityKernel::no_vertices() const
254
    { return vertices.active_size(); }
259
    { return vertices.size(); }
255
 
260
 
256
    inline size_t ConnectivityKernel::active_faces() const
261
    inline size_t ConnectivityKernel::no_faces() const
257
    { return faces.active_size(); }
262
    { return faces.size(); }
258
 
263
 
259
    inline size_t ConnectivityKernel::active_halfedges() const
264
    inline size_t ConnectivityKernel::no_halfedges() const
260
    { return halfedges.active_size(); }
265
    { return halfedges.size(); }
261
 
266
 
262
 
267
 
263
 
268
 
264
    inline size_t ConnectivityKernel::total_vertices() const
269
    inline size_t ConnectivityKernel::allocated_vertices() const
265
    { return vertices.total_size(); }
270
    { return vertices.allocated_size(); }
266
 
271
 
267
    inline size_t ConnectivityKernel::total_faces() const
272
    inline size_t ConnectivityKernel::allocated_faces() const
268
    { return faces.total_size(); }
273
    { return faces.allocated_size(); }
269
 
274
 
270
    inline size_t ConnectivityKernel::total_halfedges() const
275
    inline size_t ConnectivityKernel::allocated_halfedges() const
271
    { return halfedges.total_size(); }
276
    { return halfedges.allocated_size(); }
272
 
277
 
273
 
278
 
274
 
279
 
275
    inline bool ConnectivityKernel::in_use(VertexID id) const
280
    inline bool ConnectivityKernel::in_use(VertexID id) const
276
    { return vertices.in_use(id.index); }
281
    { return vertices.in_use(id); }
277
 
282
 
278
    inline bool ConnectivityKernel::in_use(FaceID id) const
283
    inline bool ConnectivityKernel::in_use(FaceID id) const
279
    { return faces.in_use(id.index); }
284
    { return faces.in_use(id); }
280
 
285
 
281
    inline bool ConnectivityKernel::in_use(HalfEdgeID id) const
286
    inline bool ConnectivityKernel::in_use(HalfEdgeID id) const
282
    { return halfedges.in_use(id.index); }
287
    { return halfedges.in_use(id); }
283
 
288
 
284
 
289
 
285
 
290
 
286
    inline VertexID ConnectivityKernel::vertices_next(VertexID id, bool skip) const
291
    inline VertexID ConnectivityKernel::vertices_next(VertexID id, bool skip) const
287
    { return vertices.index_next(id.index, skip); }
292
    { return vertices.index_next(id, skip); }
288
 
293
 
289
    inline HalfEdgeID ConnectivityKernel::halfedges_next(HalfEdgeID id, bool skip) const
294
    inline HalfEdgeID ConnectivityKernel::halfedges_next(HalfEdgeID id, bool skip) const
290
    { return halfedges.index_next(id.index, skip); }
295
    { return halfedges.index_next(id, skip); }
291
 
296
 
292
    inline FaceID ConnectivityKernel::faces_next(FaceID id, bool skip) const
297
    inline FaceID ConnectivityKernel::faces_next(FaceID id, bool skip) const
293
    { return faces.index_next(id.index, skip); }
298
    { return faces.index_next(id, skip); }
294
 
299
 
295
    inline VertexID ConnectivityKernel::vertices_prev(VertexID id, bool skip) const
300
    inline VertexID ConnectivityKernel::vertices_prev(VertexID id, bool skip) const
296
    { return vertices.index_prev(id.index, skip); }
301
    { return vertices.index_prev(id, skip); }
297
 
302
 
298
    inline HalfEdgeID ConnectivityKernel::halfedges_prev(HalfEdgeID id, bool skip) const
303
    inline HalfEdgeID ConnectivityKernel::halfedges_prev(HalfEdgeID id, bool skip) const
299
    { return halfedges.index_prev(id.index, skip); }
304
    { return halfedges.index_prev(id, skip); }
300
 
305
 
301
    inline FaceID ConnectivityKernel::faces_prev(FaceID id, bool skip) const
306
    inline FaceID ConnectivityKernel::faces_prev(FaceID id, bool skip) const
302
    { return faces.index_prev(id.index, skip); }
307
    { return faces.index_prev(id, skip); }
303
 
308
 
304
    inline VertexID ConnectivityKernel::vertices_begin(bool skip) const
309
    inline VertexID ConnectivityKernel::vertices_begin(bool skip) const
305
    { return vertices.index_begin(skip); }
310
    { return vertices.index_begin(skip); }
306
 
311
 
307
    inline HalfEdgeID ConnectivityKernel::halfedges_begin(bool skip) const
312
    inline HalfEdgeID ConnectivityKernel::halfedges_begin(bool skip) const