Subversion Repositories gelsvn

Rev

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