Visual Computing Library
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 "bases/component.h"
27
28#include <vclib/concepts/mesh/components/normal.h>
29#include <vclib/space/core/point.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 if constexpr (HasNormal<Element>) {
109 if (isNormalAvailableOn(e)) {
110 normal() =
111 e.normal().template cast<typename NormalType::ScalarType>();
112 }
113 }
114 }
115
116 void serialize(std::ostream& os) const { normal().serialize(os); }
117
118 void deserialize(std::istream& is) { normal().deserialize(is); }
119};
120
121/* Detector function to check if a class has Normal available */
122
135bool isNormalAvailableOn(const ElementConcept auto& element)
136{
137 return isComponentAvailableOn<CompId::NORMAL>(element);
138}
139
140/* Specialization Aliases */
141
155template<typename Scalar, typename ElementType = void, bool OPT = false>
156using Normal3 = Normal<Point3<Scalar>, ElementType, OPT>;
157
170template<typename ElementType = void, bool OPT = false>
172
185template<typename ElementType = void, bool OPT = false>
187
188} // namespace vcl::comp
189
190#endif // VCL_MESH_COMPONENTS_NORMAL_H
The Element class.
Definition element.h:57
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
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
HasNormal concept is satisfied only if a Element class provides the types and member functions specif...
Definition normal.h:47