Visual Computing Library  devel
Loading...
Searching...
No Matches
save_mesh.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_IO_MESH_SAVE_MESH_H
24#define VCL_IO_MESH_SAVE_MESH_H
25
26#include "obj/save.h"
27#include "off/save.h"
28#include "ply/save.h"
29#include "stl/save.h"
30
31#include "capability.h"
32
40namespace vcl {
41
52inline std::set<FileFormat> saveMeshFormats()
53{
54 std::set<FileFormat> ff;
55
56 ff.insert(objFileFormat());
57 ff.insert(offFileFormat());
58 ff.insert(plyFileFormat());
59 ff.insert(stlFileFormat());
60
61 return ff;
62}
63
77template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
78void saveMesh(
79 const MeshType& m,
80 const std::string& filename,
81 const SaveSettings& settings,
82 LogType& log = nullLogger)
83{
84 FileFormat ff = FileInfo::fileFormat(filename);
85
86 if (ff == objFileFormat()) {
87 saveObj(m, filename, settings, log);
88 }
89 else if (ff == offFileFormat()) {
90 saveOff(m, filename, settings, log);
91 }
92 else if (ff == plyFileFormat()) {
93 savePly(m, filename, settings, log);
94 }
95 else if (ff == stlFileFormat()) {
96 saveStl(m, filename, settings, log);
97 }
98 else {
99 throw UnknownFileFormatException(ff.extensions().front());
100 }
101}
102
121template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
122void saveMesh(
123 const MeshType& m,
124 const std::string& filename,
125 LogType& log = nullLogger,
126 const SaveSettings& settings = SaveSettings())
127{
128 saveMesh(m, filename, settings, log);
129}
130
131} // namespace vcl
132
133#endif // VCL_IO_MESH_SAVE_MESH_H
A class representing a box in N-dimensional space.
Definition box.h:46
static FileFormat fileFormat(const std::string &filename)
Get the file format of a file from its filename.
Definition file_info.h:280
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
std::set< FileFormat > saveMeshFormats()
Returns the set of mesh formats supported for saving.
Definition save_mesh.h:52
The SaveSettings structure contains the settings that can be used to save a mesh to a stream/file.
Definition settings.h:62