Beispiel #1
0
    def test_isect_b(self):
        point = Vector3(0.0, 0.0, 55.92)
        e1 = Vector3(55.28, 0.0, 0.0)
        e2 = Vector3(0.0, 54.88, 0.0)
        normal = Vector3(0.0, 0.0, -1.0)
        rectangle = Rectangle(point, e1, e2, normal)

        origin = Vector3(3.0, 2.5, 0.0)
        direction = Vector3(0.0, 0.1, 0.88)
        direction.normalize()
        ray = Ray(origin, direction)

        runtime = Runtime()
        rectangle.isect_asm_b([runtime], "ray_rectangle_intersection")

        assembler = create_assembler()
        mc = assembler.assemble(self.asm_code_bool())
        ds = runtime.load("test", mc)

        Ray.populate_ds(ds, ray, 'ray1')
        Rectangle.populate_ds(ds, rectangle, 'rec1')

        runtime.run("test")
        hp = rectangle.isect(ray)

        if hp is False: self.assertFalse(ds["ret"] != 0)
        if ds["ret"] == 0: self.assertFalse(hp)
Beispiel #2
0
def test_mesh_isect_b(mesh, nrays=1):
    runtimes = [Runtime()]
    mesh.isect_asm_b(runtimes, "ray_mesh_isect")
    assembler = create_assembler()
    mc = assembler.assemble(asm_code("ray_mesh_isect", mesh))
    runtime = runtimes[0]
    ds = runtime.load("test", mc)
    mesh.populate_ds(ds, mesh, "mesh1")

    bbox = mesh.bbox()
    print("Intersection bool tests begin")
    for i in range(nrays):
        ray = generate_ray(bbox)
        ray.populate_ds(ds, ray, "ray1")

        hp1 = mesh.isect_b(ray)
        runtime.run("test")

        if hp1 is False and ds['ret'] == 1:
            print(ray)
            print(hp1, ds['ret'])
            raise ValueError("Ray intersect bool error")

        if hp1 and ds['ret'] == 0:
            print(ray)
            print(hp1, ds['ret'])
            raise ValueError("Ray intersect bool error")

        if hp1 and ds['ret'] == 1:
            compare_floats(hp1, ds['t'])
Beispiel #3
0
    def test_isect_b(self):
        point = Vector3(0.0, 0.0, 55.92)
        e1 = Vector3(55.28, 0.0, 0.0)
        e2 = Vector3(0.0, 54.88, 0.0)
        normal = Vector3(0.0, 0.0, -1.0)
        rectangle = Rectangle(point, e1, e2, normal)

        origin = Vector3(3.0, 2.5, 0.0)
        direction = Vector3(0.0, 0.1, 0.88)
        direction.normalize()
        ray = Ray(origin, direction)

        runtime = Runtime()
        rectangle.isect_asm_b([runtime], "ray_rectangle_intersection")

        assembler = create_assembler()
        mc = assembler.assemble(self.asm_code_bool())
        ds = runtime.load("test", mc)

        Ray.populate_ds(ds, ray, 'ray1')
        Rectangle.populate_ds(ds, rectangle, 'rec1')

        runtime.run("test")
        hp = rectangle.isect(ray)

        if hp is False: self.assertFalse(ds["ret"]!=0)
        if ds["ret"] == 0: self.assertFalse(hp)
Beispiel #4
0
    def __init__(self, scene_key=0.18, saturation=0.6):
        self._asm = create_assembler()
        self._runtime = Runtime()
        self._macro_call = macro_call = MacroCall()
        self._asm.register_macro('call', macro_call.macro_call)
        macro_call.set_runtimes([self._runtime])

        self._reinhard_asm()

        self._key = float(scene_key)
        self._saturation = float(saturation)
