Visual Computing Library  devel
Loading...
Searching...
No Matches
quality.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_COMPONENTS_QUALITY_H
24#define VCL_MESH_COMPONENTS_QUALITY_H
25
26#include "base/component.h"
27#include "base/predicates.h"
28
29#include <vclib/base.h>
30
31namespace vcl::comp {
32
57template<typename Scalar, typename ParentElemType = void, bool OPT = false>
58class Quality :
59 public Component<
60 Quality<Scalar, ParentElemType, OPT>,
61 CompId::QUALITY,
62 Scalar,
63 ParentElemType,
64 !std::is_same_v<ParentElemType, void>,
65 OPT>
66{
67 using Base = Component<
69 CompId::QUALITY,
70 Scalar,
72 !std::is_same_v<ParentElemType, void>,
73 OPT>;
74
75public:
79 using QualityType = Scalar;
80
81 /* Constructors */
82
86 Quality() = default;
87
88 /* Member functions */
89
94 const QualityType& quality() const { return Base::data(); }
95
100 QualityType& quality() { return Base::data(); }
101
102protected:
103 // Component interface functions
104 template<typename Element>
105 void importFrom(const Element& e, bool = true);
106
107 void serialize(std::ostream& os) const { vcl::serialize(os, quality()); }
108
109 void deserialize(std::istream& is) { vcl::deserialize(is, quality()); }
110};
111
112/* concepts */
113
131template<typename T>
132concept HasQuality = TTB::IsDerivedFromSpecializationOfV<T, Quality>;
133
143template<typename T>
146
147/* importFrom function */
148
149template<typename Scalar, typename ParentElemType, bool OPT>
150template<typename Element>
151void Quality<Scalar, ParentElemType, OPT>::importFrom(const Element& e, bool)
152{
153 if constexpr (HasQuality<Element>) {
154 if (isQualityAvailableOn(e)) {
155 quality() = e.quality();
156 }
157 }
158}
159
160/* Detector function to check if a class has Quality available */
161
173bool isQualityAvailableOn(const auto& element)
174{
176}
177
178/* Specialization Aliases */
179
192template<typename ElementType = void, bool OPT = false>
194
207template<typename ElementType = void, bool OPT = false>
209
210} // namespace vcl::comp
211
212#endif // VCL_MESH_COMPONENTS_QUALITY_H
A class representing a box in N-dimensional space.
Definition box.h:46
The Element class.
Definition element.h:75
The Quality class represents a component that stores the quality of a mesh element,...
Definition quality.h:66
const QualityType & quality() const
Returns a const reference of the quality of the element.
Definition quality.h:94
Scalar QualityType
Exposes the scalar used as Quality type.
Definition quality.h:79
Quality()=default
Initilizes the Quality value to 0.
QualityType & quality()
Returns a reference of the quality of the element.
Definition quality.h:100
A concept that checks whether a type T (that should be a Element or a Mesh) has the Quality component...
Definition quality.h:144
A concept that checks whether a type T (that should be a Element or a Mesh) has the Quality component...
Definition quality.h:132
Evaluates to true if the type T is a component that is stored vertically in its element container,...
Definition component.h:74