def test_radiosity_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 # vertical light, opaque material lights = [(100, (0, 0, -1))] materials = [(0.1,)] * 2 res = radiosity(triangles, materials, lights) assert_almost_equal(res['area'][lower], 1, 3) assert_almost_equal(res['Ei'][lower], 0, 0) assert_almost_equal(res['area'][upper], 1, 3) assert_almost_equal(res['Ei'][upper], 100, 0) # vertical light, translucent material of upper triangle lights = [(100, (0, 0, -1))] materials = [(0.1,), (0.1, 0.2)] res = radiosity(triangles, materials, lights) assert_almost_equal(res['area'][lower], 1, 3) assert_almost_equal(res['Ei'][lower], 20, 0) assert_almost_equal(res['area'][upper], 1, 3) assert_almost_equal(res['Ei'][upper], 102, 0)
def test_radiosity_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 # vertical light, opaque material lights = [(100, (0, 0, -1))] materials = [(0.1, )] * 2 res = radiosity(triangles, materials, lights) assert_almost_equal(res['area'][lower], 1, 3) assert_almost_equal(res['Ei'][lower], 0, 0) assert_almost_equal(res['area'][upper], 1, 3) assert_almost_equal(res['Ei'][upper], 100, 0) # vertical light, translucent material of upper triangle lights = [(100, (0, 0, -1))] materials = [(0.1, ), (0.1, 0.2)] res = radiosity(triangles, materials, lights) assert_almost_equal(res['area'][lower], 1, 3) assert_almost_equal(res['Ei'][lower], 20, 0) assert_almost_equal(res['area'][upper], 1, 3) assert_almost_equal(res['Ei'][upper], 102, 0)
def test_radiosity_translucent_flip(): 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)] lower, upper = 0, 1 lights = [(100, (0, 0, -1))] materials = [(0.1, 0.2)] * 2 # upper / lower pointing facesup toward source triangles = [lower_pts, upper_pts] res = radiosity(triangles, materials, lights) assert_almost_equal(res['area'][upper], 1, 3) assert_almost_equal(res['Ei'][upper], 102, 0) assert_almost_equal(res['Eabs'][upper], 71, 0) assert_almost_equal(res['Ei_sup'][upper], 100, 0) assert_almost_equal(res['Ei_inf'][upper], 2, 0) assert_almost_equal(res['area'][lower], 1, 3) assert_almost_equal(res['Ei'][lower], 20, 0) assert_almost_equal(res['Eabs'][lower], 14, 0) assert_almost_equal(res['Ei_sup'][lower], 20, 0) assert_almost_equal(res['Ei_inf'][lower], 0, 0) # flip upper triangles = [lower_pts, reversed(upper_pts)] res = radiosity(triangles, materials, lights) assert_almost_equal(res['area'][upper], 1, 3) assert_almost_equal(res['Ei'][upper], 102, 0) assert_almost_equal(res['Eabs'][upper], 71, 0) assert_almost_equal(res['Ei_sup'][upper], 2, 0) assert_almost_equal(res['Ei_inf'][upper], 100, 0) assert_almost_equal(res['area'][lower], 1, 3) assert_almost_equal(res['Ei'][lower], 20, 0) assert_almost_equal(res['Eabs'][lower], 14, 0) assert_almost_equal(res['Ei_sup'][lower], 20, 0) assert_almost_equal(res['Ei_inf'][lower], 0, 0) # flip upper and lower triangles = [reversed(lower_pts), reversed(upper_pts)] res = radiosity(triangles, materials, lights) assert_almost_equal(res['area'][upper], 1, 3) assert_almost_equal(res['Ei'][upper], 102, 0) assert_almost_equal(res['Eabs'][upper], 71, 0) assert_almost_equal(res['Ei_sup'][upper], 2, 0) assert_almost_equal(res['Ei_inf'][upper], 100, 0) assert_almost_equal(res['area'][lower], 1, 3) assert_almost_equal(res['Ei'][lower], 20, 0) assert_almost_equal(res['Eabs'][lower], 14, 0) assert_almost_equal(res['Ei_sup'][lower], 0, 0) assert_almost_equal(res['Ei_inf'][lower], 20, 0)
def test_radiosity_translucent_flip(): 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)] lower, upper = 0, 1 lights = [(100, (0, 0, -1))] materials = [(0.1, 0.2)] * 2 # upper / lower pointing facesup toward source triangles = [lower_pts, upper_pts] res = radiosity(triangles, materials, lights) assert_almost_equal(res['area'][upper], 1, 3) assert_almost_equal(res['Ei'][upper], 102, 0) assert_almost_equal(res['Eabs'][upper], 71, 0) assert_almost_equal(res['Ei_sup'][upper], 100, 0) assert_almost_equal(res['Ei_inf'][upper], 2, 0) assert_almost_equal(res['area'][lower], 1, 3) assert_almost_equal(res['Ei'][lower], 20, 0) assert_almost_equal(res['Eabs'][lower], 14, 0) assert_almost_equal(res['Ei_sup'][lower], 20, 0) assert_almost_equal(res['Ei_inf'][lower], 0, 0) # flip upper triangles = [lower_pts, reversed(upper_pts)] res = radiosity(triangles, materials, lights) assert_almost_equal(res['area'][upper], 1, 3) assert_almost_equal(res['Ei'][upper], 102, 0) assert_almost_equal(res['Eabs'][upper], 71, 0) assert_almost_equal(res['Ei_sup'][upper], 2, 0) assert_almost_equal(res['Ei_inf'][upper], 100, 0) assert_almost_equal(res['area'][lower], 1, 3) assert_almost_equal(res['Ei'][lower], 20, 0) assert_almost_equal(res['Eabs'][lower], 14, 0) assert_almost_equal(res['Ei_sup'][lower], 20, 0) assert_almost_equal(res['Ei_inf'][lower], 0, 0) # flip upper and lower triangles = [reversed(lower_pts), reversed(upper_pts)] res = radiosity(triangles, materials, lights) assert_almost_equal(res['area'][upper], 1, 3) assert_almost_equal(res['Ei'][upper], 102, 0) assert_almost_equal(res['Eabs'][upper], 71, 0) assert_almost_equal(res['Ei_sup'][upper], 2, 0) assert_almost_equal(res['Ei_inf'][upper], 100, 0) assert_almost_equal(res['area'][lower], 1, 3) assert_almost_equal(res['Ei'][lower], 20, 0) assert_almost_equal(res['Eabs'][lower], 14, 0) assert_almost_equal(res['Ei_sup'][lower], 0, 0) assert_almost_equal(res['Ei_inf'][lower], 20, 0)
def test_mixed_radiosity_four_triangles_full_occlusion(): # a two time two stack of sticked triangles dz = 1e-5 z1 = 0.25 z2 = 0.75 lower_pts_layer1 = [(0, 0, z1), (sqrt(2), 0, z1), (0, sqrt(2), z1)] upper_pts_layer1 = [(0, 0, z1 + dz), (sqrt(2), 0, z1 + dz), (0, sqrt(2), z1 + dz)] lower_pts_layer2 = [(0, 0, z2), (sqrt(2), 0, z2), (0, sqrt(2), z2)] upper_pts_layer2 = [(0, 0, z2 + dz), (sqrt(2), 0, z2 + dz), (0, sqrt(2), z2 + dz)] triangles = [lower_pts_layer1, upper_pts_layer1, lower_pts_layer2, upper_pts_layer2] lower1, upper1, lower2, upper2 = range(4) lights = [(100, (0, 0, -1))] materials = [(0.06, 0.04)] * 4 layers, height = 2, 1 soil_reflectance = 0.2 # pure radiosity res = radiosity(triangles, materials, lights) assert_almost_equal(res['Ei'][upper2], 100, 0) assert_almost_equal(res['Ei'][lower2], 4, 0) assert_almost_equal(res['Ei'][upper1], 0.1, 1) assert_almost_equal(res['Ei'][lower1], 0, 0) # direct + pure layer, dense canopy domain = (0, 0, sqrt(2), sqrt(2)) diameter = 0 res = mixed_radiosity(triangles, materials, lights, domain, soil_reflectance, diameter, layers, height) assert_almost_equal(res['Ei'][upper2], 103, 0) assert_almost_equal(res['Ei'][lower2], 4, 0) assert_almost_equal(res['Ei'][upper1], 4, 0) assert_almost_equal(res['Ei'][lower1], 4, 0) # direct + mixed radiosity, dense canopy (20% soil reflectance) domain = (0, 0, sqrt(2), sqrt(2)) diameter = 0.1 res = mixed_radiosity(triangles, materials, lights, domain, soil_reflectance, diameter, layers, height) assert_almost_equal(res['Ei'][upper2], 101, 0) assert_almost_equal(res['Ei'][lower2], 7, 0) assert_almost_equal(res['Ei'][upper1], 2, 0) assert_almost_equal(res['Ei'][lower1], 3, 0) # direct + pure layer, sparse canopy (20% soil reflectance) domain = (-10, -10, 10, 10) diameter = 0 res = mixed_radiosity(triangles, materials, lights, domain, soil_reflectance, diameter, layers, height) assert_almost_equal(res['Ei'][upper2], 120, 0) assert_almost_equal(res['Ei'][lower2], 20, 0) assert_almost_equal(res['Ei'][upper1], 20, 0) assert_almost_equal(res['Ei'][lower1], 20, 0) # direct + mixed radiosity, sparse canopy domain = (-10, -10, 10, 10) diameter = 0.1 res = mixed_radiosity(triangles, materials, lights, domain, soil_reflectance, diameter, layers, height) assert_almost_equal(res['Ei'][upper2], 101, 0) assert_almost_equal(res['Ei'][lower2], 24, 0) assert_almost_equal(res['Ei'][upper1], 1, 0) assert_almost_equal(res['Ei'][lower1], 20, 0)
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_radiosity(): pts1 = [(0, 0, 0), (1, 0, 0), (0, 1, 0)] pts2 = [(0, 0, 1), (1, 0, 1), (0, 1, 1)] triangles = [pts1, pts2] mats = [green_leaf_PAR] * 2 # default light res = radiosity(triangles, mats, debug=DEBUG) assert 'area' in res
def test_radiosity_exception(): points = [(0, 0, 0), (1, 0, 0), (0, 1, 0)] triangles = [points] materials = [green_leaf_PAR] # one triangle assert_raises(ValueError, lambda: radiosity(triangles, materials)) pts1 = [(0, 0, 0), (1, 0, 0), (0, 1, 0)] pts2 = [(0, 0, 1), (1, 0, 1), (0, 1, 1)] triangles = [pts1, pts2] # black body materials = [(0,)] * 2 assert_raises(ValueError, lambda: radiosity(triangles, materials)) # unmatch triangles <-> materials materials = [green_leaf_PAR] assert_raises(ValueError, lambda: radiosity(triangles, materials))
def test_default_light_in_radiosity(): pts1 = [(0, 0, 0), (1, 0, 0), (0, 1, 0)] pts2 = [(0, 0, 1), (1, 0, 1), (0, 1, 1)] triangles = [pts1, pts2] mats = [green_leaf_PAR] * 2 # default light res = radiosity(triangles, mats) assert 'area' in res
def test_radiosity_exception(): points = [(0, 0, 0), (1, 0, 0), (0, 1, 0)] triangles = [points] materials = [green_leaf_PAR] # one triangle assert_raises(ValueError, lambda: radiosity(triangles, materials, debug=DEBUG)) pts1 = [(0, 0, 0), (1, 0, 0), (0, 1, 0)] pts2 = [(0, 0, 1), (1, 0, 1), (0, 1, 1)] triangles = [pts1, pts2] # black body materials = [(0, )] * 2 assert_raises(ValueError, lambda: radiosity(triangles, materials, debug=DEBUG)) # unmatch triangles <-> materials materials = [green_leaf_PAR] assert_raises(ValueError, lambda: radiosity(triangles, materials, debug=DEBUG))
def test_radiosity_two_triangles_one_null(): 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))] res = radiosity(triangles, mats, lights) 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_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_radiosity_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 = radiosity(triangles, materials, lights) assert_almost_equal(res['area'][lower], 1, 3) assert_almost_equal(res['Eabs'][lower], 3.6, 1) assert_almost_equal(res['Ei'][lower], 4, 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_radiosity_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 = radiosity(triangles, materials, lights) assert_almost_equal(res['area'][lower], 1, 3) assert_almost_equal(res['Eabs'][lower], 3.6, 1) assert_almost_equal(res['Ei'][lower], 4, 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)