Subversion Repositories gelsvn

Rev

Rev 589 | 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"
588 jab 19
#include "Iterators.h"
511 s042372 20
 
21
namespace HMesh
22
{
586 jab 23
    struct Vertex;
24
    struct Face;
25
    struct HalfEdge;
588 jab 26
 
586 jab 27
    typedef ItemVector<Vertex>::IDType VertexID;
28
    typedef ItemVector<Face>::IDType FaceID;
29
    typedef ItemVector<HalfEdge>::IDType HalfEdgeID;
515 s042372 30
 
586 jab 31
    /// The vertex struct. This contains just a single outgoing halfedge.
518 s042372 32
    struct Vertex
33
    { 
34
        HalfEdgeID out; 
35
    };
36
 
586 jab 37
    /// The face struct. Contains a single halfedge
518 s042372 38
    struct Face
39
    { 
40
        HalfEdgeID last; 
41
    };
42
 
586 jab 43
    /// The halfedge struct. Contains IDs of next, previous, and opposite edges as well as incident face and vertex.
518 s042372 44
    struct HalfEdge
45
    {
46
        HalfEdgeID next;
47
        HalfEdgeID prev;
48
        HalfEdgeID opp;
49
        VertexID vert;
50
        FaceID face;
51
    };
586 jab 52
 
588 jab 53
 
54
    typedef IDIterator<Vertex> VertexIDIterator;
55
    typedef IDIterator<Face> FaceIDIterator;
56
    typedef IDIterator<HalfEdge> HalfEdgeIDIterator;
57
 
586 jab 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
    };
518 s042372 73
 
586 jab 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
588 jab 76
     away the implementation from the ConnectivityKernel class making it possible, for instance, to use a different kernel. */
512 s042372 77
    class ConnectivityKernel
78
    {
79
    public:
588 jab 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;
511 s042372 115
 
520 s042372 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
512 s042372 127
        VertexID vert(HalfEdgeID id) const;
520 s042372 128
        /// get the ID of face owning current halfedge ID
512 s042372 129
        FaceID face(HalfEdgeID id) const;
511 s042372 130
 
588 jab 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
 
520 s042372 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);
511 s042372 159
 
515 s042372 160
        /// Clean up unused space in vectors - WARNING! Invalidates existing handles!
161
        void cleanup(IDRemap& map);
162
 
520 s042372 163
        /// clear the kernel
512 s042372 164
        void clear();
589 jab 165
 
166
    private:
511 s042372 167
 
512 s042372 168
        ItemVector<Vertex> vertices;
169
        ItemVector<Face> faces;
170
        ItemVector<HalfEdge> halfedges;
171
    };
511 s042372 172
 
512 s042372 173
    inline VertexID ConnectivityKernel::add_vertex()
586 jab 174
    { return vertices.add(Vertex()); }
511 s042372 175
 
512 s042372 176
    inline FaceID ConnectivityKernel::add_face()
586 jab 177
    { return faces.add(Face()); }
511 s042372 178
 
512 s042372 179
    inline HalfEdgeID ConnectivityKernel::add_halfedge()
586 jab 180
    { return halfedges.add(HalfEdge()); }
511 s042372 181
 
512 s042372 182
    inline void ConnectivityKernel::remove_vertex(VertexID id)
586 jab 183
    { vertices.remove(id); }
511 s042372 184
 
512 s042372 185
    inline void ConnectivityKernel::remove_face(FaceID id)
586 jab 186
    { faces.remove(id); }
511 s042372 187
 
512 s042372 188
    inline void ConnectivityKernel::remove_halfedge(HalfEdgeID id)
586 jab 189
    { halfedges.remove(id); }
511 s042372 190
 
191
 
512 s042372 192
    inline HalfEdgeID ConnectivityKernel::next(HalfEdgeID id) const
586 jab 193
    { return halfedges[id].next; }
511 s042372 194
 
512 s042372 195
    inline HalfEdgeID ConnectivityKernel::prev(HalfEdgeID id) const
586 jab 196
    { return halfedges[id].prev; }