Beispiel #5
0
def test_mesh_isect(mesh, nrays=1):
    mgr = ShapeManager()
    print("Populate shape manager with %i triangles" % mesh.ntriangles())
    start = time.clock()
    populate_mgr_with_triangles(mgr, mesh)
    print("Population of shape manager took %f seconds" % (time.clock() - start,))

    runtimes = [Runtime()]
    mesh.isect_asm(runtimes, "ray_mesh_isect")
    assembler = create_assembler()
    mc = assembler.assemble(asm_code("ray_mesh_isect", mesh))
    runtime = runtimes[0]
    ds = runtime.load("test", mc)
    mesh.populate_ds(ds, mesh, "mesh1")

    isector = LinearIsect(mgr)
    bbox = mesh.bbox()
    print("Intersection tests begin")
    for i in range(nrays):
        ray = generate_ray(bbox)
        ray.populate_ds(ds, ray, "ray1")

        hp1 = mesh.isect(ray)
        hp2 = isector.isect(ray)
        runtime.run("test")
        if hp1 is False and hp2 is False and ds['ret'] == 0:
            continue
        if hp1 is False and hp2 is not False:
            print(ray)
            raise ValueError("Intersection error!")
        if hp1 is False and ds['ret'] == 1:
            print(ray)
            raise ValueError("Intersection error!")
        compare_floats(hp1.t, hp2.t)
        compare_floats(hp1.t, ds["hp1.t"])
        normal1 = (hp1.normal.x, hp1.normal.y, hp1.normal.z)
        normal2 = (hp2.normal.x, hp2.normal.y, hp2.normal.z)
        normal3 = ds["hp1.normal"][0:3]
        compare_tuple(normal1, normal2)
        compare_tuple(normal1, normal3)

        hit1 = (hp1.hit.x, hp1.hit.y, hp1.hit.z)
        hit2 = (hp2.hit.x, hp2.hit.y, hp2.hit.z)
        hit3 = ds["hp1.hit"][0:3]
        compare_tuple(hit1, hit2)
        compare_tuple(hit1, hit3)

        if mesh.has_uv():
            compare_floats(hp1.u, hp2.u)
            compare_floats(hp1.v, hp2.v)
            compare_floats(hp1.u, ds["hp1.u"]) 
            compare_floats(hp1.v, ds["hp1.v"]) 
Beispiel #6
0
    def test_Y_rgb(self):
        mgr = ColorManager(False)
        runtime = Runtime()

        mgr.Y_asm([runtime], 'luminance')
        spec1 = mgr.create_spectrum((0.66,0.88, 0.11))

        mc = create_assembler().assemble(self.asm_code1(mgr))
        ds = runtime.load("test", mc)
        ds["sp1.values"] = spec1.to_ds()
        runtime.run("test")
        
        self.assertAlmostEqual(mgr.Y(spec1), ds["Y"], 4)
Beispiel #7
0
    def test_Y_rgb(self):
        mgr = ColorManager(False)
        runtime = Runtime()

        mgr.Y_asm([runtime], 'luminance')
        spec1 = mgr.create_spectrum((0.66, 0.88, 0.11))

        mc = create_assembler().assemble(self.asm_code1(mgr))
        ds = runtime.load("test", mc)
        ds["sp1.values"] = spec1.to_ds()
        runtime.run("test")

        self.assertAlmostEqual(mgr.Y(spec1), ds["Y"], 4)
Beispiel #8
0
    def __init__(self, m=0.6, c=0.5, a=0.5, f=1.0):

        self._asm = create_assembler()
        self._runtime = Runtime()
        self._macro_call = macro_call = MacroCall()
        self._asm.register_macro('call', macro_call.macro_call)
        macro_call.set_runtimes([self._runtime])

        self._photoreceptor_asm()

        self._m = m # contrast range usually 0.2-0.9 - you can limit this 0.0-1.0
        self._c = c # adaptation range 0.0-1.0
        self._a = a # colornes-contrast range 0.0-1.0
        self._f = f # lightnes 
