14#include <lagrange/Mesh.h>
15#include <lagrange/MeshTrait.h>
16#include <lagrange/legacy/inline.h>
29template <
typename MeshTypePtr>
32 static_assert(MeshTrait<MeshTypePtr>::is_mesh_ptr(),
"Input type is not a Mesh pointer type");
33 using MeshType =
typename std::pointer_traits<MeshTypePtr>::element_type;
34 using Scalar =
typename MeshType::Scalar;
35 using VertexArray =
typename MeshType::VertexArray;
36 using VectorType = Eigen::Matrix<Scalar, 1, VertexArray::ColsAtCompileTime>;
42 const auto DIM = meshes.front()->get_vertices().cols();
44 VectorType min_pos = VectorType::Constant(DIM, std::numeric_limits<Scalar>::max());
45 VectorType max_pos = VectorType::Constant(DIM, std::numeric_limits<Scalar>::lowest());
47 for (
const auto& mesh : meshes) {
48 const auto& V = mesh->get_vertices();
49 min_pos = min_pos.cwiseMin(V.colwise().minCoeff());
50 max_pos = max_pos.cwiseMax(V.colwise().maxCoeff());
53 const Scalar scaling = Scalar(1) / (max_pos - min_pos).maxCoeff();
54 const auto origin = Scalar(0.5) * (min_pos + max_pos);
56 for (
auto& mesh : meshes) {
58 mesh->export_vertices(vertices);
59 vertices = (vertices.array().rowwise() - origin.array()) * scaling;
60 mesh->import_vertices(vertices);
64template <
typename MeshType>
67 static_assert(MeshTrait<MeshType>::is_mesh(),
"Input type is not Mesh");
68 std::vector<MeshType*> vec = {&mesh};
void normalize_meshes(span< SurfaceMesh< Scalar, Index > * > meshes)
Normalize a list of meshes to fit in a unit box centered at the origin.
Definition: normalize_meshes.cpp:39
void normalize_mesh(SurfaceMesh< Scalar, Index > &mesh)
Normalize a mesh to fit in a unit box centered at the origin.
Definition: normalize_meshes.cpp:23
Main namespace for Lagrange.
Definition: AABBIGL.h:30