File: BaseFixture.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 (75 lines) | stat: -rw-r--r-- 1,935 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
// Copyright 2018 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "BaseFixture.h"
#include "rkcommon/utility/SaveImage.h"

#include <algorithm>

std::string BaseFixture::dumpFinalImageDir;

BaseFixture::BaseFixture(
    const std::string &n, const std::string &s, const std::string &r)
    : name(n + "/" + r), scene(s), rendererType(r)
{
  ::benchmark::Fixture::SetName(name.c_str());
}

void BaseFixture::Init()
{
  framebuffer = cpp::FrameBuffer(imgSize.x,
      imgSize.y,
      OSP_FB_SRGBA,
      OSP_FB_COLOR | OSP_FB_ACCUM | OSP_FB_DEPTH);
  framebuffer.resetAccumulation();

  auto builder = testing::newBuilder(scene);
  testing::setParam(builder, "rendererType", rendererType);
  SetBuilderParameters(builder);
  testing::commit(builder);

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

  world.commit();

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

  ArcballCamera arcballCamera(worldBounds, imgSize);

  camera = cpp::Camera("perspective");
  camera.setParam("aspect", imgSize.x / (float)imgSize.y);
  camera.setParam("position", arcballCamera.eyePos());
  camera.setParam("direction", arcballCamera.lookDir());
  camera.setParam("up", arcballCamera.upDir());
  camera.commit();

  renderer = cpp::Renderer(rendererType);
  SetRendererParameters(renderer);
  renderer.commit();
}

void BaseFixture::Shutdown()
{
  framebuffer = nullptr;
  renderer = nullptr;
  camera = nullptr;
  world = nullptr;
}

void BaseFixture::TearDown(::benchmark::State &)
{
  if (!dumpFinalImageDir.empty() && !name.empty()) {
    std::string of = name;
    std::replace(of.begin(), of.end(), '/', '_');

    framebuffer.resetAccumulation();
    framebuffer.renderFrame(renderer, camera, world);
    auto *fb = (uint32_t *)framebuffer.map(OSP_FB_COLOR);
    utility::writePPM(
        dumpFinalImageDir + "/" + of + ".ppm", imgSize.x, imgSize.y, fb);
    framebuffer.unmap(fb);
  }

  Shutdown();
}