Visual Computing Library  devel
Loading...
Searching...
No Matches
element_requirements.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2026 *
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_ELEMENT_REQUIREMENTS_H
24#define VCL_MESH_REQUIREMENTS_ELEMENT_REQUIREMENTS_H
25
26#include <vclib/mesh/exceptions.h>
27#include <vclib/mesh/mesh.h>
28
29namespace vcl {
30
45template<uint ELEM_ID, MeshConcept MeshType>
46bool isElementContainerCompact(const MeshType& m)
47{
48 return (m.template count<ELEM_ID>() == m.template containerSize<ELEM_ID>());
49}
50
80template<uint ELEM_ID, uint COMP_ID, MeshConcept MeshType>
81bool isPerElementComponentAvailable(const MeshType& m)
82{
84 using Container = mesh::ContainerOfElementType<ELEM_ID, MeshType>;
85 using Element = Container::ElementType;
88 }
89 else {
91 }
92 }
93 else {
94 return false;
95 }
96}
97
118template<uint ELEM_ID, uint COMP_ID, MeshConcept MeshType>
120{
122 using Container = mesh::ContainerOfElementType<ELEM_ID, MeshType>;
123 using Element = Container::ElementType;
126 return true;
127 }
128 else {
130 }
131 }
132 else {
133 return false;
134 }
135}
136
156template<uint ELEM_ID, MeshConcept MeshType>
158{
162 " Container of the Mesh is not compact.");
163}
164
192template<uint ELEM_ID, uint COMP_ID, MeshConcept MeshType>
193void requirePerElementComponent(const MeshType& m)
194{
195 // TODO C++26: use elementEnumString<ELEM_ID>() and
196 // componentEnumString<COMP_ID>() in static_assert messages
197 static_assert(
199 "The input Mesh does not have a Container of the given Element ID.");
200
201 using ElementType = MeshType::template ElementType<ELEM_ID>;
202
203 static_assert(
205 "The Element of the input Mesh does not have a Component of the given "
206 "Component ID.");
207
210 "Per " + std::string(elementEnumString<ELEM_ID>()) + " " +
211 std::string(componentEnumString<COMP_ID>()) +
212 " Component is not enabled.");
213 }
214}
215
216} // namespace vcl
217
218#endif // VCL_MESH_REQUIREMENTS_ELEMENT_REQUIREMENTS_H
The Element class.
Definition element.h:75
Exception thrown when the mesh is not compact.
Definition exceptions.h:84
Exception thrown when a mesh/element component is missing (not enabled).
Definition exceptions.h:108
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:41
The HasComponentOfType concept checks whether a type T (that may be a Mesh or a MeshElement) has a co...
Definition component.h:248
The HasOptionalComponentOfType concept checks whether a type T (that should be a MeshElement) has an ...
Definition component.h:290
Definition base.h:153
bool isPerElementComponentAvailable(const MeshType &m)
Returns true if the given component is available in the given element of the input mesh m.
Definition element_requirements.h:81
bool isElementContainerCompact(const MeshType &m)
Returns true if the given mesh has its Container of the given Element compact.
Definition element_requirements.h:46
void requirePerElementComponent(const MeshType &m)
This function asserts that a Mesh has the Container of the given Element ID, the Element has a Compon...
Definition element_requirements.h:193
void requireElementContainerCompactness(const MeshType &m)
This function asserts that a Mesh has the Container of the given Element ID compact (no elements flag...
Definition element_requirements.h:157
bool enableIfPerElementComponentOptional(MeshType &m)
Makes available the given Component in the given Element of the input mesh m, and returns true if it ...
Definition element_requirements.h:119