Using ShapePtr in python or is there any way to sample points on multiple shapes simultaneously? #499
-
Hello, Given a scene, I want to sample many points uniformly on all the shapes in the scene. scene = mi.load_file("data/cornell-box/scene_v3.xml")
sampler = mi.PCG32(size=1)
time = 0.5
batch_size = 32
for shape in scene.shapes():
m_area.append(shape.surface_area())
m_area = np.array(m_area)[:,0]
if len(m_area):
m_area /= m_area.sum()
batch_indices = np.random.choice(range(len(m_area)), size=batch_size, p=m_area)
for i in batch_indices:
pos_sample = mi.Point2f(sampler.next_float32(), sampler.next_float32())
ps = m_shapes[i].sample_position(time, pos_sample)
# for further applications
si = mi.SurfaceInteraction3f(ps, dr.zeros(mi.Color0f))
si.wi = ... But I guess this code is not optimized, and I feel like there may be some Mitsuba-nic (analogous to pythonic) way to vectorize the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Hi ! Indeed, |
Beta Was this translation helpful? Give feedback.
Hi !
Indeed,
Scene.shapes()
returns a Python list 🙁 . What you're looking for isScene.shapes_dr()
which returns aShapePtr
.