14#include <lagrange/create_mesh.h>
15#include <lagrange/legacy/inline.h>
18#include <lagrange/utils/warnoff.h>
19#include <openvdb/openvdb.h>
20#include <openvdb/tools/VolumeToMesh.h>
21#include <lagrange/utils/warnon.h>
44template <
typename MeshType,
typename Gr
idType>
45std::unique_ptr<MeshType> volume_to_mesh_legacy(
47 double isovalue = 0.0,
48 double adaptivity = 0.0,
49 bool relax_disoriented_triangles =
true)
51 static_assert(MeshTrait<MeshType>::is_mesh(),
"Input type is not Mesh");
53 openvdb::initialize();
55 using Scalar = ScalarOf<MeshType>;
56 using Index = IndexOf<MeshType>;
57 using VertexArray = VertexArrayOf<MeshType>;
58 using FacetArray = FacetArrayOf<MeshType>;
59 using RowVector3s = Eigen::Matrix<float, 1, 3>;
60 using RowVector3I = Eigen::Matrix<openvdb::Index32, 1, 3>;
61 using RowVector3I = Eigen::Matrix<openvdb::Index32, 1, 3>;
62 using RowVector4I = Eigen::Matrix<openvdb::Index32, 1, 4>;
63 using RowVector4i = Eigen::Matrix<Index, 1, 4>;
65 if (adaptivity < 0 || adaptivity > 1) {
66 logger().warn(
"Adaptivity needs to be between 0 and 1.");
67 adaptivity = std::max(0.0, std::min(1.0, adaptivity));
70 std::vector<openvdb::Vec3s> points;
71 std::vector<openvdb::Vec3I> triangles;
72 std::vector<openvdb::Vec4I> quads;
74 openvdb::tools::volumeToMesh(
81 relax_disoriented_triangles);
83 VertexArray vertices(points.size(), 3);
84 FacetArray facets(triangles.size() + 2 * quads.size(), 3);
87 const bool need_flip = (grid.getGridClass() == openvdb::GRID_LEVEL_SET);
89 for (
size_t v = 0; v < points.size(); ++v) {
90 const RowVector3s p(points[v].x(), points[v].y(), points[v].z());
94 for (
size_t f = 0; f < triangles.size(); ++f) {
95 const RowVector3I triangle(triangles[f].x(), triangles[f].y(), triangles[f].z());
98 facets.row(f) = facets.row(f).reverse().eval();
102 for (
size_t f = 0, o = triangles.size(); f < quads.size(); ++f) {
103 const RowVector4I quad_(quads[f].x(), quads[f].y(), quads[f].z(), quads[f].w());
104 const RowVector4i quad = quad_.template
cast<Index>();
105 facets.row(o + 2 * f) << quad(0), quad(1), quad(3);
106 facets.row(o + 2 * f + 1) << quad(3), quad(1), quad(2);
108 facets.row(o + 2 * f) = facets.row(o + 2 * f).reverse().eval();
109 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