511 s042372 197
 
512 s042372 198
    inline HalfEdgeID ConnectivityKernel::opp(HalfEdgeID id) const
586 jab 199
    { return halfedges[id].opp; }
511 s042372 200
 
512 s042372 201
    inline HalfEdgeID ConnectivityKernel::out(VertexID id) const
586 jab 202
    { return vertices[id].out; }
511 s042372 203
 
512 s042372 204
    inline HalfEdgeID ConnectivityKernel::last(FaceID id) const
586 jab 205
    { return faces[id].last; }
511 s042372 206
 
512 s042372 207
    inline VertexID ConnectivityKernel::vert(HalfEdgeID id) const
586 jab 208
    { return halfedges[id].vert; }
511 s042372 209
 
512 s042372 210
    inline FaceID ConnectivityKernel::face(HalfEdgeID id) const
586 jab 211
    { return halfedges[id].face; }
511 s042372 212
 
512 s042372 213
    inline void ConnectivityKernel::set_next(HalfEdgeID id, HalfEdgeID next)
586 jab 214
    { halfedges[id].next = next; }
511 s042372 215
 
512 s042372 216
    inline void ConnectivityKernel::set_prev(HalfEdgeID id, HalfEdgeID prev)
586 jab 217
    { halfedges[id].prev = prev; }
511 s042372 218
 
512 s042372 219
    inline void ConnectivityKernel::set_opp(HalfEdgeID id, HalfEdgeID opp)
586 jab 220
    {halfedges[id].opp = opp; }
511 s042372 221
 
512 s042372 222
    inline void ConnectivityKernel::set_out(VertexID id, HalfEdgeID out)
586 jab 223
    { vertices[id].out = out; }
511 s042372 224
 
512 s042372 225
    inline void ConnectivityKernel::set_last(FaceID id, HalfEdgeID last)
586 jab 226
    { faces[id].last = last; }
511 s042372 227
 
512 s042372 228
    inline void ConnectivityKernel::set_vert(HalfEdgeID id, VertexID vert)
586 jab 229
    { halfedges[id].vert = vert; }
511 s042372 230
 
512 s042372 231
    inline void ConnectivityKernel::set_face(HalfEdgeID id, FaceID face)
586 jab 232
    { halfedges[id].face = face; }
511 s042372 233
 
234
 
235
 
586 jab 236
    inline size_t ConnectivityKernel::no_vertices() const
237
    { return vertices.size(); }
511 s042372 238
 
586 jab 239
    inline size_t ConnectivityKernel::no_faces() const
240
    { return faces.size(); }
515 s042372 241
 
586 jab 242
    inline size_t ConnectivityKernel::no_halfedges() const
243
    { return halfedges.size(); }
515 s042372 244
 
519 s042372 245
 
246
 
586 jab 247
    inline size_t ConnectivityKernel::allocated_vertices() const
248
    { return vertices.allocated_size(); }
519 s042372 249
 
586 jab 250
    inline size_t ConnectivityKernel::allocated_faces() const
251
    { return faces.allocated_size(); }
519 s042372 252
 
586 jab 253
    inline size_t ConnectivityKernel::allocated_halfedges() const
254
    { return halfedges.allocated_size(); }
519 s042372 255
 
256
 
257
 
512 s042372 258
    inline bool ConnectivityKernel::in_use(VertexID id) const
586 jab 259
    { return vertices.in_use(id); }
511 s042372 260
 
512 s042372 261
    inline bool ConnectivityKernel::in_use(FaceID id) const
586 jab 262
    { return faces.in_use(id); }
511 s042372 263
 
512 s042372 264
    inline bool ConnectivityKernel::in_use(HalfEdgeID id) const
586 jab 265
    { return halfedges.in_use(id); }
511 s042372 266
 
588 jab 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
 
512 s042372 283
    inline void ConnectivityKernel::clear()
284
    {
285
        vertices.clear();
286
        faces.clear();
287
        halfedges.clear();
288
    }
511 s042372 289
}
290
 
291
#endif