Blue Brain BioExplorer
Loader.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2024, EPFL/Blue Brain Project
3  *
4  * Responsible Author: Daniel.Nachbaur@epfl.ch
5  *
6  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
7  *
8  * This library is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU Lesser General Public License version 3.0 as published
10  * by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #pragma once
23 
26 
27 #include <functional>
28 
29 #ifdef BRAYNS_USE_OPENMP
30 #include <omp.h>
31 #endif
32 
33 namespace core
34 {
39 {
40 public:
45  using CallbackFn = std::function<void(const std::string&, float)>;
46 
48  : _callback(std::move(callback))
49  {
50  }
51 
52  LoaderProgress() = default;
53  ~LoaderProgress() = default;
54 
58  void updateProgress(const std::string& message, const float fraction) const
59  {
60 #ifdef BRAYNS_USE_OPENMP
61  if (omp_get_thread_num() == 0)
62 #endif
63  if (_callback)
64  _callback(message, fraction);
65  }
66 
68 };
69 
74 class Loader
75 {
76 public:
77  Loader(Scene& scene)
78  : _scene(scene)
79  {
80  }
81 
82  virtual ~Loader() = default;
83 
87  virtual std::vector<std::string> getSupportedStorage() const = 0;
88 
92  virtual std::string getName() const = 0;
93 
97  virtual PropertyMap getProperties() const { return {}; }
106  virtual ModelDescriptorPtr importFromBlob(Blob&& blob, const LoaderProgress& callback,
107  const PropertyMap& properties) const = 0;
108 
117  virtual ModelDescriptorPtr importFromStorage(const std::string& storage, const LoaderProgress& callback,
118  const PropertyMap& properties) const = 0;
119 
123  virtual bool isSupported(const std::string& filename, const std::string& extension) const = 0;
124 
125 protected:
127 };
128 } // namespace core
std::function< void(const std::string &, float)> CallbackFn
Definition: Loader.h:45
CallbackFn _callback
Definition: Loader.h:67
~LoaderProgress()=default
void updateProgress(const std::string &message, const float fraction) const
Definition: Loader.h:58
LoaderProgress()=default
LoaderProgress(CallbackFn callback)
Definition: Loader.h:47
virtual ModelDescriptorPtr importFromStorage(const std::string &storage, const LoaderProgress &callback, const PropertyMap &properties) const =0
virtual ModelDescriptorPtr importFromBlob(Blob &&blob, const LoaderProgress &callback, const PropertyMap &properties) const =0
Loader(Scene &scene)
Definition: Loader.h:77
Scene & _scene
Definition: Loader.h:126
virtual bool isSupported(const std::string &filename, const std::string &extension) const =0
virtual ~Loader()=default
virtual std::string getName() const =0
virtual PropertyMap getProperties() const
Definition: Loader.h:97
virtual std::vector< std::string > getSupportedStorage() const =0
Scene object This object contains collections of geometries, materials and light sources that are use...
Definition: Scene.h:43
std::shared_ptr< ModelDescriptor > ModelDescriptorPtr
Definition: Types.h:112