Subversion Repositories gelsvn

Rev

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

Rev 511 Rev 512
Line -... Line 1...
-
 
1
/* ----------------------------------------------------------------------- *
-
 
2
 * This file is part of GEL, www.imm.dtu.dk/GEL
-
 
3
 * Copyright (C) the authors (see AUTHORS.txt) and DTU Informatics
1
/*
4
 *
2
* Written by Christian Thode Larsen 2009-2010
5
 * Principal authors:
3
* Contact: thode2d@gmail.com
6
 *  Christian Thode Larsen (thode2d@gmail.com)
4
* Based on original work by J. Andreas Baerentzen
-
 
5
* Inspired by OpenMesh (www.openmesh.org)
7
 *  J. Andreas Baerentzen (jab@imm.dtu.dk)
6
*/
8
 *
-
 
9
 * See LICENSE.txt for licensing information
-
 
10
 * ----------------------------------------------------------------------- */
7
 
11
 
8
#ifndef __HMESH_CONNECTIVITY_KERNEL_H__
12
#ifndef __HMESH_CONNECTIVITY_KERNEL_H__
9
#define __HMESH_CONNECTIVITY_KERNEL_H__
13
#define __HMESH_CONNECTIVITY_KERNEL_H__
10
 
14
 
11
#include <vector>
15
#include <vector>
12
#include "ItemVector.h"
16
#include "ItemVector.h"
13
#include "Items.h"
17
#include "Items.h"
14
 
18
 
