Subversion Repositories gelsvn

Rev

Rev 586 | Rev 589 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 586 Rev 588
Line 14... Line 14...
14
 
14
 
15
#include <vector>
15
#include <vector>
16
#include <map>
16
#include <map>
17
#include "ItemVector.h"
17
#include "ItemVector.h"
18
#include "ItemID.h"
18
#include "ItemID.h"
-
 
19
#include "Iterators.h"
19
 
20
 
20
namespace HMesh
21
namespace HMesh
21
{
22
{
22
    struct Vertex;
23
    struct Vertex;
23
    struct Face;
24
    struct Face;
24
    struct HalfEdge;
25
    struct HalfEdge;
25
    
26
 
26
    typedef ItemVector<Vertex>::IDType VertexID;
27
    typedef ItemVector<Vertex>::IDType VertexID;
27
    typedef ItemVector<Face>::IDType FaceID;
28
    typedef ItemVector<Face>::IDType FaceID;
28
    typedef ItemVector<HalfEdge>::IDType HalfEdgeID;
29
    typedef ItemVector<HalfEdge>::IDType HalfEdgeID;
29
 
30
 
30
    /// The vertex struct. This contains just a single outgoing halfedge.
31
    /// The vertex struct. This contains just a single outgoing halfedge.
Line 47... Line 48...
47
        HalfEdgeID opp;
48
        HalfEdgeID opp;
48
        VertexID vert;
49
        VertexID vert;
49
        FaceID face;
50
        FaceID face;
50
    };
51
    };
51
    
52
    
-
 
53
    
-
 
54
    typedef IDIterator<Vertex> VertexIDIterator;
-
 
55
    typedef IDIterator<Face> FaceIDIterator;
-
 
56
    typedef IDIterator<HalfEdge> HalfEdgeIDIterator;
-
 
57
 
52
    static const VertexID InvalidVertexID;
58
    static const VertexID InvalidVertexID;
53
    static const FaceID InvalidFaceID;
59
    static const FaceID InvalidFaceID;
54
    static const HalfEdgeID InvalidHalfEdgeID;
60
    static const HalfEdgeID InvalidHalfEdgeID;
55
    
61
    
56
    typedef std::map<VertexID, VertexID> VertexIDRemap;
62
    typedef std::map<VertexID, VertexID> VertexIDRemap;
Line 65... Line 71...
65
        HalfEdgeIDRemap hmap;
71
        HalfEdgeIDRemap hmap;
66
    };
72
    };
67
 
73
 
68
    /** The connectivity kernel is basically an aggregate of ItemVectors for vertices, faces, and halfedges.
74
    /** 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
75
     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. */
76
     away the implementation from the ConnectivityKernel class making it possible, for instance, to use a different kernel. */
71
    class ConnectivityKernel
77
    class ConnectivityKernel
