Subversion Repositories gelsvn

Rev

Rev 586 | 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
    {
588 jab 79
        friend class Walker;
80
 
512 s042372 81
    public:
588 jab 82
 
83
        /// number of active vertices in kernel
84
        size_t no_vertices() const;
85
        /// number of active faces in kernel
86
        size_t no_faces() const;
87
        /// number of active halfedges in kernel
88
        size_t no_halfedges() const;
89
 
90
        /// number of total vertices in kernel
91
        size_t allocated_vertices() const;
92
        /// number of total faces in kernel
93
        size_t allocated_faces() const;
94
        /// number of total halfedges in kernel
95
        size_t allocated_halfedges() const;
96
 
97
        /// check if ID of vertex is in use
98
        bool in_use(VertexID id) const;
99
        /// check if ID of face is in use
100
        bool in_use(FaceID id) const;
101
        /// check if ID of halfedge is in use
102
        bool in_use(HalfEdgeID id) const;
103
 
104
        /// Iterator to first VertexID, optional argument defines if unused items should be skipped
105
        VertexIDIterator vertices_begin(bool skip = true) const;
106
        /// Iterator to first FaceID, optional argument defines if unused items should be skipped
107
        FaceIDIterator faces_begin(bool skip = true) const;
108
        /// Iterator to first HalfEdgeID, optional argument defines if unused items should be skipped
109
        HalfEdgeIDIterator halfedges_begin(bool skip = true) const;
110
 
111
        /// Iterator to past the end VertexID
112
        VertexIDIterator vertices_end() const;
113
        /// Iterator topast the end FaceID
114
        FaceIDIterator faces_end() const;
115
        /// Iterator to past the end HalfEdgeID
116
        HalfEdgeIDIterator halfedges_end() const;
511 s042372 117
 
520 s042372 118
        /// get the ID of next halfedge, given by current halfedge ID
119
        HalfEdgeID next(HalfEdgeID current) const;
120
        /// get the ID of previous halfedge, given by current halfedge ID
121
        HalfEdgeID prev(HalfEdgeID current) const;
122
        /// get the ID of opposite halfedge, given by current halfedge ID
123
        HalfEdgeID opp(HalfEdgeID current) const;
124
        /// get the ID of outgoing halfedge, given by current vertex ID
125
        HalfEdgeID out(VertexID current) const;
126
        /// get the ID of last halfedge of current face ID
127
        HalfEdgeID last(FaceID current) const;
128
        /// get the ID of vertex pointed to by current halfedge ID
512 s042372 129
        VertexID vert(HalfEdgeID id) const;
520 s042372 130
        /// get the ID of face owning current halfedge ID
512 s042372 131
        FaceID face(HalfEdgeID id) const;
511 s042372 132
 
588 jab 133
    protected:
134
        /// add vertex to kernel
135
        VertexID add_vertex();
136
        /// add face to kernel
137
        FaceID add_face();
138
        /// add halfedge to kernel
139
        HalfEdgeID add_halfedge();
140
 
141
        /// remove vertex from kernel, given by ID
142
        void remove_vertex(VertexID id);
143
        /// remove face from kernel, given by ID
144
        void remove_face(FaceID id);
145
        /// remove halfedge from kernel, given by ID
146
        void remove_halfedge(HalfEdgeID id);
147
 
520 s042372 148
        /// set the ID of next halfedge of current halfedge to next
149
        void set_next(HalfEdgeID current, HalfEdgeID next);
150
        /// set the ID of previous halfedge of current halfedge to prev
151
        void set_prev(HalfEdgeID current, HalfEdgeID prev);
152
        /// set the ID of opposite halfedge of current halfedge to opp
153
        void set_opp(HalfEdgeID current, HalfEdgeID opp);
154
        /// set the ID of outgoing halfedge of current vertex to out
155
        void set_out(VertexID current, HalfEdgeID out);
156
        /// set the ID of last halfedge of current face to last
157
        void set_last(FaceID current, HalfEdgeID last);
158
        /// set the ID of vertex pointed to by current halfedge to vert
159
        void set_vert(HalfEdgeID current, VertexID vert);
160
        /// set the ID of face owning current halfedge to face
161
        void set_face(HalfEdgeID current, FaceID face);
511 s042372 162
 
163
 
515 s042372 164
        /// Clean up unused space in vectors - WARNING! Invalidates existing handles!
165
        void cleanup(IDRemap& map);
166
 
520 s042372 167
        /// clear the kernel
512 s042372 168
        void clear();
511 s042372 169
 
512 s042372 170
        ItemVector<Vertex> vertices;
171
        ItemVector<Face> faces;
172
        ItemVector<HalfEdge> halfedges;
173
    };
511 s042372 174
 
512 s042372 175
    inline VertexID ConnectivityKernel::add_vertex()
586 jab 176
    { return vertices.add(Vertex()); }
511 s042372 177
 
512 s042372 178
    inline FaceID ConnectivityKernel::add_face()
586 jab 179
    { return faces.add(Face()); }
511 s042372 180
 
512 s042372 181
    inline HalfEdgeID ConnectivityKernel::add_halfedge()
586 jab 182
    { return halfedges.add(HalfEdge()); }
511 s042372 183
 
512 s042372 184
    inline void ConnectivityKernel::remove_vertex(VertexID id)
586 jab 185
    { vertices.remove(id); }
511 s042372 186
 
512 s042372 187
    inline void ConnectivityKernel::remove_face(FaceID id)
586 jab 188
    { faces.remove(id); }
511 s042372 189
 
