Visual Computing Library  devel
Loading...
Searching...
No Matches
utility.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_UTILITY_H
24#define VCL_ALGORITHMS_MESH_UTILITY_H
25
26#include <vclib/base.h>
27#include <vclib/mesh.h>
28
29namespace vcl::detail {
30
31// returns a non-empty vector if the ELEM_ID container is not compact and the
32// user wants compact indices
33template<uint ELEM_ID>
34std::vector<uint> elemCompactIndices(const auto& mesh, bool wantCompact)
35{
36 std::vector<uint> elemCompIndices;
37
38 bool isCompact = mesh.template number<ELEM_ID>() ==
39 mesh.template containerSize<ELEM_ID>();
40
41 if (wantCompact && !isCompact)
42 elemCompIndices = mesh.template compactIndices<ELEM_ID>();
43 return elemCompIndices;
44}
45
46// returns a non-empty vector if the vertex container is not compact and the
47// user wants compact indices
48std::vector<uint> vertCompactIndices(const auto& mesh, bool wantCompact)
49{
50 return elemCompactIndices<ElemId::VERTEX>(mesh, wantCompact);
51}
52
53// lambda to get the vertex index of a face (considering compact vertex indices)
54auto vIndexLambda(const auto& mesh, const std::vector<uint>& vertCompIndices)
55{
56 // lambda to get the vertex index of a face (considering compact indices)
57 auto vIndex = [&vertCompIndices](const auto& f, uint i) {
58 if (vertCompIndices.size() > 0)
59 return vertCompIndices[f.vertexIndex(i)];
60 else
61 return f.vertexIndex(i);
62 };
63
64 return vIndex;
65}
66
67// returns a non-empty vector if the face container is not compact and the
68// user wants compact indices
69std::vector<uint> faceCompactIndices(const auto& mesh, bool wantCompact)
70{
71 return elemCompactIndices<ElemId::FACE>(mesh, wantCompact);
72}
73
74} // namespace vcl::detail
75
76#endif // VCL_ALGORITHMS_MESH_UTILITY_H
bool isCompact(const MeshType &m)
Checks if a Mesh is compact, that is if it does not contains deleted elements.
Definition mesh_requirements.h:194