23#ifndef VCL_ALGORITHMS_MESH_UPDATE_TRANSFORM_H
24#define VCL_ALGORITHMS_MESH_UPDATE_TRANSFORM_H
26#include <vclib/mesh.h>
27#include <vclib/space/core.h>
31template<MeshConcept MeshType,
typename ScalarM>
32void applyTransformMatrix(
34 const Matrix44<ScalarM>& matrix,
35 bool updateNormals =
true)
37 using VertexType = MeshType::VertexType;
39 multiplyPointsByMatrix(mesh.vertices() | vcl::views::positions, matrix);
44 if constexpr (HasPerVertexNormal<MeshType>) {
45 if (isPerVertexNormalAvailable(mesh)) {
46 multiplyNormalsByMatrix(
47 mesh.vertices() | vcl::views::normals, matrix);
50 if constexpr (HasPerFaceNormal<MeshType>) {
52 multiplyNormalsByMatrix(
53 mesh.faces() | vcl::views::normals, matrix);
59template<MeshConcept MeshType, Po
intConcept Po
intType>
60void translate(MeshType& mesh,
const PointType& t)
62 using VertexType = MeshType::VertexType;
63 for (VertexType& v : mesh.
vertices()) {
68template<MeshConcept MeshType, Po
intConcept Po
intType>
69void scale(MeshType& mesh,
const PointType& s)
71 using VertexType = MeshType::VertexType;
72 for (VertexType& v : mesh.
vertices()) {
73 v.position()(0) *= s(0);
74 v.position()(1) *= s(1);
75 v.position()(2) *= s(2);
79template<MeshConcept MeshType,
typename Scalar =
double>
80void scale(MeshType& mesh,
const Scalar& s)
82 using VertexType = MeshType::VertexType;
83 for (VertexType& v : mesh.
vertices()) {
88template<MeshConcept MeshType,
typename Scalar>
91 const Matrix33<Scalar>& m,
92 bool updateNormals =
true)
95 v.position() = m * v.position();
99 if constexpr (HasPerVertexNormal<MeshType>) {
100 if (isPerVertexNormalAvailable(mesh)) {
102 v.normal() = m * v.normal();
107 if constexpr (HasPerFaceNormal<MeshType>) {
109 for (
auto& f : mesh.
faces()) {
110 f.normal() = m * f.normal();
117template<MeshConcept MeshType, Po
intConcept Po
intType,
typename Scalar =
double>
120 const PointType& axis,
121 const Scalar& angleRad,
122 bool updateNormals =
true)
124 using ScalarType = MeshType::VertexType::PositionType::ScalarType;
126 Matrix33<ScalarType> m;
129 rotate(mesh, m, updateNormals);
132template<MeshConcept MeshType, Po
intConcept Po
intType,
typename Scalar =
double>
135 const PointType& axis,
136 const Scalar& angleDeg,
137 bool updateNormals =
true)
139 rotate(mesh, axis,
toRad(angleDeg), updateNormals);
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:48
Scalar toRad(const Scalar °)
Converts an angle in degrees to radians.
Definition math.h:81
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:592
constexpr detail::FacesView faces
A view that allows to iterate overt the Face elements of an object.
Definition face.h:84
constexpr detail::VerticesView vertices
A view that allows to iterate over the Vertex elements of an object.
Definition vertex.h:92