1 // Copyright 2020-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 #include "../../external/catch.hpp"
7 #include "openvkl_testing.h"
8 #include "rkcommon/utility/multidim_index_sequence.h"
9 
10 using namespace rkcommon;
11 using namespace openvkl::testing;
12 
13 inline void scalar_sampling_on_vertices_vs_procedural_values(
14     vec3i dimensions,
15     VKLUnstructuredCellType primType,
16     VKLDataCreationFlags dataCreationFlags = VKL_DATA_DEFAULT,
17     size_t byteStride                      = 0,
18     vec3i step                             = vec3i(1))
19 {
20   std::unique_ptr<WaveletUnstructuredProceduralVolume> v(
21       new WaveletUnstructuredProceduralVolume(
22           dimensions,
23           vec3f(0.f),
24           vec3f(1.f),
25           primType,
26           true,  // matching defaults of ProceduralUnstructuredVolume...
27           true,
28           false,
29           false,
30           dataCreationFlags,
31           byteStride));
32 
33   VKLVolume vklVolume   = v->getVKLVolume(getOpenVKLDevice());
34   VKLSampler vklSampler = vklNewSampler(vklVolume);
35   vklCommit(vklSampler);
36 
37   multidim_index_sequence<3> mis(v->getDimensions() / step);
38 
39   for (const auto &offset : mis) {
40     const auto offsetWithStep = offset * step;
41 
42     vec3f objectCoordinates =
43         v->getGridOrigin() + offsetWithStep * v->getGridSpacing();
44 
45     INFO("offset = " << offsetWithStep.x << " " << offsetWithStep.y << " "
46                      << offsetWithStep.z);
47     INFO("objectCoordinates = " << objectCoordinates.x << " "
48                                 << objectCoordinates.y << " "
49                                 << objectCoordinates.z);
50 
51     vec3f offsetCoordinates = objectCoordinates + vec3f(0.1f);
52     CHECK(
53         vklComputeSample(vklSampler, (const vkl_vec3f *)&(offsetCoordinates)) ==
54         Approx(v->computeProceduralValue(objectCoordinates)).margin(1e-4f));
55   }
56 
57   vklRelease(vklSampler);
58 }
59