Visual Computing Library
Loading...
Searching...
No Matches
load.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_LOAD_SAVE_LOAD_H
24#define VCL_LOAD_SAVE_LOAD_H
25
26#include "obj/load.h"
27#include "off/load.h"
28#include "ply/load.h"
29#include "stl/load.h"
30
39namespace vcl {
40
62template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
63void load(
64 MeshType& m,
65 const std::string& filename,
67 LogType& log = nullLogger,
68 const LoadSettings& settings = LoadSettings())
69{
70 std::string ext = FileInfo::extension(filename);
71 ext = toLower(ext);
72
73 loadedInfo.clear();
74
75 if (ext == ".obj") {
76 loadObj(m, filename, loadedInfo, log, settings);
77 }
78 else if (ext == ".off") {
79 loadOff(m, filename, loadedInfo, log, settings);
80 }
81 else if (ext == ".ply") {
82 loadPly(m, filename, loadedInfo, log, settings);
83 }
84 else if (ext == ".stl") {
85 loadStl(m, filename, loadedInfo, log, settings);
86 }
87 else {
89 }
90}
91
111template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
112void load(
113 MeshType& m,
114 const std::string& filename,
115 LogType& log = nullLogger,
116 const LoadSettings& settings = LoadSettings())
117{
119 load(m, filename, loadedInfo, log, settings);
120}
121
143template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
144MeshType load(
145 const std::string& filename,
147 LogType& log = nullLogger,
148 const LoadSettings& settings = LoadSettings())
149{
150 MeshType m;
151 load(m, filename, loadedInfo, log, settings);
152 return m;
153}
154
174template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
175MeshType load(
176 const std::string& filename,
177 const LoadSettings& settings,
178 LogType& log = nullLogger)
179{
181 return load<MeshType>(filename, loadedInfo, log, settings);
182}
183
203template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
204MeshType load(
205 const std::string& filename,
206 LogType& log = nullLogger,
207 const LoadSettings& settings = LoadSettings())
208{
210 return load<MeshType>(filename, loadedInfo, log, settings);
211}
212
213} // namespace vcl
214
215#endif // VCL_LOAD_SAVE_LOAD_H
static std::string extension(const std::string &filename)
Get the extension of a file.
Definition file_info.h:257
A simple class that allows to store which elements and their components have been imported/loaded or ...
Definition mesh_info.h:76
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
Exception thrown when the file format is unknown.
Definition io.h:37
void loadOff(MeshType &m, std::istream &inputOffStream, MeshInfo &loadedInfo, LogType &log=nullLogger, const LoadSettings &settings=LoadSettings())
Loads from the given input off stream and puts the content into the mesh m.
Definition load.h:511
void loadStl(MeshType &m, std::istream &inputStlStream, MeshInfo &loadedInfo, bool isBinary=false, LogType &log=nullLogger, const LoadSettings &settings=LoadSettings())
Loads from the given input stl stream and puts the content into the mesh m.
Definition load.h:310
void load(MeshType &m, const std::string &filename, MeshInfo &loadedInfo, LogType &log=nullLogger, const LoadSettings &settings=LoadSettings())
Loads a mesh from a file with the given filename and stores it in the given mesh object....
Definition load.h:63
void loadObj(MeshType &m, std::istream &inputObjStream, const std::vector< std::istream * > &inputMtlStreams, MeshInfo &loadedInfo, LogType &log=nullLogger, const LoadSettings &settings=LoadSettings())
Loads from the given input obj stream and puts the content into the mesh m.
Definition load.h:710
void loadPly(MeshType &m, std::istream &inputPlyStream, MeshInfo &loadedInfo, LogType &log=nullLogger, const LoadSettings &settings=LoadSettings())
Loads from the given input ply stream and puts the content into the mesh m.
Definition load.h:159
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
The LoadSettings structure contains the settings that can be used to load a mesh from a stream/file.
Definition settings.h:35