Beispiel #9
0
    def test_Y(self):
        mgr = ColorManager(False)
        runtime = Runtime()

        mgr.XYZ_to_RGB_asm([runtime], 'XYZ_to_RGB')
        mc = create_assembler().assemble(self.asm_code1())
        ds = runtime.load("test", mc)

        ds["XYZ"] = (0.69, 0.78, 0.88, 0.00)
        runtime.run("test")
        ret1 = ds["RGB"]
        ret2 = mgr.XYZ_to_RGB(0.69, 0.78, 0.88)

        self.assertAlmostEqual(ret1[0], ret2[0], 4)
        self.assertAlmostEqual(ret1[1], ret2[1], 4)
        self.assertAlmostEqual(ret1[2], ret2[2], 4)
Beispiel #10
0
    def test_Y(self):
        mgr = ColorManager(False)
        runtime = Runtime()

        mgr.XYZ_to_RGB_asm([runtime], 'XYZ_to_RGB')
        mc = create_assembler().assemble(self.asm_code1())
        ds = runtime.load("test", mc)

        ds["XYZ"] = (0.69, 0.78, 0.88, 0.00)
        runtime.run("test")
        ret1 = ds["RGB"]
        ret2 = mgr.XYZ_to_RGB(0.69, 0.78, 0.88)

        self.assertAlmostEqual(ret1[0], ret2[0], 4)
        self.assertAlmostEqual(ret1[1], ret2[1], 4)
        self.assertAlmostEqual(ret1[2], ret2[2], 4)
    def test_chromacity_to_spectrum2(self):
        mgr = ColorManager(spectral=True)
        runtime = Runtime()

        mgr.chromacity_to_spectrum_asm([runtime], 'chromacity_to_spectrum')
        mc = create_assembler().assemble(self.asm_code1(mgr))
        ds = runtime.load("test", mc)
        ds['x'] = 0.45
        ds['y'] = 0.41

        spec = mgr.chromacity_to_spectrum(0.45, 0.41)
        runtime.run("test")

        vals = ds['sp1.values']
        for i in range(len(vals)):
            self.assertAlmostEqual(vals[i], spec.samples[i], 4)
Beispiel #12
0
    def test_isect1(self):
        direction = Vector3(-1.0, -1.0, -1.0)
        direction.normalize()
        ray = Ray(Vector3(5.0, 5.0, 5.0), direction)
        sphere = Sphere(Vector3(0.0, 0.0, 0.0), 2)

        runtime = Runtime()
        assembler = create_assembler()
        sphere.isect_asm([runtime], "ray_sphere_intersection")
        mc = assembler.assemble(self.asm_code())
        ds = runtime.load("test", mc)

        self.intersect(ray, sphere, runtime, ds)
        for i in range(100):
            r = self.random_ray()
            s = self.random_sphere()
            self.intersect(r, s, runtime, ds)
Beispiel #13
0
    def test_isect1(self):
        direction = Vector3(-1.0, -1.0, -1.0)
        direction.normalize()
        ray = Ray(Vector3(5.0, 5.0, 5.0), direction)
        sphere = Sphere(Vector3(0.0, 0.0, 0.0), 2)

        runtime = Runtime()
        assembler = create_assembler()
        sphere.isect_asm([runtime], "ray_sphere_intersection")
        mc = assembler.assemble(self.asm_code())
        ds = runtime.load("test", mc)

        self.intersect(ray, sphere, runtime, ds)
        for i in range(100):
            r = self.random_ray()
            s = self.random_sphere()
            self.intersect(r, s, runtime, ds)
Beispiel #14
0
    def test_spectrum_to_rgb2(self):
        mgr = ColorManager(spectral=True)
        runtime = Runtime()

        mgr.rgb_to_sampled_asm([runtime], 'rgb_to_spectrum')
        spec1 = mgr.create_spectrum((0.66,0.88, 0.11))

        mc = create_assembler().assemble(self.asm_code1(mgr))
        ds = runtime.load("test", mc)

        ds["rgb"] = (0.66, 0.88, 0.11, 0.00)
        runtime.run("test")
        
        vals = ds['sp1.values']
        
        for i in range(len(vals)):
            self.assertAlmostEqual(vals[i], spec1.samples[i], 4)