72
    {
78
    {
-
 
79
        friend class Walker;
-
 
80
        
73
    public:
81
    public:
-
 
82
        
74
        /// add vertex to kernel
83
        /// number of active vertices in kernel
75
        VertexID add_vertex();
84
        size_t no_vertices() const;
76
        /// add face to kernel
85
        /// number of active faces in kernel
77
        FaceID add_face();
86
        size_t no_faces() const;
78
        /// add halfedge to kernel
87
        /// number of active halfedges in kernel
79
        HalfEdgeID add_halfedge();
88
        size_t no_halfedges() const;
80
 
89
        
81
        /// remove vertex from kernel, given by ID
90
        /// number of total vertices in kernel
82
        void remove_vertex(VertexID id);
91
        size_t allocated_vertices() const;
83
        /// remove face from kernel, given by ID
92
        /// number of total faces in kernel
84
        void remove_face(FaceID id);
93
        size_t allocated_faces() const;
85
        /// remove halfedge from kernel, given by ID
94
        /// number of total halfedges in kernel
86
        void remove_halfedge(HalfEdgeID id);
95
        size_t allocated_halfedges() const;
87
 
96
        
88
        /// resize kernel vertices container to size
97
        /// check if ID of vertex is in use
89
        void resize_vertices(size_t size);
98
        bool in_use(VertexID id) const;
90
        /// resize kernel faces container to size
99
        /// check if ID of face is in use
91
        void resize_faces(size_t size);
100
        bool in_use(FaceID id) const;
92
        /// resize kernel halfedges container to size
101
        /// check if ID of halfedge is in use
93
        void resize_halfedges(size_t size);
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;
94
 
117
 
95
        /// get the ID of next halfedge, given by current halfedge ID
118
        /// get the ID of next halfedge, given by current halfedge ID
96
        HalfEdgeID next(HalfEdgeID current) const;
119
        HalfEdgeID next(HalfEdgeID current) const;
97
        /// get the ID of previous halfedge, given by current halfedge ID
120
        /// get the ID of previous halfedge, given by current halfedge ID
98
        HalfEdgeID prev(HalfEdgeID current) const;
121
        HalfEdgeID prev(HalfEdgeID current) const;
Line 105... Line 128...
105
        /// get the ID of vertex pointed to by current halfedge ID
128
        /// get the ID of vertex pointed to by current halfedge ID
106
        VertexID vert(HalfEdgeID id) const;
129
        VertexID vert(HalfEdgeID id) const;
107
        /// get the ID of face owning current halfedge ID
130
        /// get the ID of face owning current halfedge ID
108
        FaceID face(HalfEdgeID id) const;
131
        FaceID face(HalfEdgeID id) const;
109
 
132
 
-
 
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
 
110
        /// set the ID of next halfedge of current halfedge to next
148
        /// set the ID of next halfedge of current halfedge to next
111
        void set_next(HalfEdgeID current, HalfEdgeID next);
149
        void set_next(HalfEdgeID current, HalfEdgeID next);
112
        /// set the ID of previous halfedge of current halfedge to prev
150
        /// set the ID of previous halfedge of current halfedge to prev
113
        void set_prev(HalfEdgeID current, HalfEdgeID prev);
151
        void set_prev(HalfEdgeID current, HalfEdgeID prev);
114
        /// set the ID of opposite halfedge of current halfedge to opp
152
        /// set the ID of opposite halfedge of current halfedge to opp
Line 120... Line 158...
120
        /// set the ID of vertex pointed to by current halfedge to vert
158
        /// set the ID of vertex pointed to by current halfedge to vert
121
        void set_vert(HalfEdgeID current, VertexID vert);
159
        void set_vert(HalfEdgeID current, VertexID vert);
122
        /// set the ID of face owning current halfedge to face
160
        /// set the ID of face owning current halfedge to face
123
        void set_face(HalfEdgeID current, FaceID face);
161
        void set_face(HalfEdgeID current, FaceID face);
124
 
162
 
125
        /// number of active vertices in kernel
-
 
126
        size_t no_vertices() const;
-
 
127
        /// number of active faces in kernel
-
 
128
        size_t no_faces() const;
-
 
129
        /// number of active halfedges in kernel
-
 
130
        size_t no_halfedges() const;
-
 
131
 
-
 
132
        /// number of total vertices in kernel
-
 
133
        size_t allocated_vertices() const;
-
 
134
        /// number of total faces in kernel
-
 
135
        size_t allocated_faces() const;
-
 
136
        /// number of total halfedges in kernel
-
 
137
        size_t allocated_halfedges() const;
-
 
138
 
-
 
139
        /// check if ID of vertex is in use
-
 
140
        bool in_use(VertexID id) const;
-
 
141
        /// check if ID of face is in use
-
 
142
        bool in_use(FaceID id) const;
-
 
143
        /// check if ID of halfedge is in use
-
 
144
        bool in_use(HalfEdgeID id) const;
-
 
145
 
-
 
146
        /// get the ID of next vertex in container (default: skip unused IDs)
-
 
147
        VertexID vertices_next(VertexID id, bool skip = true) const;
-
 
148
        /// get the ID of next face in container (default: skip unused IDs)
-
 
149
        HalfEdgeID halfedges_next(HalfEdgeID id, bool skip = true) const;
-
 
150
        /// get the ID of next halfedge in container (default: skip unused IDs)
-
 
151
        FaceID faces_next(FaceID id, bool skip = true) const;
-
 
152
 
-
 
153
        /// get the ID of previous vertex in container (default: skip unused IDs)
-
 
154
        VertexID vertices_prev(VertexID id, bool skip = true) const;
-
 
155
        /// get the ID of previous face in container (default: skip unused IDs)
-
 
156
        HalfEdgeID halfedges_prev(HalfEdgeID id, bool skip = true) const;
-
 
157
        /// get the ID of previous halfedge in container (default: skip unused IDs)
-
 
158
        FaceID faces_prev(FaceID id, bool skip = true) const;
-
 
159
 
-
 
160
        /// get the ID of first vertex in container (default: skip unused IDs)
-
 
161
        VertexID vertices_begin(bool skip = true) const;
-
 
162
        /// get the ID of first vertex in container (default: skip unused IDs)
-
 
163
        HalfEdgeID halfedges_begin(bool skip = true) const;
-
 
164
        /// get the ID of first vertex in container (default: skip unused IDs)
-
 
165
        FaceID faces_begin(bool skip = true) const;
-
 
166
 
-
 
167
        /// get the ID of one past the end vertex in container
-
 
168
        VertexID vertices_end() const;
-
 
169
        /// get the ID of one past the end face in container 
-
 
170
        HalfEdgeID halfedges_end() const;
-
 
171
        /// get the ID of one past the end halfedge in container
-
 
172
        FaceID faces_end() const;
-
 
173
 
163
 
174
        /// Clean up unused space in vectors - WARNING! Invalidates existing handles!
164
        /// Clean up unused space in vectors - WARNING! Invalidates existing handles!
175
        void cleanup(IDRemap& map);
165
        void cleanup(IDRemap& map);
176
 
166
 
177
        /// clear the kernel
167
        /// clear the kernel
178
        void clear();
168
        void clear();
179
 
169
 
180
    private:
-
 
181
        ItemVector<Vertex> vertices;
170
        ItemVector<Vertex> vertices;
182
        ItemVector<Face> faces;
171
        ItemVector<Face> faces;
183
        ItemVector<HalfEdge> halfedges;
172
        ItemVector<HalfEdge> halfedges;
184
    };
173
    };
