Visual Computing Library  devel
Loading...
Searching...
No Matches
transform_matrix.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_TRANSFORM_MATRIX_H
24#define VCL_MESH_COMPONENTS_TRANSFORM_MATRIX_H
25
26#include "base/component.h"
27#include "base/predicates.h"
28
29#include <vclib/space/core.h>
30
31namespace vcl::comp {
32
61template<typename Scalar, typename ParentElemType = void, bool OPT = false>
63 public Component<
64 TransformMatrix<Scalar, ParentElemType, OPT>,
65 CompId::TRANSFORM_MATRIX,
66 Matrix44<Scalar>,
67 ParentElemType,
68 !std::is_same_v<ParentElemType, void>,
69 OPT>
70{
71 using Base = Component<
73 CompId::TRANSFORM_MATRIX,
76 !std::is_same_v<ParentElemType, void>,
77 OPT>;
78
79public:
84
85 /* Constructors */
86
91 {
92 if constexpr (!Base::IS_VERTICAL) {
93 init();
94 }
95 }
96
107 void init() { transformMatrix().setIdentity(); }
108
109 /* Member functions */
110
115 const TransformMatrixType& transformMatrix() const { return Base::data(); }
116
121 TransformMatrixType& transformMatrix() { return Base::data(); }
122
123protected:
124 // Component interface functions
125 template<typename Element>
126 void importFrom(const Element& e, bool = true);
127
128 void serialize(std::ostream& os) const { transformMatrix().serialize(os); }
129
130 void deserialize(std::istream& is) { transformMatrix().deserialize(is); }
131};
132
133/* concept */
134
146template<typename T>
148 TTB::IsDerivedFromSpecializationOfV<T, TransformMatrix>;
149
150/* importFrom function */
151
152template<typename Scalar, typename ParentElemType, bool OPT>
153template<typename Element>
154void TransformMatrix<Scalar, ParentElemType, OPT>::importFrom(
155 const Element& e,
156 bool)
157{
158 if constexpr (HasTransformMatrix<Element>) {
159 transformMatrix() = e.transformMatrix().template cast<Scalar>();
160 }
161}
162
163/* Detector function to check if a class has TransformMatrix available */
164
176bool isTransformMatrixAvailableOn(const auto& element)
177{
179}
180
181/* Specialization Aliases */
182
195template<typename ElementType = void, bool OPT = false>
197
210template<typename ElementType = void, bool OPT = false>
212
213} // namespace vcl::comp
214
215#endif // VCL_MESH_COMPONENTS_TRANSFORM_MATRIX_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 TransformMatrix class represents a component that stores a 4x4 matrix that can be used for a tran...
Definition transform_matrix.h:70
TransformMatrix()
Initializes the transform matrix to identity.
Definition transform_matrix.h:90
TransformMatrixType & transformMatrix()
Returns a reference to the transform matrix.
Definition transform_matrix.h:121
void init()
Initializes transform matrix to identity.
Definition transform_matrix.h:107
const TransformMatrixType & transformMatrix() const
Returns a const reference to the transform matrix.
Definition transform_matrix.h:115
A concept that checks whether a type T (that should be a Mesh) has the TransformMatrix component (inh...
Definition transform_matrix.h:147