File: test_fixture.cpp

package info (click to toggle)
ospray 3.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,048 kB
  • sloc: cpp: 80,569; ansic: 951; sh: 805; makefile: 170; python: 69
file content (230 lines) | stat: -rw-r--r-- 5,382 bytes parent folder | download | duplicates (2)
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// Copyright 2017 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "test_fixture.h"
#include "ArcballCamera.h"
#include "ospray_testing.h"

extern OSPRayEnvironment *ospEnv;

namespace OSPRayTestScenes {

Base::Base()
{
  const ::testing::TestCase *const testCase =
      ::testing::UnitTest::GetInstance()->current_test_case();
  const ::testing::TestInfo *const testInfo =
      ::testing::UnitTest::GetInstance()->current_test_info();

  {
    std::string testCaseName = testCase->name();
    std::string testInfoName = testInfo->name();
    size_t pos = testCaseName.find('/');
    if (pos == std::string::npos) {
      testName = testCaseName + "_" + testInfoName;
    } else {
      std::string instantiationName = testCaseName.substr(0, pos);
      std::string className = testCaseName.substr(pos + 1);
      testName = className + "_" + instantiationName + "_" + testInfoName;
    }
    for (char &byte : testName)
      if (byte == '/')
        byte = '_';
  }

  imgSize = ospEnv->GetImgSize();
  rendererType = "scivis";
  frames = 1;
  samplesPerPixel = 16;
}

void Base::SetUp()
{
  framebuffer = cpp::FrameBuffer(imgSize.x,
      imgSize.y,
      frameBufferFormat,
      OSP_FB_COLOR | OSP_FB_ACCUM | OSP_FB_DEPTH);

  imageTool.reset(new OSPImageTools(imgSize, GetTestName(), frameBufferFormat));

  CreateEmptyScene();
}

void Base::AddLight(cpp::Light light)
{
  light.commit();
  lightsList.push_back(light);
}

void Base::AddModel(cpp::GeometricModel model, affine3f xfm)
{
  model.commit();

  cpp::Group group;
  group.setParam("geometry", cpp::CopiedData(model));
  group.commit();

  cpp::Instance instance(group);
  instance.setParam("transform", xfm);

  AddInstance(instance);
}

void Base::AddModel(cpp::VolumetricModel model, affine3f xfm)
{
  model.commit();

  cpp::Group group;
  group.setParam("volume", cpp::CopiedData(model));
  group.commit();

  cpp::Instance instance(group);
  instance.setParam("transform", xfm);

  AddInstance(instance);
}

void Base::AddInstance(cpp::Instance instance)
{
  instance.commit();
  instances.push_back(instance);
}

void Base::PerformRenderTest()
{
  SetLights();

  if (!instances.empty())
    world.setParam("instance", cpp::CopiedData(instances));

  camera.commit();
  world.commit();
  renderer.commit();

  framebuffer.resetAccumulation();

  RenderFrame();

  void *framebuffer_data = framebuffer.map(OSP_FB_COLOR);

  if (ospEnv->GetDumpImg()) {
    EXPECT_EQ(imageTool->saveTestImage(framebuffer_data), OsprayStatus::Ok);
  } else {
    EXPECT_EQ(
        imageTool->compareImgWithBaseline(framebuffer_data), OsprayStatus::Ok);
  }

  framebuffer.unmap(framebuffer_data);
}

void Base::CreateEmptyScene()
{
  camera = cpp::Camera("perspective");
  camera.setParam("aspect", imgSize.x / (float)imgSize.y);
  camera.setParam("position", vec3f(0.f));
  camera.setParam("direction", vec3f(0.f, 0.f, 1.f));
  camera.setParam("up", vec3f(0.f, 1.f, 0.f));

  renderer = cpp::Renderer(rendererType);

  if (rendererType == "ao")
    renderer.setParam("aoSamples", 0);

  if (rendererType == "scivis") {
    renderer.setParam("shadows", true);
    renderer.setParam("aoSamples", 16);
  }

  renderer.setParam("backgroundColor", vec3f(1.0f));
  renderer.setParam("pixelSamples", samplesPerPixel);

  world = cpp::World();
}

void Base::SetLights()
{
  if (!lightsList.empty())
    world.setParam("light", cpp::CopiedData(lightsList));
}

void Base::RenderFrame()
{
  for (int frame = 0; frame < frames; ++frame)
    cpp::Future future = framebuffer.renderFrame(renderer, camera, world);
}

FromOsprayTesting::FromOsprayTesting()
{
  auto params = GetParam();

  sceneName = std::get<0>(params);
  rendererType = std::get<1>(params);
  samplesPerPixel = std::get<2>(params);
}

void FromOsprayTesting::SetUp()
{
  Base::SetUp();

  auto builder = ospray::testing::newBuilder(sceneName);
  ospray::testing::setParam(builder, "rendererType", rendererType);
  ospray::testing::commit(builder);

  world = ospray::testing::buildWorld(builder);
  ospray::testing::release(builder);

  world.commit();

  auto worldBounds = world.getBounds<box3f>();

  ArcballCamera arcballCamera(worldBounds, imgSize);

  camera.setParam("position", arcballCamera.eyePos());
  camera.setParam("direction", arcballCamera.lookDir());
  camera.setParam("up", arcballCamera.upDir());

  if (rendererType == "pathtracer")
    renderer.setParam("limitIndirectLightSamples", false);
}

void FromOsprayTestingMaxDepth::SetUp()
{
  FromOsprayTesting::SetUp();

  // set up max depth texture
  {
    cpp::Texture maxDepthTex("texture2d");

    std::vector<float> maxDepth = {3.f, 3.f, 3.f, 3.f};
    maxDepthTex.setParam(
        "data", cpp::CopiedData(maxDepth.data(), vec2ul(2, 2)));
    maxDepthTex.setParam("format", OSP_TEXTURE_R32F);
    maxDepthTex.setParam("filter", OSP_TEXTURE_FILTER_NEAREST);
    maxDepthTex.commit();

    renderer.setParam("map_maxDepth", maxDepthTex);
  }
}

void FromOsprayTestingVariance::SetUp()
{
  FromOsprayTesting::SetUp();

  frames = 22;

  framebuffer = cpp::FrameBuffer(imgSize.x,
      imgSize.y,
      frameBufferFormat,
      OSP_FB_COLOR | OSP_FB_ACCUM | OSP_FB_VARIANCE);

  renderer.setParam("varianceThreshold", 10.0f);
}

void FromOsprayTestingLightSamples::SetUp()
{
  FromOsprayTesting::SetUp();

  renderer.setParam("lightSamples", 8);
}

} // namespace OSPRayTestScenes