Blue Brain BioExplorer
NeuronsLoader.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 "NeuronsLoader.h"
25 #include "Neurons.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_NEURONS;
43 const std::string SUPPORTED_PROTOCOL_NEURONS = "neurons://";
44 
45 NeuronsLoader::NeuronsLoader(Scene& scene, PropertyMap&& loaderParams)
46  : Loader(scene)
47  , _defaults(loaderParams)
48 {
49 }
50 
51 std::string NeuronsLoader::getName() const
52 {
53  return LOADER_NAME;
54 }
55 
56 std::vector<std::string> NeuronsLoader::getSupportedStorage() const
57 {
59 }
60 
61 bool NeuronsLoader::isSupported(const std::string& storage, const std::string& /*extension*/) const
62 {
63  return (storage.find(SUPPORTED_PROTOCOL_NEURONS) == 0);
64 }
65 
67  const PropertyMap& /*properties*/) const
68 {
69  PLUGIN_THROW("Loading Neurons from blob is not supported");
70 }
71 
72 ModelDescriptorPtr NeuronsLoader::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;
82  details.sqlNodeFilter = props.getProperty<std::string>(LOADER_PROPERTY_DATABASE_SQL_FILTER.name);
83  details.radiusMultiplier = props.getProperty<double>(LOADER_PROPERTY_RADIUS_MULTIPLIER.name);
84  details.populationColorScheme = stringToEnum<morphology::PopulationColorScheme>(
85  props.getProperty<std::string>(LOADER_PROPERTY_POPULATION_COLOR_SCHEME.name));
86  details.morphologyColorScheme = stringToEnum<morphology::MorphologyColorScheme>(
87  props.getProperty<std::string>(LOADER_PROPERTY_MORPHOLOGY_COLOR_SCHEME.name));
88  details.realismLevel = static_cast<int64_t>(morphology::MorphologyRealismLevel::none);
89  details.realismLevel += (props.getProperty<bool>(LOADER_PROPERTY_MORPHOLOGY_REALISM_LEVEL_SOMA.name)
90  ? static_cast<int64_t>(morphology::MorphologyRealismLevel::soma)
91  : 0);
92  details.realismLevel += (props.getProperty<bool>(LOADER_PROPERTY_MORPHOLOGY_REALISM_LEVEL_DENDRITE.name)
93  ? static_cast<int64_t>(morphology::MorphologyRealismLevel::dendrite)
94  : 0);
95  details.realismLevel += (props.getProperty<bool>(LOADER_PROPERTY_NEURONS_REALISM_LEVEL_SPINE.name)
96  ? static_cast<int64_t>(morphology::MorphologyRealismLevel::spine)
97  : 0);
98  details.realismLevel += (props.getProperty<bool>(LOADER_PROPERTY_MORPHOLOGY_REALISM_LEVEL_AXON.name)
99  ? static_cast<int64_t>(morphology::MorphologyRealismLevel::axon)
100  : 0);
101  details.realismLevel += (props.getProperty<bool>(LOADER_PROPERTY_NEURONS_REALISM_LEVEL_EXTERNALS.name)
102  ? static_cast<int64_t>(morphology::MorphologyRealismLevel::externals)
103  : 0);
104  details.realismLevel += (props.getProperty<bool>(LOADER_PROPERTY_MORPHOLOGY_REALISM_LEVEL_INTERNALS.name)
105  ? static_cast<int64_t>(morphology::MorphologyRealismLevel::internals)
106  : 0);
107  details.loadSomas = props.getProperty<bool>(LOADER_PROPERTY_MORPHOLOGY_LOAD_SOMA.name);
108  details.loadAxon = props.getProperty<bool>(LOADER_PROPERTY_NEURONS_LOAD_AXON.name);
109  details.loadBasalDendrites = props.getProperty<bool>(LOADER_PROPERTY_NEURONS_LOAD_BASAL_DENDRITES.name);
110  details.loadApicalDendrites = props.getProperty<bool>(LOADER_PROPERTY_NEURONS_LOAD_APICAL_DENDRITES.name);
111  details.generateInternals = props.getProperty<bool>(LOADER_PROPERTY_MORPHOLOGY_GENERATE_INTERNALS.name);
112  details.generateExternals = props.getProperty<bool>(LOADER_PROPERTY_NEURONS_GENERATE_EXTERNALS.name);
113  details.morphologyRepresentation = stringToEnum<morphology::MorphologyRepresentation>(
114  props.getProperty<std::string>(LOADER_PROPERTY_MORPHOLOGY_REPRESENTATION.name));
115  details.alignToGrid = props.getProperty<double>(LOADER_PROPERTY_ALIGN_TO_GRID.name);
116  details.synapsesType = stringToEnum<morphology::MorphologySynapseType>(
117  props.getProperty<std::string>(LOADER_PROPERTY_NEURONS_SYNAPSE_TYPE.name));
118  const auto position = props.getProperty<std::array<double, 3>>(LOADER_PROPERTY_POSITION.name);
119  const Vector3d pos = core::Vector3d(position[0], position[1], position[2]);
120  const auto rotation = props.getProperty<std::array<double, 4>>(LOADER_PROPERTY_ROTATION.name);
121  const Quaterniond rot = core::Quaterniond(rotation[3], rotation[0], rotation[1], rotation[2]);
122  const auto scale = props.getProperty<std::array<double, 3>>(LOADER_PROPERTY_SCALE.name);
123  details.scale = {scale[0], scale[1], scale[2]};
124  Neurons Neurons(_scene, details, pos, rot, callback);
125  return std::move(Neurons.getModelDescriptor());
126 }
127 
129 {
130  return _defaults;
131 }
132 
134 {
136  pm.setProperty(LOADER_PROPERTY_DATABASE_SQL_FILTER);
137  pm.setProperty(LOADER_PROPERTY_ALIGN_TO_GRID);
138  pm.setProperty(LOADER_PROPERTY_RADIUS_MULTIPLIER);
139  pm.setProperty(LOADER_PROPERTY_POPULATION_COLOR_SCHEME);
140  pm.setProperty(LOADER_PROPERTY_MORPHOLOGY_COLOR_SCHEME);
141  pm.setProperty(LOADER_PROPERTY_MORPHOLOGY_REPRESENTATION);
142  pm.setProperty(LOADER_PROPERTY_MORPHOLOGY_LOAD_SOMA);
143  pm.setProperty(LOADER_PROPERTY_NEURONS_LOAD_AXON);
144  pm.setProperty(LOADER_PROPERTY_NEURONS_LOAD_APICAL_DENDRITES);
145  pm.setProperty(LOADER_PROPERTY_NEURONS_LOAD_BASAL_DENDRITES);
146  pm.setProperty(LOADER_PROPERTY_MORPHOLOGY_GENERATE_INTERNALS);
147  pm.setProperty(LOADER_PROPERTY_NEURONS_GENERATE_EXTERNALS);
148  pm.setProperty(LOADER_PROPERTY_MORPHOLOGY_REALISM_LEVEL_SOMA);
149  pm.setProperty(LOADER_PROPERTY_MORPHOLOGY_REALISM_LEVEL_AXON);
150  pm.setProperty(LOADER_PROPERTY_MORPHOLOGY_REALISM_LEVEL_DENDRITE);
151  pm.setProperty(LOADER_PROPERTY_MORPHOLOGY_REALISM_LEVEL_INTERNALS);
152  pm.setProperty(LOADER_PROPERTY_NEURONS_REALISM_LEVEL_EXTERNALS);
153  pm.setProperty(LOADER_PROPERTY_NEURONS_REALISM_LEVEL_SPINE);
154  pm.setProperty(LOADER_PROPERTY_NEURONS_SYNAPSE_TYPE);
155  pm.setProperty(LOADER_PROPERTY_POSITION);
156  pm.setProperty(LOADER_PROPERTY_ROTATION);
157  pm.setProperty(LOADER_PROPERTY_SCALE);
158  return pm;
159 }
160 } // namespace morphology
161 } // namespace bioexplorer
const core::ModelDescriptorPtr getModelDescriptor() const
Get the Model Descriptor object.
Definition: Node.cpp:44
static core::PropertyMap getCLIProperties()
strings getSupportedStorage() const final
core::ModelDescriptorPtr importFromBlob(core::Blob &&blob, const core::LoaderProgress &callback, const core::PropertyMap &properties) const final
core::PropertyMap getProperties() const final
std::string getName() const final
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
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
Definition: AtlasLoader.cpp:42
const std::string LOADER_NAME
const std::string SUPPORTED_PROTOCOL_NEURONS
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::MorphologyColorScheme morphologyColorScheme
Definition: Types.h:1558
morphology::MorphologyRepresentation morphologyRepresentation
Definition: Types.h:1556
morphology::MorphologySynapseType synapsesType
Definition: Types.h:1543
morphology::PopulationColorScheme populationColorScheme
Definition: Types.h:1560