cursors.hh 7.28 KB
Newer Older
1
2
3
4
#pragma once

namespace polymesh
{
Philip Trettner's avatar
Philip Trettner committed
5
6
7
class Mesh;

template <typename PropT>
8
struct vertex_attribute;
Philip Trettner's avatar
Philip Trettner committed
9
template <typename PropT>
10
struct face_attribute;
Philip Trettner's avatar
Philip Trettner committed
11
template <typename PropT>
12
struct edge_attribute;
Philip Trettner's avatar
Philip Trettner committed
13
template <typename PropT>
14
struct halfedge_attribute;
15

Philip Trettner's avatar
Philip Trettner committed
16
17
18
19
20
21
struct vertex_handle;
struct face_handle;
struct edge_handle;
struct halfedge_handle;

struct face_vertex_ring;
22
23
24
25
26
27
28
29
30
struct face_edge_ring;
struct face_halfedge_ring;
struct face_face_ring;

struct vertex_halfedge_out_ring;
struct vertex_halfedge_in_ring;
struct vertex_face_ring;
struct vertex_edge_ring;
struct vertex_vertex_ring;
Philip Trettner's avatar
Philip Trettner committed
31

32
33
34
35
36
37
38
39
40
41
42
43
44
45
// ======================== INDICES ========================

struct face_index
{
    int value = -1;

    face_index() = default;
    explicit face_index(int idx) : value(idx) {}

    bool is_valid() const { return value >= 0; }
    static face_index invalid() { return {}; }

    bool operator==(face_index const& rhs) const { return value == rhs.value; }
    bool operator!=(face_index const& rhs) const { return value != rhs.value; }
Philip Trettner's avatar
Philip Trettner committed
46
47

    template <typename PropT>
48
    PropT& operator[](face_attribute<PropT>& prop) const;
Philip Trettner's avatar
Philip Trettner committed
49
    template <typename PropT>
50
    PropT const& operator[](face_attribute<PropT> const& prop) const;
51
52
53
54
55
56
57
58
59
60
61
62
63
64
};

struct vertex_index
{
    int value = -1;

    vertex_index() = default;
    explicit vertex_index(int idx) : value(idx) {}

    bool is_valid() const { return value >= 0; }
    static vertex_index invalid() { return {}; }

    bool operator==(vertex_index const& rhs) const { return value == rhs.value; }
    bool operator!=(vertex_index const& rhs) const { return value != rhs.value; }
Philip Trettner's avatar
Philip Trettner committed
65
66

    template <typename PropT>
67
    PropT& operator[](vertex_attribute<PropT>& prop) const;
Philip Trettner's avatar
Philip Trettner committed
68
    template <typename PropT>
69
    PropT const& operator[](vertex_attribute<PropT> const& prop) const;
70
71
72
73
74
75
76
77
78
79
80
81
82
83
};

struct edge_index
{
    int value = -1;

    edge_index() = default;
    explicit edge_index(int idx) : value(idx) {}

    bool is_valid() const { return value >= 0; }
    static edge_index invalid() { return {}; }

    bool operator==(edge_index const& rhs) const { return value == rhs.value; }
    bool operator!=(edge_index const& rhs) const { return value != rhs.value; }
Philip Trettner's avatar
Philip Trettner committed
84
85

    template <typename PropT>
86
    PropT& operator[](edge_attribute<PropT>& prop) const;
Philip Trettner's avatar
Philip Trettner committed
87
    template <typename PropT>
88
    PropT const& operator[](edge_attribute<PropT> const& prop) const;
89
90
91
92
93
94
95
96
97
98
99
100
101
102
};

struct halfedge_index
{
    int value = -1;

    halfedge_index() = default;
    explicit halfedge_index(int idx) : value(idx) {}

    bool is_valid() const { return value >= 0; }
    static halfedge_index invalid() { return {}; }

    bool operator==(halfedge_index const& rhs) const { return value == rhs.value; }
    bool operator!=(halfedge_index const& rhs) const { return value != rhs.value; }
Philip Trettner's avatar
Philip Trettner committed
103
104

    template <typename PropT>
105
    PropT& operator[](halfedge_attribute<PropT>& prop) const;
Philip Trettner's avatar
Philip Trettner committed
106
    template <typename PropT>
107
    PropT const& operator[](halfedge_attribute<PropT> const& prop) const;
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
};

// ======================== HANDLES ========================

struct face_handle
{
    Mesh const* mesh;
    face_index idx;

    face_handle(Mesh const* mesh, face_index idx) : mesh(mesh), idx(idx) {}

    bool operator==(face_index const& rhs) const { return idx == rhs; }
    bool operator!=(face_index const& rhs) const { return idx != rhs; }
    bool operator==(face_handle const& rhs) const { return mesh == rhs.mesh && idx == rhs.idx; }
    bool operator!=(face_handle const& rhs) const { return mesh != rhs.mesh || idx != rhs.idx; }
123

Philip Trettner's avatar
Philip Trettner committed
124
    template <typename PropT>
125
    PropT& operator[](face_attribute<PropT>& prop) const;
Philip Trettner's avatar
Philip Trettner committed
126
    template <typename PropT>
127
    PropT const& operator[](face_attribute<PropT> const& prop) const;
Philip Trettner's avatar
Philip Trettner committed
128

129
    bool is_valid() const;   ///< valid idx and not deleted
Philip Trettner's avatar
Philip Trettner committed
130
    bool is_removed() const; ///< marked for deletion (or invalid idx)
Philip Trettner's avatar
Philip Trettner committed
131
132
133
134
135

