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)
Beispiel #2
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']
Beispiel #3
0
def test_mixed_radiosity_two_triangles_one_null():
    pts1 = [(0, 1, 0), (0, 0, 0), (1, 0, 0)]
    pts2 = [(2, 1, 0.5), (3, 0, 0.5), (3, 0, 0.5)]
    triangles = [pts1, pts2]
    mats = [green_leaf_PAR] * 2
    lights = [(100, (0, 0, -1))]
    domain = (-2, -2, 2, 2)
    soil_reflectance = 0.2
    diameter = 1
    layers, height = 2, 1

    res = mixed_radiosity(triangles, mats, lights, domain, soil_reflectance, diameter, layers, height)

    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])