Blue Brain BioExplorer
AddModelTask.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2024, EPFL/Blue Brain Project
3  * All rights reserved. Do not distribute without permission.
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 #include "AddModelTask.h"
23 
24 #include "Errors.h"
25 #include "LoadModelFunctor.h"
26 
30 
31 namespace core
32 {
33 AddModelTask::AddModelTask(const ModelParams& modelParams, Engine& engine)
34 {
35  const auto& registry = engine.getScene().getLoaderRegistry();
36 
37  // pre-check for validity of given paths
38  const auto& path = modelParams.getPath();
39  if (path.empty())
40  throw MISSING_PARAMS;
41 
42  if (!registry.isSupportedFile(path))
43  throw UNSUPPORTED_TYPE;
44 
45  LoadModelFunctor functor{engine, modelParams};
46  functor.setCancelToken(_cancelToken);
47  functor.setProgressFunc([&progress = progress](const auto& msg, auto, auto amount)
48  { progress.update(msg, amount); });
49 
50  // load data, return model descriptor
51  _task = async::spawn(std::move(functor))
52  .then(
53  [&engine](async::task<ModelDescriptorPtr> result)
54  {
55  engine.triggerRender();
56  return result.get();
57  });
58 }
59 } // namespace core
Progress progress
Definition: Task.h:76
async::cancellation_token _cancelToken
Definition: Task.h:79
AddModelTask(const ModelParams &model, Engine &engine)
Provides an abstract implementation of a ray-tracing engine.
Definition: Engine.h:59
PLATFORM_API std::function< void()> triggerRender
Callback when a new frame shall be triggered. Currently called by event plugins Deflect and Rockets.
Definition: Engine.h:174
PLATFORM_API Scene & getScene()
Returns the scene.
Definition: Engine.h:147
The ModelParams class represents the parameters needed for initializing a model instance.
Definition: Model.h:178
PLATFORM_API const std::string & getPath() const
getPath gets the path of the model
Definition: Model.h:238
void update(const std::string &operation, const float amount)
Definition: Progress.h:46
PLATFORM_API LoaderRegistry & getLoaderRegistry()
Get the registry for all supported loaders of this scene.
Definition: Scene.h:214
ModelDescriptorPtr result()
Definition: Task.h:121
const TaskRuntimeError MISSING_PARAMS
Definition: Errors.h:34
const TaskRuntimeError UNSUPPORTED_TYPE
Definition: Errors.h:36