Visual Computing Library  devel
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
29#include <vclib/mesh.h>
30
31namespace vcl {
32
33template<uint ELEM_ID, MeshConcept MeshType>
34void clearElementSelection(MeshType& mesh)
35{
36 for (auto&& e : mesh.template elements<ELEM_ID>()) {
37 e.selected() = false;
38 }
39}
40
41template<MeshConcept MeshType>
42void clearVertexSelection(MeshType& m)
43{
44 clearElementSelection<ElemId::VERTEX>(m);
45}
46
47template<FaceMeshConcept MeshType>
48void clearFaceSelection(MeshType& m)
49{
50 clearElementSelection<ElemId::FACE>(m);
51}
52
53template<FaceMeshConcept MeshType>
54void clearFaceEdgesSelection(MeshType& m)
55{
56 for (auto& f : m.faces()) {
57 for (uint i = 0; i < f.vertexNumber(); ++i) {
58 f.edgeSelected(i) = false;
59 }
60 }
61}
62
63template<EdgeMeshConcept MeshType>
64void clearEdgeSelection(MeshType& m)
65{
66 clearElementSelection<ElemId::EDGE>(m);
67}
68
69template<FaceMeshConcept MeshType>
70void selectNonManifoldVertices(MeshType& m, bool clearSelectionFirst = true)
71{
72 std::vector<bool> nonManifoldVertices =
73 detail::nonManifoldVerticesVectorBool(m);
74
75 using VertexType = MeshType::VertexType;
76
77 for (VertexType& v : m.vertices()) {
78 if (nonManifoldVertices[m.index(v)]) {
79 v.selected() = true;
80 }
81 else if (clearSelectionFirst) {
82 v.selected() = false;
83 }
84 }
85}
86
87template<FaceMeshConcept MeshType>
88void selectCreaseFaceEdges(
89 MeshType& m,
90 double angleRadNeg,
91 double angleRadPos,
92 bool alsoBorderEdges = false)
93{
94 clearFaceEdgesSelection(m);
95
96 std::vector<std::pair<uint, uint>> creaseEdges =
97 creaseFaceEdges(m, angleRadNeg, angleRadPos, alsoBorderEdges);
98
99 for (const auto& [fi, ei] : creaseEdges) {
100 m.face(fi).edgeSelected(ei) = true;
101 }
102}
103
104} // namespace vcl
105
106#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:84
constexpr detail::VerticesView vertices
A view that allows to iterate over the Vertex elements of an object.
Definition vertex.h:92