cursors.hh 6.54 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
22
struct vertex_handle;
struct face_handle;
struct edge_handle;
struct halfedge_handle;

struct face_vertex_ring;

23
24
25
26
27
28
29
30
31
32
33
34
35
36
// ======================== 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
37
38

    template <typename PropT>
39
    PropT& operator[](face_attribute<PropT>& prop) const;
Philip Trettner's avatar
Philip Trettner committed
40
    template <typename PropT>
41
    PropT const& operator[](face_attribute<PropT> const& prop) const;
42
43
44
45
46
47
48
49
50
51
52
53
54
55
};

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
56
57

    template <typename PropT>
58
    PropT& operator[](vertex_attribute<PropT>& prop) const;
Philip Trettner's avatar
Philip Trettner committed
59
    template <typename PropT>
60
    PropT const& operator[](vertex_attribute<PropT> const& prop) const;
61
62
63
64
65
66
67
68
69
70
71
72
73
74
};

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
75
76

    template <typename PropT>
77
    PropT& operator[](edge_attribute<PropT>& prop) const;
Philip Trettner's avatar
Philip Trettner committed
78
    template <typename PropT>
79
    PropT const& operator[](edge_attribute<PropT> const& prop) const;
80
81
82
83
84
85
86
87
88
89
90
91
92
93
};

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
94
95

    template <typename PropT>
96
    PropT& operator[](halfedge_attribute<PropT>& prop) const;
Philip Trettner's avatar
Philip Trettner committed
97
    template <typename PropT>
98
    PropT const& operator[](halfedge_attribute<PropT> const& prop) const;
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
};

// ======================== 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; }
114

Philip Trettner's avatar
Philip Trettner committed
115
    template <typename PropT>
116
    PropT& operator[](face_attribute<PropT>& prop) const;
Philip Trettner's avatar
Philip Trettner committed
117
    template <typename PropT>
118
    PropT const& operator[](face_attribute<PropT> const& prop) const;
Philip Trettner's avatar
Philip Trettner committed
119

120
    bool is_valid() const;   ///< valid idx and not deleted
Philip Trettner's avatar
Philip Trettner committed
121
    bool is_removed() const; ///< marked for deletion (or invalid idx)
Philip Trettner's avatar
Philip Trettner committed
122
123
124
125
126
127
128
129
130
131
132

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

    face_vertex_ring vertices() const;

    // TODO:
    // faces (1-ring)
    // edges
    // halfedges
    // vertices
133
134
135
136
137
138
139
140
141
142
143
144
145
};

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; }
146

Philip Trettner's avatar
Philip Trettner committed
147
    template <typename PropT>
148
    PropT& operator[](vertex_attribute<PropT>& prop) const;
Philip Trettner's avatar
Philip Trettner committed
149
    template <typename PropT>
150
    PropT const& operator[](vertex_attribute<PropT> const& prop) const;
Philip Trettner's avatar
Philip Trettner committed
151

152
    bool is_valid() const;   ///< valid idx and not deleted
Philip Trettner's avatar
Philip Trettner committed
153
    bool is_removed() const; ///< marked for deletion (or invalid idx)
Philip Trettner's avatar
Philip Trettner committed
154
155
156

    face_handle any_face() const;
    halfedge_handle any_halfedge() const;
157
158
159
160
161
162
163
164
165
166
167
168
169
};

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; }
170

Philip Trettner's avatar
Philip Trettner committed
171
    template <typename PropT>
172
    PropT& operator[](edge_attribute<PropT>& prop) const;
Philip Trettner's avatar
Philip Trettner committed
173
    template <typename PropT>
174
    PropT const& operator[](edge_attribute<PropT> const& prop) const;
Philip Trettner's avatar
Philip Trettner committed
175

176
    bool is_valid() const;   ///< valid idx and not deleted
Philip Trettner's avatar
Philip Trettner committed
177
    bool is_removed() const; ///< marked for deletion (or invalid idx)
Philip Trettner's avatar
Philip Trettner committed
178
179
180

    halfedge_handle halfedgeA() const;
    halfedge_handle halfedgeB() const;
181
182
183
184
185
186
187
188
189
190
191
192
193
};

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
194

Philip Trettner's avatar
Philip Trettner committed
195
    template <typename PropT>
196
    PropT& operator[](halfedge_attribute<PropT>& prop) const;
Philip Trettner's avatar
Philip Trettner committed
197
    template <typename PropT>
198
    PropT const& operator[](halfedge_attribute<PropT> const& prop) const;
Philip Trettner's avatar
Philip Trettner committed
199

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

Philip Trettner's avatar
Philip Trettner committed
203
204
205
206
207
208
209
    vertex_handle vertex_to() const;
    vertex_handle vertex_from() const;
    face_handle face() const;
    halfedge_handle next() const;
    halfedge_handle prev() const;
    halfedge_handle opposite() const;
    face_handle opposite_face() const;
210
};
211

212
}