Visual Computing Library
Loading...
Searching...
No Matches
mesh_requirements.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_MESH_REQUIREMENTS_MESH_REQUIREMENTS_H
24#define VCL_MESH_REQUIREMENTS_MESH_REQUIREMENTS_H
25
26#include <vclib/concepts/mesh.h>
27#include <vclib/exceptions/mesh.h>
28
29namespace vcl {
30
31/********************
32 * is/has functions *
33 ********************/
34
52template<MeshConcept MeshType>
53bool isTriangleMesh(const MeshType& m)
54{
55 if constexpr (HasTriangles<MeshType>) {
56 return true;
57 }
58 else if constexpr (HasFaces<MeshType>) {
59 using F = MeshType::FaceType;
60 for (const F& f : m.faces()) {
61 if (f.vertexNumber() != 3)
62 return false;
63 }
64 return true;
65 }
66 else {
67 return false;
68 }
69}
70
88template<MeshConcept MeshType>
89bool isQuadMesh(const MeshType& m)
90{
91 if constexpr (HasQuads<MeshType>) {
92 return true;
93 }
94 else if constexpr (HasFaces<MeshType>) {
95 using F = MeshType::FaceType;
96 for (const F& f : m.faces()) {
97 if (f.vertexNumber() != 4)
98 return false;
99 }
100 return true;
101 }
102 else {
103 return false;
104 }
105}
106
117template<MeshConcept MeshType>
118bool isCompact(const MeshType& m)
119{
120 return m.isCompact();
121}
122
123/*********************
124 * require functions *
125 *********************/
126
147template<FaceMeshConcept MeshType>
148void requireTriangleMesh(const MeshType& m)
149{
150 if constexpr (!HasTriangles<MeshType>) {
151 for (const auto& f : m.faces()) {
152 if (f.vertexNumber() != 3) {
154 "Triangle Mesh Required.");
155 }
156 }
157 }
158}
159
180template<FaceMeshConcept MeshType>
181void requireQuadMesh(const MeshType& m)
182{
183 if constexpr (!HasQuads<MeshType>) {
184 for (const auto& f : m.faces()) {
185 if (f.vertexNumber() != 4) {
186 throw MissingQuadRequirementException("Quad Mesh Required.");
187 }
188 }
189 }
190}
191
204template<MeshConcept MeshType>
205void requireCompactness(const MeshType& m)
206{
207 if (!m.isCompact())
208 throw MissingCompactnessException("Mesh is not compact.");
209}
210
211} // namespace vcl
212
213#endif // VCL_MESH_REQUIREMENTS_MESH_REQUIREMENTS_H
Exception thrown when the mesh is not compact.
Definition mesh.h:81
Exception thrown when an input/output mesh is not composed of quads.
Definition mesh.h:148
Exception thrown when an input/output mesh is not composed of triangles.
Definition mesh.h:126
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
HasFaces concepts is satisfied when at least one of its template types is (or inherits from) a vcl::m...
Definition face_container.h:133
Definition per_face.h:44
Definition per_face.h:40
bool isQuadMesh(const MeshType &m)
Checks at run time if the mesh is composed of quads.
Definition mesh_requirements.h:89
bool isTriangleMesh(const MeshType &m)
Checks at run time if the mesh m is composed of triangles.
Definition mesh_requirements.h:53
void requireTriangleMesh(const MeshType &m)
Checks if the mesh is composed of triangles, and if not, throws an exception.
Definition mesh_requirements.h:148
void requireCompactness(const MeshType &m)
Checks if a Mesh is compact, that is if it does not contains deleted elements, and if not,...
Definition mesh_requirements.h:205
void requireQuadMesh(const MeshType &m)
Checks if the mesh is composed of quads, and if not, throws an exception.
Definition mesh_requirements.h:181
bool isCompact(const MeshType &m)
Checks if a Mesh is compact, that is if it does not contains deleted elements.
Definition mesh_requirements.h:118