14#include <lagrange/create_mesh.h>
15#include <lagrange/legacy/inline.h>
17#include <openvdb/openvdb.h>
18#include <openvdb/tools/VolumeToMesh.h>
40template <
typename MeshType,
typename Gr
idType>
41std::unique_ptr<MeshType> volume_to_mesh_legacy(
43 double isovalue = 0.0,
44 double adaptivity = 0.0,
45 bool relax_disoriented_triangles =
true)
47 static_assert(MeshTrait<MeshType>::is_mesh(),
"Input type is not Mesh");
49 openvdb::initialize();
51 using Scalar = ScalarOf<MeshType>;
52 using Index = IndexOf<MeshType>;
53 using VertexArray = VertexArrayOf<MeshType>;
54 using FacetArray = FacetArrayOf<MeshType>;
55 using RowVector3s = Eigen::Matrix<float, 1, 3>;
56 using RowVector3I = Eigen::Matrix<openvdb::Index32, 1, 3>;
57 using RowVector3I = Eigen::Matrix<openvdb::Index32, 1, 3>;
58 using RowVector4I = Eigen::Matrix<openvdb::Index32, 1, 4>;
59 using RowVector4i = Eigen::Matrix<Index, 1, 4>;
61 if (adaptivity < 0 || adaptivity > 1) {
62 logger().warn(
"Adaptivity needs to be between 0 and 1.");
63 adaptivity = std::max(0.0, std::min(1.0, adaptivity));
66 std::vector<openvdb::Vec3s> points;
67 std::vector<openvdb::Vec3I> triangles;
68 std::vector<openvdb::Vec4I> quads;
70 openvdb::tools::volumeToMesh(
77 relax_disoriented_triangles);
79 VertexArray vertices(points.size(), 3);
80 FacetArray facets(triangles.size() + 2 * quads.size(), 3);
83 const bool need_flip = (grid.getGridClass() == openvdb::GRID_LEVEL_SET);
85 for (
size_t v = 0; v < points.size(); ++v) {
86 const RowVector3s p(points[v].x(), points[v].y(), points[v].z());
90 for (
size_t f = 0; f < triangles.size(); ++f) {
91 const RowVector3I triangle(triangles[f].x(), triangles[f].y(), triangles[f].z());
94 facets.row(f) = facets.row(f).reverse().eval();
98 for (
size_t f = 0, o = triangles.size(); f < quads.size(); ++f) {
99 const RowVector4I quad_(quads[f].x(), quads[f].y(), quads[f].z(), quads[f].w());
100 const RowVector4i quad = quad_.template
cast<Index>();
101 facets.row(o + 2 * f) << quad(0), quad(1), quad(3);
102 facets.row(o + 2 * f + 1) << quad(3), quad(1), quad(2);
104 facets.row(o + 2 * f) = facets.row(o + 2 * f).reverse().eval();
105 facets.row(o + 2 * f + 1) = facets.row(o + 2 * f + 1).reverse().eval();
LA_CORE_API spdlog::logger & logger()
Retrieves the current logger.
Definition Logger.cpp:40
@ Scalar
Mesh attribute must have exactly 1 channel.
Definition AttributeFwd.h:56
SurfaceMesh< ToScalar, ToIndex > cast(const SurfaceMesh< FromScalar, FromIndex > &source_mesh, const AttributeFilter &convertible_attributes={}, std::vector< std::string > *converted_attributes_names=nullptr)
Cast a mesh to a mesh of different scalar and/or index type.
Main namespace for Lagrange.
auto create_mesh(const Eigen::MatrixBase< DerivedV > &vertices, const Eigen::MatrixBase< DerivedF > &facets)
This function create a new mesh given the vertex and facet arrays by copying data into the Mesh objec...
Definition create_mesh.h:39