14#include <lagrange/fs/filesystem.h>
15#include <lagrange/io/types.h>
17#include <lagrange/MeshTrait.h>
18#include <lagrange/create_mesh.h>
19#include <lagrange/utils/safe_cast.h>
20#include <lagrange/legacy/inline.h>
23#include <lagrange/utils/warnoff.h>
24#include <igl/writePLY.h>
25#include <lagrange/utils/warnon.h>
38 std::enable_if_t<lagrange::MeshTraitHelper::is_mesh<MeshType>::value>* =
nullptr>
40 const fs::path& filename,
42 FileEncoding encoding = FileEncoding::Binary)
44 static_assert(MeshTrait<MeshType>::is_mesh(),
"Input type is not Mesh");
45 using VertexArray =
typename MeshType::VertexArray;
46 using AttributeArray =
typename MeshType::AttributeArray;
47 using Index =
unsigned int;
49 const VertexArray& V = mesh.get_vertices();
50 const auto F = mesh.get_facets().template cast<Index>();
51 Eigen::Matrix<Index, Eigen::Dynamic, Eigen::Dynamic> E;
55 Eigen::Matrix<unsigned char, Eigen::Dynamic, Eigen::Dynamic> VD;
56 std::vector<std::string> VDheader;
59 std::vector<std::string> FDheader;
62 std::vector<std::string> EDheader;
63 std::vector<std::string> comments;
65 if (mesh.has_vertex_attribute(
"normal")) {
66 N = mesh.get_vertex_attribute(
"normal");
69 if (mesh.has_vertex_attribute(
"color")) {
70 VDheader = {
"red",
"green",
"blue"};
71 auto C = mesh.get_vertex_attribute(
"color");
72 if (C.maxCoeff() <= 1.0 && C.maxCoeff() > 0.0) {
73 logger().warn(
"Max color value is > 0.0 but <= 1.0, but colors are saved as char. "
74 "Please convert your colors to the range [0, 255].");
76 VD = C.template cast<unsigned char>();
78 VDheader.push_back(
"alpha");
97 encoding == FileEncoding::Binary ? igl::FileEncoding::Binary : igl::FileEncoding::Ascii);
LA_CORE_API spdlog::logger & logger()
Retrieves the current logger.
Definition: Logger.cpp:40
@ UV
Mesh attribute must have exactly 2 channels.
#define la_runtime_assert(...)
Runtime assertion check.
Definition: assert.h:169
Mesh input/output.
Definition: detect_file_format.h:18
void save_mesh_ply(std::ostream &output_stream, const SurfaceMesh< Scalar, Index > &mesh, const SaveOptions &options={})
Saves a mesh to a stream in PLY format.
Definition: save_mesh_ply.cpp:214