Blue Brain BioExplorer
AstrocytesLoader.cpp
Go to the documentation of this file.
1 /*
2  *
3  * The Blue Brain BioExplorer is a tool for scientists to extract and analyse
4  * scientific data from visualization
5  *
6  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
7  *
8  * Copyright 2020-2024 Blue BrainProject / EPFL
9  *
10  * This program is free software: you can redistribute it and/or modify it under
11  * the terms of the GNU General Public License as published by the Free Software
12  * Foundation, either version 3 of the License, or (at your option) any later
13  * version.
14  *
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License along with
21  * this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
24 #include "AstrocytesLoader.h"
25 #include "Astrocytes.h"
26 
27 #include <science/common/Logs.h>
29 
31 
32 #include <filesystem>
33 
34 using namespace core;
35 
36 namespace bioexplorer
37 {
38 namespace morphology
39 {
40 using namespace common;
41 
42 const std::string LOADER_NAME = LOADER_ASTROCYTES;
43 const std::string SUPPORTED_PROTOCOL_ASTROCYTES = "astrocytes://";
44 
45 AstrocytesLoader::AstrocytesLoader(Scene& scene, PropertyMap&& loaderParams)
46  : Loader(scene)
47  , _defaults(loaderParams)
48 {
49 }
50 
51 std::string AstrocytesLoader::getName() const
52 {
53  return LOADER_NAME;
54 }
55 
56 std::vector<std::string> AstrocytesLoader::getSupportedStorage() const
57 {
59 }
60 
61 bool AstrocytesLoader::isSupported(const std::string& storage, const std::string& /*extension*/) const
62 {
63  return (storage.find(SUPPORTED_PROTOCOL_ASTROCYTES) == 0);
64 }
65 
67  const PropertyMap& /*properties*/) const
68 {
69  PLUGIN_THROW("Loading astrocytes from blob is not supported");
70 }
71 
72 ModelDescriptorPtr AstrocytesLoader::importFromStorage(const std::string& storage, const LoaderProgress& callback,
73  const PropertyMap& properties) const
74 {
75  PropertyMap props = _defaults;
76  props.merge(properties);
77 
79  const auto baseName = std::filesystem::path(storage).filename();
80  details.assemblyName = baseName;
81  details.populationName = baseName;
83  props.getProperty<std::string>(LOADER_PROPERTY_ASTROCYTES_VASCULATURE_SCHEMA.name);
84  details.sqlFilter = props.getProperty<std::string>(LOADER_PROPERTY_DATABASE_SQL_FILTER.name);
85  details.radiusMultiplier = props.getProperty<double>(LOADER_PROPERTY_RADIUS_MULTIPLIER.name);
86  details.populationColorScheme = stringToEnum<morphology::PopulationColorScheme>(
87  props.getProperty<std::string>(LOADER_PROPERTY_POPULATION_COLOR_SCHEME.name));
88  details.morphologyColorScheme = stringToEnum<morphology::MorphologyColorScheme>(
89  props.getProperty<std::string>(LOADER_PROPERTY_MORPHOLOGY_COLOR_SCHEME.name));
90  details.realismLevel = 0;
91  details.realismLevel += (props.getProperty<bool>(LOADER_PROPERTY_MORPHOLOGY_REALISM_LEVEL_SOMA.name)
92  ? static_cast<int64_t>(morphology::MorphologyRealismLevel::soma)
93  : 0);
94  details.realismLevel += (props.getProperty<bool>(LOADER_PROPERTY_MORPHOLOGY_REALISM_LEVEL_DENDRITE.name)
95  ? static_cast<int64_t>(morphology::MorphologyRealismLevel::dendrite)
96  : 0);
97  details.loadSomas = props.getProperty<bool>(LOADER_PROPERTY_MORPHOLOGY_LOAD_SOMA.name);
98  details.loadDendrites = props.getProperty<bool>(LOADER_PROPERTY_MORPHOLOGY_LOAD_DENDRITES.name);
99  details.generateInternals = props.getProperty<bool>(LOADER_PROPERTY_MORPHOLOGY_GENERATE_INTERNALS.name);
100  details.loadMicroDomains = props.getProperty<bool>(LOADER_PROPERTY_ASTROCYTES_LOAD_MICRO_DOMAINS.name);
101  details.morphologyRepresentation = stringToEnum<morphology::MorphologyRepresentation>(
102  props.getProperty<std::string>(LOADER_PROPERTY_MORPHOLOGY_REPRESENTATION.name));
103  details.alignToGrid = props.getProperty<double>(LOADER_PROPERTY_ALIGN_TO_GRID.name);
104  const auto position = props.getProperty<std::array<double, 3>>(LOADER_PROPERTY_POSITION.name);
105  const Vector3d pos = core::Vector3d(position[0], position[1], position[2]);
106  const auto rotation = props.getProperty<std::array<double, 4>>(LOADER_PROPERTY_ROTATION.name);
107  const Quaterniond rot = core::Quaterniond(rotation[3], rotation[0], rotation[1], rotation[2]);
108  const auto scale = props.getProperty<std::array<double, 3>>(LOADER_PROPERTY_SCALE.name);
109  details.scale = {scale[0], scale[1], scale[2]};
110  Astrocytes astrocytes(_scene, details, pos, rot, callback);
111  return std::move(astrocytes.getModelDescriptor());
112 }
113 
115 {
116  return _defaults;
117 }
118 
120 {
122  pm.setProperty(LOADER_PROPERTY_DATABASE_SQL_FILTER);
123  pm.setProperty(LOADER_PROPERTY_ALIGN_TO_GRID);
124  pm.setProperty(LOADER_PROPERTY_RADIUS_MULTIPLIER);
125  pm.setProperty(LOADER_PROPERTY_POPULATION_COLOR_SCHEME);
126  pm.setProperty(LOADER_PROPERTY_MORPHOLOGY_COLOR_SCHEME);
127  pm.setProperty(LOADER_PROPERTY_MORPHOLOGY_REPRESENTATION);
128  pm.setProperty(LOADER_PROPERTY_MORPHOLOGY_LOAD_SOMA);
129  pm.setProperty(LOADER_PROPERTY_MORPHOLOGY_LOAD_DENDRITES);
130  pm.setProperty(LOADER_PROPERTY_MORPHOLOGY_GENERATE_INTERNALS);
131  pm.setProperty(LOADER_PROPERTY_ASTROCYTES_LOAD_MICRO_DOMAINS);
132  pm.setProperty(LOADER_PROPERTY_ASTROCYTES_VASCULATURE_SCHEMA);
133  pm.setProperty(LOADER_PROPERTY_MORPHOLOGY_REALISM_LEVEL_SOMA);
134  pm.setProperty(LOADER_PROPERTY_MORPHOLOGY_REALISM_LEVEL_DENDRITE);
135  pm.setProperty(LOADER_PROPERTY_POSITION);
136  pm.setProperty(LOADER_PROPERTY_ROTATION);
137  pm.setProperty(LOADER_PROPERTY_SCALE);
138  return pm;
139 }
140 } // namespace morphology
141 } // namespace bioexplorer
const core::ModelDescriptorPtr getModelDescriptor() const
Get the Model Descriptor object.
Definition: Node.cpp:44
core::ModelDescriptorPtr importFromStorage(const std::string &storage, const core::LoaderProgress &callback, const core::PropertyMap &properties) const final
bool isSupported(const std::string &storage, const std::string &extension) const final
core::PropertyMap getProperties() const final
core::ModelDescriptorPtr importFromBlob(core::Blob &&blob, const core::LoaderProgress &callback, const core::PropertyMap &properties) const final
Scene & _scene
Definition: Loader.h:126
void setProperty(const Property &newProperty)
Definition: PropertyMap.h:307
T getProperty(const std::string &name, T valIfNotFound) const
Definition: PropertyMap.h:323
void merge(const PropertyMap &input)
Scene object This object contains collections of geometries, materials and light sources that are use...
Definition: Scene.h:43
const std::string LOADER_NAME
const std::string SUPPORTED_PROTOCOL_ASTROCYTES
glm::vec< 3, double > Vector3d
Definition: MathTypes.h:143
std::shared_ptr< ModelDescriptor > ModelDescriptorPtr
Definition: Types.h:112
glm::tquat< double, glm::highp > Quaterniond
Double quaternion.
Definition: MathTypes.h:153
#define PLUGIN_THROW(message)
Definition: Logs.h:45
morphology::MorphologyRepresentation morphologyRepresentation
Definition: Types.h:1486
morphology::PopulationColorScheme populationColorScheme
Definition: Types.h:1492
morphology::MorphologyColorScheme morphologyColorScheme
Definition: Types.h:1490