-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtesting.h
114 lines (89 loc) · 2.63 KB
/
testing.h
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
#ifndef TESTING_H
#define TESTING_H
#include <pybind11/pybind11.h>
//#include <ospray/ospray_testing/ospray_testing.h>
namespace ospray {
namespace testing {
using SceneBuilderHandle = void *;
SceneBuilderHandle newBuilder(const std::string &type);
template <typename T>
void setParam(SceneBuilderHandle b, const std::string &type, const T &val);
cpp::Group buildGroup(SceneBuilderHandle b);
cpp::World buildWorld(SceneBuilderHandle b);
void commit(SceneBuilderHandle b);
void release(SceneBuilderHandle b);
}
}
namespace py = pybind11;
/*
# Create scene
builder = ospray.testing.new_builder(SCENE)
builder.set_param('rendererType', RENDERER)
builder.commit()
if True:
world = builder.build_world()
world.commit()
*/
struct SceneBuilder
{
SceneBuilder(const std::string& scene)
{
handle = ospray::testing::newBuilder(scene);
}
~SceneBuilder()
{
ospray::testing::release(handle);
}
void
commit()
{
ospray::testing::commit(handle);
}
ospray::cpp::Group
build_group()
{
return ospray::testing::buildGroup(handle);
}
ospray::cpp::World
build_world()
{
return ospray::testing::buildWorld(handle);
}
void
set_param(const std::string& type, py::object value)
{
const std::string vtype = value.get_type().attr("__name__").cast<std::string>();
if (vtype == "bool")
ospray::testing::setParam(handle, type, value.cast<bool>());
else if (vtype == "int")
ospray::testing::setParam(handle, type, value.cast<int>());
else if (vtype == "str")
ospray::testing::setParam(handle, type, value.cast<std::string>());
else
printf("Warning: unhandled type '%s' in SceneBuilder.set_param('%s', ...)\n", vtype.c_str(), type.c_str());
}
ospray::testing::SceneBuilderHandle handle;
};
inline void
define_testing(py::module& m)
{
py::module t = m.def_submodule("testing", "ospray_testing");
py::class_<SceneBuilder>(t, "SceneBuilder")
.def(py::init<const std::string &>())
.def("build_group", &SceneBuilder::build_group)
.def("build_world", &SceneBuilder::build_world)
.def("set_param", &SceneBuilder::set_param)
.def("commit", &SceneBuilder::commit)
;
/*
auto builder = testing::newBuilder(scene);
testing::setParam(builder, "rendererType", rendererTypeStr);
if (scene == "curves") {
testing::setParam(builder, "curveBasis", curveBasis);
}
testing::commit(builder);
world = testing::buildWorld(builder);
testing::release(builder);
*/
}
#endif