Skip to content

Commit

Permalink
Add missing Python bindings for Sensor/Emitter/Endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
njroussel committed Feb 7, 2023
1 parent 0e49716 commit 8f03c7d
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 25 deletions.
3 changes: 2 additions & 1 deletion include/mitsuba/render/emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ NAMESPACE_END(mitsuba)

DRJIT_VCALL_TEMPLATE_BEGIN(mitsuba::Emitter)
DRJIT_VCALL_METHOD(sample_ray)
DRJIT_VCALL_METHOD(eval)
DRJIT_VCALL_METHOD(sample_direction)
DRJIT_VCALL_METHOD(pdf_direction)
DRJIT_VCALL_METHOD(eval_direction)
DRJIT_VCALL_METHOD(sample_position)
DRJIT_VCALL_METHOD(pdf_position)
DRJIT_VCALL_METHOD(eval)
DRJIT_VCALL_METHOD(sample_wavelengths)
DRJIT_VCALL_METHOD(is_environment)
DRJIT_VCALL_GETTER(flags, uint32_t)
Expand Down
4 changes: 3 additions & 1 deletion include/mitsuba/render/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class MI_EXPORT_LIB Sensor : public Endpoint<Float, Spectrum> {
const Point2f &sample2, const Point2f &sample3,
Mask active = true) const;


