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>
97
103template<typename MeshType>
106
107/********************
108 * is/has functions *
109 ********************/
110
128template<MeshConcept MeshType>
129bool isTriangleMesh(const MeshType& m)
130{
131 if constexpr (HasTriangles<MeshType>) {
132 return true;
133 }
134 else if constexpr (HasFaces<MeshType>) {
135 using F = MeshType::FaceType;
136 for (const F& f : m.faces()) {
137 if (f.vertexNumber() != 3)
138 return false;
139 }
140 return true;
141 }
142 else {
143 return false;
144 }
145}
146
164template<MeshConcept MeshType>
165bool isQuadMesh(const MeshType& m)
166{
167 if constexpr (HasQuads<MeshType>) {
168 return true;
169 }
170 else if constexpr (HasFaces<MeshType>) {
171 using F = MeshType::FaceType;
172 for (const F& f : m.faces()) {
173 if (f.vertexNumber() != 4)
174 return false;
175 }
176 return true;
177 }
178 else {
179 return false;
180 }
181}
182
193template<MeshConcept MeshType>
194bool isCompact(const MeshType& m)
195{
196 return m.isCompact();
197}
198
199/*********************
200 * require functions *
201 *********************/
202
223template<FaceMeshConcept MeshType>
224void requireTriangleMesh(const MeshType& m)
225{
226 if constexpr (!HasTriangles<MeshType>) {
227 for (const auto& f : m.faces()) {
228 if (f.vertexNumber() != 3) {
230 "Triangle Mesh Required.");
231 }
232 }
233 }
234}
235
256template<FaceMeshConcept MeshType>
257void requireQuadMesh(const MeshType& m)
258{
259 if constexpr (!HasQuads<MeshType>) {
260 for (const auto& f : m.faces()) {
261 if (f.vertexNumber() != 4) {
262 throw MissingQuadRequirementException("Quad Mesh Required.");
263 }
264 }
265 }
266}
267
280template<MeshConcept MeshType>
281void requireCompactness(const MeshType& m)
282{
283 if (!m.isCompact())
284 throw MissingCompactnessException("Mesh is not compact.");
285}
286
287} // namespace vcl
288
289#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:1429
Concept that is evaluated true if a Mesh has the Mark component.
Definition mesh_requirements.h:80
Concept that is evaluated true if a Mesh has the Materials component.
Definition mesh_requirements.h:88
Concept that checks if a Mesh has the Name component.
Definition mesh_requirements.h:96
Definition face_requirements.h:56
Concept that checks if a Mesh has the TransformMatrix component.
Definition mesh_requirements.h:104
Definition face_requirements.h:52
A concept that checks whether a class is (inherits from) a Mesh class.
Definition mesh.h:2169
Definition mesh_components.h:47
Definition mesh_components.h:49
Definition mesh_components.h:51
Definition mesh_components.h:53
Definition mesh_components.h:55
Definition mesh_components.h:57
Definition mesh_components.h:59
bool isQuadMesh(const MeshType &m)
Checks at run time if the mesh is composed of quads.
Definition mesh_requirements.h:165
bool isTriangleMesh(const MeshType &m)
Checks at run time if the mesh m is composed of triangles.
Definition mesh_requirements.h:129
void requireTriangleMesh(const MeshType &m)
Checks if the mesh is composed of triangles, and if not, throws an exception.
Definition mesh_requirements.h:224
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:281
void requireQuadMesh(const MeshType &m)
Checks if the mesh is composed of quads, and if not, throws an exception.
Definition mesh_requirements.h:257
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