Visual Computing Library  devel
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 "face_requirements.h"
27
28#include <vclib/mesh/mesh.h>
29#include <vclib/mesh/mesh_components.h>
30
40namespace vcl {
41
42/************
43 * concepts *
44 ************/
45
52template<typename MeshType>
55
61template<typename MeshType>
63
70template<typename MeshType>
73
79template<typename MeshType>
81
87template<typename MeshType>
89
95template<typename MeshType>
98
104template<typename MeshType>
107
113template<typename MeshType>
116
117/********************
118 * is/has functions *
119 ********************/
120
138template<MeshConcept MeshType>
139bool isTriangleMesh(const MeshType& m)
140{
141 if constexpr (HasTriangles<MeshType>) {
142 return true;
143 }
144 else if constexpr (HasFaces<MeshType>) {
145 using F = MeshType::FaceType;
146 for (const F& f : m.faces()) {
147 if (f.vertexNumber() != 3)
148 return false;
149 }
150 return true;
151 }
152 else {
153 return false;
154 }
155}
156
174template<MeshConcept MeshType>
175bool isQuadMesh(const MeshType& m)
176{
177 if constexpr (HasQuads<MeshType>) {
178 return true;
179 }
180 else if constexpr (HasFaces<MeshType>) {
181 using F = MeshType::FaceType;
182 for (const F& f : m.faces()) {
183 if (f.vertexNumber() != 4)
184 return false;
185 }
186 return true;
187 }
188 else {
189 return false;
190 }
191}
192
203template<MeshConcept MeshType>
204bool isCompact(const MeshType& m)
205{
206 return m.isCompact();
207}
208
209/*********************
210 * require functions *
211 *********************/
212
233template<FaceMeshConcept MeshType>
234void requireTriangleMesh(const MeshType& m)
235{
236 if constexpr (!HasTriangles<MeshType>) {
237 for (const auto& f : m.faces()) {
238 if (f.vertexNumber() != 3) {
240 "Triangle Mesh Required.");
241 }
242 }
243 }
244}
245
266template<FaceMeshConcept MeshType>
267void requireQuadMesh(const MeshType& m)
268{
269 if constexpr (!HasQuads<MeshType>) {
270 for (const auto& f : m.faces()) {
271 if (f.vertexNumber() != 4) {
272 throw MissingQuadRequirementException("Quad Mesh Required.");
273 }
274 }
275 }
276}
277
290template<MeshConcept MeshType>
291void requireCompactness(const MeshType& m)
292{
293 if (!m.isCompact())
294 throw MissingCompactnessException("Mesh is not compact.");
295}
296
297} // namespace vcl
298
299#endif // VCL_MESH_REQUIREMENTS_MESH_REQUIREMENTS_H
A class representing a box in N-dimensional space.
Definition box.h:46
Exception thrown when the mesh is not compact.
Definition exceptions.h:84
Exception thrown when an input/output mesh is not composed of quads.
Definition exceptions.h:154
Exception thrown when an input/output mesh is not composed of triangles.
Definition exceptions.h:131
Concept that is evaluated true if a Mesh has the BoundingBox component.
Definition mesh_requirements.h:53
Concept that is evaluated true if a Mesh has the Color component.
Definition mesh_requirements.h:62
Concept that is evaluated true if a Mesh has the CustomComponents component.
Definition mesh_requirements.h:71
HasFaces concepts is satisfied when at least one of its template types is (or inherits from) a vcl::m...
Definition face_container.h:1389
Concept that is evaluated true if a Mesh has the Mark component.
Definition mesh_requirements.h:80
Concept that checks if a Mesh has the Name component.
Definition mesh_requirements.h:88
Definition face_requirements.h:56
Concept that checks if a Mesh has the TextureImages component.
Definition mesh_requirements.h:96
Concept that checks if a Mesh has the TexturePaths component.
Definition mesh_requirements.h:105
Concept that checks if a Mesh has the TransformMatrix component.
Definition mesh_requirements.h:114
Definition face_requirements.h:52
A concept that checks whether a class is (inherits from) a Mesh class.
Definition mesh.h:2167
Definition mesh_components.h:48
Definition mesh_components.h:50
Definition mesh_components.h:52
Definition mesh_components.h:54
Definition mesh_components.h:56
Definition mesh_components.h:58
Definition mesh_components.h:60
Definition mesh_components.h:62
bool isQuadMesh(const MeshType &m)
Checks at run time if the mesh is composed of quads.
Definition mesh_requirements.h:175
bool isTriangleMesh(const MeshType &m)
Checks at run time if the mesh m is composed of triangles.
Definition mesh_requirements.h:139
void requireTriangleMesh(const MeshType &m)
Checks if the mesh is composed of triangles, and if not, throws an exception.
Definition mesh_requirements.h:234
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:291
void requireQuadMesh(const MeshType &m)
Checks if the mesh is composed of quads, and if not, throws an exception.
Definition mesh_requirements.h:267
bool isCompact(const MeshType &m)
Checks if a Mesh is compact, that is if it does not contains deleted elements.
Definition mesh_requirements.h:204