23#ifndef VCL_LOAD_SAVE_OFF_SAVE_H
24#define VCL_LOAD_SAVE_OFF_SAVE_H
26#include <vclib/exceptions/io.h>
27#include <vclib/io/write.h>
28#include <vclib/load_save/settings.h>
29#include <vclib/misc/logger.h>
30#include <vclib/space/complex/mesh_info.h>
34template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
39 const SaveSettings& settings = SaveSettings())
47 if (!settings.info.isEmpty())
48 meshInfo = settings.info.intersect(meshInfo);
50 if (meshInfo.hasVertexNormals())
52 if (meshInfo.hasVertexColors())
54 if (meshInfo.hasVertexTexCoords())
56 fp <<
"OFF" << std::endl;
61 if constexpr (HasVertices<MeshType>) {
62 vn = m.vertexNumber();
64 if constexpr (HasFaces<MeshType>) {
68 io::writeInt(fp, vn,
false);
69 io::writeInt(fp, fn,
false);
70 io::writeInt(fp, en,
false);
74 if constexpr (HasVertices<MeshType>) {
75 using VertexType = MeshType::VertexType;
76 for (
const VertexType& v : m.
vertices()) {
77 io::writeDouble(fp, v.coord().x(),
false);
78 io::writeDouble(fp, v.coord().y(),
false);
79 io::writeDouble(fp, v.coord().z(),
false);
81 if constexpr (HasPerVertexColor<MeshType>) {
82 if (meshInfo.hasVertexColors()) {
83 io::writeInt(fp, v.color().red(),
false);
84 io::writeInt(fp, v.color().green(),
false);
85 io::writeInt(fp, v.color().blue(),
false);
86 io::writeInt(fp, v.color().alpha(),
false);
89 if constexpr (HasPerVertexNormal<MeshType>) {
90 if (meshInfo.hasVertexNormals()) {
91 io::writeDouble(fp, v.normal().x(),
false);
92 io::writeDouble(fp, v.normal().y(),
false);
93 io::writeDouble(fp, v.normal().z(),
false);
96 if constexpr (HasPerVertexTexCoord<MeshType>) {
97 if (meshInfo.hasVertexTexCoords()) {
98 io::writeDouble(fp, v.texCoord().u(),
false);
99 io::writeDouble(fp, v.texCoord().v(),
false);
108 if constexpr (HasFaces<MeshType>) {
109 using VertexType = MeshType::VertexType;
110 using FaceType = MeshType::FaceType;
113 std::vector<uint> vIndices = m.vertexCompactIndices();
115 for (
const FaceType& f : m.
faces()) {
116 io::writeInt(fp, f.vertexNumber(),
false);
117 for (
const VertexType* v : f.
vertices()) {
118 io::writeInt(fp, vIndices[m.index(v)],
false);
120 if constexpr (HasPerFaceColor<MeshType>) {
121 if (meshInfo.hasFaceColors()) {
122 io::writeInt(fp, f.color().red(),
false);
123 io::writeInt(fp, f.color().green(),
false);
124 io::writeInt(fp, f.color().blue(),
false);
125 io::writeInt(fp, f.color().alpha(),
false);
134template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
138 const SaveSettings& settings,
141 saveOff(m, fp, log, settings);
144template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
147 const std::string& filename,
149 const SaveSettings& settings = SaveSettings())
151 std::ofstream fp = openOutputFileStream(filename,
"off");
152 saveOff(m, fp, log, settings);
156template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
159 const std::string& filename,
160 const SaveSettings& settings,
163 saveOff(m, filename, log, settings);
NullLogger nullLogger
The nullLogger object is an object of type NullLogger that is used as default argument in the functio...
Definition null_logger.h:125
constexpr detail::FacesView faces
A view that allows to iterate overt the Face elements of an object.
Definition face.h:52
constexpr detail::VerticesView vertices
A view that allows to iterate over the Vertex elements of an object.
Definition vertex.h:60