Visual Computing Library
Loading...
Searching...
No Matches
selection.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_ALGORITHMS_MESH_UPDATE_SELECTION_H
24#define VCL_ALGORITHMS_MESH_UPDATE_SELECTION_H
25
26#include <vclib/algorithms/mesh/clean.h>
27#include <vclib/algorithms/mesh/stat.h>
28#include <vclib/concepts/range.h>
29#include <vclib/mesh/requirements.h>
30
31namespace vcl {
32
33namespace detail {
34
35template<Range Rng>
36void clearSelection(Rng&& r)
37{
38 for (auto& e : r) {
39 e.selected() = false;
40 }
41}
42
43} // namespace detail
44
45template<MeshConcept MeshType>
46void clearVertexSelection(MeshType& m)
47{
48 detail::clearSelection(m.vertices());
49}
50
51template<FaceMeshConcept MeshType>
52void clearFaceSelection(MeshType& m)
53{
54 detail::clearSelection(m.faces());
55}
56
57template<FaceMeshConcept MeshType>
58void clearFaceEdgesSelection(MeshType& m)
59{
60 for (auto& f : m.faces()) {
61 for (uint i = 0; i < f.vertexNumber(); ++i) {
62 f.edgeSelected(i) = false;
63 }
64 }
65}
66
67template<EdgeMeshConcept MeshType>
68void clearEdgeSelection(MeshType& m)
69{
70 detail::clearSelection(m.edges());
71}
72
73template<FaceMeshConcept MeshType>
74void selectNonManifoldVertices(MeshType& m, bool clearSelectionFirst)
75{
76 std::vector<bool> nonManifoldVertices =
77 detail::nonManifoldVerticesVectorBool(m);
78
79 using VertexType = MeshType::VertexType;
80
81 for (VertexType& v : m.vertices()) {
82 if (nonManifoldVertices[m.index(v)]) {
83 v.selected() = true;
84 }
85 else if (clearSelectionFirst) {
86 v.selected() = false;
87 }
88 }
89}
90
91template<FaceMeshConcept MeshType>
92void selectCreaseFaceEdges(
93 MeshType& m,
94 double angleRadNeg,
95 double angleRadPos,
96 bool alsoBorderEdges = false)
97{
98 clearFaceEdgesSelection(m);
99
100 std::vector<std::pair<uint, uint>> creaseEdges =
101 creaseFaceEdges(m, angleRadNeg, angleRadPos, alsoBorderEdges);
102
103 for (const auto& [fi, ei] : creaseEdges) {
104 m.face(fi).edgeSelected(ei) = true;
105 }
106}
107
108} // namespace vcl
109
110#endif // VCL_ALGORITHMS_MESH_UPDATE_SELECTION_H
constexpr detail::FacesView faces
A view that allows to iterate overt the Face elements of an object.
Definition face.h:52
constexpr detail::VerticesView vertices
A view that allows to iterate over the Vertex elements of an object.
Definition vertex.h:60