OpenMesh: OpenMesh/Core/Utils/Predicates.hh Source File

| OpenMesh

Predicates.hh
1 /* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2020, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openmesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenMesh. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 * ========================================================================= */
41
42
43 #pragma once
44
45 #include <OpenMesh/Core/Mesh/PolyConnectivity.hh>
46 #include <OpenMesh/Core/Utils/PropertyManager.hh>
47
48 #include <utility>
49 #include <array>
50 #include <vector>
51 #include <set>
52 #include <type_traits>
53
54 //== NAMESPACES ===============================================================
55
56 namespace OpenMesh {
57
58 namespace Predicates {
59
60 //== FORWARD DECLARATION ======================================================
61
62 //== CLASS DEFINITION =========================================================
63
64 template <typename PredicateT>
65 struct PredicateBase
66 {
67 };
68
69 template <typename PredicateT>
70 struct Predicate : public PredicateBase<Predicate<PredicateT>>
71 {
72 Predicate(PredicateT _p)
73 :
74 p_(_p)
75 {}
76
77 template <typename T>
78 bool operator()(const T& _t) const { return p_(_t); }
79
80 PredicateT p_;
81 };
82
83 template <typename PredicateT>
84 Predicate<const PredicateT&> make_predicate(PredicateT& _p) { return { _p }; }
85
86 template <typename PredicateT>
87 Predicate<PredicateT> make_predicate(PredicateT&& _p) { return { _p }; }
88
89 template <typename Predicate1T, typename Predicate2T>
90 struct Disjunction : public PredicateBase<Disjunction<Predicate1T, Predicate2T>>
91 {
92 Disjunction(Predicate1T _p1, Predicate2T _p2)
93 :
94 p1_(_p1),
95 p2_(_p2)
96 {}
97
98 template <typename T>
99 bool operator()(const T& _t) const { return p1_( _t) || p2_( _t); }
100
101 Predicate1T p1_;
102 Predicate2T p2_;
103 };
104
105 template <typename Predicate1T, typename Predicate2T>
106 struct Conjunction : public PredicateBase<Conjunction<Predicate1T, Predicate2T>>
107 {
108 Conjunction(Predicate1T _p1, Predicate2T _p2)
109 :
110 p1_(_p1),
111 p2_(_p2)
112 {}
113
114 template <typename T>
115 bool operator()(const T& _t) const { return p1_( _t) && p2_( _t); }
116
117 Predicate1T p1_;
118 Predicate2T p2_;
119 };
120
121
122 template <typename PredicateT>
123 struct Negation : public PredicateBase<Negation<PredicateT>>
124 {
125 Negation(const PredicateT& _p1)
126 :
127 p1_(_p1)
128 {}
129
130 template <typename T>
131 bool operator()(const T& _t) const { return !p1_( _t); }
132
133 PredicateT p1_;
134 };
135
136 template <typename P1, typename P2>
137 Disjunction<const P1&, const P2&> operator||(PredicateBase<P1>& p1, PredicateBase<P2>& p2)
138 {
139 return Disjunction<const P1&, const P2&>(static_cast<const P1&>(p1), static_cast<const P2&>(p2));
140 }
141
142 template <typename P1, typename P2>
143 Disjunction<const P1&, P2> operator||(PredicateBase<P1>& p1, PredicateBase<P2>&& p2)
144 {
145 return Disjunction<const P1&, P2>(static_cast<const P1&>(p1), static_cast<P2&&>(p2));
146 }
147
148 template <typename P1, typename P2>
149 Disjunction<P1, const P2&> operator||(PredicateBase<P1>&& p1, PredicateBase<P2>& p2)
150 {
151 return Disjunction<P1, const P2&>(static_cast<P1&&>(p1), static_cast<const P2&>(p2));
152 }
153
154 template <typename P1, typename P2>
155 Disjunction<P1, P2> operator||(PredicateBase<P1>&& p1, PredicateBase<P2>&& p2)
156 {
157 return Disjunction<P1, P2>(static_cast<P1&&>(p1), static_cast<P2&&>(p2));
158 }
159
160 template <typename P1, typename P2>
161 Conjunction<const P1&, const P2&> operator&&(PredicateBase<P1>& p1, PredicateBase<P2>& p2)
162 {
163 return Conjunction<const P1&, const P2&>(static_cast<const P1&>(p1), static_cast<const P2&>(p2));
164 }
165
166 template <typename P1, typename P2>
167 Conjunction<const P1&, P2> operator&&(PredicateBase<P1>& p1, PredicateBase<P2>&& p2)
168 {
169 return Conjunction<const P1&, P2>(static_cast<const P1&>(p1), static_cast<P2&&>(p2));
170 }
171
172 template <typename P1, typename P2>
173 Conjunction<P1, const P2&> operator&&(PredicateBase<P1>&& p1, PredicateBase<P2>& p2)
174 {
175 return Conjunction<P1, const P2&>(static_cast<P1>(p1), static_cast<const P2&>(p2));
176 }
177
178 template <typename P1, typename P2>
179 Conjunction<P1, P2> operator&&(PredicateBase<P1>&& p1, PredicateBase<P2>&& p2)
180 {
181 return Conjunction<P1, P2>(static_cast<P1&&>(p1), static_cast<P2&&>(p2));
182 }
183
184 template <typename P>
185 Negation<const P&> operator!(PredicateBase<P>& p)
186 {
187 return Negation<const P&>(static_cast<const P&>(p));
188 }
189
190 template <typename P>
191 Negation<P> operator!(PredicateBase<P>&& p)
192 {
193 return Negation<P>(static_cast<P&&>(p));
194 }
195
196 struct Feature : public PredicateBase<Feature>
197 {
198 template <typename HandleType>
199 bool operator()(const SmartHandleStatusPredicates<HandleType>& _h) const { return _h.feature(); }
200 };
201
202 struct Selected : public PredicateBase<Selected>
203 {
204 template <typename HandleType>
205 bool operator()(const SmartHandleStatusPredicates<HandleType>& _h) const { return _h.selected(); }
206 };
207
208 struct Tagged : public PredicateBase<Tagged>
209 {
210 template <typename HandleType>
211 bool operator()(const SmartHandleStatusPredicates<HandleType>& _h) const { return _h.tagged(); }
212 };
213
214 struct Tagged2 : public PredicateBase<Tagged2>
215 {
216 template <typename HandleType>
217 bool operator()(const SmartHandleStatusPredicates<HandleType>& _h) const { return _h.tagged2(); }
218 };
219
220 struct Locked : public PredicateBase<Locked>
221 {
222 template <typename HandleType>
223 bool operator()(const SmartHandleStatusPredicates<HandleType>& _h) const { return _h.locked(); }
224 };
225
226 struct Hidden : public PredicateBase<Hidden>
227 {
228 template <typename HandleType>
229 bool operator()(const SmartHandleStatusPredicates<HandleType>& _h) const { return _h.hidden(); }
230 };
231
232 struct Deleted : public PredicateBase<Deleted>
233 {
234 template <typename HandleType>
235 bool operator()(const SmartHandleStatusPredicates<HandleType>& _h) const { return _h.deleted(); }
236 };
237
238 struct Boundary : public PredicateBase<Boundary>
239 {
240 template <typename HandleType>
241 bool operator()(const SmartHandleBoundaryPredicate<HandleType>& _h) const { return _h.is_boundary(); }
242 };
243
244 template <int inner_reg, int boundary_reg>
245 struct Regular: public PredicateBase<Regular<inner_reg, boundary_reg>>
246 {
247 bool operator()(const SmartVertexHandle& _vh) const { return _vh.valence() == (_vh.is_boundary() ? boundary_reg : inner_reg); }
248 };
249
250 using RegularQuad = Regular<4,3>;
251 using RegularTri = Regular<6,4>;
252
253
256 template <typename T, typename MF>
257 struct MemberFunctionWrapper
258 {
259 T t_; // Objects whose member function we want to call
260 MF mf_; // pointer to member function
261
262 MemberFunctionWrapper(T _t, MF _mf)
263 :
264 t_(_t),
265 mf_(_mf)
266 {}
267
268 template <typename O>
269 auto operator()(const O& _o) -> decltype ((t_.*mf_)(_o))
270 {
271 return (t_.*mf_)(_o);
272 }
273 };
274
276 template <typename T, typename MF>
277 MemberFunctionWrapper<T,MF> make_member_function_wrapper(T&& _t, MF _mf)
278 {
279 return MemberFunctionWrapper<T,MF>(std::forward<T>(_t), _mf);
280 }
281
283 #define OM_MFW(member_function) OpenMesh::Predicates::make_member_function_wrapper(*this, &std::decay<decltype(*this)>::type::member_function)
284
285
286
287 //=============================================================================
288 } // namespace Predicates
289
290 } // namespace OpenMesh
291 //=============================================================================
292
293 //=============================================================================
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
OpenMesh::SmartHandleStatusPredicates
Base class for all smart handle types that contains status related methods.
Definition: SmartHandles.hh:81
OpenMesh::SmartHandleStatusPredicates::selected
bool selected() const
Returns true iff the handle is marked as selected.
Definition: SmartHandles.hh:293
OpenMesh::SmartHandleStatusPredicates::feature
bool feature() const
Returns true iff the handle is marked as feature.
Definition: SmartHandles.hh:285
OpenMesh::SmartHandleStatusPredicates::locked
bool locked() const
Returns true iff the handle is marked as locked.
Definition: SmartHandles.hh:317
OpenMesh::SmartHandleStatusPredicates::deleted
bool deleted() const
Returns true iff the handle is marked as deleted.
Definition: SmartHandles.hh:333
OpenMesh::SmartHandleStatusPredicates::tagged
bool tagged() const
Returns true iff the handle is marked as tagged.
Definition: SmartHandles.hh:301
OpenMesh::SmartHandleStatusPredicates::tagged2
bool tagged2() const
Returns true iff the handle is marked as tagged2.
Definition: SmartHandles.hh:309
OpenMesh::SmartHandleStatusPredicates::hidden
bool hidden() const
Returns true iff the handle is marked as hidden.
Definition: SmartHandles.hh:325
OpenMesh::SmartHandleBoundaryPredicate
Base class for all smart handle types that contains status related methods.
Definition: SmartHandles.hh:102
OpenMesh::SmartHandleBoundaryPredicate::is_boundary
bool is_boundary() const
Returns true iff the handle is boundary.
Definition: SmartHandles.hh:341
OpenMesh::SmartVertexHandle
Smart version of VertexHandle contains a pointer to the corresponding mesh and allows easier access t...
Definition: SmartHandles.hh:110
OpenMesh::SmartVertexHandle::valence
uint valence() const
Returns valence of the vertex.
Definition: SmartHandles.hh:364
OpenMesh::Predicates::PredicateBase
Definition: Predicates.hh:66
OpenMesh::Predicates::Predicate
Definition: Predicates.hh:71
OpenMesh::Predicates::Disjunction
Definition: Predicates.hh:91
OpenMesh::Predicates::Conjunction
Definition: Predicates.hh:107
OpenMesh::Predicates::Negation
Definition: Predicates.hh:124
OpenMesh::Predicates::Feature
Definition: Predicates.hh:197
OpenMesh::Predicates::Selected
Definition: Predicates.hh:203
OpenMesh::Predicates::Tagged
Definition: Predicates.hh:209
OpenMesh::Predicates::Tagged2
Definition: Predicates.hh:215
OpenMesh::Predicates::Locked
Definition: Predicates.hh:221
OpenMesh::Predicates::Hidden
Definition: Predicates.hh:227
OpenMesh::Predicates::Deleted
Definition: Predicates.hh:233
OpenMesh::Predicates::Boundary
Definition: Predicates.hh:239
OpenMesh::Predicates::Regular
Definition: Predicates.hh:246
OpenMesh::Predicates::MemberFunctionWrapper
Wrapper object to hold an object and a member function pointer, and provides operator() to call that ...
Definition: Predicates.hh:258