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

namespace polymesh
{
Philip Trettner's avatar
Philip Trettner committed
5
6
7
8
9
10
11
12
13
14
class Mesh;

template <typename PropT>
struct vertex_property;
template <typename PropT>
struct face_property;
template <typename PropT>
struct edge_property;
template <typename PropT>
struct halfedge_property;
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

// ======================== 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
30
31
32
33
34

    template <typename PropT>
    PropT& operator[](face_property<PropT>& prop) const;
    template <typename PropT>
    PropT const& operator[](face_property<PropT> const& prop) const;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
};

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
49
50
51
52
53

    template <typename PropT>
    PropT& operator[](vertex_property<PropT>& prop) const;
    template <typename PropT>
    PropT const& operator[](vertex_property<PropT> const& prop) const;
54
55
56
57
58
59
60
61
62
63
64
65
66
67
};

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
68
69
70
71
72

    template <typename PropT>
    PropT& operator[](edge_property<PropT>& prop) const;
    template <typename PropT>
    PropT const& operator[](edge_property<PropT> const& prop) const;
73
74
75
76
77
78
79
80
81
82
83
84
85
86
};

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
87
88
89
90
91

    template <typename PropT>
    PropT& operator[](halfedge_property<PropT>& prop) const;
    template <typename PropT>
    PropT const& operator[](halfedge_property<PropT> const& prop) const;
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
};

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

Philip Trettner's avatar
Philip Trettner committed
108
109
110
111
112
    template <typename PropT>
    PropT& operator[](face_property<PropT>& prop) const;
    template <typename PropT>
    PropT const& operator[](face_property<PropT> const& prop) const;

113
114
    bool is_valid() const;   ///< valid idx and not deleted
    bool is_deleted() const; ///< marked for deletion (or invalid idx)
115
116
117
118
119
120
121
122
123
124
125
126
127
};

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

Philip Trettner's avatar
Philip Trettner committed
129
130
131
132
133
    template <typename PropT>
    PropT& operator[](vertex_property<PropT>& prop) const;
    template <typename PropT>
    PropT const& operator[](vertex_property<PropT> const& prop) const;

134
135
    bool is_valid() const;   ///< valid idx and not deleted
    bool is_deleted() const; ///< marked for deletion (or invalid idx)
136
137
138
139
140
141
142
143
144
145
146
147
148
};

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

Philip Trettner's avatar
Philip Trettner committed
150
151
152
153
154
    template <typename PropT>
    PropT& operator[](edge_property<PropT>& prop) const;
    template <typename PropT>
    PropT const& operator[](edge_property<PropT> const& prop) const;

155
156
    bool is_valid() const;   ///< valid idx and not deleted
    bool is_deleted() const; ///< marked for deletion (or invalid idx)
157
158
159
160
161
162
163
164
165
166
167
168
169
};

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
170

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

176
177
178
    bool is_valid() const;   ///< valid idx and not deleted
    bool is_deleted() const; ///< marked for deletion (or invalid idx)

Philip Trettner's avatar
Philip Trettner committed
179
180
181
182
183
184
    // TODO:
    // vertex_to
    // vertex_from
    // face
    // opposite_face
    // opposite
185
};
186

187
}