    vertex_handle any_vertex() const;
    halfedge_handle any_halfedge() const;

    face_vertex_ring vertices() const;
136
137
138
    face_edge_ring edges() const;
    face_halfedge_ring halfedges() const;
    face_face_ring adjacent_faces() const;
139
140
141
142
143
144
145
146
147
148
149
150
151
};

struct vertex_handle
{
    Mesh const* mesh;
    vertex_index idx;

    vertex_handle(Mesh const* mesh, vertex_index idx) : mesh(mesh), idx(idx) {}

    bool operator==(vertex_index const& rhs) const { return idx == rhs; }
    bool operator!=(vertex_index const& rhs) const { return idx != rhs; }
    bool operator==(vertex_handle const& rhs) const { return mesh == rhs.mesh && idx == rhs.idx; }
    bool operator!=(vertex_handle const& rhs) const { return mesh != rhs.mesh || idx != rhs.idx; }
152

Philip Trettner's avatar
Philip Trettner committed
153
    template <typename PropT>
154
    PropT& operator[](vertex_attribute<PropT>& prop) const;
Philip Trettner's avatar
Philip Trettner committed
155
    template <typename PropT>
156
    PropT const& operator[](vertex_attribute<PropT> const& prop) const;
Philip Trettner's avatar
Philip Trettner committed
157

158
    bool is_valid() const;   ///< valid idx and not deleted
Philip Trettner's avatar
Philip Trettner committed
159
    bool is_removed() const; ///< marked for deletion (or invalid idx)
Philip Trettner's avatar
Philip Trettner committed
160
161

    face_handle any_face() const;
162
163
164
165
166
167
168
169
    halfedge_handle any_outgoing_halfedge() const;
    halfedge_handle any_incoming_halfedge() const;

    vertex_halfedge_in_ring incoming_halfedges() const;
    vertex_halfedge_out_ring outcoming_halfedges() const;
    vertex_edge_ring edges() const;
    vertex_face_ring faces() const; ///< includes invalid ones for boundaries!
    vertex_vertex_ring adjacent_vertices() const;
170
171
172
173
174
175
176
177
178
179
180
181
182
};

struct edge_handle
{
    Mesh const* mesh;
    edge_index idx;

    edge_handle(Mesh const* mesh, edge_index idx) : mesh(mesh), idx(idx) {}

    bool operator==(edge_index const& rhs) const { return idx == rhs; }
    bool operator!=(edge_index const& rhs) const { return idx != rhs; }
    bool operator==(edge_handle const& rhs) const { return mesh == rhs.mesh && idx == rhs.idx; }
    bool operator!=(edge_handle const& rhs) const { return mesh != rhs.mesh || idx != rhs.idx; }
183

Philip Trettner's avatar
Philip Trettner committed
184
    template <typename PropT>
185
    PropT& operator[](edge_attribute<PropT>& prop) const;
Philip Trettner's avatar
Philip Trettner committed
186
    template <typename PropT>
187
    PropT const& operator[](edge_attribute<PropT> const& prop) const;
Philip Trettner's avatar
Philip Trettner committed
188

189
    bool is_valid() const;   ///< valid idx and not deleted
Philip Trettner's avatar
Philip Trettner committed
190
    bool is_removed() const; ///< marked for deletion (or invalid idx)
Philip Trettner's avatar
Philip Trettner committed
191
192
193

    halfedge_handle halfedgeA() const;
    halfedge_handle halfedgeB() const;
194
195
196
197
    vertex_handle vertexA() const;
    vertex_handle vertexB() const;
    face_handle faceA() const;
    face_handle faceB() const;
198
199
200
201
202
203
204
205
206
207
208
209
210
};

struct halfedge_handle
{
    Mesh const* mesh;
    halfedge_index idx;

    halfedge_handle(Mesh const* mesh, halfedge_index idx) : mesh(mesh), idx(idx) {}

    bool operator==(halfedge_index const& rhs) const { return idx == rhs; }
    bool operator!=(halfedge_index const& rhs) const { return idx != rhs; }
    bool operator==(halfedge_handle const& rhs) const { return mesh == rhs.mesh && idx == rhs.idx; }
    bool operator!=(halfedge_handle const& rhs) const { return mesh != rhs.mesh || idx != rhs.idx; }
Philip Trettner's avatar
Philip Trettner committed
211

Philip Trettner's avatar
Philip Trettner committed
212
    template <typename PropT>
213
    PropT& operator[](halfedge_attribute<PropT>& prop) const;
Philip Trettner's avatar
Philip Trettner committed
214
    template <typename PropT>
215
    PropT const& operator[](halfedge_attribute<PropT> const& prop) const;
Philip Trettner's avatar
Philip Trettner committed
216

217
    bool is_valid() const;   ///< valid idx and not deleted
Philip Trettner's avatar
Philip Trettner committed
218
    bool is_removed() const; ///< marked for deletion (or invalid idx)
219

Philip Trettner's avatar
Philip Trettner committed
220
221
    vertex_handle vertex_to() const;
    vertex_handle vertex_from() const;
222
    edge_handle edge() const;
Philip Trettner's avatar
Philip Trettner committed
223
224
225
226
227
    face_handle face() const;
    halfedge_handle next() const;
    halfedge_handle prev() const;
    halfedge_handle opposite() const;
    face_handle opposite_face() const;
228
};
229

230
}