185
 
174
 
Line 199... Line 188...
199
    { faces.remove(id); }
188
    { faces.remove(id); }
200
 
189
 
201
    inline void ConnectivityKernel::remove_halfedge(HalfEdgeID id)
190
    inline void ConnectivityKernel::remove_halfedge(HalfEdgeID id)
202
    { halfedges.remove(id); }
191
    { halfedges.remove(id); }
203
 
192
 
204
    inline void ConnectivityKernel::resize_vertices(size_t size)
-
 
205
    {  vertices.resize(size); }
-
 
206
 
-
 
207
    inline void ConnectivityKernel::resize_faces(size_t size)
-
 
208
    {  faces.resize(size); }
-
 
209
 
-
 
210
    inline void ConnectivityKernel::resize_halfedges(size_t size)
-
 
211
    {  halfedges.resize(size); }
-
 
212
 
-
 
213
 
193
 
214
    inline HalfEdgeID ConnectivityKernel::next(HalfEdgeID id) const
194
    inline HalfEdgeID ConnectivityKernel::next(HalfEdgeID id) const
215
    { return halfedges[id].next; }
195
    { return halfedges[id].next; }
216
 
196
 
217
    inline HalfEdgeID ConnectivityKernel::prev(HalfEdgeID id) const
197
    inline HalfEdgeID ConnectivityKernel::prev(HalfEdgeID id) const
