Skip to content

Commit

Permalink
Make Sensors' members opaque
Browse files Browse the repository at this point in the history
  • Loading branch information
njroussel committed Mar 3, 2023
1 parent df940c1 commit c864e08
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 31 deletions.
11 changes: 6 additions & 5 deletions include/mitsuba/render/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,16 @@ class MI_EXPORT_LIB Sensor : public Endpoint<Float, Spectrum> {
// =============================================================

void traverse(TraversalCallback *callback) override {
callback->put_parameter("shutter_open", m_shutter_open, +ParamFlags::NonDifferentiable);
callback->put_parameter("shutter_open_time", m_shutter_open_time, +ParamFlags::NonDifferentiable);
callback->put_object("film", m_film.get(), +ParamFlags::NonDifferentiable);
callback->put_object("sampler", m_sampler.get(), +ParamFlags::NonDifferentiable);
Base::traverse(callback);
callback->put_parameter("shutter_open", m_shutter_open, +ParamFlags::NonDifferentiable);
callback->put_parameter("shutter_open_time", m_shutter_open_time, +ParamFlags::NonDifferentiable);
callback->put_object("film", m_film.get(), +ParamFlags::NonDifferentiable);
callback->put_object("sampler", m_sampler.get(), +ParamFlags::NonDifferentiable);
}

void parameters_changed(const std::vector<std::string> &/*keys*/ = {}) override {
void parameters_changed(const std::vector<std::string> &keys = {}) override {
m_resolution = ScalarVector2f(m_film->crop_size());
Base::parameters_changed(keys);
}

DRJIT_VCALL_REGISTER(Float, mitsuba::Sensor)
Expand Down
12 changes: 6 additions & 6 deletions src/sensors/irradiancemeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ MI_VARIANT class IrradianceMeter final : public Sensor<Float, Spectrum> {
using string::indent;

std::ostringstream oss;
oss << "IrradianceMeter[" << std::endl
<< " surface_area = ";
oss << "IrradianceMeter[" << std::endl << " surface_area = ";

if (m_shape) oss << m_shape->surface_area();
else oss << " <no shape attached!>";
if (m_shape)
oss << m_shape->surface_area();
else
oss << " <no shape attached!>";
oss << "," << std::endl;

oss << " film = " << indent(m_film) << "," << std::endl
<< "]";
oss << " film = " << indent(m_film) << "," << std::endl << "]";
return oss.str();
}

Expand Down
6 changes: 1 addition & 5 deletions src/sensors/orthographic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ class OrthographicCamera final : public ProjectiveCamera<Float, Spectrum> {
}

void parameters_changed(const std::vector<std::string> &keys) override {
if (keys.empty() || string::contains(keys, "to_world")) {
// Update the scalar value of the matrix
m_to_world = m_to_world.value();
}
Base::parameters_changed(keys);
update_camera_transforms();
}
Expand Down Expand Up @@ -207,4 +203,4 @@ class OrthographicCamera final : public ProjectiveCamera<Float, Spectrum> {

MI_IMPLEMENT_CLASS_VARIANT(OrthographicCamera, ProjectiveCamera)
MI_EXPORT_PLUGIN(OrthographicCamera, "Orthographic Camera");
NAMESPACE_END(mitsuba)
NAMESPACE_END(mitsuba)
12 changes: 5 additions & 7 deletions src/sensors/perspective.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,29 +143,27 @@ class PerspectiveCamera final : public ProjectiveCamera<Float, Spectrum> {
if (m_to_world.scalar().has_scale())
Throw("Scale factors in the camera-to-world transformation are not allowed!");

update_camera_transforms();

m_principal_point_offset = ScalarPoint2f(
props.get<ScalarFloat>("principal_point_offset_x", 0.f),
props.get<ScalarFloat>("principal_point_offset_y", 0.f)
);

update_camera_transforms();
}

void traverse(TraversalCallback *callback) override {
Base::traverse(callback);
callback->put_parameter("x_fov", m_x_fov, ParamFlags::Differentiable | ParamFlags::Discontinuous);
callback->put_parameter("x_fov", m_x_fov, ParamFlags::Differentiable | ParamFlags::Discontinuous);
callback->put_parameter("to_world", *m_to_world.ptr(), ParamFlags::Differentiable | ParamFlags::Discontinuous);
}

void parameters_changed(const std::vector<std::string> &keys) override {
Base::parameters_changed(keys);
if (keys.empty() || string::contains(keys, "to_world")) {
// Update the scalar value of the matrix
m_to_world = m_to_world.value();
if (m_to_world.scalar().has_scale())
Throw("Scale factors in the camera-to-world transformation are not allowed!");
}

Base::parameters_changed(keys);
update_camera_transforms();
}

Expand Down Expand Up @@ -193,7 +191,7 @@ class PerspectiveCamera final : public ProjectiveCamera<Float, Spectrum> {
m_normalization = 1.f / m_image_rect.volume();
m_needs_sample_3 = false;

dr::make_opaque(m_to_world, m_camera_to_sample, m_sample_to_camera, m_dx, m_dy, m_x_fov,
dr::make_opaque(m_camera_to_sample, m_sample_to_camera, m_dx, m_dy, m_x_fov,
m_image_rect, m_normalization, m_principal_point_offset);
}

Expand Down
15 changes: 7 additions & 8 deletions src/sensors/thinlens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Perspective camera with a thin lens (:monosp:`thinlens`)
- |transform|
- Specifies an optional camera-to-world transformation.
(Default: none (i.e. camera space = world space))
- |exposed|
- |exposed|, |differentiable|, |discontinuous|

* - aperture_radius
- |float|
Expand Down Expand Up @@ -171,19 +171,18 @@ class ThinLensCamera final : public ProjectiveCamera<Float, Spectrum> {
void traverse(TraversalCallback *callback) override {
Base::traverse(callback);
callback->put_parameter("aperture_radius", m_aperture_radius, ParamFlags::Differentiable | ParamFlags::Discontinuous);
callback->put_parameter("focus_distance", m_focus_distance, ParamFlags::Differentiable | ParamFlags::Discontinuous);
callback->put_parameter("x_fov", m_x_fov, ParamFlags::Differentiable | ParamFlags::Discontinuous);
callback->put_parameter("to_world", *m_to_world.ptr(), ParamFlags::Differentiable | ParamFlags::Discontinuous);
callback->put_parameter("focus_distance", m_focus_distance, ParamFlags::Differentiable | ParamFlags::Discontinuous);
callback->put_parameter("x_fov", m_x_fov, ParamFlags::Differentiable | ParamFlags::Discontinuous);
callback->put_parameter("to_world", *m_to_world.ptr(), ParamFlags::Differentiable | ParamFlags::Discontinuous);
}

void parameters_changed(const std::vector<std::string> &keys) override {
Base::parameters_changed(keys);
if (keys.empty() || string::contains(keys, "to_world")) {
// Update the scalar value of the matrix
m_to_world = m_to_world.value();
if (m_to_world.scalar().has_scale())
Throw("Scale factors in the camera-to-world transformation are not allowed!");
}
Base::parameters_changed(keys);

update_camera_transforms();
}

Expand All @@ -210,7 +209,7 @@ class ThinLensCamera final : public ProjectiveCamera<Float, Spectrum> {
m_image_rect.expand(Point2f(pmax.x(), pmax.y()) / pmax.z());
m_normalization = 1.f / m_image_rect.volume();

dr::make_opaque(m_to_world, m_camera_to_sample, m_sample_to_camera, m_dx, m_dy,
dr::make_opaque(m_camera_to_sample, m_sample_to_camera, m_dx, m_dy,
m_x_fov, m_image_rect, m_normalization);
}

Expand Down

0 comments on commit c864e08

Please sign in to comment.