4#include "pybind11/pybind11.h"
5#include "pybind11/operators.h"
7namespace py = pybind11;
43 template<
typename CONF>
44 void core(py::module& m)
47 using BsdfPtr = bsdf_ptr<Config>;
50 py::enum_<bsdf_flag>(m,
"bsdf_flag")
55 .def(py::self | py::self)
56 .def(py::self & py::self)
57 .def(py::self ^ py::self)
62 py::enum_<bsdf_attr>(m,
"bsdf_attr")
74 .def(py::self | py::self)
75 .def(py::self & py::self)
76 .def(py::self ^ py::self)
81 py::enum_<unit_t>(m,
"unit_t")
88 fresnel<Spectrum>(m,
"Spectral");
89 complex_fresnel<Value>(m);
90 complex_fresnel<Spectrum>(m,
"Spectral");
93 py::class_<BsdfSample>(m,
"BsdfSample")
94 .def_readonly(
"direction", &BsdfSample::direction,
"Sampled direction")
95 .def_readonly(
"pdf", &BsdfSample::pdf,
"PDF of the sampled direction")
96 .def_readonly(
"flag", &BsdfSample::flag,
"Type of the sampled direction")
97 .def(
"__str__", [](
const BsdfSample& sample) {
return bbm::toString(sample); });
100 py::class_<Vec3dPair>(m,
"Vec3dPair")
101 .def_readonly(
"in", &Vec3dPair::in,
"Incident direction")
102 .def_readonly(
"out", &Vec3dPair::out,
"Outgoing direction")
103 .def(
"__str__", [](
const Vec3dPair& sample) {
return bbm::toString(sample); });
106 py::class_<BsdfPtr>(m,
"BsdfPtr")
107 .def(py::init<const BsdfPtr &>())
108 .def(
"eval", [](
const BsdfPtr& self,
const Vec3d& in,
const Vec3d& out, BsdfFlag component=
bsdf_flag::All,
unit_t unit=
unit_t::Radiance, Mask mask=
true) {
return self.eval(in,out,component,unit,mask); },
"Given an 'in' and 'out' direction, return the radiance/importance of the BSDF", py::arg(
"in"), py::arg(
"out"), py::arg_v(
"component",
bsdf_flag::All), py::arg_v(
"unit",
unit_t::Radiance), py::arg_v(
"mask",
true))
109 .def(
"sample", [](
const BsdfPtr& self,
const Vec3d& out,
const Vec2d& xi, BsdfFlag component=
bsdf_flag::All,
unit_t unit=
unit_t::Radiance, Mask mask=
true) {
return self.sample(out, xi, component, unit, mask); },
"Given an 'in' direction, and 2D random variable ('xi'), generate a 'out' directions and corresponding PDF stored in a bsdfSample accordining to the radiance/importance distribution", py::arg(
"in"), py::arg(
"xi"), py::arg_v(
"component",
bsdf_flag::All), py::arg_v(
"unit",
unit_t::Radiance), py::arg_v(
"mask",
true))
110 .def(
"pdf", [](
const BsdfPtr& self,
const Vec3d& in,
const Vec3d& out, BsdfFlag component=
bsdf_flag::All,
unit_t unit=
unit_t::Radiance, Mask mask=
true) {
return self.pdf(in, out, component, unit, mask); },
"Given an 'in' direction, produce the pdf of sampling the 'out' direction according to the radiance/importance distribution", py::arg(
"in"), py::arg(
"out"), py::arg_v(
"component",
bsdf_flag::All), py::arg_v(
"unit",
unit_t::Radiance), py::arg_v(
"mask",
true))
111 .def(
"reflectance", [](
const BsdfPtr& self,
const Vec3d& out, BsdfFlag component=
bsdf_flag::All,
unit_t unit=
unit_t::Radiance, Mask mask=
true) {
return self.reflectance(out, component, unit, mask); },
"Given an 'in' direction, return the approximate hemispherical reflectance (i.e., integral over all outgoing directions) of the radiance/importance of the BSDF", py::arg(
"in"), py::arg_v(
"component",
bsdf_flag::All), py::arg_v(
"unit",
unit_t::Radiance), py::arg_v(
"mask",
true))
112 .def(
"__str__", &BsdfPtr::toString,
"BSDF attributes to string")
116 m.def(
"Aggregate", [](py::args args)
120 arg_list.push_back( py::cast<BsdfPtr&>(*a) );
123 },
"AggregateBsdf(BsdfPtr...) combines as many BsdfPtrs as provided.");
128 py::class_<bbm::vector<Value&>>(m,
"RefValueVector")
131 .def(
"__setitem__", [](
bbm::vector<Value&>& self,
size_t index,
const Value& val) { self[index] = val; })
133 .def(py::self + py::self)
134 .def(py::self + Value())
135 .def(py::self += py::self)
136 .def(py::self += Value())
137 .def(py::self - py::self)
138 .def(py::self - Value())
139 .def(py::self -= py::self)
140 .def(py::self -= Value())
141 .def(py::self * py::self)
142 .def(py::self * Value())
143 .def(py::self *= py::self)
144 .def(py::self *= Value())
145 .def(py::self / py::self)
146 .def(py::self / Value())
147 .def(py::self /= py::self)
148 .def(py::self /= Value())
152 py::class_<bbm::vector<Value>>(m,
"ValueVector")
155 .def(
"__setitem__", [](
bbm::vector<Value>& self,
size_t index,
const Value& val) { self[index] = val; })
156 .def(
"__getitem__", [](
bbm::vector<Value>& self,
size_t index) {
return self[index]; })
157 .def(py::self + py::self)
158 .def(py::self + Value())
159 .def(py::self += py::self)
160 .def(py::self += Value())
161 .def(py::self - py::self)
162 .def(py::self - Value())
163 .def(py::self -= py::self)
164 .def(py::self -= Value())
165 .def(py::self * py::self)
166 .def(py::self * Value())
167 .def(py::self *= py::self)
168 .def(py::self *= Value())
169 .def(py::self / py::self)
170 .def(py::self / Value())
171 .def(py::self /= py::self)
172 .def(py::self /= Value())
180 m.def(
"parameter_values", ¶meter_values<BsdfPtr>, py::arg(
"bsdf"), py::arg_v(
"flag",
bsdf_attr::All),
"List all parameter values of a given BSDF");
181 m.def(
"parameter_default_values", ¶meter_default_values<BsdfPtr>, py::arg(
"bsdf"), py::arg_v(
"flag",
bsdf_attr::All),
"List all default parameter values of a given BSDF");
182 m.def(
"parameter_lower_bound", ¶meter_lower_bound<BsdfPtr>, py::arg(
"bsdf"), py::arg_v(
"flag",
bsdf_attr::All),
"List the lower bound of all parameter values of a given BSDF");
183 m.def(
"parameter_upper_bound", ¶meter_upper_bound<BsdfPtr>, py::arg(
"bsdf"), py::arg_v(
"flag",
bsdf_attr::All),
"List the upper vound of all parameter values of a given BSDF");
A run-time aggregation of BSDFs.
A shared_ptr wrapper for bsdfs.
#define BBM_IMPORT_CONFIG(...)
Import the configs typedefs in the current scope
Definition: config.h:103
Enumerate all BSDF parameters (e.g., stack in a vector).
Structure to hold a sampled direction and corresponding pdf.
Definition: vector_util.h:27
Definition: aggregatebsdf.h:29
bsdf_flag
Reflectance Component Evaluation Flags.
Definition: bsdf_flag.h:22
std::string toString(const T &)
toString alias
Definition: stringconvert.h:594
auto aggregate(const bsdf< BSDFMODELs > &... src)
Helper methods for simplifying the creation of a aggregate bsdf.
Definition: aggregatebsdf.h:329
bsdf_ptr< get_config< BSDFTYPE > > make_bsdf_ptr(ARGS... args)
Helper method for making a bsdf_ptr from a BSDF (new construction)
Definition: bsdf_ptr.h:180
bsdf_attr
Attribute Property Flags.
Definition: bsdf_attr_flag.h:17
unit_t
Light Unit.
Definition: unit.h:21
Export ior::ior and ior::reflectance to pyton.
Structure to hold a pair of directions.
Extensions for the STL vector class.