Visual Computing Library  devel
Loading...
Searching...
No Matches
position.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_POSITION_H
24#define VCL_MESH_COMPONENTS_POSITION_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 Position :
60 public Component<
61 Position<P, ParentElemType, OPT>,
62 CompId::POSITION,
63 P,
64 ParentElemType,
65 !std::is_same_v<ParentElemType, void>,
66 OPT>
67{
68 using Base = Component<
70 CompId::POSITION,
71 P,
73 !std::is_same_v<ParentElemType, void>,
74 OPT>;
75
76public:
80 using PositionType = P;
81
82 /* Constructors */
83
87 Position() = default;
88
89 /* Member functions */
90
95 const P& position() const { return Base::data(); }
96
101 P& position() { return Base::data(); }
102
103protected:
104 // Component interface functions
105 template<typename Element>
106 void importFrom(const Element& v, bool = true);
107
108 void serialize(std::ostream& os) const { position().serialize(os); }
109
110 void deserialize(std::istream& is) { position().deserialize(is); }
111};
112
113/* concept */
114
126template<typename T>
127concept HasPosition = TTB::IsDerivedFromSpecializationOfV<T, Position>;
128
129/* importFrom function */
130
131template<PointConcept P, typename ParentElemType, bool OPT>
132template<typename Element>
133void Position<P, ParentElemType, OPT>::importFrom(const Element& v, bool)
134{
135 using ScalarType = PositionType::ScalarType;
136 if constexpr (HasPosition<Element>) {
137 if (isPositionAvailableOn(v)) {
138 position() = v.position().template cast<ScalarType>();
139 }
140 }
141}
142
143/* Detector function to check if a class has Position available */
144
156bool isPositionAvailableOn(const auto& element)
157{
159}
160
161/* Specialization Aliases */
162
176template<typename Scalar, typename ElementType = void, bool OPT = false>
177using Position3 = Position<Point3<Scalar>, ElementType, OPT>;
178
191template<typename ElementType = void, bool OPT = false>
193
206template<typename ElementType = void, bool OPT = false>
208
209} // namespace vcl::comp
210
211#endif // VCL_MESH_COMPONENTS_POSITION_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 Position class represents a N-Dimensional point that will be part of an Element (e....
Definition position.h:67
P PositionType
Expose the type of the Position.
Definition position.h:80
const P & position() const
Returns a const reference of the position of the element.
Definition position.h:95
Position()=default
Initilizes the Position to (0, 0, 0).
P & position()
Returns a reference of the position of the element.
Definition position.h:101
A concept that checks whether a type T (that should be a Element) has the Position component (inherit...
Definition position.h:127