23#ifndef VCL_ALGORITHMS_MESH_UPDATE_TRANSFORM_H
24#define VCL_ALGORITHMS_MESH_UPDATE_TRANSFORM_H
28#include <vclib/math/transform.h>
29#include <vclib/mesh/requirements.h>
33template<MeshConcept MeshType,
typename ScalarM>
34void applyTransformMatrix(
36 const Matrix44<ScalarM>& matrix,
37 bool updateNormals =
true)
39 using VertexType = MeshType::VertexType;
40 for (VertexType& v : mesh.
vertices()) {
44 if constexpr (HasPerVertexNormal<MeshType>) {
45 if (isPerVertexNormalAvailable(mesh)) {
46 multiplyPerVertexNormalsByMatrix(mesh, matrix);
49 if constexpr (HasPerFaceNormal<MeshType>) {
51 multiplyPerFaceNormalsByMatrix(mesh, matrix);
57template<MeshConcept MeshType, Po
intConcept Po
intType>
58void translate(MeshType& mesh,
const PointType& t)
60 using VertexType = MeshType::VertexType;
61 for (VertexType& v : mesh.
vertices()) {
66template<MeshConcept MeshType, Po
intConcept Po
intType>
67void scale(MeshType& mesh,
const PointType& s)
69 using VertexType = MeshType::VertexType;
70 for (VertexType& v : mesh.
vertices()) {
77template<MeshConcept MeshType,
typename Scalar =
double>
78void scale(MeshType& mesh,
const Scalar& s)
80 using VertexType = MeshType::VertexType;
81 for (VertexType& v : mesh.
vertices()) {
86template<MeshConcept MeshType,
typename Scalar>
89 const Matrix33<Scalar>& m,
90 bool updateNormals =
true)
93 v.coord() = m * v.coord();
97 if constexpr (HasPerVertexNormal<MeshType>) {
98 if (isPerVertexNormalAvailable(mesh)) {
100 v.normal() = m * v.normal();
105 if constexpr (HasPerFaceNormal<MeshType>) {
107 for (
auto& f : mesh.
faces()) {
108 f.normal() = m * f.normal();
115template<MeshConcept MeshType, Po
intConcept Po
intType,
typename Scalar =
double>
118 const PointType& axis,
119 const Scalar& angleRad,
120 bool updateNormals =
true)
122 using ScalarType = MeshType::VertexType::CoordType::ScalarType;
124 Matrix33<ScalarType> m;
127 rotate(mesh, m, updateNormals);
130template<MeshConcept MeshType, Po
intConcept Po
intType,
typename Scalar =
double>
133 const PointType& axis,
134 const Scalar& angleDeg,
135 bool updateNormals =
true)
137 rotate(mesh, axis,
toRad(angleDeg), updateNormals);
bool isPerFaceNormalAvailable(const MeshType &m)
Returns true if the Normal component is available (enabled) in the Face element of the input mesh m.
Definition face_requirements.h:330
void setTransformMatrixRotation(MatrixType &matrix, PointType axis, const ScalarType &angleRad)
Given an 3D axis and an angle expressed in radiants, fills the given matrix with a transform matrix t...
Definition transform.h:49
Scalar toRad(const Scalar °)
Converts an angle in degrees to radians.
Definition base.h:83
constexpr detail::FacesView faces
A view that allows to iterate overt the Face elements of an object.
Definition face.h:52
constexpr detail::VerticesView vertices
A view that allows to iterate over the Vertex elements of an object.
Definition vertex.h:60