BioDynaMo  v1.03.58-27764645
helper.cc
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
16 #include "core/agent/agent.h"
17 #include "core/param/param.h"
18 #include "core/shape.h"
19 #include "core/simulation.h"
20 
21 namespace bdm {
22 
23 // -----------------------------------------------------------------------------
25  const std::unordered_map<std::string, VtkAgents*>& vtk_agents,
26  const std::unordered_map<std::string, VtkDiffusionGrid*>& vtk_dgrids) {
27  auto* sim = Simulation::GetActive();
28  auto* param = sim->GetParam();
29  // agents
30  std::stringstream agents;
31  uint64_t num_agents = param->visualize_agents.size();
32  uint64_t counter = 0;
33  for (const auto& entry : param->visualize_agents) {
34  std::string agent_name = entry.first;
35 
36  auto search = vtk_agents.find(agent_name);
37  if (search == vtk_agents.end()) {
38  continue;
39  }
40  auto* agent_grid = search->second;
41 
42  agents << " {" << std::endl
43  << " \"name\":\"" << agent_name << "\"," << std::endl;
44  if (agent_grid->GetShape() == Shape::kSphere) {
45  agents << " \"glyph\":\"Glyph\"," << std::endl
46  << " \"shape\":\"Sphere\"," << std::endl
47  << " \"scaling_attribute\":\"diameter_\"" << std::endl;
48  } else if (agent_grid->GetShape() == kCylinder) {
49  agents << " \"glyph\":\"BDMGlyph\"," << std::endl
50  << " \"shape\":\"Cylinder\"," << std::endl
51  << " \"x_scaling_attribute\":\"diameter_\"," << std::endl
52  << " \"y_scaling_attribute\":\"actual_length_\"," << std::endl
53  << " \"z_scaling_attribute\":\"diameter_\"," << std::endl
54  << " \"Vectors\":\"spring_axis_\"," << std::endl
55  << " \"MassLocation\":\"mass_location_\"" << std::endl;
56  }
57  agents << " }";
58  if (counter != num_agents - 1) {
59  agents << ",";
60  }
61  agents << std::endl;
62  counter++;
63  }
64 
65  // extracellular substances
66  std::stringstream substances;
67  uint64_t num_substances = param->visualize_diffusion.size();
68  bool write_comma = false;
69  for (uint64_t i = 0; i < num_substances; i++) {
70  auto& name = param->visualize_diffusion[i].name;
71 
72  auto search = vtk_dgrids.find(name);
73  if (search == vtk_dgrids.end()) {
74  continue;
75  }
76  auto* dgrid = search->second;
77  // user wanted to export this substance, but it did not exist during
78  // the entire simulation
79  if (!dgrid->IsUsed()) {
81  "Visualize Diffusion Grids",
82  "You are trying to visualize diffusion grid ", name,
83  ", but it has not been created during the entire simulation. "
84  "Please make sure the names in the "
85  "configuration file match the ones in the simulation.");
86  continue;
87  }
88 
89  if (write_comma) {
90  substances << ",\n";
91  }
92  substances << " { \"name\":\"" << name << "\", ";
93  std::string has_gradient =
94  param->visualize_diffusion[i].gradient ? "true" : "false";
95  substances << "\"has_gradient\":\"" << has_gradient << "\" }";
96  write_comma = true;
97  }
98 
99  std::stringstream str;
100  str << "{" << std::endl
101  << " \"simulation\": {" << std::endl
102  << " \"name\":\"" << sim->GetUniqueName() << "\"," << std::endl
103  << " \"result_dir\":\"" << sim->GetOutputDir() << "\"" << std::endl
104  << " }," << std::endl
105  << " \"agents\": [" << std::endl
106  << agents.str() << " ]," << std::endl
107  << " \"extracellular_substances\": [" << std::endl
108  << substances.str() << std::endl
109  << " ]," << std::endl
110  << " \"insitu_script_arguments\": \""
111  << param->pv_insitu_pipelinearguments << "\"" << std::endl
112  << "}" << std::endl;
113  return str.str();
114 }
115 
116 } // namespace bdm
shape.h
bdm
Definition: agent.cc:39
bdm::GenerateSimulationInfoJson
std::string GenerateSimulationInfoJson(const std::unordered_map< std::string, VtkAgents * > &vtk_agents, const std::unordered_map< std::string, VtkDiffusionGrid * > &vtk_dgrids)
Definition: helper.cc:24
bdm::Log::Warning
static void Warning(const std::string &location, const Args &... parts)
Prints warning message.
Definition: log.h:67
bdm::kSphere
@ kSphere
Definition: shape.h:20
agent.h
simulation.h
bdm::kCylinder
@ kCylinder
Definition: shape.h:20
param.h
helper.h
bdm::Simulation::GetActive
static Simulation * GetActive()
This function returns the currently active Simulation simulation.
Definition: simulation.cc:67