Blue Brain BioExplorer
GeometryParameters.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2024, EPFL/Blue Brain Project
3  *
4  * The Blue Brain BioExplorer is a tool for scientists to extract and analyse
5  * scientific data from visualization
6  *
7  * This file is part of Blue Brain BioExplorer <https://github.com/BlueBrain/BioExplorer>
8  *
9  * This library is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU Lesser General Public License version 3.0 as published
11  * by the Free Software Foundation.
12  *
13  * This library is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #include "GeometryParameters.h"
26 
27 namespace
28 {
29 const std::string PARAM_MEMORY_MODE = "memory-mode";
30 const std::string PARAM_DEFAULT_BVH_FLAG = "default-bvh-flag";
31 const std::string PARAM_GEOMETRY_QUALITY = "geometry-quality";
32 const std::string PARAM_DEFAULT_SDF_EPSILON = "sdf-epsilon";
33 const std::string PARAM_DEFAULT_SDF_NB_MARCH_ITERATIONS = "sdf-nb-march-iterations";
34 const std::string PARAM_DEFAULT_SDF_BLEND_FACTOR = "sdf-blend-factor";
35 const std::string PARAM_DEFAULT_SDF_BLEND_LERP_FACTOR = "sdf-blend-lerp-factor";
36 const std::string PARAM_DEFAULT_SDF_OMEGA = "sdf-omega";
37 const std::string PARAM_DEFAULT_SDF_DISTANCE = "sdf-distance";
38 
39 const std::string GEOMETRY_QUALITIES[3] = {"low", "medium", "high"};
40 const std::string GEOMETRY_MEMORY_MODES[2] = {"shared", "replicated"};
41 const std::map<std::string, core::BVHFlag> BVH_TYPES = {{"dynamic", core::BVHFlag::dynamic},
42  {"compact", core::BVHFlag::compact},
43  {"robust", core::BVHFlag::robust}};
44 } // namespace
45 
46 namespace core
47 {
49  : AbstractParameters("Geometry")
50 {
51  _parameters.add_options()
52  //
53  (PARAM_DEFAULT_SDF_EPSILON.c_str(), po::value<float>(), "Signed distance fields geometry epsilon [float]")
54  //
55  (PARAM_DEFAULT_SDF_NB_MARCH_ITERATIONS.c_str(), po::value<uint64_t>(),
56  "Signed distance fields geometry number of ray-marching iterations [int]")
57  //
58  (PARAM_DEFAULT_SDF_BLEND_FACTOR.c_str(), po::value<float>(),
59  "Signed distance fields geometry blending factor [float]")
60  //
61  (PARAM_DEFAULT_SDF_BLEND_LERP_FACTOR.c_str(), po::value<float>(),
62  "Signed distance fields geometry lerp blending factor [float]")
63  //
64  (PARAM_DEFAULT_SDF_OMEGA.c_str(), po::value<float>(),
65  "Signed distance fields geometry ray-marching omega [float]")
66  //
67  (PARAM_DEFAULT_SDF_DISTANCE.c_str(), po::value<float>(),
68  "Distance until which Signed distance fields geometries are processed (blending and displacement) [float]")
69  //
70  (PARAM_GEOMETRY_QUALITY.c_str(), po::value<std::string>(), "Geometry rendering quality [low|medium|high]")
71  //
72  (PARAM_MEMORY_MODE.c_str(), po::value<std::string>(),
73  "Defines what memory mode should be used between Core and "
74  "the underlying renderer [shared|replicated]")
75  //
76  (PARAM_DEFAULT_BVH_FLAG.c_str(), po::value<std::vector<std::string>>()->multitoken(),
77  "Set a default flag to apply to BVH creation, one of "
78  "[dynamic|compact|robust], may appear multiple times.");
79 }
80 
81 void GeometryParameters::parse(const po::variables_map& vm)
82 {
83  if (vm.count(PARAM_GEOMETRY_QUALITY))
84  {
86  const auto& geometryQuality = vm[PARAM_GEOMETRY_QUALITY].as<std::string>();
87  for (size_t i = 0; i < sizeof(GEOMETRY_QUALITIES) / sizeof(GEOMETRY_QUALITIES[0]); ++i)
88  if (geometryQuality == GEOMETRY_QUALITIES[i])
89  _geometryQuality = static_cast<GeometryQuality>(i);
90  }
91  if (vm.count(PARAM_DEFAULT_SDF_EPSILON))
92  _sdfEpsilon = vm[PARAM_DEFAULT_SDF_EPSILON].as<float>();
93  if (vm.count(PARAM_DEFAULT_SDF_BLEND_FACTOR))
94  _sdfBlendFactor = vm[PARAM_DEFAULT_SDF_BLEND_FACTOR].as<float>();
95  if (vm.count(PARAM_DEFAULT_SDF_BLEND_LERP_FACTOR))
96  _sdfBlendLerpFactor = vm[PARAM_DEFAULT_SDF_BLEND_LERP_FACTOR].as<float>();
97  if (vm.count(PARAM_DEFAULT_SDF_OMEGA))
98  _sdfOmega = vm[PARAM_DEFAULT_SDF_OMEGA].as<float>();
99  if (vm.count(PARAM_DEFAULT_SDF_DISTANCE))
100  _sdfDistance = vm[PARAM_DEFAULT_SDF_DISTANCE].as<float>();
101  if (vm.count(PARAM_MEMORY_MODE))
102  {
103  const auto& memoryMode = vm[PARAM_MEMORY_MODE].as<std::string>();
104  for (size_t i = 0; i < sizeof(GEOMETRY_MEMORY_MODES) / sizeof(GEOMETRY_MEMORY_MODES[0]); ++i)
105  if (memoryMode == GEOMETRY_MEMORY_MODES[i])
106  _memoryMode = static_cast<MemoryMode>(i);
107  }
108  if (vm.count(PARAM_DEFAULT_BVH_FLAG))
109  {
110  const auto& bvhs = vm[PARAM_DEFAULT_BVH_FLAG].as<std::vector<std::string>>();
111  for (const auto& bvh : bvhs)
112  {
113  const auto kv = BVH_TYPES.find(bvh);
114  if (kv != BVH_TYPES.end())
115  _defaultBVHFlags.insert(kv->second);
116  else
117  throw std::runtime_error("Invalid bvh flag '" + bvh + "'.");
118  }
119  }
120 
121  markModified();
122 }
123 
125 {
127  CORE_INFO("Geometry quality : "
128  << GEOMETRY_QUALITIES[static_cast<size_t>(_geometryQuality)]);
129  CORE_INFO("SDF geometry epsilon : " << _sdfEpsilon);
130  CORE_INFO("SDF geometry number of ray-marching iterations : " << _sdfNbMarchIterations);
131  CORE_INFO("SDF geometry blend factor : " << _sdfBlendFactor);
132  CORE_INFO("SDF geometry blend factor (lerp) : " << _sdfBlendLerpFactor);
133  CORE_INFO("SDF geometry ray-marching omega : " << _sdfOmega);
134  CORE_INFO("SDF geometry distance : " << _sdfDistance);
135  CORE_INFO("Memory mode : "
136  << (_memoryMode == MemoryMode::shared ? "Shared" : "Replicated"));
137 }
138 } // namespace core
po::options_description _parameters
void markModified(const bool triggerCallback=true)
Definition: BaseObject.h:65
std::set< BVHFlag > _defaultBVHFlags
void parse(const po::variables_map &vm) final
GeometryQuality _geometryQuality
GeometryQuality
Definition: Types.h:222
MemoryMode
Definition: Types.h:281
#define CORE_INFO(__msg)
Definition: Logs.h:33