Line 284... Line 264...
284
    { return faces.in_use(id); }
264
    { return faces.in_use(id); }
285
 
265
 
286
    inline bool ConnectivityKernel::in_use(HalfEdgeID id) const
266
    inline bool ConnectivityKernel::in_use(HalfEdgeID id) const
287
    { return halfedges.in_use(id); }
267
    { return halfedges.in_use(id); }
288
 
268
 
289
 
-
 
290
 
-
 
291
    inline VertexID ConnectivityKernel::vertices_next(VertexID id, bool skip) const
269
    inline VertexIDIterator ConnectivityKernel::vertices_begin(bool skip) const
292
    { return vertices.index_next(id, skip); }
270
    { return VertexIDIterator(vertices, vertices.index_begin(skip), skip); }
293
 
-
 
294
    inline HalfEdgeID ConnectivityKernel::halfedges_next(HalfEdgeID id, bool skip) const
-
 
295
    { return halfedges.index_next(id, skip); }
-
 
296
 
-
 
297
    inline FaceID ConnectivityKernel::faces_next(FaceID id, bool skip) const
271
    inline  FaceIDIterator ConnectivityKernel::faces_begin(bool skip) const
298
    { return faces.index_next(id, skip); }
-
 
299
 
-
 
300
    inline VertexID ConnectivityKernel::vertices_prev(VertexID id, bool skip) const
-
 
301
    { return vertices.index_prev(id, skip); }
272
    { return FaceIDIterator(faces, faces.index_begin(skip), skip); }
302
 
-
 
303
    inline HalfEdgeID ConnectivityKernel::halfedges_prev(HalfEdgeID id, bool skip) const
273
    inline HalfEdgeIDIterator ConnectivityKernel:: halfedges_begin(bool skip) const
304
    { return halfedges.index_prev(id, skip); }
274
    { return HalfEdgeIDIterator(halfedges, halfedges.index_begin(skip), skip); }
305
 
275
    
306
    inline FaceID ConnectivityKernel::faces_prev(FaceID id, bool skip) const
-
 
307
    { return faces.index_prev(id, skip); }
-
 
308
 
276
    
309
    inline VertexID ConnectivityKernel::vertices_begin(bool skip) const
277
    inline VertexIDIterator ConnectivityKernel::vertices_end() const
310
    { return vertices.index_begin(skip); }
278
    { return VertexIDIterator(vertices, vertices.index_end()); }
311
 
-
 
312
    inline HalfEdgeID ConnectivityKernel::halfedges_begin(bool skip) const
-
 
313
    { return halfedges.index_begin(skip); }
-
 
314
 
-
 
315
    inline FaceID ConnectivityKernel::faces_begin(bool skip) const
-
 
316
    { return faces.index_begin(skip); }
-
 
317
 
-
 
318
    inline VertexID ConnectivityKernel::vertices_end() const
279
    inline FaceIDIterator ConnectivityKernel::faces_end() const
319
    { return vertices.index_end(); }
280
    { return FaceIDIterator(faces, faces.index_end()); }
320
 
-
 
321
    inline HalfEdgeID ConnectivityKernel::halfedges_end() const
281
    inline HalfEdgeIDIterator ConnectivityKernel::halfedges_end() const
322
    { return halfedges.index_end(); }
282
    { return HalfEdgeIDIterator(halfedges, halfedges.index_end()); }
323
 
283
    
324
    inline FaceID ConnectivityKernel::faces_end() const
-
 
325
    { return faces.index_end(); }
-
 
326
 
284
    
327
    inline void ConnectivityKernel::clear()
285
    inline void ConnectivityKernel::clear()
328
    {
286
    {
329
        vertices.clear();
287
        vertices.clear();
330
        faces.clear();
288
        faces.clear();
331
        halfedges.clear();
289
        halfedges.clear();