Subversion Repositories gelsvn

Rev

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