Visual Computing Library  devel
Loading...
Searching...
No Matches
normal.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_NORMAL_H
24#define VCL_MESH_COMPONENTS_NORMAL_H
25
26#include "base/component.h"
27#include "base/predicates.h"
28
29#include <vclib/space/core.h>
30
31namespace vcl::comp {
32
58template<PointConcept P, typename ParentElemType = void, bool OPT = false>
59class Normal :
60 public Component<
61 Normal<P, ParentElemType, OPT>,
62 CompId::NORMAL,
63 P,
64 ParentElemType,
65 !std::is_same_v<ParentElemType, void>,
66 OPT>
67{
68 using Base = Component<
70 CompId::NORMAL,
71 P,
73 !std::is_same_v<ParentElemType, void>,
74 OPT>;
75
76public:
80 using NormalType = P;
81
82 /* Constructors */
83
87 Normal() = default;
88
89 /* Member functions */
90
95 const P& normal() const { return Base::data(); }
96
101 P& normal() { return Base::data(); }
102
103protected:
104 // Component interface functions
105 template<typename Element>
106 void importFrom(const Element& e, bool = true);
107
108 void serialize(std::ostream& os) const { normal().serialize(os); }
109
110 void deserialize(std::istream& is) { normal().deserialize(is); }
111};
112
113/* concepts */
114
132template<typename T>
133concept HasNormal = TTB::IsDerivedFromSpecializationOfV<T, Normal>;
134
145template<typename T>
148
149/* importFrom function */
150
151template<PointConcept P, typename ParentElemType, bool OPT>
152template<typename Element>
153void Normal<P, ParentElemType, OPT>::importFrom(const Element& e, bool)
154{
155 using ScalarType = NormalType::ScalarType;
156 if constexpr (HasNormal<Element>) {
157 if (isNormalAvailableOn(e)) {
158 normal() = e.normal().template cast<ScalarType>();
159 }
160 }
161}
162
163/* Detector function to check if a class has Normal available */
164
176bool isNormalAvailableOn(const auto& element)
177{
179}
180
181/* Specialization Aliases */
182
196template<typename Scalar, typename ElementType = void, bool OPT = false>
197using Normal3 = Normal<Point3<Scalar>, ElementType, OPT>;
198
211template<typename ElementType = void, bool OPT = false>
213
226template<typename ElementType = void, bool OPT = false>
228
229} // namespace vcl::comp
230
231#endif // VCL_MESH_COMPONENTS_NORMAL_H
A class representing a box in N-dimensional space.
Definition box.h:46
void deserialize(std::istream &is)
Deserializes the box from the given input stream.
Definition box.h:476
void serialize(std::ostream &os) const
Serializes the box to the given output stream.
Definition box.h:466
The Element class.
Definition element.h:75
The Normal class represents a N-Dimensional normal vector that will be part of an Element (e....
Definition normal.h:67
P NormalType
Expose the type of the Normal.
Definition normal.h:80
Normal()=default
Initilizes the Normal to (0, 0, 0).
const P & normal() const
Returns a const reference of the normal of the element.
Definition normal.h:95
P & normal()
Returns a reference of the normal of the element.
Definition normal.h:101
A concept that checks whether a type T (that should be a Element) has the Normal component (inherits ...
Definition normal.h:133
A concept that checks whether a type T (that should be a Element) has the Normal component (inherits ...
Definition normal.h:146
Evaluates to true if the type T is a component that is stored vertically in its element container,...
Definition component.h:74