ranges.hh 6.89 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#pragma once

#include <cstddef>
#include <vector>

#include "iterators.hh"

namespace polymesh
{
/// Collection of all vertices of a mesh, including deleted ones
/// Basically a smart std::vector
struct vertex_collection
{
    Mesh* mesh;

    /// Number of vertices, INCLUDING deleted/invalid ones
    /// O(1) computation
    int size() const;
    /// Ensures that a given number of vertices can be stored without reallocation
    void reserve(int capacity) const;

    /// Adds a new vertex and returns its handle
    /// Does NOT invalidate any iterator!
    vertex_handle add() const;

    // TODO: delete

Philip Trettner's avatar
Philip Trettner committed
28
29
30
31
    /// Creates a new vertex property
    template<typename PropT>
    vertex_property<PropT> make_property(PropT const& def_value = PropT());

32
33
34
35
36
    // Iteration:
    vertex_iterator begin() const;
    vertex_iterator end() const;
};

37
38
39
40
41
42
43
44
45
46
47
48
49
50
/// same as vertex_collection but const
struct const_vertex_collection
{
    Mesh const* mesh;

    /// Number of vertices, INCLUDING deleted/invalid ones
    /// O(1) computation
    int size() const;

    // Iteration:
    vertex_iterator begin() const;
    vertex_iterator end() const;
};

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/// Same as vertex_collection but only including valid, non-deleted vertices
/// (a bit slower than the normal collection)
/// (if mesh->is_compact(), identical to vertex_collection)
struct valid_vertex_collection
{
    Mesh const* mesh;

    /// Number of vertices, EXCLUDING deleted/invalid ones
    /// O(1) computation
    int size() const;

    // Iteration:
    valid_vertex_iterator begin() const;
    valid_vertex_iterator end() const;
};

/// Collection of all faces of a mesh, including deleted ones
/// Basically a smart std::vector
struct face_collection
{
    Mesh* mesh;

    /// Number of vertices, INCLUDING deleted/invalid ones
    /// O(1) computation
    int size() const;
    /// Ensures that a given number of faces can be stored without reallocation
    void reserve(int capacity) const;

    /// Adds a face consisting of N vertices
    /// The vertices must already be sorted in CCW order
    /// (note: trying to add already existing halfedges triggers assertions)
    template <size_t N>
Philip Trettner's avatar
Philip Trettner committed
83
84
85
86
87
    face_handle add(const vertex_handle (&v_handles)[N]) const;
    face_handle add(vertex_handle v0, vertex_handle v1, vertex_handle v2) const;
    face_handle add(vertex_handle v0, vertex_handle v1, vertex_handle v2, vertex_handle v3) const;
    face_handle add(std::vector<vertex_handle> const& v_handles) const;
    face_handle add(vertex_handle const* v_handles, size_t vcnt) const;
Philip Trettner's avatar
Philip Trettner committed
88
    template <size_t N>
Philip Trettner's avatar
Philip Trettner committed
89
90
91
92
93
    face_handle add(const halfedge_handle (&half_loop)[N]) const;
    face_handle add(halfedge_handle h0, halfedge_handle h1, halfedge_handle h2) const;
    face_handle add(halfedge_handle h0, halfedge_handle h1, halfedge_handle h2, halfedge_handle h3) const;
    face_handle add(std::vector<halfedge_handle> const& half_loop) const;
    face_handle add(halfedge_handle const* half_loop, size_t vcnt) const;
94
95
96

    // TODO: delete

Philip Trettner's avatar
Philip Trettner committed
97
98
99
100
    /// Creates a new face property
    template<typename PropT>
    face_property<PropT> make_property(PropT const& def_value = PropT());

101
102
103
104
105
    // Iteration:
    face_iterator begin() const;
    face_iterator end() const;
};

106
107
108
109
110
111
112
113
114
115
116
117
118
119
/// same as face_collection but const
struct const_face_collection
{
    Mesh const* mesh;

    /// Number of faces, INCLUDING deleted/invalid ones
    /// O(1) computation
    int size() const;

