-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
traverse() and parameters_changed() enhanced #108
Conversation
@@ -326,6 +326,8 @@ class MTS_EXPORT_RENDER Shape : public Object { | |||
inline Shape() { } | |||
virtual ~Shape(); | |||
|
|||
/// Set this shape to its associated children |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "Explicitly register this shape as the parent of the provided sub-objects (emitters, sensors, etc.)"
This looks great -- one question I am wondering about is what happens when one of the changed parameters is a sub-object? Is this just handled using the (potentially auto-generated) ID? The following is worthy of some discussion:
IIRC the current python code calls functions from child to parent. If there are other update directions that must be considered, I think it would be better not to go through the |
In this case Does that answer your question? |
I first used the In the current implementation, the convention is that the python At some point I was thinking of a more generic solution, where the
At then end, I realized that this relation Truth is, in the future, as the codebase grows it might be necessary to handle this properly. Happy to discuss this futher.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks awesome, extremely minor comments at this point.
m_aspect = m_film->size().x() / (ScalarFloat) m_film->size().y(); | ||
m_resolution = ScalarVector2f(m_film->crop_size()); | ||
void parameters_changed(const std::vector<std::string> &/*keys*/ = {}) override { | ||
m_aspect = m_film->size().x() / (ScalarFloat) m_film->size().y(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong indentation?
@@ -52,5 +52,12 @@ std::string trim(const std::string &s, const std::string &whitespace) { | |||
return s.substr(it1, it2 - it1 + 1); | |||
} | |||
|
|||
bool contains(const std::vector<std::string> &keys, const std::string &key) { | |||
for (auto& k: keys) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love auto
, but let's reserve its use for complicated types like std::some_complex_stl_type<>::iterator
and spell out types explicitly in all other cases to aid readability. No big deal in this case, but I thought I'd point it out for the future.
key, name = key.rsplit('.', 1) | ||
|
||
self.update_list.setdefault((depth, node), []) | ||
self.update_list[(depth, node)].append(name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
Overview
The primary goal of this PR is to enhance the traversal mechanism to prevent unnecessary updates of the object parameters.
This is achieved by adding an optional argument to the
parameters_changed()
, carrying the list of names (a.k.a.keys
) of the object's attributes that have being modified since the last call to this function.These names correspond to the names given in the
traverse()
method.When
keys
is empty, it should be assumed that any parameters might have been modified.The implementation of the
parameters_changed
methods in every plugin can then be fine-tuned to avoid unnecessary computation when only a subset of the attributes have changed. For instance, we shouldn't recompute the optix BVH every time a mesh's BSDF reflectance value is modified (children triggerparameters_changed()
on their parents).keys
might also contain the key"parent"
(we could define a more "unique" key for this) which specifies thatparameters_changed()
has been called from a parent object. E.g., when a shape's geometry is modified, the attachedarea
emitter (if any) should be notified so it can recompute some internal variables (herem_inv_surface_area
).Remaining questions
Scene
and not children of the objects they are referenced by. This might cause some issues as "parents" might not be updated properly.const
intraverse()
? In which caseParametersMap.__set_item__()
would throw an error / warning.TODOs
Scene
should upate its bounding sphere when some geometry is modified