Beispiel #15
0
    def test_spectrum_to_rgb2(self):
        mgr = ColorManager()
        runtime = Runtime()

        mgr.to_RGB_asm([runtime], 'spectrum_to_rgb')
        spec1 = mgr.create_spectrum((0.66,0.88, 0.11))

        mc = create_assembler().assemble(self.asm_code1(mgr))
        ds = runtime.load("test", mc)
        ds["sp1.values"] = spec1.to_ds()
        runtime.run("test")
        
        rgb = mgr.to_RGB(spec1)
        rgb2 = ds['rgb']

        self.assertAlmostEqual(rgb.r, rgb2[0], 4)
        self.assertAlmostEqual(rgb.g, rgb2[1], 4)
        self.assertAlmostEqual(rgb.b, rgb2[2], 4)
Beispiel #16
0
    def test_spectrum_to_rgb2(self):
        mgr = ColorManager()
        runtime = Runtime()

        mgr.to_RGB_asm([runtime], 'spectrum_to_rgb')
        spec1 = mgr.create_spectrum((0.66, 0.88, 0.11))

        mc = create_assembler().assemble(self.asm_code1(mgr))
        ds = runtime.load("test", mc)
        ds["sp1.values"] = spec1.to_ds()
        runtime.run("test")

        rgb = mgr.to_RGB(spec1)
        rgb2 = ds['rgb']

        self.assertAlmostEqual(rgb.r, rgb2[0], 4)
        self.assertAlmostEqual(rgb.g, rgb2[1], 4)
        self.assertAlmostEqual(rgb.b, rgb2[2], 4)
    def test_chromacity_to_spectrum(self):
        mgr = ColorManager(spectral=False)
        runtime = Runtime()

        mgr.chromacity_to_spectrum_asm([runtime], 'chromacity_to_spectrum')
        mc = create_assembler().assemble(self.asm_code1(mgr))
        ds = runtime.load("test", mc)
        ds['x'] = 0.45
        ds['y'] = 0.41

        spec = mgr.chromacity_to_spectrum(0.45, 0.41)

        runtime.run("test")
        rgb = ds['sp1.values']

        self.assertAlmostEqual(spec.r, rgb[0], 4)
        self.assertAlmostEqual(spec.g, rgb[1], 4)
        self.assertAlmostEqual(spec.b, rgb[2], 4)
Beispiel #18
0
    def test_spectrum_to_rgb1(self):
        mgr = ColorManager(False)
        runtime = Runtime()

        mgr.rgb_to_sampled_asm([runtime], 'rgb_to_spectrum')
        spec1 = mgr.create_spectrum((0.66,0.88, 0.11))

        mc = create_assembler().assemble(self.asm_code1(mgr))
        ds = runtime.load("test", mc)

        ds["rgb"] = spec1.to_ds()

        runtime.run("test")

        rgb = ds["sp1.values"]

        self.assertAlmostEqual(spec1.r, rgb[0], 4)
        self.assertAlmostEqual(spec1.g, rgb[1], 4)
        self.assertAlmostEqual(spec1.b, rgb[2], 4)
Beispiel #19
0
    def test_isect1(self):
        point = Vector3(0.0, 0.0, 55.92)
        e1 = Vector3(55.28, 0.0, 0.0)
        e2 = Vector3(0.0, 54.88, 0.0)
        normal = Vector3(0.0, 0.0, -1.0)
        rectangle = Rectangle(point, e1, e2, normal)

        origin = Vector3(3.0, 2.5, 0.0)
        direction = Vector3(0.0, 0.1, 0.88)
        direction.normalize()
        ray = Ray(origin, direction)

        runtime = Runtime()
        rectangle.isect_asm([runtime], "ray_rectangle_intersection")

        assembler = create_assembler()
        mc = assembler.assemble(self.asm_code())
        ds = runtime.load("test", mc)

        self.intersect(ray, rectangle, runtime, ds)
