Visual Computing Library
Loading...
Searching...
No Matches
sort.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_SORT_H
24#define VCL_ALGORITHMS_MESH_SORT_H
25
26#include <vclib/misc/parallel.h>
27#include <vclib/space/complex/mesh_edge_util.h>
28
29#include <algorithm>
30
31namespace vcl {
32
33template<FaceMeshConcept MeshType>
34std::vector<MeshEdgeUtil<MeshType>> fillAndSortMeshEdgeUtilVector(
35 MeshType& m,
36 bool includeFauxEdges = true)
37{
38 using FaceType = MeshType::FaceType;
39
40 std::vector<MeshEdgeUtil<MeshType>> vec;
41
42 int n_edges = 0;
43 for (const FaceType& f : m.faces())
44 n_edges += f.vertexNumber();
45
46 vec.reserve(n_edges);
47
48 for (FaceType& f : m.faces()) { // Lo riempio con i dati delle facce
49 for (uint j = 0; j < f.vertexNumber(); ++j) {
50 if (includeFauxEdges || !f.edgeFaux(j)) {
51 vec.emplace_back(f, j);
52 }
53 }
54 }
55
56 // Lo ordino per vertici
57 std::sort(std::execution::par_unseq, vec.begin(), vec.end());
58
59 return vec;
60}
61
62template<FaceMeshConcept MeshType>
63std::vector<ConstMeshEdgeUtil<MeshType>> fillAndSortMeshEdgeUtilVector(
64 const MeshType& m,
65 bool includeFauxEdges = true)
66{
67 using FaceType = MeshType::FaceType;
68
69 std::vector<ConstMeshEdgeUtil<MeshType>> vec;
70
71 int n_edges = 0;
72 for (const FaceType& f : m.faces())
73 n_edges += f.vertexNumber();
74
75 vec.reserve(n_edges);
76
77 for (const FaceType& f : m.faces()) { // Lo riempio con i dati delle facce
78 for (uint j = 0; j < f.vertexNumber(); ++j) {
79 if (includeFauxEdges || !f.edgeFaux(j)) {
80 vec.emplace_back(f, j);
81 }
82 }
83 }
84
85 // Lo ordino per vertici
86 std::sort(std::execution::par_unseq, vec.begin(), vec.end());
87
88 return vec;
89}
90
91} // namespace vcl
92
93#endif // VCL_ALGORITHMS_MESH_SORT_H
constexpr detail::FacesView faces
A view that allows to iterate overt the Face elements of an object.
Definition face.h:52