23#ifndef VCL_IO_MESH_OFF_SAVE_H
24#define VCL_IO_MESH_OFF_SAVE_H
26#include <vclib/io/mesh/settings.h>
27#include <vclib/io/write.h>
29#include <vclib/space/complex.h>
33template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
37 const SaveSettings& settings = SaveSettings(),
46 if (!settings.info.isEmpty())
47 meshInfo = settings.info.intersect(meshInfo);
49 if (meshInfo.hasPerVertexNormal())
51 if (meshInfo.hasPerVertexColor())
53 if (meshInfo.hasPerVertexTexCoord())
55 fp <<
"OFF" << std::endl;
60 if constexpr (HasVertices<MeshType>) {
61 vn = m.vertexNumber();
63 if constexpr (HasFaces<MeshType>) {
67 io::writeInt(fp, vn,
false);
68 io::writeInt(fp, fn,
false);
69 io::writeInt(fp, en,
false);
73 if constexpr (HasVertices<MeshType>) {
74 using VertexType = MeshType::VertexType;
75 for (
const VertexType& v : m.
vertices()) {
76 io::writeDouble(fp, v.position().x(),
false);
77 io::writeDouble(fp, v.position().y(),
false);
78 io::writeDouble(fp, v.position().z(),
false);
80 if constexpr (HasPerVertexColor<MeshType>) {
81 if (meshInfo.hasPerVertexColor()) {
82 io::writeInt(fp, v.color().red(),
false);
83 io::writeInt(fp, v.color().green(),
false);
84 io::writeInt(fp, v.color().blue(),
false);
85 io::writeInt(fp, v.color().alpha(),
false);
88 if constexpr (HasPerVertexNormal<MeshType>) {
89 if (meshInfo.hasPerVertexNormal()) {
90 io::writeDouble(fp, v.normal().x(),
false);
91 io::writeDouble(fp, v.normal().y(),
false);
92 io::writeDouble(fp, v.normal().z(),
false);
95 if constexpr (HasPerVertexTexCoord<MeshType>) {
96 if (meshInfo.hasPerVertexTexCoord()) {
97 io::writeDouble(fp, v.texCoord().u(),
false);
98 io::writeDouble(fp, v.texCoord().v(),
false);
107 if constexpr (HasFaces<MeshType>) {
108 using VertexType = MeshType::VertexType;
109 using FaceType = MeshType::FaceType;
112 std::vector<uint> vIndices = m.vertexCompactIndices();
114 for (
const FaceType& f : m.
faces()) {
115 io::writeInt(fp, f.vertexNumber(),
false);
116 for (
const VertexType* v : f.
vertices()) {
117 io::writeInt(fp, vIndices[m.index(v)],
false);
119 if constexpr (HasPerFaceColor<MeshType>) {
120 if (meshInfo.hasPerFaceColor()) {
121 io::writeInt(fp, f.color().red(),
false);
122 io::writeInt(fp, f.color().green(),
false);
123 io::writeInt(fp, f.color().blue(),
false);
124 io::writeInt(fp, f.color().alpha(),
false);
133template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
136 const std::string& filename,
137 const SaveSettings& settings = SaveSettings(),
140 std::ofstream fp = openOutputFileStream(filename,
"off");
141 saveOff(m, fp, settings, log);
NullLogger nullLogger
The nullLogger object is an object of type NullLogger that is used as default argument in the functio...
Definition null_logger.h:123
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