Visual Computing Library
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 "bases/component.h"
27
28#include <vclib/concepts/mesh/components/transform_matrix.h>
29#include <vclib/space/core/matrix.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 if constexpr (HasTransformMatrix<Element>) {
129 transformMatrix() = e.transformMatrix().template cast<Scalar>();
130 }
131 }
132
133 void serialize(std::ostream& os) const { transformMatrix().serialize(os); }
134
135 void deserialize(std::istream& is) { transformMatrix().deserialize(is); }
136};
137
138/* Detector function to check if a class has TransformMatrix available */
139
153bool isTransformMatrixAvailableOn(const ElementOrMeshConcept auto& element)
154{
155 return isComponentAvailableOn<CompId::TRANSFORM_MATRIX>(element);
156}
157
158/* Specialization Aliases */
159
172template<typename ElementType = void, bool OPT = false>
174
187template<typename ElementType = void, bool OPT = false>
189
190} // namespace vcl::comp
191
192#endif // VCL_MESH_COMPONENTS_TRANSFORM_MATRIX_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 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
HasTransformMatrix concept is satisfied only if a Element or Mesh class provides the member functions...
Definition transform_matrix.h:39