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