OpenMesh
Predicates.hh
1/* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2023, 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
56namespace OpenMesh {
57
58namespace Predicates {
59
60//== FORWARD DECLARATION ======================================================
61
62//== CLASS DEFINITION =========================================================
63
64template <typename PredicateT>
66{
67};
68
69template <typename PredicateT>
70struct 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
83template <typename PredicateT>
84Predicate<const PredicateT&> make_predicate(PredicateT& _p) { return { _p }; }
85
86template <typename PredicateT>
87Predicate<PredicateT> make_predicate(PredicateT&& _p) { return { _p }; }
88
89template <typename Predicate1T, typename Predicate2T>
90struct 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
105template <typename Predicate1T, typename Predicate2T>
106struct 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
122template <typename PredicateT>
123struct 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
136template <typename P1, typename P2>
138{
139 return Disjunction<const P1&, const P2&>(static_cast<const P1&>(p1), static_cast<const P2&>(p2));
140}
141
142template <typename P1, typename P2>
143Disjunction<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
148template <typename P1, typename P2>
149Disjunction<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
154template <typename P1, typename P2>
155Disjunction<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
160template <typename P1, typename P2>
161Conjunction<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
166template <typename P1, typename P2>
167Conjunction<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
172template <typename P1, typename P2>
173Conjunction<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
178template <typename P1, typename P2>
179Conjunction<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
184template <typename P>
185Negation<const P&> operator!(PredicateBase<P>& p)
186{
187 return Negation<const P&>(static_cast<const P&>(p));
188}
189
190template <typename P>
191Negation<P> operator!(PredicateBase<P>&& p)
192{
193 return Negation<P>(static_cast<P&&>(p));
194}
195
196struct Feature : public PredicateBase<Feature>
197{
198 template <typename HandleType>
199 bool operator()(const SmartHandleStatusPredicates<HandleType>& _h) const { return _h.feature(); }
200};
201
202struct Selected : public PredicateBase<Selected>
203{
204 template <typename HandleType>
205 bool operator()(const SmartHandleStatusPredicates<HandleType>& _h) const { return _h.selected(); }
206};
207
208struct Tagged : public PredicateBase<Tagged>
209{
210 template <typename HandleType>
211 bool operator()(const SmartHandleStatusPredicates<HandleType>& _h) const { return _h.tagged(); }
212};
213
214struct Tagged2 : public PredicateBase<Tagged2>
215{
216 template <typename HandleType>
217 bool operator()(const SmartHandleStatusPredicates<HandleType>& _h) const { return _h.tagged2(); }
218};
219
220struct Locked : public PredicateBase<Locked>
221{
222 template <typename HandleType>
223 bool operator()(const SmartHandleStatusPredicates<HandleType>& _h) const { return _h.locked(); }
224};
225
226struct Hidden : public PredicateBase<Hidden>
227{
228 template <typename HandleType>
229 bool operator()(const SmartHandleStatusPredicates<HandleType>& _h) const { return _h.hidden(); }
230};
231
232struct Deleted : public PredicateBase<Deleted>
233{
234 template <typename HandleType>
235 bool operator()(const SmartHandleStatusPredicates<HandleType>& _h) const { return _h.deleted(); }
236};
237
238struct Boundary : public PredicateBase<Boundary>
239{
240 template <typename HandleType>
241 bool operator()(const SmartHandleBoundaryPredicate<HandleType>& _h) const { return _h.is_boundary(); }
242};
243
244template <int inner_reg, int boundary_reg>
245struct 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
252
253
256template <typename T, typename MF>
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
276template <typename T, typename MF>
277MemberFunctionWrapper<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//=============================================================================
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
Base class for all smart handle types that contains status related methods.
Definition: SmartHandles.hh:81
bool selected() const
Returns true iff the handle is marked as selected.
Definition: SmartHandles.hh:302
bool feature() const
Returns true iff the handle is marked as feature.
Definition: SmartHandles.hh:294
bool locked() const
Returns true iff the handle is marked as locked.
Definition: SmartHandles.hh:326
bool deleted() const
Returns true iff the handle is marked as deleted.
Definition: SmartHandles.hh:342
bool tagged() const
Returns true iff the handle is marked as tagged.
Definition: SmartHandles.hh:310
bool tagged2() const
Returns true iff the handle is marked as tagged2.
Definition: SmartHandles.hh:318
bool hidden() const
Returns true iff the handle is marked as hidden.
Definition: SmartHandles.hh:334
Base class for all smart handle types that contains status related methods.
Definition: SmartHandles.hh:102
bool is_boundary() const
Returns true iff the handle is boundary.
Definition: SmartHandles.hh:350
Smart version of VertexHandle contains a pointer to the corresponding mesh and allows easier access t...
Definition: SmartHandles.hh:110
uint valence() const
Returns valence of the vertex.
Definition: SmartHandles.hh:373
Definition: Predicates.hh:66
Definition: Predicates.hh:71
Definition: Predicates.hh:91
Definition: Predicates.hh:107
Definition: Predicates.hh:124
Definition: Predicates.hh:197
Definition: Predicates.hh:203
Definition: Predicates.hh:209
Definition: Predicates.hh:215
Definition: Predicates.hh:221
Definition: Predicates.hh:227
Definition: Predicates.hh:233
Definition: Predicates.hh:239
Definition: Predicates.hh:246
Wrapper object to hold an object and a member function pointer, and provides operator() to call that ...
Definition: Predicates.hh:258

Project OpenMesh, ©  Visual Computing Institute, RWTH Aachen. Documentation generated using doxygen .