15
namespace HMesh
19
namespace HMesh
16
{
20
{
17
	class ConnectivityKernel
21
    class ConnectivityKernel
18
	{
22
    {
19
	public:
23
    public:
20
		VertexID add_vertex();
24
        VertexID add_vertex();
21
		FaceID add_face();
25
        FaceID add_face();
22
		HalfEdgeID add_halfedge();
26
        HalfEdgeID add_halfedge();
23
 
27
 
24
		void remove_vertex(VertexID id);
28
        void remove_vertex(VertexID id);
25
        void remove_face(FaceID id);
29
        void remove_face(FaceID id);
26
        void remove_halfedge(HalfEdgeID id);
30
        void remove_halfedge(HalfEdgeID id);
27
 
31
 
28
		void resize_vertices(IndexType size);
32
        void resize_vertices(IndexType size);
29
		void resize_faces(IndexType size);
33
        void resize_faces(IndexType size);
30
		void resize_halfedges(IndexType size);
34
        void resize_halfedges(IndexType size);
31
 
35
 
32
		HalfEdgeID next(HalfEdgeID id) const;
36
        HalfEdgeID next(HalfEdgeID id) const;
33
		HalfEdgeID prev(HalfEdgeID id) const;
37
        HalfEdgeID prev(HalfEdgeID id) const;
34
		HalfEdgeID opp(HalfEdgeID id) const;
38
        HalfEdgeID opp(HalfEdgeID id) const;
35
		HalfEdgeID out(VertexID id) const;
39
        HalfEdgeID out(VertexID id) const;
36
		HalfEdgeID last(FaceID id) const;
40
        HalfEdgeID last(FaceID id) const;
37
		VertexID vert(HalfEdgeID id) const;
41
        VertexID vert(HalfEdgeID id) const;
38
		FaceID face(HalfEdgeID id) const;
42
        FaceID face(HalfEdgeID id) const;
39
 
43
 
40
		void set_next(HalfEdgeID id, HalfEdgeID next);
44
        void set_next(HalfEdgeID id, HalfEdgeID next);
41
		void set_prev(HalfEdgeID id, HalfEdgeID prev);
45
        void set_prev(HalfEdgeID id, HalfEdgeID prev);
42
		void set_opp(HalfEdgeID id, HalfEdgeID opp);
46
        void set_opp(HalfEdgeID id, HalfEdgeID opp);
43
		void set_out(VertexID id, HalfEdgeID out);
47
        void set_out(VertexID id, HalfEdgeID out);
44
		void set_last(FaceID id, HalfEdgeID last);
48
        void set_last(FaceID id, HalfEdgeID last);
45
		void set_vert(HalfEdgeID id, VertexID vert);
49
        void set_vert(HalfEdgeID id, VertexID vert);
46
		void set_face(HalfEdgeID id, FaceID face);
50
        void set_face(HalfEdgeID id, FaceID face);
47
 
51
 
48
		IndexType no_vertices(bool active = true) const;
52
        IndexType no_vertices(bool active = true) const;
49
		IndexType no_faces(bool active = true) const;
53
        IndexType no_faces(bool active = true) const;
50
		IndexType no_halfedges(bool active = true) const;
54
        IndexType no_halfedges(bool active = true) const;
51
 
55
 
52
		bool in_use(VertexID id) const;
56
        bool in_use(VertexID id) const;
53
		bool in_use(FaceID id) const;
57
        bool in_use(FaceID id) const;
54
		bool in_use(HalfEdgeID id) const;
58
        bool in_use(HalfEdgeID id) const;
55
 
59
 
56
		VertexID vertices_next(VertexID id, bool skip = true) const;
60
        VertexID vertices_next(VertexID id, bool skip = true) const;
57
		HalfEdgeID halfedges_next(HalfEdgeID id, bool skip = true) const;
61
        HalfEdgeID halfedges_next(HalfEdgeID id, bool skip = true) const;
58
		FaceID faces_next(FaceID id, bool skip = true) const;
62
        FaceID faces_next(FaceID id, bool skip = true) const;
59
 
63
 
60
		VertexID vertices_prev(VertexID id, bool skip = true) const;
64
        VertexID vertices_prev(VertexID id, bool skip = true) const;
61
		HalfEdgeID halfedges_prev(HalfEdgeID id, bool skip = true) const;
65
        HalfEdgeID halfedges_prev(HalfEdgeID id, bool skip = true) const;
62
		FaceID faces_prev(FaceID id, bool skip = true) const;
66
        FaceID faces_prev(FaceID id, bool skip = true) const;
63
		
67
 
64
		VertexID vertices_begin(bool skip = true) const;
68
        VertexID vertices_begin(bool skip = true) const;
65
        HalfEdgeID halfedges_begin(bool skip = true) const;
69
        HalfEdgeID halfedges_begin(bool skip = true) const;
66
        FaceID faces_begin(bool skip = true) const;
70
        FaceID faces_begin(bool skip = true) const;
67
 
71
 
68
        VertexID vertices_end() const;
72
        VertexID vertices_end() const;
69
        HalfEdgeID halfedges_end() const;
73
        HalfEdgeID halfedges_end() const;
70
        FaceID faces_end() const;
74
        FaceID faces_end() const;
71
 
75
 
72
		void cleanup();
76
        void cleanup();
73
		void clear();
77
        void clear();
-
 
78
 
-
 
79
    private:
-
 
80
        ItemVector<Vertex> vertices;
-
 
81
        ItemVector<Face> faces;
-
 
82
        ItemVector<HalfEdge> halfedges;
-
 
83
    };
74
 
84
 
-
 
85
    inline VertexID ConnectivityKernel::add_vertex()
75
	private:
86
    {
76
		ItemVector<Vertex> vertices;
87
        vertices.add(Vertex());
77
		ItemVector<Face> faces;
-
 
78
		ItemVector<HalfEdge> halfedges;
88
        return VertexID(vertices.size() - 1);
79
	};
89
    }
80
 
90
 
81
	inline VertexID ConnectivityKernel::add_vertex()
91
    inline FaceID ConnectivityKernel::add_face()
82
	{
92
    {
83
		vertices.add(Vertex());
93
        faces.add(Face());
84
		return VertexID(vertices.size());
94
        return FaceID(faces.size() - 1);
85
	}
95
    }
86
 
96
 
87
	inline FaceID ConnectivityKernel::add_face()
97
    inline HalfEdgeID ConnectivityKernel::add_halfedge()
88
	{
98
    {
89
		faces.add(Face());
99
        halfedges.add(HalfEdge());
90
		return FaceID(faces.size());
100
        return HalfEdgeID(halfedges.size() - 1);
91
	}
101
    }
92
 
102
 
93
	inline HalfEdgeID ConnectivityKernel::add_halfedge()
-
 
94
	{
-
 
95
		halfedges.add(HalfEdge());
-
 
96
		return HalfEdgeID(halfedges.size());
-
 
97
	}
-
 
98
 
103
 
99
 
104
 
-
 
105
    inline void ConnectivityKernel::remove_vertex(VertexID id)
-
 
106
    { vertices.remove(id.idx()); }
100
 
107
 
101
	inline void ConnectivityKernel::remove_vertex(VertexID id)
108
    inline void ConnectivityKernel::remove_face(FaceID id)
102
	{ vertices.remove(id.idx()); }
109
    { faces.remove(id.idx()); }
103
 
110
 
104
	inline void ConnectivityKernel::remove_face(FaceID id)
111
    inline void ConnectivityKernel::remove_halfedge(HalfEdgeID id)
105
	{ faces.remove(id.idx()); }
112
    { halfedges.remove(id.idx()); }
106
 
113
 
107
	inline void ConnectivityKernel::remove_halfedge(HalfEdgeID id)
-
 
108
	{ halfedges.remove(id.idx()); }
-
 
109
 
114
 
110
 
115
 
-
 
116
    inline void ConnectivityKernel::resize_vertices(IndexType size)
-
 
117
    {  vertices.resize(size); }
111
 
118
 
112
	inline void ConnectivityKernel::resize_vertices(IndexType size)
119
    inline void ConnectivityKernel::resize_faces(IndexType size)
113
	{  vertices.resize(size); }
120
    {  faces.resize(size); }
114
 
121
 
115
	inline void ConnectivityKernel::resize_faces(IndexType size)
122
    inline void ConnectivityKernel::resize_halfedges(IndexType size)
116
	{  faces.resize(size); }
123
    {  halfedges.resize(size); }
117
 
124
 
118
	inline void ConnectivityKernel::resize_halfedges(IndexType size)
-
 
119
	{  halfedges.resize(size); }
-
 
120
 
125
 
-
 
126
    inline HalfEdgeID ConnectivityKernel::next(HalfEdgeID id) const
-
 
127
    { return HalfEdgeID(halfedges[id.idx()].next); }
121
 
128
 
122
	inline HalfEdgeID ConnectivityKernel::next(HalfEdgeID id) const
129
    inline HalfEdgeID ConnectivityKernel::prev(HalfEdgeID id) const
123
	{ return HalfEdgeID(halfedges[id.idx()].next); }
130
    { return HalfEdgeID(halfedges[id.idx()].prev); }
124
 
131
 
125
	inline HalfEdgeID ConnectivityKernel::prev(HalfEdgeID id) const
132
    inline HalfEdgeID ConnectivityKernel::opp(HalfEdgeID id) const
126
	{ return HalfEdgeID(halfedges[id.idx()].prev); }
133
    { return HalfEdgeID(halfedges[id.idx()].opp); }
127
 
134
 
128
	inline HalfEdgeID ConnectivityKernel::opp(HalfEdgeID id) const
135
    inline HalfEdgeID ConnectivityKernel::out(VertexID id) const
129
	{ return HalfEdgeID(halfedges[id.idx()].opp); }
136
    { return HalfEdgeID(vertices[id.idx()].out); }
130
 
137
 
131
	inline HalfEdgeID ConnectivityKernel::out(VertexID id) const
138
    inline HalfEdgeID ConnectivityKernel::last(FaceID id) const
132
	{ return HalfEdgeID(vertices[id.idx()].out); }
139
    { return HalfEdgeID(faces[id.idx()].last); }
133
 
140
 
134
	inline HalfEdgeID ConnectivityKernel::last(FaceID id) const
141
    inline VertexID ConnectivityKernel::vert(HalfEdgeID id) const
135
	{ return HalfEdgeID(faces[id.idx()].last); }
142
    { return VertexID(halfedges[id.idx()].vert); }
136
 
143
 
137
	inline VertexID ConnectivityKernel::vert(HalfEdgeID id) const
144
    inline FaceID ConnectivityKernel::face(HalfEdgeID id) const
138
	{ return VertexID(halfedges[id.idx()].vert); }
145
    { return FaceID(halfedges[id.idx()].face); }
139
 
146
 
140
	inline FaceID ConnectivityKernel::face(HalfEdgeID id) const
147
    inline void ConnectivityKernel::set_next(HalfEdgeID id, HalfEdgeID next)
141
	{ return FaceID(halfedges[id.idx()].face); }
148
    { halfedges[id.idx()].next = next; }
142
 
149
 
143
	inline void ConnectivityKernel::set_next(HalfEdgeID id, HalfEdgeID next)
150
    inline void ConnectivityKernel::set_prev(HalfEdgeID id, HalfEdgeID prev)
144
	{ halfedges[id.idx()].next = next; }
151
    { halfedges[id.idx()].prev = prev; }
145
 
152
 
146
	inline void ConnectivityKernel::set_prev(HalfEdgeID id, HalfEdgeID prev)
153
    inline void ConnectivityKernel::set_opp(HalfEdgeID id, HalfEdgeID opp)
147
	{ halfedges[id.idx()].prev = prev; }
154
    {halfedges[id.idx()].opp = opp; }
148
 
155
 
149
	inline void ConnectivityKernel::set_opp(HalfEdgeID id, HalfEdgeID opp)
156
    inline void ConnectivityKernel::set_out(VertexID id, HalfEdgeID out)
150
	{halfedges[id.idx()].opp = opp; }
157
    { vertices[id.idx()].out = out; }
151
 
158
 
152
	inline void ConnectivityKernel::set_out(VertexID id, HalfEdgeID out)
159
    inline void ConnectivityKernel::set_last(FaceID id, HalfEdgeID last)
153
	{ vertices[id.idx()].out = out; }
160
    { faces[id.idx()].last = last; }
154
 
161
 
155
	inline void ConnectivityKernel::set_last(FaceID id, HalfEdgeID last)
162
    inline void ConnectivityKernel::set_vert(HalfEdgeID id, VertexID vert)
156
	{ faces[id.idx()].last = last; }
163
    { halfedges[id.idx()].vert = vert; }
157
 
164
 
158
	inline void ConnectivityKernel::set_vert(HalfEdgeID id, VertexID vert)
165
    inline void ConnectivityKernel::set_face(HalfEdgeID id, FaceID face)
159
	{ halfedges[id.idx()].vert = vert; }
166
    { halfedges[id.idx()].face = face; }
160
 
167
 
161
	inline void ConnectivityKernel::set_face(HalfEdgeID id, FaceID face)
168
    inline IndexType ConnectivityKernel::no_vertices(bool active) const
162
	{ halfedges[id.idx()].face = face; }
169
    { return vertices.size(active); }
163
 
170
 
164
	inline IndexType ConnectivityKernel::no_vertices(bool active) const
171
    inline IndexType ConnectivityKernel::no_faces(bool active) const
165
	{ return vertices.size(active); }
172
    { return faces.size(active); }
166
 
173
 
167
	inline IndexType ConnectivityKernel::no_faces(bool active) const
174
    inline IndexType ConnectivityKernel::no_halfedges(bool active) const
168
	{ return faces.size(active); }
175
    { return halfedges.size(active); }
169
 
176
 
170
	inline IndexType ConnectivityKernel::no_halfedges(bool active) const
177
    inline bool ConnectivityKernel::in_use(VertexID id) const
171
	{ return halfedges.size(active); }
178
    { return vertices.in_use(id.idx()); }
172
 
179
 
173
	inline bool ConnectivityKernel::in_use(VertexID id) const
180
    inline bool ConnectivityKernel::in_use(FaceID id) const
174
	{ return vertices.in_use(id.idx()); }
181
    { return faces.in_use(id.idx()); }
175
 
182
 
176
	inline bool ConnectivityKernel::in_use(FaceID id) const
183
    inline bool ConnectivityKernel::in_use(HalfEdgeID id) const
177
	{ return faces.in_use(id.idx()); }
184
    { return halfedges.in_use(id.idx()); }
178
 
185
 
179
	inline bool ConnectivityKernel::in_use(HalfEdgeID id) const
186
    inline VertexID ConnectivityKernel::vertices_next(VertexID id, bool skip) const
180
	{ return halfedges.in_use(id.idx()); }
187
    { return vertices.index_next(id.idx(), skip); }
181
 
188
 
182
	inline VertexID ConnectivityKernel::vertices_next(VertexID id, bool skip) const
189
    inline HalfEdgeID ConnectivityKernel::halfedges_next(HalfEdgeID id, bool skip) const
183
	{ return vertices.index_next(id.idx(), skip); }
190
    { return halfedges.index_next(id.idx(), skip); }
184
 
191
 
185
	inline HalfEdgeID ConnectivityKernel::halfedges_next(HalfEdgeID id, bool skip) const
192
    inline FaceID ConnectivityKernel::faces_next(FaceID id, bool skip) const
186
	{ return halfedges.index_next(id.idx(), skip); }
193
    { return faces.index_next(id.idx(), skip); }
187
 
194
 
188
	inline FaceID ConnectivityKernel::faces_next(FaceID id, bool skip) const
195
    inline VertexID ConnectivityKernel::vertices_prev(VertexID id, bool skip) const
189
	{ return faces.index_next(id.idx(), skip); }
196
    { return vertices.index_prev(id.idx(), skip); }
190
 
197
 
191
	inline VertexID ConnectivityKernel::vertices_prev(VertexID id, bool skip) const
198
    inline HalfEdgeID ConnectivityKernel::halfedges_prev(HalfEdgeID id, bool skip) const
192
	{ return vertices.index_prev(id.idx(), skip); }
199
    { return halfedges.index_prev(id.idx(), skip); }
193
 
200
 
194
	inline HalfEdgeID ConnectivityKernel::halfedges_prev(HalfEdgeID id, bool skip) const
201
    inline FaceID ConnectivityKernel::faces_prev(FaceID id, bool skip) const
195
	{ return halfedges.index_prev(id.idx(), skip); }
202
    { return faces.index_prev(id.idx(), skip); }
196
 
203
 
197
	inline FaceID ConnectivityKernel::faces_prev(FaceID id, bool skip) const
-
 
198
	{ return faces.index_prev(id.idx(), skip); }
-
 
199
		
-
 
200
	inline VertexID ConnectivityKernel::vertices_begin(bool skip) const
204
    inline VertexID ConnectivityKernel::vertices_begin(bool skip) const
201
	{ return vertices.index_begin(skip); }
205
    { return vertices.index_begin(skip); }
202
 
206
 
203
    inline HalfEdgeID ConnectivityKernel::halfedges_begin(bool skip) const
207
    inline HalfEdgeID ConnectivityKernel::halfedges_begin(bool skip) const
204
	{ return halfedges.index_begin(skip); }
208
    { return halfedges.index_begin(skip); }
205
 
209
 
206
    inline FaceID ConnectivityKernel::faces_begin(bool skip) const
210
    inline FaceID ConnectivityKernel::faces_begin(bool skip) const
207
	{ return faces.index_begin(skip); }
211
    { return faces.index_begin(skip); }
208
 
212
 
209
    inline VertexID ConnectivityKernel::vertices_end() const
213
    inline VertexID ConnectivityKernel::vertices_end() const
210
	{ return vertices.index_end(); }
214
    { return vertices.index_end(); }
211
 
215
 
212
    inline HalfEdgeID ConnectivityKernel::halfedges_end() const
216
    inline HalfEdgeID ConnectivityKernel::halfedges_end() const
213
	{ return halfedges.index_end(); }
217
    { return halfedges.index_end(); }
214
 
218
 
215
    inline FaceID ConnectivityKernel::faces_end() const
219
    inline FaceID ConnectivityKernel::faces_end() const
216
	{ return faces.index_end(); }
220
    { return faces.index_end(); }
217
 
221
 
218
	inline void ConnectivityKernel::clear()
222
    inline void ConnectivityKernel::clear()
219
	{
223
    {
220
		vertices.clear();
224
        vertices.clear();
221
		faces.clear();
225
        faces.clear();
222
		halfedges.clear();
226
        halfedges.clear();
223
	}
227
    }
224
 
228
 
225
	inline void ConnectivityKernel::cleanup()
229
    inline void ConnectivityKernel::cleanup()
226
	{
230
    {
227
		vertices.cleanup();
231
        vertices.cleanup();
228
		faces.cleanup();
232
        faces.cleanup();
229
		halfedges.cleanup();
233
        halfedges.cleanup();
230
	}
234
    }
231
}
235
}
232
 
236
 
233
#endif
237
#endif
234
 
238