File: test_interpolation.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 (137 lines) | stat: -rw-r--r-- 3,576 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
// Copyright 2022 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "ArcballCamera.h"
#include "ospray_testing.h"
#include "rkcommon/utility/random.h"
#include "test_fixture.h"

extern OSPRayEnvironment *ospEnv;

namespace OSPRayTestScenes {

class Interpolation
    : public Base,
      public ::testing::TestWithParam<std::tuple<bool /*use subd*/,
          unsigned int /*attribute*/,
          unsigned int /*interpolation*/>>
{
 public:
  Interpolation();
  void SetUp() override;
  void PerformRenderTest() override;

 protected:
  OSPFrameBufferChannel idBuffer{OSP_FB_COLOR};
  bool useSubd{false};
  unsigned int attribute{0};
  unsigned int interpolation{0};
};

Interpolation::Interpolation()
{
  samplesPerPixel = 2;
  rendererType = "scivis";

  auto params = GetParam();
  useSubd = std::get<0>(params);
  attribute = std::get<1>(params);
  interpolation = std::get<2>(params);

  if (attribute == 2)
    idBuffer = OSP_FB_NORMAL;
}

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

  framebuffer =
      cpp::FrameBuffer(imgSize.x, imgSize.y, frameBufferFormat, idBuffer);

  instances.clear();

  auto builder = ospray::testing::newBuilder("interpolation");
  ospray::testing::setParam(builder, "rendererType", rendererType);
  ospray::testing::setParam(builder, "useSubd", useSubd);
  ospray::testing::setParam(builder, "attribute", attribute);
  ospray::testing::setParam(builder, "interpolation", interpolation);
  ospray::testing::commit(builder);

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

inline uint8_t to_uc(const float f)
{
  return 255.f * clamp(f, 0.f, 1.0f);
}
inline uint32_t to_rgba8(const vec3f c)
{
  return to_uc(c.x) | (to_uc(c.y) << 8) | (to_uc(c.z) << 16) | 0xff000000;
}

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

  world.commit();

  ArcballCamera arcballCamera(world.getBounds<box3f>(), imgSize);
  camera.setParam("position", arcballCamera.eyePos());
  camera.setParam("direction", arcballCamera.lookDir());
  camera.setParam("up", arcballCamera.upDir());
  camera.commit();

  renderer.commit();

  framebuffer.resetAccumulation();

  RenderFrame();

  auto *framebuffer_data = (uint32_t *)framebuffer.map(idBuffer);
  std::vector<uint32_t> framebufferData(imgSize.product());
  for (int i = 0; i < imgSize.product(); i++) {
    if (attribute == 2) { // normals
      const vec3f normal = ((vec3f *)framebuffer_data)[i];
      framebufferData[i] = to_rgba8(0.5f * normal + 0.5f);
    } else
      framebufferData[i] = framebuffer_data[i];
  }
  framebuffer.unmap(framebuffer_data);

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

// Test Instantiations //////////////////////////////////////////////////////

TEST_P(Interpolation, Interpolation)
{
  PerformRenderTest();
}

INSTANTIATE_TEST_SUITE_P(Color,
    Interpolation,
    ::testing::Combine(::testing::Bool(),
        ::testing::Values(0),
        ::testing::Values(0, 1, 2, 3)));

INSTANTIATE_TEST_SUITE_P(Texcoord,
    Interpolation,
    ::testing::Combine(
        ::testing::Bool(), ::testing::Values(1), ::testing::Values(0, 1)));

INSTANTIATE_TEST_SUITE_P(Normal,
    Interpolation,
    ::testing::Combine(::testing::Values(false),
        ::testing::Values(2),
        ::testing::Values(0, 1)));

} // namespace OSPRayTestScenes