Visual Computing Library  devel
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_RENDER_IO_CAMERA_LOAD_H
24#define VCL_RENDER_IO_CAMERA_LOAD_H
25
26#ifdef VCLIB_WITH_TINYGLTF
27#include "gltf/load.h"
28#endif
29
30#include <vclib/io/file_format.h>
31#include <vclib/io/mesh/gltf/capability.h>
32
33#include <set>
34#include <string>
35#include <vector>
36
37namespace vcl {
38
47inline std::set<FileFormat> loadCameraFormats()
48{
49 std::set<FileFormat> ff;
50
51#ifdef VCLIB_WITH_TINYGLTF
52 ff.insert(gltfFileFormat());
53#endif
54
55 return ff;
56}
57
58template<CameraConcept CameraType = Camera<float>>
59inline std::vector<CameraType> loadCameras(const std::string& filename)
60{
61 FileFormat ff = FileInfo::fileFormat(filename);
62#ifdef VCLIB_WITH_TINYGLTF
63 if (ff == gltfFileFormat())
64 return loadCamerasGltf<CameraType>(filename);
65 else
66#endif
67 throw UnknownFileFormatException(ff.extensions().front());
68}
69
70template<CameraConcept CameraType = Camera<float>>
71inline CameraType loadCamera(const std::string& filename)
72{
73 auto cams = loadCameras<CameraType>(filename);
74 if (cams.empty())
75 throw std::runtime_error("No cameras in file: " + filename);
76 return cams.front();
77}
78
79} // namespace vcl
80
81#endif // VCL_RENDER_IO_CAMERA_LOAD_H
static FileFormat fileFormat(const std::string &filename)
Get the file format of a file from its filename.
Definition file_info.h:280