Visual Computing Library  devel
Loading...
Searching...
No Matches
load_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_LOAD_MESH_H
24#define VCL_IO_MESH_LOAD_MESH_H
25
26#include "obj/load.h"
27#include "off/load.h"
28#include "ply/load.h"
29#include "stl/load.h"
30
31#ifdef VCLIB_WITH_TINYGLTF
32#include "gltf/load.h"
33#endif
34
35#include "capability.h"
36
44namespace vcl {
45
57inline std::set<FileFormat> loadMeshFormats()
58{
59 std::set<FileFormat> ff;
60
61 ff.insert(objFileFormat());
62 ff.insert(offFileFormat());
63 ff.insert(plyFileFormat());
64 ff.insert(stlFileFormat());
65
66#ifdef VCLIB_WITH_TINYGLTF
67 ff.insert(gltfFileFormat());
68#endif
69
70 return ff;
71}
72
94template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
96 MeshType& m,
97 const std::string& filename,
99 const LoadSettings& settings,
100 LogType& log = nullLogger)
101{
103
104 loadedInfo.clear();
105
106 if (ff == objFileFormat()) {
107 loadObj(m, filename, loadedInfo, settings, log);
108 }
109 else if (ff == offFileFormat()) {
110 loadOff(m, filename, loadedInfo, settings, log);
111 }
112 else if (ff == plyFileFormat()) {
113 loadPly(m, filename, loadedInfo, settings, log);
114 }
115 else if (ff == stlFileFormat()) {
116 loadStl(m, filename, loadedInfo, settings, log);
117 }
118#ifdef VCLIB_WITH_TINYGLTF
119 else if (ff == gltfFileFormat()) {
120 loadGltf(m, filename, loadedInfo, settings, log);
121 }
122#endif
123 else {
124 throw UnknownFileFormatException(ff.extensions().front());
125 }
126}
127
149template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
151 MeshType& m,
152 const std::string& filename,
154 LogType& log = nullLogger,
155 const LoadSettings& settings = LoadSettings())
156{
157 loadMesh(m, filename, loadedInfo, settings, log);
158}
159
179template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
181 MeshType& m,
182 const std::string& filename,
183 const LoadSettings& settings,
184 LogType& log = nullLogger)
185{
187 loadMesh(m, filename, loadedInfo, settings, log);
188}
189
209template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
211 MeshType& m,
212 const std::string& filename,
213 LogType& log = nullLogger,
214 const LoadSettings& settings = LoadSettings())
215{
217 loadMesh(m, filename, loadedInfo, settings, log);
218}
219
241template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
242MeshType loadMesh(
243 const std::string& filename,
245 const LoadSettings& settings,
246 LogType& log = nullLogger)
247{
248 MeshType m;
249 loadMesh(m, filename, loadedInfo, settings, log);
250 return m;
251}
252
274template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
275MeshType loadMesh(
276 const std::string& filename,
278 LogType& log = nullLogger,
279 const LoadSettings& settings = LoadSettings())
280{
281 MeshType m;
282 loadMesh(m, filename, loadedInfo, settings, log);
283 return m;
284}
285
305template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
306MeshType loadMesh(
307 const std::string& filename,
308 const LoadSettings& settings,
309 LogType& log = nullLogger)
310{
312 return loadMesh<MeshType>(filename, loadedInfo, settings, log);
313}
314
334template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
335MeshType loadMesh(
336 const std::string& filename,
337 LogType& log = nullLogger,
338 const LoadSettings& settings = LoadSettings())
339{
341 return loadMesh<MeshType>(filename, loadedInfo, settings, log);
342}
343
344} // namespace vcl
345
346#endif // VCL_IO_MESH_LOAD_MESH_H
A class representing a box in N-dimensional space.
Definition box.h:46
The FileFormat class represents a file format.
Definition file_format.h:40
static FileFormat fileFormat(const std::string &filename)
Get the file format of a file from its filename.
Definition file_info.h:280
A simple class that allows to store which elements and their components have been imported/loaded or ...
Definition mesh_info.h:76
Exception thrown when the file format is unknown.
Definition exceptions.h:37
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
void loadPly(MeshType &m, std::istream &inputPlyStream, MeshInfo &loadedInfo, const LoadSettings &settings=LoadSettings(), LogType &log=nullLogger)
Loads from the given input ply stream and puts the content into the mesh m.
Definition load.h:159
void loadObj(MeshType &m, std::istream &inputObjStream, const std::vector< std::istream * > &inputMtlStreams, MeshInfo &loadedInfo, const LoadSettings &settings=LoadSettings(), LogType &log=nullLogger)
Loads from the given input obj stream and puts the content into the mesh m.
Definition load.h:712
void loadOff(MeshType &m, std::istream &inputOffStream, MeshInfo &loadedInfo, const LoadSettings &settings=LoadSettings(), LogType &log=nullLogger)
Loads from the given input off stream and puts the content into the mesh m.
Definition load.h:510
std::set< FileFormat > loadMeshFormats()
Returns the set of mesh formats supported for loading a single Mesh from file.
Definition load_mesh.h:57
void loadMesh(MeshType &m, const std::string &filename, MeshInfo &loadedInfo, const LoadSettings &settings, LogType &log=nullLogger)
Loads a mesh from a file with the given filename and stores it in the given mesh object....
Definition load_mesh.h:95
void loadStl(MeshType &m, std::istream &inputStlStream, MeshInfo &loadedInfo, bool isBinary=false, const LoadSettings &settings=LoadSettings(), LogType &log=nullLogger)
Loads from the given input stl stream and puts the content into the mesh m.
Definition load.h:310
The LoadSettings structure contains the settings that can be used to load a mesh from a stream/file.
Definition settings.h:35