How to initialize an integrator instance by a scene's parameters? #507
-
Let's say I'm writing a new integrator that requires to do some heavy computation relying on the scene parameters (e.g., bbox, shapes, bsdfs) once before rendering. This computation is only required once per scene, and every later rendering does not require this computation but just needs to query the precomputed result. Thus, I'd like to compute the value in the init() function. That means, as far as I think, I need to get the scene parameters from the input of init() function, that is The below code is an example. class MyIntegrator(mi.ad.common.ADIntegrator):
def __init__(
self, props=mi.Properties()
):
super().__init__(props)
self.scene = # HOW???
m_area = []
for shape in scene.shapes():
m_area.append(shape.surface_area())
m_area = np.array(m_area)[:, 0]
self.m_area = m_area
def sample(...):
var1 = self.m_area[...] |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @Mephisto405 Plugins in Mitsuba have a unidirectional parent->child relationship, which makes something like you're trying to do a bit complicated as usually the scene is the parent and the integrator is one of its children. There's not really a way to (easily) get around this. There are a few options to work around it though. The issue here is that the
Basically, I don't think there is any built-in mitsuba way of achieving this cleanly. You would need to abuse some of the existing interface. |
Beta Was this translation helpful? Give feedback.
-
Very similar case: https://github.com/mitsuba-renderer/mitsuba3/blob/master/src/python/python/ad/integrators/prbvolpath.py |
Beta Was this translation helpful? Give feedback.
Hi @Mephisto405
Plugins in Mitsuba have a unidirectional parent->child relationship, which makes something like you're trying to do a bit complicated as usually the scene is the parent and the integrator is one of its children. There's not really a way to (easily) get around this.
There are a few options to work around it though. The issue here is that the
__init__
constructor cannot take themi.Scene
it is a part of as an argument, however you can use any other method or even create a new method which takes a scene as a parameter.A few options:
initialize(scene: mi.Scene)
method to your integrator which you need to explicitly call.sample()
check if it already has initia…