/
CADiffusionSimulationHandler.cpp
118 lines (105 loc) · 3.73 KB
/
CADiffusionSimulationHandler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* Copyright (c) 2015-2017, EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
* Responsible Author: Cyrille Favreau <cyrille.favreau@epfl.ch>
*
* This file is part of Brayns <https://github.com/BlueBrain/Brayns>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3.0 as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "CADiffusionSimulationHandler.h"
#include <brayns/common/geometry/Sphere.h>
#include <brayns/common/scene/Scene.h>
#include <brayns/common/utils/Utils.h>
#include <brayns/parameters/GeometryParameters.h>
#include <fstream>
namespace
{
const float CALCIUM_RADIUS = 0.00194f;
}
namespace brayns
{
CADiffusionSimulationHandler::CADiffusionSimulationHandler(
const std::string& simulationFolder)
{
BRAYNS_DEBUG << "Loading Calcium simulation from " << simulationFolder
<< std::endl;
const strings filters = {".dat"};
strings files = parseFolder(simulationFolder, filters);
for (size_t i = 0; i < files.size(); ++i)
{
BRAYNS_DEBUG << "CA diffusion: " << files[i] << std::endl;
_simulationFiles[i] = files[i];
}
}
bool CADiffusionSimulationHandler::_loadCalciumPositions(const size_t frame)
{
if (_simulationFiles.find(frame) == _simulationFiles.end())
{
BRAYNS_ERROR << "No simulation file for frame " << frame << std::endl;
return false;
}
BRAYNS_DEBUG << "Loading Calcium positions for frame " << frame
<< ", filename: " << _simulationFiles[frame] << std::endl;
// Load Calcium positions
std::ifstream filePositions(_simulationFiles[frame], std::ios::in);
if (!filePositions.good())
{
BRAYNS_ERROR << "Could not open file " << _simulationFiles[frame]
<< std::endl;
return false;
}
_calciumPositions.clear();
std::string line;
while (filePositions.good() && std::getline(filePositions, line))
{
std::stringstream lineStream(line);
size_t id;
Vector3f position;
lineStream >> id >> position.x() >> position.y() >> position.z();
_calciumPositions.push_back(position);
}
filePositions.close();
BRAYNS_DEBUG << _calciumPositions.size() << " Calcium positions loaded"
<< std::endl;
return true;
}
void CADiffusionSimulationHandler::setFrame(Scene& scene, const size_t frame)
{
BRAYNS_DEBUG << "Setting Calcium Positions frame to " << frame << std::endl;
if (frame == _currentFrame)
return;
_currentFrame = frame;
// Load Calcium positions
_loadCalciumPositions(frame);
const size_t materialId =
static_cast<size_t>(MaterialType::calcium_simulation);
if (!_spheresCreated)
{
BRAYNS_INFO << "Creating " << _calciumPositions.size() << " CA spheres"
<< std::endl;
for (const auto position : _calciumPositions)
scene.addSphere(materialId, {position, CALCIUM_RADIUS});
_spheresCreated = true;
}
else
{
uint64_t i = 0;
for (const auto position : _calciumPositions)
{
scene.setSphere(i, materialId, Sphere(position, CALCIUM_RADIUS));
++i;
}
}
}
}