Subversion Repositories gelsvn

Rev

Rev 520 | Rev 578 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
512 s042372 1
/* ----------------------------------------------------------------------- *
572 jab 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
512 s042372 5
 * ----------------------------------------------------------------------- */
511 s042372 6
 
7
#ifndef __HMESH_CONNECTIVITY_KERNEL_H__
8
#define __HMESH_CONNECTIVITY_KERNEL_H__
9
 
10
#include <vector>
515 s042372 11
#include <map>
511 s042372 12
#include "ItemVector.h"
518 s042372 13
#include "ItemID.h"
511 s042372 14
 
15
namespace HMesh
16
{
515 s042372 17
    typedef std::map<VertexID, VertexID> VertexIDRemap;
18
    typedef std::map<FaceID, FaceID> FaceIDRemap;
19
    typedef std::map<HalfEdgeID, HalfEdgeID> HalfEdgeIDRemap;
20
 
21
    struct IDRemap
22
    {
23
        VertexIDRemap vmap;
24
        FaceIDRemap fmap;
25
        HalfEdgeIDRemap hmap;
26
    };
27
 
518 s042372 28
    struct Vertex
29
    { 
30
        HalfEdgeID out; 
31
    };
32
 
33
    struct Face
34
    { 
35
        HalfEdgeID last; 
36
    };
37
 
38
    struct HalfEdge
39
    {
40
        HalfEdgeID next;
41
        HalfEdgeID prev;
42
        HalfEdgeID opp;
43
        VertexID vert;
44
        FaceID face;
45
    };
46
 
512 s042372 47
    class ConnectivityKernel
48
    {
49
    public:
520 s042372 50
        /// add vertex to kernel
512 s042372 51
        VertexID add_vertex();
520 s042372 52
        /// add face to kernel
512 s042372 53
        FaceID add_face();
520 s042372 54
        /// add halfedge to kernel
512 s042372 55
        HalfEdgeID add_halfedge();
511 s042372 56
 
520 s042372 57
        /// remove vertex from kernel, given by ID
512 s042372 58
        void remove_vertex(VertexID id);
520 s042372 59
        /// remove face from kernel, given by ID
511 s042372 60
        void remove_face(FaceID id);
520 s042372 61
        /// remove halfedge from kernel, given by ID
511 s042372 62
        void remove_halfedge(HalfEdgeID id);
63
 
520 s042372 64
        /// resize kernel vertices container to size
518 s042372 65
        void resize_vertices(size_t size);
520 s042372 66
        /// resize kernel faces container to size
518 s042372 67
        void resize_faces(size_t size);
520 s042372 68
        /// resize kernel halfedges container to size
518 s042372 69
        void resize_halfedges(size_t size);
511 s042372 70
 
520 s042372 71
        /// get the ID of next halfedge, given by current halfedge ID
72
        HalfEdgeID next(HalfEdgeID current) const;
73
        /// get the ID of previous halfedge, given by current halfedge ID
74
        HalfEdgeID prev(HalfEdgeID current) const;
75
        /// get the ID of opposite halfedge, given by current halfedge ID
76
        HalfEdgeID opp(HalfEdgeID current) const;
77
        /// get the ID of outgoing halfedge, given by current vertex ID
78
        HalfEdgeID out(VertexID current) const;
79
        /// get the ID of last halfedge of current face ID
80
        HalfEdgeID last(FaceID current) const;
81
        /// get the ID of vertex pointed to by current halfedge ID
512 s042372 82
        VertexID vert(HalfEdgeID id) const;
520 s042372 83
        /// get the ID of face owning current halfedge ID
512 s042372 84
        FaceID face(HalfEdgeID id) const;
511 s042372 85
 
520 s042372 86
        /// set the ID of next halfedge of current halfedge to next
87
        void set_next(HalfEdgeID current, HalfEdgeID next);
88
        /// set the ID of previous halfedge of current halfedge to prev
89
        void set_prev(HalfEdgeID current, HalfEdgeID prev);
90
        /// set the ID of opposite halfedge of current halfedge to opp
91
        void set_opp(HalfEdgeID current, HalfEdgeID opp);
92
        /// set the ID of outgoing halfedge of current vertex to out
93
        void set_out(VertexID current, HalfEdgeID out);
94
        /// set the ID of last halfedge of current face to last
95
        void set_last(FaceID current, HalfEdgeID last);
96
        /// set the ID of vertex pointed to by current halfedge to vert
97
        void set_vert(HalfEdgeID current, VertexID vert);
98
        /// set the ID of face owning current halfedge to face
99
        void set_face(HalfEdgeID current, FaceID face);
511 s042372 100
 
520 s042372 101
        /// number of active vertices in kernel
519 s042372 102
        size_t active_vertices() const;
520 s042372 103
        /// number of active faces in kernel
519 s042372 104
        size_t active_faces() const;
520 s042372 105
        /// number of active halfedges in kernel
519 s042372 106
        size_t active_halfedges() const;
511 s042372 107
 
520 s042372 108
        /// number of total vertices in kernel
519 s042372 109
        size_t total_vertices() const;
520 s042372 110
        /// number of total faces in kernel
519 s042372 111
        size_t total_faces() const;
520 s042372 112
        /// number of total halfedges in kernel
519 s042372 113
        size_t total_halfedges() const;
114
 
520 s042372 115
        /// check if ID of vertex is in use
512 s042372 116
        bool in_use(VertexID id) const;
520 s042372 117
        /// check if ID of face is in use
512 s042372 118
        bool in_use(FaceID id) const;
520 s042372 119
        /// check if ID of halfedge is in use
512 s042372 120
        bool in_use(HalfEdgeID id) const;
511 s042372 121
 
520 s042372 122
        /// get the ID of next vertex in container (default: skip unused IDs)
512 s042372 123
        VertexID vertices_next(VertexID id, bool skip = true) const;
520 s042372 124
        /// get the ID of next face in container (default: skip unused IDs)
512 s042372 125
        HalfEdgeID halfedges_next(HalfEdgeID id, bool skip = true) const;
520 s042372 126
        /// get the ID of next halfedge in container (default: skip unused IDs)
512 s042372 127
        FaceID faces_next(FaceID id, bool skip = true) const;
511 s042372 128
 
520 s042372 129
        /// get the ID of previous vertex in container (default: skip unused IDs)
512 s042372 130
        VertexID vertices_prev(VertexID id, bool skip = true) const;
520 s042372 131
        /// get the ID of previous face in container (default: skip unused IDs)
512 s042372 132
        HalfEdgeID halfedges_prev(HalfEdgeID id, bool skip = true) const;
520 s042372 133
        /// get the ID of previous halfedge in container (default: skip unused IDs)
512 s042372 134
        FaceID faces_prev(FaceID id, bool skip = true) const;
135
 
520 s042372 136
        /// get the ID of first vertex in container (default: skip unused IDs)
512 s042372 137
        VertexID vertices_begin(bool skip = true) const;
520 s042372 138
        /// get the ID of first vertex in container (default: skip unused IDs)
511 s042372 139
        HalfEdgeID halfedges_begin(bool skip = true) const;
520 s042372 140
        /// get the ID of first vertex in container (default: skip unused IDs)
511 s042372 141
        FaceID faces_begin(bool skip = true) const;
142
 
520 s042372 143
        /// get the ID of one past the end vertex in container
511 s042372 144
        VertexID vertices_end() const;
520 s042372 145
        /// get the ID of one past the end face in container 
511 s042372 146
        HalfEdgeID halfedges_end() const;
520 s042372 147
        /// get the ID of one past the end halfedge in container
511 s042372 148
        FaceID faces_end() const;
149
 
515 s042372 150
        /// Clean up unused space in vectors - WARNING! Invalidates existing handles!
151
        void cleanup(IDRemap& map);
152
 
520 s042372 153
        /// clear the kernel
512 s042372 154
        void clear();
511 s042372 155
 
512 s042372 156
    private:
157
        ItemVector<Vertex> vertices;
158
        ItemVector<Face> faces;
159
        ItemVector<HalfEdge> halfedges;
160
    };
511 s042372 161
 
512 s042372 162
    inline VertexID ConnectivityKernel::add_vertex()
163
    {
164
        vertices.add(Vertex());
519 s042372 165
        return VertexID(vertices.total_size() - 1);
512 s042372 166
    }
511 s042372 167
 
512 s042372 168
    inline FaceID ConnectivityKernel::add_face()
169
    {
170
        faces.add(Face());
519 s042372 171
        return FaceID(faces.total_size() - 1);
512 s042372 172
    }
511 s042372 173
 
512 s042372 174
    inline HalfEdgeID ConnectivityKernel::add_halfedge()
175
    {
176
        halfedges.add(HalfEdge());
519 s042372 177
        return HalfEdgeID(halfedges.total_size() - 1);
512 s042372 178
    }
511 s042372 179
 
180
 
181
 
515 s042372 182
 
512 s042372 183
    inline void ConnectivityKernel::remove_vertex(VertexID id)
515 s042372 184
    { vertices.remove(id.index); }
511 s042372 185
 
512 s042372 186
    inline void ConnectivityKernel::remove_face(FaceID id)
515 s042372 187
    { faces.remove(id.index); }
511 s042372 188
 
512 s042372 189
    inline void ConnectivityKernel::remove_halfedge(HalfEdgeID id)
515 s042372 190
    { halfedges.remove(id.index); }
511 s042372 191
 
192
 
193
 
518 s042372 194
    inline void ConnectivityKernel::resize_vertices(size_t size)
512 s042372 195
    {  vertices.resize(size); }
511 s042372 196
 
518 s042372 197
    inline void ConnectivityKernel::resize_faces(size_t size)
512 s042372 198
    {  faces.resize(size); }
511 s042372 199
 
518 s042372 200
    inline void ConnectivityKernel::resize_halfedges(size_t size)
512 s042372 201
    {  halfedges.resize(size); }
511 s042372 202
 
203
 
512 s042372 204
    inline HalfEdgeID ConnectivityKernel::next(HalfEdgeID id) const
515 s042372 205
    { return HalfEdgeID(halfedges[id.index].next); }
511 s042372 206
 
512 s042372 207
    inline HalfEdgeID ConnectivityKernel::prev(HalfEdgeID id) const
515 s042372 208
    { return HalfEdgeID(halfedges[id.index].prev); }
511 s042372 209
 
512 s042372 210
    inline HalfEdgeID ConnectivityKernel::opp(HalfEdgeID id) const
515 s042372 211
    { return HalfEdgeID(halfedges[id.index].opp); }
511 s042372 212
 
512 s042372 213
    inline HalfEdgeID ConnectivityKernel::out(VertexID id) const
515 s042372 214
    { return HalfEdgeID(vertices[id.index].out); }
511 s042372 215
 
512 s042372 216
    inline HalfEdgeID ConnectivityKernel::last(FaceID id) const
515 s042372 217
    { return HalfEdgeID(faces[id.index].last); }
511 s042372 218
 
512 s042372 219
    inline VertexID ConnectivityKernel::vert(HalfEdgeID id) const
515 s042372 220
    { return VertexID(halfedges[id.index].vert); }
511 s042372 221
 
512 s042372 222
    inline FaceID ConnectivityKernel::face(HalfEdgeID id) const
515 s042372 223
    { return FaceID(halfedges[id.index].face); }
511 s042372 224
 
512 s042372 225
    inline void ConnectivityKernel::set_next(HalfEdgeID id, HalfEdgeID next)
515 s042372 226
    { halfedges[id.index].next = next; }
511 s042372 227
 
512 s042372 228
    inline void ConnectivityKernel::set_prev(HalfEdgeID id, HalfEdgeID prev)
515 s042372 229
    { halfedges[id.index].prev = prev; }
511 s042372 230
 
512 s042372 231
    inline void ConnectivityKernel::set_opp(HalfEdgeID id, HalfEdgeID opp)
515 s042372 232
    {halfedges[id.index].opp = opp; }
511 s042372 233
 
512 s042372 234
    inline void ConnectivityKernel::set_out(VertexID id, HalfEdgeID out)
515 s042372 235
    { vertices[id.index].out = out; }
511 s042372 236
 
512 s042372 237
    inline void ConnectivityKernel::set_last(FaceID id, HalfEdgeID last)
515 s042372 238
    { faces[id.index].last = last; }
511 s042372 239
 
512 s042372 240
    inline void ConnectivityKernel::set_vert(HalfEdgeID id, VertexID vert)
515 s042372 241
    { halfedges[id.index].vert = vert; }
511 s042372 242
 
512 s042372 243
    inline void ConnectivityKernel::set_face(HalfEdgeID id, FaceID face)
515 s042372 244
    { halfedges[id.index].face = face; }
511 s042372 245
 
246
 
247
 
519 s042372 248
    inline size_t ConnectivityKernel::active_vertices() const
249
    { return vertices.active_size(); }
511 s042372 250
 
519 s042372 251
    inline size_t ConnectivityKernel::active_faces() const
252
    { return faces.active_size(); }
515 s042372 253
 
519 s042372 254
    inline size_t ConnectivityKernel::active_halfedges() const
255
    { return halfedges.active_size(); }
515 s042372 256
 
519 s042372 257
 
258
 
259
    inline size_t ConnectivityKernel::total_vertices() const
260
    { return vertices.total_size(); }
261
 
262
    inline size_t ConnectivityKernel::total_faces() const
263
    { return faces.total_size(); }
264
 
265
    inline size_t ConnectivityKernel::total_halfedges() const
266
    { return halfedges.total_size(); }
267
 
268
 
269
 
512 s042372 270
    inline bool ConnectivityKernel::in_use(VertexID id) const
515 s042372 271
    { return vertices.in_use(id.index); }
511 s042372 272
 
512 s042372 273
    inline bool ConnectivityKernel::in_use(FaceID id) const
515 s042372 274
    { return faces.in_use(id.index); }
511 s042372 275
 
512 s042372 276
    inline bool ConnectivityKernel::in_use(HalfEdgeID id) const
515 s042372 277
    { return halfedges.in_use(id.index); }
511 s042372 278
 
515 s042372 279
 
280
 
512 s042372 281
    inline VertexID ConnectivityKernel::vertices_next(VertexID id, bool skip) const
515 s042372 282
    { return vertices.index_next(id.index, skip); }
511 s042372 283
 
512 s042372 284
    inline HalfEdgeID ConnectivityKernel::halfedges_next(HalfEdgeID id, bool skip) const
515 s042372 285
    { return halfedges.index_next(id.index, skip); }
511 s042372 286
 
512 s042372 287
    inline FaceID ConnectivityKernel::faces_next(FaceID id, bool skip) const
515 s042372 288
    { return faces.index_next(id.index, skip); }
511 s042372 289
 
512 s042372 290
    inline VertexID ConnectivityKernel::vertices_prev(VertexID id, bool skip) const
515 s042372 291
    { return vertices.index_prev(id.index, skip); }
511 s042372 292
 
512 s042372 293
    inline HalfEdgeID ConnectivityKernel::halfedges_prev(HalfEdgeID id, bool skip) const
515 s042372 294
    { return halfedges.index_prev(id.index, skip); }
511 s042372 295
 
512 s042372 296
    inline FaceID ConnectivityKernel::faces_prev(FaceID id, bool skip) const
515 s042372 297
    { return faces.index_prev(id.index, skip); }
511 s042372 298
 
512 s042372 299
    inline VertexID ConnectivityKernel::vertices_begin(bool skip) const
300
    { return vertices.index_begin(skip); }
301
 
511 s042372 302
    inline HalfEdgeID ConnectivityKernel::halfedges_begin(bool skip) const
512 s042372 303
    { return halfedges.index_begin(skip); }
511 s042372 304
 
305
    inline FaceID ConnectivityKernel::faces_begin(bool skip) const
512 s042372 306
    { return faces.index_begin(skip); }
511 s042372 307
 
308
    inline VertexID ConnectivityKernel::vertices_end() const
512 s042372 309
    { return vertices.index_end(); }
511 s042372 310
 
311
    inline HalfEdgeID ConnectivityKernel::halfedges_end() const
512 s042372 312
    { return halfedges.index_end(); }
511 s042372 313
 
314
    inline FaceID ConnectivityKernel::faces_end() const
512 s042372 315
    { return faces.index_end(); }
511 s042372 316
 
512 s042372 317
    inline void ConnectivityKernel::clear()
318
    {
319
        vertices.clear();
320
        faces.clear();
321
        halfedges.clear();
322
    }
511 s042372 323
}
324
 
325
#endif