Beispiel #20
0
    def test_isect1(self):
        point = Vector3(0.0, 0.0, 55.92)
        e1 = Vector3(55.28, 0.0, 0.0)
        e2 = Vector3(0.0, 54.88, 0.0)
        normal = Vector3(0.0, 0.0, -1.0)
        rectangle = Rectangle(point, e1, e2, normal)

        origin = Vector3(3.0, 2.5, 0.0)
        direction = Vector3(0.0, 0.1, 0.88)
        direction.normalize()
        ray = Ray(origin, direction)

        runtime = Runtime()
        rectangle.isect_asm([runtime], "ray_rectangle_intersection")

        assembler = create_assembler()
        mc = assembler.assemble(self.asm_code())
        ds = runtime.load("test", mc)

        self.intersect(ray, rectangle, runtime, ds)
Beispiel #21
0
linear.isect_asm([runtime], 'ray_scene_intersection')

code = "#DATA \n"
code += Ray.asm_struct() + HitPoint.asm_struct() + """
    Ray ray1
    Hitpoint hp1
    uint32 ret

    #CODE
    macro mov eax, ray1
    macro mov ebx, hp1
    call ray_scene_intersection 
    mov dword [ret], eax
    #END
"""
asm = create_assembler()
mc = asm.assemble(code)

ds = runtime.load('test', mc)

def ray_ds(ds, ray, name):
    ds[name+ ".origin"] = ray.origin.to_ds() 
    ds[name+ ".dir"] = ray.dir.to_ds()

ray_ds(ds, ray, 'ray1')
runtime.run('test')
print (hit, hit.t)
print (hit.normal)
print (ds['ret'], ds['hp1.t'])
print (ds['hp1.normal'])
print ('------------------')
Beispiel #22
0
linear.isect_asm([runtime], 'ray_scene_intersection')

code = "#DATA \n"
code += Ray.asm_struct() + HitPoint.asm_struct() + """
    Ray ray1
    Hitpoint hp1
    uint32 ret

    #CODE
    macro mov eax, ray1
    macro mov ebx, hp1
    call ray_scene_intersection 
    mov dword [ret], eax
    #END
"""
asm = create_assembler()
mc = asm.assemble(code)

ds = runtime.load('test', mc)


def ray_ds(ds, ray, name):
    ds[name + ".origin"] = ray.origin.to_ds()
    ds[name + ".dir"] = ray.dir.to_ds()


ray_ds(ds, ray, 'ray1')
runtime.run('test')
print(hit, hit.t)
print(hit.normal)
print(ds['ret'], ds['hp1.t'])
Beispiel #23
0
macro eq128 nrez = xmm4 {xmm4}

macro broadcast xmm5 = xmm4[3]
macro eq128 brod = xmm5 {xmm0}

macro if xmm5 < d goto _lab

_lab:
macro dot xmm7 = n1 * n2 {xmm7, xmm6}
macro eq32 dot_rez = xmm7 {xmm7}

macro mov eax, t1
macro eq128 temp5 = eax.triangle.p0 + one {xmm7}
#END
'''

runtime = Runtime()
mac_call = MacroCall()
mac_call.set_runtimes([runtime])
assembler = create_assembler()
mc = assembler.assemble(ASM)
mc.print_machine_code()
ds = runtime.load('test_arithmetic', mc)

runtime.run('test_arithmetic')
print(ds['m4'])
print(ds['nrez'])
print(ds['brod'])
print(ds['dot_rez'])
print(ds['temp5'])
Beispiel #24
0
macro eq128 nrez = xmm4 {xmm4}

macro broadcast xmm5 = xmm4[3]
macro eq128 brod = xmm5 {xmm0}

macro if xmm5 < d goto _lab

_lab:
macro dot xmm7 = n1 * n2 {xmm7, xmm6}
macro eq32 dot_rez = xmm7 {xmm7}

macro mov eax, t1
macro eq128 temp5 = eax.triangle.p0 + one {xmm7}
#END
'''

runtime = Runtime()
mac_call = MacroCall()
mac_call.set_runtimes([runtime])
assembler = create_assembler()
mc = assembler.assemble(ASM)
mc.print_machine_code()
ds = runtime.load('test_arithmetic', mc)

runtime.run('test_arithmetic')
print(ds['m4'])
print(ds['nrez'])
print(ds['brod'])
print(ds['dot_rez'])
print(ds['temp5'])