    // Iteration:
    face_iterator begin() const;
    face_iterator end() const;
};

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/// Same as face_collection but only including valid, non-deleted faces
/// (a bit slower than the normal collection)
/// (if mesh->is_compact(), identical to face_collection)
struct valid_face_collection
{
    Mesh const* mesh;

    /// Number of faces, EXCLUDING deleted/invalid ones
    /// O(1) computation
    int size() const;

    // Iteration:
    valid_face_iterator begin() const;
    valid_face_iterator end() const;
};

/// Collection of all edges of a mesh, including deleted ones
/// Basically a smart std::vector
struct edge_collection
{
    Mesh* mesh;

    /// Number of vertices, INCLUDING deleted/invalid ones
    /// O(1) computation
    int size() const;
    /// Ensures that a given number of edges can be stored without reallocation
    void reserve(int capacity) const;

Philip Trettner's avatar
Philip Trettner committed
148
149
150
151
    /// Adds an edge between two existing, distinct vertices
    /// if edge already exists, returns it
    edge_handle add_or_get(vertex_handle v_from, vertex_handle v_to);

Philip Trettner's avatar
Philip Trettner committed
152
153
154
155
156
157
    // TODO: delete

    /// Creates a new edge property
    template<typename PropT>
    edge_property<PropT> make_property(PropT const& def_value = PropT());

158
159
160
161
162
    // Iteration:
    edge_iterator begin() const;
    edge_iterator end() const;
};

163
164
165
166
167
168
169
170
171
172
173
174
175
176
/// same as edge_collection but const
struct const_edge_collection
{
    Mesh const* mesh;

    /// Number of edges, INCLUDING deleted/invalid ones
    /// O(1) computation
    int size() const;

    // Iteration:
    edge_iterator begin() const;
    edge_iterator end() const;
};

177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/// Same as edge_collection but only including valid, non-deleted edges
/// (a bit slower than the normal collection)
/// (if mesh->is_compact(), identical to edge_collection)
struct valid_edge_collection
{
    Mesh const* mesh;

    /// Number of edges, EXCLUDING deleted/invalid ones
    /// O(1) computation
    int size() const;

    // Iteration:
    valid_edge_iterator begin() const;
    valid_edge_iterator end() const;
};

/// Collection of all half-edges of a mesh, including deleted ones
/// Basically a smart std::vector
struct halfedge_collection
{
    Mesh* mesh;

    /// Number of vertices, INCLUDING deleted/invalid ones
    /// O(1) computation
    int size() const;
    /// Ensures that a given number of half-edges can be stored without reallocation
    void reserve(int capacity) const;

Philip Trettner's avatar
Philip Trettner committed
205
206
207
208
209
    /// Adds an half-edge between two existing, distinct vertices
    /// if half-edge already exists, returns it
    /// (always adds opposite half-edge as well)
    halfedge_handle add_or_get(vertex_handle v_from, vertex_handle v_to);

Philip Trettner's avatar
Philip Trettner committed
210
211
212
213
    /// Creates a new half-edge property
    template<typename PropT>
    halfedge_property<PropT> make_property(PropT const& def_value = PropT());

214
215
216
217
218
    // Iteration:
    halfedge_iterator begin() const;
    halfedge_iterator end() const;
};

219
220
221
222
223
224
225
226
227
228
229
230
231
232
/// same as halfedge_collection but const
struct const_halfedge_collection
{
    Mesh const* mesh;

    /// Number of halfedges, INCLUDING deleted/invalid ones
    /// O(1) computation
    int size() const;

    // Iteration:
    halfedge_iterator begin() const;
    halfedge_iterator end() const;
};

233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/// Same as halfedge_collection but only including valid, non-deleted halfedges
/// (a bit slower than the normal collection)
/// (if mesh->is_compact(), identical to halfedge_collection)
struct valid_halfedge_collection
{
    Mesh const* mesh;

    /// Number of halfedges, EXCLUDING deleted/invalid ones
    /// O(1) computation
    int size() const;

    // Iteration:
    valid_halfedge_iterator begin() const;
    valid_halfedge_iterator end() const;
};
Philip Trettner's avatar
Philip Trettner committed
248

249
}