def test_horizontal_light(): pts1 = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] triangles = [pts1] mats = [green_leaf_PAR] # horizontal light no intensity lights = [(0, (-1, 0, 0))] res = raycasting(triangles, mats, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei'][0], 0, 0) # horizontal light full intensity lights = [(100, (-1, 0, 0))] res = raycasting(triangles, mats, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei'][0], 0, 0) # horizontal light full intensity, infinite canopy lights = [(100, (-1, 0, 0))] domain = (-2, -2, 2, 2) res = raycasting(triangles, mats, lights, domain) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei'][0], 0, 0) # horizontal light full intensity, vertical triangle (impossible case) pts1 = [(0, 0, 0), (0, sqrt(2), 0), (0, 0, sqrt(2))] triangles = [pts1] lights = [(100, (-1, 0, 0))] res = raycasting(triangles, mats, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei'][0], 0, 0)
def test_vertical_light(): pts1 = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] triangles = [pts1] mats = [green_leaf_PAR] # vertical light no intensity lights = [(0, (0, 0, -1))] res = raycasting(triangles, mats, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei'][0], 0, 0) # vertical light full intensity lights = [(100, (0, 0, -1))] res = raycasting(triangles, mats, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei'][0], 100, 0) # vertical light full intensity, vertical triangle pts1 = [(0, 0, 0), (0, sqrt(2), 0), (0, 0, sqrt(2))] triangles = [pts1] lights = [(100, (-1, 0, 0))] res = raycasting(triangles, mats, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei'][0], 0, 0)
def test_raycasting_closed_box(): pts1 = [(0, 0, 0), (1, 0, 0), (0, 0, 1)] pts2 = [(0, 0, 0), (0, 0, 1), (0, 1, 0)] pts3 = [(0, 0, 0), (0, 1, 0), (1, 0, 0)] pts4 = [(1, 0, 0), (0, 1, 0), (0, 0, 1)] triangles = [pts1, pts2, pts3, pts4] lights = [(100, (0, 0, -1))] # no transmittance materials = [(0.1, 0.)] * len(triangles) res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 0.5, 3) assert_almost_equal(res['Ei_sup'][0], 0, 3) assert_almost_equal(res['Ei_inf'][0], 0, 3) assert_almost_equal(res['Eabs'][0], 0, 3) assert_almost_equal(res['area'][1], 0.5, 3) assert_almost_equal(res['Ei_sup'][1], 0, 3) assert_almost_equal(res['Ei_inf'][1], 0, 3) assert_almost_equal(res['Eabs'][1], 0, 3) assert_almost_equal(res['area'][2], 0.5, 3) assert_almost_equal(res['Ei_sup'][2], 0, 3) assert_almost_equal(res['Ei_inf'][2], 0, 0) assert_almost_equal(res['Eabs'][2], 0, 0) assert_almost_equal(res['area'][3], 0.866, 3) # TODO assert_almost_equal(res['Ei_sup'][3], 57.6, 0) assert_almost_equal(res['Ei_inf'][3], 0, 3) assert_almost_equal(res['Eabs'][3], 57.6 * 0.9, 0)
def test_raycasting_closed_box(): pts1 = [(0, 0, 0), (1, 0, 0), (0, 0, 1)] pts2 = [(0, 0, 0), (0, 0, 1), (0, 1, 0)] pts3 = [(0, 0, 0), (0, 1, 0), (1, 0, 0)] pts4 = [(1, 0, 0), (0, 1, 0), (0, 0, 1)] triangles = [pts1, pts2, pts3, pts4] lights = [(100, (0, 0, -1))] # no transmittance materials = [(0.1, 0.)] * len(triangles) res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 0.5, 3) assert_almost_equal(res['Ei_sup'][0], 0, 3) assert_almost_equal(res['Ei_inf'][0], 0, 3) assert_almost_equal(res['Eabs'][0], 0, 3) assert_almost_equal(res['area'][1], 0.5, 3) assert_almost_equal(res['Ei_sup'][1], 0, 3) assert_almost_equal(res['Ei_inf'][1], 0, 3) assert_almost_equal(res['Eabs'][1], 0, 3) assert_almost_equal(res['area'][2], 0.5, 3) assert_almost_equal(res['Ei_sup'][2], 0, 3) assert_almost_equal(res['Ei_inf'][2], 0, 0) assert_almost_equal(res['Eabs'][2], 0, 0) assert_almost_equal(res['area'][3], 0.866, 3) # TODO assert_almost_equal(res['Ei_sup'][3], 57.6, 0) assert_almost_equal(res['Ei_inf'][3], 0, 3) assert_almost_equal(res['Eabs'][3], 57.6 * 0.9, 0)
def test_raycasting_opaque_box(): # need a closed box pts1 = [(0, 0, 0), (1, 0, 0), (0, 0, 1)] pts2 = [(0, 0, 0), (0, 0, 1), (0, 1, 0)] pts3 = [(0, 0, 0), (0, 1, 0), (1, 0, 0)] pts4 = [(1, 0, 0), (0, 1, 0), (0, 0, 1)] triangles = [pts1, pts2, pts3, pts4] lights = [(100, (0, 0, -1))] materials = [(0.1,)] * len(triangles) res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 0.5, 3) # assert_almost_equal(res['Ei_sup'][0], 0, 3) # assert_almost_equal(res['Ei_inf'][0], 0, 3) assert_almost_equal(res['Eabs'][0], 0, 3) assert_almost_equal(res['area'][1], 0.5, 3) # assert_almost_equal(res['Ei_sup'][1], 0, 3) # assert_almost_equal(res['Ei_inf'][1], 0, 3) assert_almost_equal(res['Eabs'][1], 0, 3) assert_almost_equal(res['area'][2], 0.5, 3) # assert_almost_equal(res['Ei_sup'][2], 0, 3) # assert_almost_equal(res['Ei_inf'][2], 0, 0) assert_almost_equal(res['Eabs'][2], 0, 0) assert_almost_equal(res['area'][3], 0.866, 3) # TODO # assert_almost_equal(res['Ei_sup'][3], 57.6, 0) # assert_almost_equal(res['Ei_inf'][3], 0, 3) assert_almost_equal(res['Eabs'][3], 57.6 * 0.9, 0)
def test_raycasting_opaque_box(): # need a closed box pts1 = [(0, 0, 0), (1, 0, 0), (0, 0, 1)] pts2 = [(0, 0, 0), (0, 0, 1), (0, 1, 0)] pts3 = [(0, 0, 0), (0, 1, 0), (1, 0, 0)] pts4 = [(1, 0, 0), (0, 1, 0), (0, 0, 1)] triangles = [pts1, pts2, pts3, pts4] lights = [(100, (0, 0, -1))] materials = [(0.1, )] * len(triangles) res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 0.5, 3) # assert_almost_equal(res['Ei_sup'][0], 0, 3) # assert_almost_equal(res['Ei_inf'][0], 0, 3) assert_almost_equal(res['Eabs'][0], 0, 3) assert_almost_equal(res['area'][1], 0.5, 3) # assert_almost_equal(res['Ei_sup'][1], 0, 3) # assert_almost_equal(res['Ei_inf'][1], 0, 3) assert_almost_equal(res['Eabs'][1], 0, 3) assert_almost_equal(res['area'][2], 0.5, 3) # assert_almost_equal(res['Ei_sup'][2], 0, 3) # assert_almost_equal(res['Ei_inf'][2], 0, 0) assert_almost_equal(res['Eabs'][2], 0, 0) assert_almost_equal(res['area'][3], 0.866, 3) # TODO # assert_almost_equal(res['Ei_sup'][3], 57.6, 0) # assert_almost_equal(res['Ei_inf'][3], 0, 3) assert_almost_equal(res['Eabs'][3], 57.6 * 0.9, 0)
def test_raycasting_exception(): points = [(0, 0, 0), (1, 0, 0), (0, 1, 0)] triangles = [points] # black body materials = [(0,)] assert_raises(ValueError, lambda: raycasting(triangles, materials)) materials = [(0.,)] assert_raises(ValueError, lambda: raycasting(triangles, materials)) materials = [(0., 0)] assert_raises(ValueError, lambda: raycasting(triangles, materials)) materials = [(0., 0, 0, 0.)] assert_raises(ValueError, lambda: raycasting(triangles, materials)) # unmatch materials = [(0.1,)] * 2 assert_raises(ValueError, lambda: raycasting(triangles, materials))
def test_other_algos(): pts1 = [(0, 0, 0), (1, 0, 0), (0, 1, 0)] pts2 = [(0, 0, 1), (1, 0, 1), (0, 1, 1)] triangles = [pts1, pts2] domain = (0, 0, 1, 1) height = 1 mats = [green_leaf_PAR] * 2 x_mats = {'PAR': mats, 'NIR': mats} sensors = [[(0, 0, 2), (1, 0, 2), (0, 1, 2)], [(0, 0, 2), (1, 0, 2), (1, 0, 3)]] lights = [(1, (0, 0, -1))] res = raycasting(triangles, mats, sensors=sensors, debug=DEBUG) assert 'sensors' in res assert 'Ei' in res['sensors'] res = x_raycasting(triangles, x_mats, sensors=sensors, debug=DEBUG) assert 'PAR' in res assert 'NIR' in res assert 'sensors' in res['PAR'] assert 'Ei' in res['PAR']['sensors'] res = radiosity(triangles, mats, sensors=sensors, debug=DEBUG) assert 'sensors' in res assert 'Ei' in res['sensors'] res = x_radiosity(triangles, x_mats, sensors=sensors, debug=DEBUG) assert 'PAR' in res assert 'NIR' in res assert 'sensors' in res['PAR'] assert 'Ei' in res['PAR']['sensors'] res = mixed_radiosity(triangles, mats, lights=lights, domain=domain, soil_reflectance=0.3, diameter=1, layers=2, height=height, debug=DEBUG) assert 'Eabs' in res res = x_mixed_radiosity(triangles, x_mats, lights=lights, domain=domain, soil_reflectance={ 'PAR': 0.3, 'NIR': 0.1 }, diameter=1, layers=2, height=height, debug=DEBUG) assert 'PAR' in res assert 'NIR' in res assert 'Eabs' in res['PAR']
def test_default_light_in_raycasting(): pts1 = [(0, 0, 0), (1, 0, 0), (0, 1, 0)] triangles = [pts1] mats = [green_leaf_PAR] # default light res = raycasting(triangles, mats, debug=DEBUG) assert 'area' in res
def test_default_light_in_raycasting(): pts1 = [(0, 0, 0), (1, 0, 0), (0, 1, 0)] triangles = [pts1] mats = [green_leaf_PAR] # default light res = raycasting(triangles, mats) assert 'area' in res
def test_raycasting_translucent(): points = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] triangles = [points] lights = [(100, (0, 0, -1))] # full reflectance, mirror materials = [(1., 0.)] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei_sup'][0], 100, 0) assert_almost_equal(res['Ei_inf'][0], 0, 3) assert_almost_equal(res['Eabs'][0], 0, 3) # semi reflectance materials = [(0.5, 0.)] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei_sup'][0], 100, 0) assert_almost_equal(res['Ei_inf'][0], 0, 3) assert_almost_equal(res['Eabs'][0], 50, 0)
def test_raycasting_asymmetric_material(): points = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] triangles = [points] lights = [(100, (0, 0, -1))] materials = [(0.1, 0., 0.2, 0.)] # top res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei_sup'][0], 100, 0) assert_almost_equal(res['Ei_inf'][0], 0, 0) assert_almost_equal(res['Eabs'][0], 90, 0) # bottom triangles = [reversed(points)] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei_sup'][0], 0, 0) assert_almost_equal(res['Ei_inf'][0], 100, 0) assert_almost_equal(res['Eabs'][0], 80, 0)
def test_raycasting_asymmetric_material(): points = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] triangles = [points] lights = [(100, (0, 0, -1))] materials = [(0.1, 0., 0.2, 0.)] # top res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei_sup'][0], 100, 0) assert_almost_equal(res['Ei_inf'][0], 0, 0) assert_almost_equal(res['Eabs'][0], 90, 0) # bottom triangles = [reversed(points)] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei_sup'][0], 0, 0) assert_almost_equal(res['Ei_inf'][0], 100, 0) assert_almost_equal(res['Eabs'][0], 80, 0)
def test_raycasting_single_triangle(): points = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] triangles = [points] materials = [(0.06, 0.04)] # vertical light lights = [(100, (0, 0, -1))] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Eabs'][0], 90, 0) assert_almost_equal(res['Ei'][0], 100, 0)
def test_raycasting_single_triangle(): points = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] triangles = [points] materials = [(0.06, 0.04)] # vertical light lights = [(100, (0, 0, -1))] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Eabs'][0], 90, 0) assert_almost_equal(res['Ei'][0], 100, 0)
def test_raycasting_translucent(): points = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] triangles = [points] lights = [(100, (0, 0, -1))] # full reflectance, mirror materials = [(1., 0.)] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei_sup'][0], 100, 0) assert_almost_equal(res['Ei_inf'][0], 0, 3) assert_almost_equal(res['Eabs'][0], 0, 3) # semi reflectance materials = [(0.5, 0.)] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei_sup'][0], 100, 0) assert_almost_equal(res['Ei_inf'][0], 0, 3) assert_almost_equal(res['Eabs'][0], 50, 0)
def test_raycasting_opaque(): points = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] triangles = [points] lights = [(100, (0, 0, -1))] # top materials = [(0.1,)] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei_sup'][0], 100, 0) assert_almost_equal(res['Ei_inf'][0], -1, 0) assert_almost_equal(res['Eabs'][0], 90, 0)
def test_raycasting_opaque(): points = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] triangles = [points] lights = [(100, (0, 0, -1))] # top materials = [(0.1, )] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei_sup'][0], 100, 0) assert_almost_equal(res['Ei_inf'][0], -1, 0) assert_almost_equal(res['Eabs'][0], 90, 0)
def test_raycasting_two_triangles_no_occlusion(): pts1 = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] pts2 = [(10, 10, 0), (10 - sqrt(2), 10, 0), (10, 10 - sqrt(2), 0)] triangles = [pts1, pts2] materials = [(0.06, 0.04)] * 2 # vertical light lights = [(100, (0, 0, -1))] res = raycasting(triangles, materials, lights) for i in (0, 1): assert_almost_equal(res['area'][i], 1, 3) assert_almost_equal(res['Eabs'][i], 90, 0) assert_almost_equal(res['Ei'][i], 100, 0)
def test_raycasting_translucent_flip(): points = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] lights = [(100, (0, 0, -1))] materials = [(0.06, 0.04)] # pointing facesup toward source triangles = [points] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Eabs'][0], 90, 0) assert_almost_equal(res['Ei'][0], 100, 0) assert_almost_equal(res['Ei_sup'][0], 100, 0) assert_almost_equal(res['Ei_inf'][0], 0, 0) # pointing faceinf toward source triangles = [reversed(points)] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Eabs'][0], 90, 0) assert_almost_equal(res['Ei'][0], 100, 0) assert_almost_equal(res['Ei_inf'][0], 100, 0) assert_almost_equal(res['Ei_sup'][0], 0, 0)
def test_raycasting_exception(): points = [(0, 0, 0), (1, 0, 0), (0, 1, 0)] triangles = [points] # black body materials = [(0, )] assert_raises(ValueError, lambda: raycasting(triangles, materials, debug=DEBUG)) materials = [(0., )] assert_raises(ValueError, lambda: raycasting(triangles, materials, debug=DEBUG)) materials = [(0., 0)] assert_raises(ValueError, lambda: raycasting(triangles, materials, debug=DEBUG)) materials = [(0., 0, 0, 0.)] assert_raises(ValueError, lambda: raycasting(triangles, materials, debug=DEBUG)) # unmatch materials = [(0.1, )] * 2 assert_raises(ValueError, lambda: raycasting(triangles, materials, debug=DEBUG))
def test_unresolved_faces(): points = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] lights = [(100, (0, 0, -1))] triangles = [points] # reflectance == transmittance materials = [(0.05, 0.05)] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Eabs'][0], 90, 0) assert_almost_equal(res['Ei'][0], 100, 0) assert_almost_equal(res['Ei_sup'][0], -1, 0) assert_almost_equal(res['Ei_inf'][0], -1, 0) # reflectance_product == transmittance_product materials = [(0.05, 0.01, 0.01, 0.05)] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Eabs'][0], 94, 0) assert_almost_equal(res['Ei'][0], 100, 0) assert_almost_equal(res['Ei_sup'][0], -1, 0) assert_almost_equal(res['Ei_inf'][0], -1, 0)
def test_raycasting_two_triangles_no_occlusion(): pts1 = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] pts2 = [(10, 10, 0), (10 - sqrt(2), 10, 0), (10, 10 - sqrt(2), 0)] triangles = [pts1, pts2] materials = [(0.06, 0.04)] * 2 # vertical light lights = [(100, (0, 0, -1))] res = raycasting(triangles, materials, lights) for i in (0, 1): assert_almost_equal(res['area'][i], 1, 3) assert_almost_equal(res['Eabs'][i], 90, 0) assert_almost_equal(res['Ei'][i], 100, 0)
def test_raycasting_null_triangle_superposed_points(): pts1 = [(0, 0, 0), (1, 0, 0), (1, 0, 0)] triangles = [pts1] mats = [green_leaf_PAR] lights = [(100, (0, 0, -1))] res = raycasting(triangles, mats, lights) assert_almost_equal(res['area'][0], 0, 3) assert isnan(res['Ei'][0]) assert isnan(res['Eabs'][0]) assert isnan(res['Ei_sup'][0]) assert isnan(res['Ei_inf'][0])
def test_triangle_inside(): pts1 = [(0, 1, 0), (0, 0, 0), (1, 0, 0)] triangles = [pts1] mats = [green_leaf_PAR] domain = (-2, -2, 2, 2) # vertical light lights = [(100, (0, 0, -1))] res = raycasting(triangles, mats, lights, domain) assert_almost_equal(res['area'][0], 0.5, 3) assert_almost_equal(res['Ei_sup'][0], 100, 0) assert_almost_equal(res['Ei_inf'][0], 0, 3)
def test_unresolved_faces(): points = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] lights = [(100, (0, 0, -1))] triangles = [points] # reflectance == transmittance materials = [(0.05, 0.05)] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Eabs'][0], 90, 0) assert_almost_equal(res['Ei'][0], 100, 0) assert_almost_equal(res['Ei_sup'][0], -1, 0) assert_almost_equal(res['Ei_inf'][0], -1, 0) # reflectance_product == transmittance_product materials = [(0.05, 0.01, 0.01, 0.05)] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Eabs'][0], 94, 0) assert_almost_equal(res['Ei'][0], 100, 0) assert_almost_equal(res['Ei_sup'][0], -1, 0) assert_almost_equal(res['Ei_inf'][0], -1, 0)
def test_raycasting_translucent_flip(): points = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] lights = [(100, (0, 0, -1))] materials = [(0.06, 0.04)] # pointing facesup toward source triangles = [points] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Eabs'][0], 90, 0) assert_almost_equal(res['Ei'][0], 100, 0) assert_almost_equal(res['Ei_sup'][0], 100, 0) assert_almost_equal(res['Ei_inf'][0], 0, 0) # pointing faceinf toward source triangles = [reversed(points)] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Eabs'][0], 90, 0) assert_almost_equal(res['Ei'][0], 100, 0) assert_almost_equal(res['Ei_inf'][0], 100, 0) assert_almost_equal(res['Ei_sup'][0], 0, 0)
def test_diagonal_light(): pts1 = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] triangles = [pts1] materials = [green_leaf_PAR] # full intensity on horizontal surface lights = [(100, (-1, 0, -1))] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei'][0], 100, 0) # full intensity perpendicular to the source emission = 100 apparent_emission = emission * cos(radians(45)) lights = [(apparent_emission, (-1, 0, -1))] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei'][0], 100 * cos(radians(45)), 0) # full intensity perpendicular to the source, inclined triangle emission = 100 apparent_emission = emission * cos(radians(45)) lights = [(apparent_emission, (-1, 0, -1))] proj = cos(radians(45)) pts1 = [(0, 0, 0), (0, sqrt(2), 0), (-sqrt(2) * proj, 0, proj * sqrt(2))] triangles = [pts1] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 0) assert_almost_equal(res['Ei'][0], 100, 0) # full intensity on horizontal surface, inclined triangle lights = [(100, (-1, 0, -1))] proj = cos(radians(45)) pts1 = [(0, 0, 0), (0, sqrt(2), 0), (-sqrt(2) * proj, 0, proj * sqrt(2))] triangles = [pts1] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][0], 1, 0) assert_almost_equal(res['Ei'][0], 141, 0)
def test_triangle_outside(): pts1 = [(0, 1, 0), (0, 0, 0), (1, 0, 0)] triangles = [pts1] mats = [green_leaf_PAR] lights = [(100, (0, 0, -1))] # just on the right domain = (-2, -2, 0, 2) res = raycasting(triangles, mats, lights, domain) assert_almost_equal(res['area'][0], 0.5, 3) assert_almost_equal(res['Ei_sup'][0], 100, 0) assert_almost_equal(res['Ei_inf'][0], 0, 3) # just on the left domain = (2, -2, 4, 2) res = raycasting(triangles, mats, lights, domain) assert_almost_equal(res['area'][0], 0.5, 3) assert_almost_equal(res['Ei_sup'][0], 100, 0) assert_almost_equal(res['Ei_inf'][0], 0, 3) # further on the left domain = (12, -2, 14, 2) res = raycasting(triangles, mats, lights, domain) assert_almost_equal(res['area'][0], 0.5, 3) assert_almost_equal(res['Ei_sup'][0], 100, 0) assert_almost_equal(res['Ei_inf'][0], 0, 3) # both directions domain = (12, 12, 14, 14) res = raycasting(triangles, mats, lights, domain) assert_almost_equal(res['area'][0], 0.5, 3) assert_almost_equal(res['Ei_sup'][0], 100, 0) assert_almost_equal(res['Ei_inf'][0], 0, 3)
def test_two_triangle_confounded(): pts1 = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] triangles = [pts1, pts1] materials = [(0.06, 0.04)] * 2 lights = [(100, (0, 0, -1))] # raycasting res = raycasting(triangles, materials, lights) assert_almost_equal(res['Ei'][0], 100, 0) assert_almost_equal(res['Ei'][1], 0, 0) #radiosity res = radiosity(triangles, materials, lights) assert_almost_equal(res['Ei'][0], 100, 0) assert_almost_equal(res['Ei'][1], 0, 0)
def test_raycasting_two_triangles_one_null(): pts1 = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] pts2 = [(10, 10, 0), (10 - sqrt(2), 10, 0), (10, 10, 0)] triangles = [pts1, pts2] mats = [green_leaf_PAR] * 2 # vertical light lights = [(100, (0, 0, -1))] res = raycasting(triangles, mats, lights) assert_almost_equal(res['area'][0], 1, 3) assert_almost_equal(res['Ei'][0], 100, 0) assert_almost_equal(res['area'][1], 0, 3) assert isnan(res['Ei'][1])
def test_raycasting_infinite_null_triangle_outside_domain(): pts1 = [(0, 1, 0), (0, 0, 0), (1, 0, 0)] pts2 = [(2, 1, 0), (3, 0, 0), (3, 0, 0)] triangles = [pts1, pts2] mats = [green_leaf_PAR] * 2 lights = [(100, (0, 0, -1))] domain = (-2, -2, 2, 2) res = raycasting(triangles, mats, lights, domain) assert_almost_equal(res['area'][0], 0.5, 3) assert_almost_equal(res['Ei'][0], 100, 0) assert_almost_equal(res['area'][1], 0, 3) assert isnan(res['Ei'][1])
def test_two_triangle_confounded(): pts1 = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] triangles = [pts1, pts1] materials = [(0.06, 0.04)] * 2 lights = [(100, (0, 0, -1))] # raycasting res = raycasting(triangles, materials, lights) assert_almost_equal(res['Ei'][0], 100, 0) assert_almost_equal(res['Ei'][1], 0, 0) #radiosity res = radiosity(triangles, materials, lights) assert_almost_equal(res['Ei'][0], 100, 0) assert_almost_equal(res['Ei'][1], 0, 0)
def test_raycasting_two_triangles_full_occlusion(): lower_pts = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] upper_pts = [(0, 0, 1e-5), (sqrt(2), 0, 1e-5), (0, sqrt(2), 1e-5)] triangles = [lower_pts, upper_pts] lower, upper = 0, 1 materials = [(0.06, 0.04)] * 2 # vertical light lights = [(100, (0, 0, -1))] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][lower], 1, 3) assert_almost_equal(res['Eabs'][lower], 0, 0) assert_almost_equal(res['Ei'][lower], 0, 0) assert_almost_equal(res['area'][upper], 1, 3) assert_almost_equal(res['Eabs'][upper], 90, 0) assert_almost_equal(res['Ei'][upper], 100, 0)
def test_raycasting_two_triangles_full_occlusion(): lower_pts = [(0, 0, 0), (sqrt(2), 0, 0), (0, sqrt(2), 0)] upper_pts = [(0, 0, 1e-5), (sqrt(2), 0, 1e-5), (0, sqrt(2), 1e-5)] triangles = [lower_pts, upper_pts] lower, upper = 0, 1 materials = [(0.06, 0.04)] * 2 # vertical light lights = [(100, (0, 0, -1))] res = raycasting(triangles, materials, lights) assert_almost_equal(res['area'][lower], 1, 3) assert_almost_equal(res['Eabs'][lower], 0, 0) assert_almost_equal(res['Ei'][lower], 0, 0) assert_almost_equal(res['area'][upper], 1, 3) assert_almost_equal(res['Eabs'][upper], 90, 0) assert_almost_equal(res['Ei'][upper], 100, 0)