forked from BlueBrain/Brayns
/
brayns.cpp
179 lines (157 loc) · 7.82 KB
/
brayns.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* Copyright (c) 2016, EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
* Responsible Author: Daniel.Nachbaur@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 <brayns/Brayns.h>
#include <brayns/common/camera/Camera.h>
#include <brayns/common/camera/InspectCenterManipulator.h>
#include <brayns/common/engine/Engine.h>
#include <brayns/common/renderer/FrameBuffer.h>
#include <brayns/common/scene/Scene.h>
#include <brayns/parameters/ParametersManager.h>
#define BOOST_TEST_MODULE brayns
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(simple_construction)
{
auto& testSuite = boost::unit_test::framework::master_test_suite();
BOOST_CHECK_NO_THROW(
brayns::Brayns(testSuite.argc,
const_cast<const char**>(testSuite.argv)));
}
BOOST_AUTO_TEST_CASE(defaults)
{
auto& testSuite = boost::unit_test::framework::master_test_suite();
const char* app = testSuite.argv[0];
const char* argv[] = {app, "--synchronous-mode", "on"};
const int argc = sizeof(argv) / sizeof(char*);
brayns::Brayns brayns(argc, argv);
auto& camera = brayns.getEngine().getCamera();
BOOST_CHECK(camera.getType() == brayns::CameraType::default_);
BOOST_CHECK_EQUAL(camera.getPosition(), brayns::Vector3f(0.5f, 0.5f, 1.5f));
BOOST_CHECK_EQUAL(camera.getTarget(), brayns::Vector3f(0.5f, 0.5f, 0.5f));
BOOST_CHECK_EQUAL(camera.getUp(), brayns::Vector3f(0, 1, 0));
BOOST_CHECK_EQUAL(camera.getAspectRatio(), 4.f / 3.f);
BOOST_CHECK_EQUAL(camera.getAperture(), 0.f);
BOOST_CHECK_EQUAL(camera.getFocalLength(), 0.f);
auto& manipulator = brayns.getCameraManipulator();
BOOST_CHECK(dynamic_cast<brayns::InspectCenterManipulator*>(&manipulator));
auto& fb = brayns.getEngine().getFrameBuffer();
BOOST_CHECK(!fb.getColorBuffer());
BOOST_CHECK_EQUAL(fb.getColorDepth(), 4);
BOOST_CHECK(!fb.getDepthBuffer());
BOOST_CHECK_EQUAL(fb.getSize(), brayns::Vector2i(800, 600));
auto& pm = brayns.getParametersManager();
const auto& appParams = pm.getApplicationParameters();
BOOST_CHECK_EQUAL(appParams.getWindowSize(), brayns::Vector2ui(800, 600));
BOOST_CHECK_EQUAL(appParams.getCamera(), "perspective");
BOOST_CHECK(!appParams.isBenchmarking());
BOOST_CHECK_EQUAL(appParams.getJpegCompression(), 90);
BOOST_CHECK_EQUAL(appParams.getImageStreamFPS(), 60);
const auto& renderParams = pm.getRenderingParameters();
BOOST_CHECK(renderParams.getEngine() == brayns::EngineType::ospray);
BOOST_CHECK_EQUAL(renderParams.getModule(), "");
BOOST_CHECK(renderParams.getRenderer() == brayns::RendererType::default_);
BOOST_CHECK_EQUAL(renderParams.getRenderers().size(), 7);
BOOST_CHECK(!renderParams.getShadows());
BOOST_CHECK(!renderParams.getSoftShadows());
BOOST_CHECK_EQUAL(renderParams.getAmbientOcclusionStrength(), 0.f);
BOOST_CHECK(renderParams.getShading() == brayns::ShadingType::diffuse);
BOOST_CHECK_EQUAL(renderParams.getSamplesPerPixel(), 1);
BOOST_CHECK(!renderParams.getLightEmittingMaterials());
BOOST_CHECK_EQUAL(renderParams.getBackgroundColor(),
brayns::Vector3f(0, 0, 0));
BOOST_CHECK_EQUAL(renderParams.getDetectionDistance(), 1.f);
BOOST_CHECK(renderParams.getDetectionOnDifferentMaterial());
BOOST_CHECK_EQUAL(renderParams.getDetectionNearColor(),
brayns::Vector3f(1, 0, 0));
BOOST_CHECK_EQUAL(renderParams.getDetectionFarColor(),
brayns::Vector3f(0, 1, 0));
BOOST_CHECK(renderParams.getCameraType() == brayns::CameraType::default_);
const auto& geomParams = pm.getGeometryParameters();
BOOST_CHECK_EQUAL(geomParams.getMorphologyFolder(), "");
BOOST_CHECK_EQUAL(geomParams.getPDBFile(), "");
BOOST_CHECK_EQUAL(geomParams.getMeshFolder(), "");
BOOST_CHECK_EQUAL(geomParams.getCircuitConfiguration(), "");
BOOST_CHECK_EQUAL(geomParams.getLoadCacheFile(), "");
BOOST_CHECK_EQUAL(geomParams.getSaveCacheFile(), "");
BOOST_CHECK_EQUAL(geomParams.getCircuitTargets(), "");
BOOST_CHECK_EQUAL(geomParams.getCircuitReport(), "");
BOOST_CHECK_EQUAL(geomParams.getRadiusMultiplier(), 1.f);
BOOST_CHECK_EQUAL(geomParams.getRadiusCorrection(), 0.f);
BOOST_CHECK(geomParams.getColorScheme() == brayns::ColorScheme::none);
BOOST_CHECK(geomParams.getSceneEnvironment() ==
brayns::SceneEnvironment::none);
BOOST_CHECK(geomParams.getGeometryQuality() ==
brayns::GeometryQuality::high);
BOOST_CHECK_EQUAL(
brayns::enumsToBitmask(geomParams.getMorphologySectionTypes()),
brayns::enumsToBitmask(std::vector<brayns::MorphologySectionType>{
brayns::MorphologySectionType::all}));
BOOST_CHECK_EQUAL(geomParams.getMorphologyLayout().nbColumns, 0);
BOOST_CHECK_EQUAL(geomParams.getCircuitStartSimulationTime(), 0.f);
BOOST_CHECK_EQUAL(geomParams.getCircuitEndSimulationTime(),
std::numeric_limits<float>::max());
BOOST_CHECK_EQUAL(geomParams.getCircuitSimulationValuesRange().x(),
std::numeric_limits<float>::max());
BOOST_CHECK_EQUAL(geomParams.getCircuitSimulationValuesRange().y(),
std::numeric_limits<float>::min());
const auto& animParams = pm.getAnimationParameters();
BOOST_CHECK_EQUAL(animParams.getFrame(), 0);
const auto& volumeParams = pm.getVolumeParameters();
BOOST_CHECK_EQUAL(volumeParams.getDimensions(), brayns::Vector3ui(0, 0, 0));
BOOST_CHECK_EQUAL(volumeParams.getElementSpacing(),
brayns::Vector3f(1.f, 1.f, 1.f));
BOOST_CHECK_EQUAL(volumeParams.getOffset(),
brayns::Vector3f(0.f, 0.f, 0.f));
BOOST_CHECK_EQUAL(volumeParams.getSamplesPerRay(), 128);
const auto& sceneParams = pm.getSceneParameters();
BOOST_CHECK_EQUAL(sceneParams.getEnvironmentMap(), "");
auto& scene = brayns.getEngine().getScene();
brayns::Boxf defaultBoundingBox;
defaultBoundingBox.merge(brayns::Vector3f(0, 0, 0));
defaultBoundingBox.merge(brayns::Vector3f(1, 1, 1));
BOOST_CHECK_EQUAL(scene.getWorldBounds(), defaultBoundingBox);
BOOST_CHECK(geomParams.getMemoryMode() == brayns::MemoryMode::shared);
}
BOOST_AUTO_TEST_CASE(render_two_frames_and_compare_they_are_same)
{
auto& testSuite = boost::unit_test::framework::master_test_suite();
const char* app = testSuite.argv[0];
const char* argv[] = {app, "--synchronous-mode", "on"};
const int argc = sizeof(argv) / sizeof(char*);
brayns::Brayns brayns(argc, argv);
auto& fb = brayns.getEngine().getFrameBuffer();
const auto& size = fb.getSize();
fb.setAccumulation(false);
fb.resize(size);
uint16_t depth = fb.getColorDepth();
const size_t bytes = size[0] * size[1] * depth;
std::vector<uint8_t> oldBuffer(bytes, 0);
fb.clear();
brayns.render();
fb.map();
memcpy(oldBuffer.data(), fb.getColorBuffer(), bytes);
fb.unmap();
fb.clear();
brayns.render();
fb.map();
BOOST_CHECK_EQUAL_COLLECTIONS(oldBuffer.begin(), oldBuffer.end(),
fb.getColorBuffer(),
fb.getColorBuffer() + bytes);
fb.unmap();
}