512 s042372 190
    inline void ConnectivityKernel::remove_halfedge(HalfEdgeID id)
586 jab 191
    { halfedges.remove(id); }
511 s042372 192
 
193
 
512 s042372 194
    inline HalfEdgeID ConnectivityKernel::next(HalfEdgeID id) const
586 jab 195
    { return halfedges[id].next; }
511 s042372 196
 
512 s042372 197
    inline HalfEdgeID ConnectivityKernel::prev(HalfEdgeID id) const
586 jab 198
    { return halfedges[id].prev; }
511 s042372 199
 
512 s042372 200
    inline HalfEdgeID ConnectivityKernel::opp(HalfEdgeID id) const
586 jab 201
    { return halfedges[id].opp; }
511 s042372 202
 
512 s042372 203
    inline HalfEdgeID ConnectivityKernel::out(VertexID id) const
586 jab 204
    { return vertices[id].out; }
511 s042372 205
 
512 s042372 206
    inline HalfEdgeID ConnectivityKernel::last(FaceID id) const
586 jab 207
    { return faces[id].last; }
511 s042372 208
 
512 s042372 209
    inline VertexID ConnectivityKernel::vert(HalfEdgeID id) const
586 jab 210
    { return halfedges[id].vert; }
511 s042372 211
 
512 s042372 212
    inline FaceID ConnectivityKernel::face(HalfEdgeID id) const
586 jab 213
    { return halfedges[id].face; }
511 s042372 214
 
512 s042372 215
    inline void ConnectivityKernel::set_next(HalfEdgeID id, HalfEdgeID next)
586 jab 216
    { halfedges[id].next = next; }
511 s042372 217
 
512 s042372 218
    inline void ConnectivityKernel::set_prev(HalfEdgeID id, HalfEdgeID prev)
586 jab 219
    { halfedges[id].prev = prev; }
511 s042372 220
 
512 s042372 221
    inline void ConnectivityKernel::set_opp(HalfEdgeID id, HalfEdgeID opp)
586 jab 222
    {halfedges[id].opp = opp; }
511 s042372 223
 
512 s042372 224
    inline void ConnectivityKernel::set_out(VertexID id, HalfEdgeID out)
586 jab 225
    { vertices[id].out = out; }
511 s042372 226
 
512 s042372 227
    inline void ConnectivityKernel::set_last(FaceID id, HalfEdgeID last)
586 jab 228
    { faces[id].last = last; }
511 s042372 229
 
512 s042372 230
    inline void ConnectivityKernel::set_vert(HalfEdgeID id, VertexID vert)
586 jab 231
    { halfedges[id].vert = vert; }
511 s042372 232
 
512 s042372 233
    inline void ConnectivityKernel::set_face(HalfEdgeID id, FaceID face)
586 jab 234
    { halfedges[id].face = face; }
511 s042372 235
 
236
 
237
 
586 jab 238
    inline size_t ConnectivityKernel::no_vertices() const
239
    { return vertices.size(); }
511 s042372 240
 
586 jab 241
    inline size_t ConnectivityKernel::no_faces() const
242
    { return faces.size(); }
515 s042372 243
 
586 jab 244
    inline size_t ConnectivityKernel::no_halfedges() const
245
    { return halfedges.size(); }
515 s042372 246
 
519 s042372 247
 
248
 
586 jab 249
    inline size_t ConnectivityKernel::allocated_vertices() const
250
    { return vertices.allocated_size(); }
519 s042372 251
 
586 jab 252
    inline size_t ConnectivityKernel::allocated_faces() const
253
    { return faces.allocated_size(); }
519 s042372 254
 
586 jab 255
    inline size_t ConnectivityKernel::allocated_halfedges() const
256
    { return halfedges.allocated_size(); }
519 s042372 257
 
258
 
259
 
512 s042372 260
    inline bool ConnectivityKernel::in_use(VertexID id) const
586 jab 261
    { return vertices.in_use(id); }
511 s042372 262
 
512 s042372 263
    inline bool ConnectivityKernel::in_use(FaceID id) const
586 jab 264
    { return faces.in_use(id); }
511 s042372 265
 
512 s042372 266
    inline bool ConnectivityKernel::in_use(HalfEdgeID id) const
586 jab 267
    { return halfedges.in_use(id); }
511 s042372 268
 
588 jab 269
    inline VertexIDIterator ConnectivityKernel::vertices_begin(bool skip) const
270
    { return VertexIDIterator(vertices, vertices.index_begin(skip), skip); }
271
    inline  FaceIDIterator ConnectivityKernel::faces_begin(bool skip) const
272
    { return FaceIDIterator(faces, faces.index_begin(skip), skip); }
273
    inline HalfEdgeIDIterator ConnectivityKernel:: halfedges_begin(bool skip) const
274
    { return HalfEdgeIDIterator(halfedges, halfedges.index_begin(skip), skip); }
275
 
276
 
277
    inline VertexIDIterator ConnectivityKernel::vertices_end() const
278
    { return VertexIDIterator(vertices, vertices.index_end()); }
279
    inline FaceIDIterator ConnectivityKernel::faces_end() const
280
    { return FaceIDIterator(faces, faces.index_end()); }
281
    inline HalfEdgeIDIterator ConnectivityKernel::halfedges_end() const
282
    { return HalfEdgeIDIterator(halfedges, halfedges.index_end()); }
283
 
284
 
512 s042372 285
    inline void ConnectivityKernel::clear()
286
    {
287
        vertices.clear();
288
        faces.clear();
289
        halfedges.clear();
290
    }
511 s042372 291
}
292
 
293
#endif