Visual Computing Library  devel
Loading...
Searching...
No Matches
load.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2026 *
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_CAMERA_LOAD_H
24#define VCL_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
32#ifdef VCLIB_WITH_TINYGLTF
33#include <vclib/io/mesh/gltf/capability.h>
34#endif
35
36#include <vclib/space/core.h>
37
38#include <set>
39#include <string>
40#include <vector>
41
42namespace vcl {
43
52inline std::set<FileFormat> loadCameraFormats()
53{
54 std::set<FileFormat> ff;
55
56#ifdef VCLIB_WITH_TINYGLTF
57 ff.insert(gltfFileFormat());
58#endif
59
60 return ff;
61}
62
63template<CameraConcept CameraType = Camera<float>>
64std::vector<CameraType> loadCameras(const std::string& filename)
65{
66 FileFormat ff = FileInfo::fileFormat(filename);
67#ifdef VCLIB_WITH_TINYGLTF
68 if (ff == gltfFileFormat())
69 return loadCamerasGltf<CameraType>(filename);
70 else
71#endif
72 throw UnknownFileFormatException(ff.extensions().front());
73}
74
75template<CameraConcept CameraType = Camera<float>>
76CameraType loadCamera(const std::string& filename)
77{
78 auto cams = loadCameras<CameraType>(filename);
79 if (cams.empty())
80 throw std::runtime_error("No cameras in file: " + filename);
81 return cams.front();
82}
83
84} // namespace vcl
85
86#endif // VCL_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