def test_tea_vectorized(variant_packet_rgb):
    from mitsuba.core import sample_tea_float32, sample_tea_float64, UInt32

    count = 100

    result = sample_tea_float32(UInt32.full(1, count), UInt32.arange(count), 4)
    for i in range(count):
        assert result[i] == sample_tea_float32(1, i, 4)

    result = sample_tea_float64(UInt32.full(1, count), UInt32.arange(count), 4)
    for i in range(count):
        assert result[i] == sample_tea_float64(1, i, 4)
Пример #2
0
 def ravel(buf, dim=3):
     idx = dim * UInt32.arange(ek.slices(buf) // dim)
     if dim == 2:
         return Vector2f(ek.gather(buf, idx), ek.gather(buf, idx + 1))
     elif dim == 3:
         return Vector3f(ek.gather(buf, idx), ek.gather(buf, idx + 1),
                         ek.gather(buf, idx + 2))
Пример #3
0
def _render_helper(scene, spp=None, sensor_index=0):
    """
    Internally used function: render the specified Mitsuba scene and return a
    floating point array containing RGB values and AOVs, if applicable
    """
    from mitsuba.core import (Float, UInt32, UInt64, Vector2f,
                              is_monochromatic, is_rgb, is_polarized)
    from mitsuba.render import ImageBlock

    sensor = scene.sensors()[sensor_index]
    film = sensor.film()
    sampler = sensor.sampler()
    film_size = film.crop_size()
    if spp is None:
        spp = sampler.sample_count()

    total_sample_count = ek.hprod(film_size) * spp

    if sampler.wavefront_size() != total_sample_count:
        sampler.seed(ek.arange(UInt64, total_sample_count))

    pos = ek.arange(UInt32, total_sample_count)
    pos //= spp
    scale = Vector2f(1.0 / film_size[0], 1.0 / film_size[1])
    pos = Vector2f(Float(pos % int(film_size[0])),
                   Float(pos // int(film_size[0])))

    pos += sampler.next_2d()

    rays, weights = sensor.sample_ray_differential(
        time=0,
        sample1=sampler.next_1d(),
        sample2=pos * scale,
        sample3=0
    )

    spec, mask, aovs = scene.integrator().sample(scene, sampler, rays)
    spec *= weights
    del mask

    if is_polarized:
        from mitsuba.core import depolarize
        spec = depolarize(spec)

    if is_monochromatic:
        rgb = [spec[0]]
    elif is_rgb:
        rgb = spec
    else:
        from mitsuba.core import spectrum_to_xyz, xyz_to_srgb
        xyz = spectrum_to_xyz(spec, rays.wavelengths)
        rgb = xyz_to_srgb(xyz)
        del xyz

    aovs.insert(0, Float(1.0))
    for i in range(len(rgb)):
        aovs.insert(i + 1, rgb[i])
    del rgb, spec, weights, rays

    block = ImageBlock(
        size=film.crop_size(),
        channel_count=len(aovs),
        filter=film.reconstruction_filter(),
        warn_negative=False,
        warn_invalid=False,
        border=False
    )

    block.clear()
    block.put(pos, aovs)

    del pos
    del aovs

    data = block.data()

    ch = block.channel_count()
    i = UInt32.arange(ek.hprod(block.size()) * (ch - 1))

    weight_idx = i // (ch - 1) * ch
    values_idx = (i * ch) // (ch - 1) + 1

    weight = ek.gather(data, weight_idx)
    values = ek.gather(data, values_idx)

    return values / (weight + 1e-8)
Пример #4
0
 def unravel(source, target, dim=3):
     idx = UInt32.arange(ek.slices(source))
     for i in range(dim):
         ek.scatter(target, source[i], dim * idx + i)