/**
* \brief Importance sample a set of wavelengths proportional to the
* sensitivity spectrum.
Expand Down Expand Up @@ -313,10 +312,13 @@ NAMESPACE_END(mitsuba)

DRJIT_VCALL_TEMPLATE_BEGIN(mitsuba::Sensor)
DRJIT_VCALL_METHOD(sample_ray)
DRJIT_VCALL_METHOD(sample_ray_differential)
DRJIT_VCALL_METHOD(sample_direction)
DRJIT_VCALL_METHOD(pdf_direction)
DRJIT_VCALL_METHOD(eval_direction)
DRJIT_VCALL_METHOD(sample_position)
DRJIT_VCALL_METHOD(pdf_position)
DRJIT_VCALL_METHOD(eval)
DRJIT_VCALL_METHOD(sample_wavelengths)
DRJIT_VCALL_GETTER(flags, uint32_t)
DRJIT_VCALL_GETTER(shape, const typename Class::Shape *)
Expand Down
63 changes: 50 additions & 13 deletions src/render/python/emitter_v.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,35 @@ MI_VARIANT class PyEmitter : public Emitter<Float, Spectrum> {
PYBIND11_OVERRIDE_PURE(Float, Emitter, pdf_direction, ref, ds, active);
}

Spectrum eval_direction(const Interaction3f &ref,
const DirectionSample3f &ds,
Mask active) const override {
PYBIND11_OVERRIDE_PURE(Spectrum, Emitter, eval_direction, ref, ds, active);
}

std::pair<PositionSample3f, Float>
sample_position(Float time, const Point2f &sample,
Mask active) const override {
using Return = std::pair<PositionSample3f, Float>;
PYBIND11_OVERRIDE_PURE(Return, Emitter, sample_position, time, sample, active);
}

Float pdf_position(const PositionSample3f &ps,
Mask active) const override {
PYBIND11_OVERRIDE_PURE(Float, Emitter, pdf_position, ps, active);
}

Spectrum eval(const SurfaceInteraction3f &si, Mask active) const override {
PYBIND11_OVERRIDE_PURE(Spectrum, Emitter, eval, si, active);
}

std::pair<Wavelength, Spectrum>
sample_wavelengths(const SurfaceInteraction3f &si, Float sample,
Mask active) const override {
using Return = std::pair<Wavelength, Spectrum>;
PYBIND11_OVERRIDE_PURE(Return, Emitter, sample_wavelengths, si, sample, active);
}

ScalarBoundingBox3f bbox() const override {
PYBIND11_OVERRIDE_PURE(ScalarBoundingBox3f, Emitter, bbox,);
}
Expand Down Expand Up @@ -85,33 +110,45 @@ MI_PY_EXPORT(Emitter) {
D(Endpoint, sample_ray))
.def("sample_direction",
[](EmitterPtr ptr, const Interaction3f &it, const Point2f &sample, Mask active) {
return ptr->sample_direction(it, sample, active);
return ptr->sample_direction(it, sample, active);
},
"it"_a, "sample"_a, "active"_a = true,
D(Endpoint, sample_direction))
.def("sample_position",
[](EmitterPtr ptr, Float time, const Point2f &sample, Mask active) {
return ptr->sample_position(time, sample, active);
},
"time"_a, "sample"_a, "active"_a = true,
D(Endpoint, sample_position))
.def("sample_wavelengths",
[](EmitterPtr ptr, const SurfaceInteraction3f &si, Float sample, Mask active) {
return ptr->sample_wavelengths(si, sample, active);
},
"si"_a, "sample"_a, "active"_a = true,
D(Endpoint, sample_wavelengths))
.def("pdf_direction",
[](EmitterPtr ptr, const Interaction3f &it, const DirectionSample3f &ds, Mask active) {
return ptr->pdf_direction(it, ds, active);
},
"it"_a, "ds"_a, "active"_a = true,
D(Endpoint, pdf_direction))
.def("eval_direction",
[](EmitterPtr ptr, const Interaction3f &it, const DirectionSample3f &ds, Mask active) {
return ptr->eval_direction(it, ds, active);
},
"it"_a, "ds"_a, "active"_a = true,
D(Endpoint, eval_direction))
.def("sample_position",
[](EmitterPtr ptr, Float time, const Point2f &sample, Mask active) {
return ptr->sample_position(time, sample, active);
},
"time"_a, "sample"_a, "active"_a = true,
D(Endpoint, sample_position))
.def("pdf_position",
[](EmitterPtr ptr, const PositionSample3f &ps, Mask active) {
return ptr->pdf_position(ps, active);
},
"ps"_a, "active"_a = true,
D(Endpoint, pdf_position))
.def("eval",
[](EmitterPtr ptr, const SurfaceInteraction3f &si, Mask active) {
return ptr->eval(si, active);
},
"si"_a, "active"_a = true, D(Endpoint, eval))
.def("sample_wavelengths",
[](EmitterPtr ptr, const SurfaceInteraction3f &si, Float sample, Mask active) {
return ptr->sample_wavelengths(si, sample, active);
},
"si"_a, "sample"_a, "active"_a = true,
D(Endpoint, sample_wavelengths))
.def("flags", [](EmitterPtr ptr) { return ptr->flags(); }, D(Emitter, flags))
.def("shape", [](EmitterPtr ptr) { return ptr->shape(); }, D(Endpoint, shape))
.def("is_environment",
Expand Down
4 changes: 4 additions & 0 deletions src/render/python/endpoint_v.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ MI_PY_EXPORT(Endpoint) {
"it"_a, "ds"_a, "active"_a = true, D(Endpoint, pdf_direction))
.def("eval_direction", &Endpoint::eval_direction,
"it"_a, "ds"_a, "active"_a = true, D(Endpoint, eval_direction))
.def("sample_position", &Endpoint::sample_position,
"ref"_a, "ds"_a, "active"_a = true, D(Endpoint, sample_position))
.def("pdf_position", &Endpoint::pdf_position,
"ps"_a, "active"_a = true, D(Endpoint, pdf_position))
.def("eval", &Endpoint::eval,
"si"_a, "active"_a = true, D(Endpoint, eval))
.def("sample_wavelengths", &Endpoint::sample_wavelengths,
Expand Down
61 changes: 51 additions & 10 deletions src/render/python/sensor_v.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,35 @@ MI_VARIANT class PySensor : public Sensor<Float, Spectrum> {
PYBIND11_OVERRIDE_PURE(Float, Sensor, pdf_direction, ref, ds, active);
}

Spectrum eval_direction(const Interaction3f &ref,
const DirectionSample3f &ds,
Mask active) const override {
PYBIND11_OVERRIDE_PURE(Spectrum, Sensor, eval_direction, ref, ds, active);
}

std::pair<PositionSample3f, Float>
sample_position(Float time, const Point2f &sample,
Mask active) const override {
using Return = std::pair<PositionSample3f, Float>;
PYBIND11_OVERRIDE_PURE(Return, Sensor, sample_position, time, sample, active);
}

Float pdf_position(const PositionSample3f &ps,
Mask active) const override {
PYBIND11_OVERRIDE_PURE(Float, Sensor, pdf_position, ps, active);
}

Spectrum eval(const SurfaceInteraction3f &si, Mask active) const override {
PYBIND11_OVERRIDE_PURE(Spectrum, Sensor, eval, si, active);
}

std::pair<Wavelength, Spectrum>
sample_wavelengths(const SurfaceInteraction3f &si, Float sample,
Mask active) const override {
using Return = std::pair<Wavelength, Spectrum>;
PYBIND11_OVERRIDE_PURE(Return, Sensor, sample_wavelengths, si, sample, active);
}

ScalarBoundingBox3f bbox() const override {
PYBIND11_OVERRIDE_PURE(ScalarBoundingBox3f, Sensor, bbox,);
}
Expand All @@ -66,7 +91,6 @@ MI_PY_EXPORT(Sensor) {
.def_method(Sensor, shutter_open)
.def_method(Sensor, shutter_open_time)
.def_method(Sensor, needs_aperture_sample)
.def_method(Sensor, sample_ray_differential)
.def("film", py::overload_cast<>(&Sensor::film, py::const_), D(Sensor, film))
.def("sampler", py::overload_cast<>(&Sensor::sampler, py::const_), D(Sensor, sampler))
.def_readwrite("m_needs_sample_2", &PySensor::m_needs_sample_2)
Expand Down Expand Up @@ -98,28 +122,45 @@ MI_PY_EXPORT(Sensor) {
D(Endpoint, sample_ray))
.def("sample_direction",
[](SensorPtr ptr, const Interaction3f &it, const Point2f &sample, Mask active) {
return ptr->sample_direction(it, sample, active);
return ptr->sample_direction(it, sample, active);
},
"it"_a, "sample"_a, "active"_a = true,
D(Endpoint, sample_direction))
.def("pdf_direction",
[](SensorPtr ptr, const Interaction3f &it, const DirectionSample3f &ds, Mask active) {
return ptr->pdf_direction(it, ds, active);
},
"it"_a, "ds"_a, "active"_a = true,
D(Endpoint, pdf_direction))
.def("eval_direction",
[](SensorPtr ptr, const Interaction3f &it, const DirectionSample3f &ds, Mask active) {
return ptr->eval_direction(it, ds, active);
},
"it"_a, "ds"_a, "active"_a = true,
D(Endpoint, eval_direction))
.def("sample_position",
[](SensorPtr ptr, Float time, const Point2f &sample, Mask active) {
return ptr->sample_position(time, sample, active);
return ptr->sample_position(time, sample, active);
},
"time"_a, "sample"_a, "active"_a = true,
D(Endpoint, sample_position))
.def("pdf_position",
[](SensorPtr ptr, const PositionSample3f &ps, Mask active) {
return ptr->pdf_position(ps, active);
},
"ps"_a, "active"_a = true,
D(Endpoint, pdf_position))
.def("eval",
[](SensorPtr ptr, const SurfaceInteraction3f &si, Mask active) {
return ptr->eval(si, active);
},
"si"_a, "active"_a = true, D(Endpoint, eval))
.def("sample_wavelengths",
[](SensorPtr ptr, const SurfaceInteraction3f &si, Float sample, Mask active) {
return ptr->sample_wavelengths(si, sample, active);
return ptr->sample_wavelengths(si, sample, active);
},
"si"_a, "sample"_a, "active"_a = true,
D(Endpoint, sample_wavelengths))
.def("pdf_direction",
[](SensorPtr ptr, const Interaction3f &it, const DirectionSample3f &ds, Mask active) {
return ptr->pdf_direction(it, ds, active);
},
"it"_a, "ds"_a, "active"_a = true,
D(Endpoint, pdf_direction))
.def("shape", [](SensorPtr ptr) { return ptr->shape(); }, D(Endpoint, shape));

bind_drjit_ptr_array(cls);
Expand Down

0 comments on commit 8f03c7d

Please sign in to comment.