示例#1
0
文件: caribu.py 项目: pradal/caribu
def mixed_radiosity(triangles, materials, lights, domain, soil_reflectance,
                    diameter, layers, height, screen_size=1536, debug=False):
    """Compute monochrome illumination of triangles using mixed-radiosity model.

    Args:
        triangles: (list of list of tuples) a list of triangles, each being defined
                    by an ordered triplet of 3-tuple points coordinates.
        materials: (list of tuple) a list of materials defining optical properties of triangles
                    A material is a 1-, 2- or 4-tuple depending on its optical behavior.
                    A 1-tuple encode an opaque material characterised by its reflectance
                    A 2-tuple encode a symmetric translucent material defined by a reflectance and a transmittance
                    A 4-tuple encode an asymmetric translucent material defined the reflectance and transmittance
                    of the upper and lower side respectively
        lights: (list of tuples) a list of (Energy, (vx, vy, vz)) tuples defining ligh sources
                Energy is ligth flux passing throuh a unit area (scene unit) horizontal plane.
        domain: (tuple of floats) 2D Coordinates of the domain bounding the scene for its replication.
                 (xmin, ymin, xmax, ymax) scene is not bounded along z axis
        soil_reflectance: (float) the reflectance of the soil
        diameter: diameter (scene unit) of the sphere defining the close neighbourhood for local radiosity.
        layers: vertical subdivisions of scene used for approximation of far contrbution
        height: upper limit of canopy layers (scene unit)
        screen_size: (int) buffer size for projection images (pixels)
        debug: (bool) Whether Caribu should be called in debug mode

    Returns:
        (dict of str:property) properties computed:
          - index(int) : the indices of the input triangles present in outputs ?
          - label(str) : the internal barcode (canlabel) used by caribu (for debuging)
          - area (float): the indiviual areas of triangles
          - Eabs (float): the surfacic density of energy absorbed by the triangles (absorbed_energy / area)
          - Ei (float): the surfacic density of energy incoming on the triangles
          - Ei_inf (float): the surfacic density of energy incoming on the inferior face of the triangle
          - Ei_sup (float): the surfacic density of energy incoming on the superior face of the triangle
    """

    if len(triangles) <= 1:
        raise ValueError('Radiosity method needs at least two primitives')

    o_string, labels = opt_string_and_labels(materials, soil_reflectance)
    can_string = triangles_string(triangles, labels)
    sky_string = light_string(lights)
    pattern_str = pattern_string(domain)

    algo = Caribu(canfile=can_string,
                  skyfile=sky_string,
                  optfiles=o_string,
                  patternfile=pattern_str,
                  direct=False,
                  infinitise=True,
                  nb_layers=layers,
                  can_height=height,
                  sphere_diameter=diameter,
                  projection_image_size=screen_size,
                  resdir=None, resfile=None, debug=debug)
    algo.run()
    out = algo.nrj['band0']['data']
    out['Ei'] = get_incident(out['Eabs'], materials)

    return out
示例#2
0
文件: caribu.py 项目: pradal/caribu
def raycasting(triangles, materials, lights=(default_light,), domain=None,
               screen_size=1536):
    """Compute monochrome illumination of triangles using caribu raycasting mode.

    Args:
        triangles: (list of list of tuples) a list of triangles, each being defined
                    by an ordered triplet of 3-tuple points coordinates.
        materials: (list of tuple) a list of materials defining optical properties of triangles
                    A material is a 1-, 2- or 4-tuple depending on its optical behavior.
                    A 1-tuple encode the reflectance of an opaque material
                    A 2-tuple encode the reflectance and transmittance of a symmetric translucent material
                    A 4-tuple encode the reflectance and transmittance
                    of the upper and lower side of an asymmetric translucent material
        lights: (list of tuples) a list of (Energy, (vx, vy, vz)) tuples defining ligh sources
                By default a normalised zenithal light is used.
                Energy is light flux passing through a unit area (scene unit) horizontal plane.
        domain: (tuple of floats) 2D Coordinates of the domain bounding the scene for its replication.
                 (xmin, ymin, xmax, ymax) scene is not bounded along z axis
                 if None (default), scene is not repeated
        screen_size: (int) buffer size for projection images (pixels)

    Returns:
        (dict of str:property) properties computed:
          - index(int) : the indices of the input triangles present in outputs ?
          - label(str) : the internal barcode (canlabel) used by caribu (for debugging)
          - area (float): the individual areas of triangles
          - Eabs (float): the surfacic density of energy absorbed by the triangles (absorbed_energy / area)
          - Ei (float): the surfacic density of energy incoming on the triangles
          - Ei_inf (float): the surfacic density of energy incoming on the inferior face of the triangle.
          - Ei_sup (float): the surfacic density of energy incoming on the superior face of the triangle
    """

    o_string, labels = opt_string_and_labels(materials)
    can_string = triangles_string(triangles, labels)
    sky_string = light_string(lights)

    if domain is None:
        infinite = False
        pattern_str = None
    else:
        infinite = True
        pattern_str = pattern_string(domain)

    algo = Caribu(canfile=can_string,
                  skyfile=sky_string,
                  optfiles=o_string,
                  patternfile=pattern_str,
                  direct=True,
                  infinitise=infinite,
                  projection_image_size=screen_size,
                  resdir=None, resfile=None)
    algo.run()
    out = algo.nrj['band0']['data']
    out['Ei'] = get_incident(out['Eabs'], materials)

    return out
示例#3
0
文件: caribu.py 项目: pradal/caribu
def x_radiosity(triangles, x_materials, lights=(default_light,), screen_size=1536):
    """Compute multi-chromatic illumination of triangles using radiosity method.

    Args:
        triangles: (list of list of tuples) a list of triangles, each being defined
                    by an ordered triplet of 3-tuple points coordinates.
        x_materials: (dict of list of tuple) a {band_name: [materials]} dict defining optical properties of triangles
                    for different band/wavelength
                    A material is a 1-, 2- or 4-tuple depending on its optical behavior.
                    A 1-tuple encode an opaque material characterised by its reflectance
                    A 2-tuple encode a symmetric translucent material defined by a reflectance and a transmittance
                    A 4-tuple encode an asymmetric translucent material defined the reflectance and transmittance
                    of the upper and lower side respectively
        lights: (list of tuples) a list of (Energy, (vx, vy, vz)) tuples defining ligh sources
                By default a normalised zenital light is used.
                Energy is ligth flux passing throuh a unit area (scene unit) horizontal plane.
        screen_size: (int) buffer size for projection images (pixels)

    Returns:
        a {band_name: {property_name:property_values} } dict of dict) with  properties:
          - index(int) : the indices of the input triangles present in outputs ?
          - label(str) : the internal barcode (canlabel) used by caribu (for debuging)
          - area (float): the individual areas of triangles
          - Eabs (float): the surfacic density of energy absorbed by the triangles (absorbed_energy / area)
          - Ei (float): the surfacic density of energy incoming on the triangles
          - Ei_inf (float): the surfacic density of energy incoming on the inferior face of the triangle
          - Ei_sup (float): the surfacic density of energy incoming on the superior face of the triangle
    """

    if len(triangles) <= 1:
        raise ValueError('Radiosity method needs at least two primitives')

    no_soil = {band:-1 for band in x_materials}
    opt_strings, labels = x_opt_strings_and_labels(x_materials, no_soil)
    can_string = triangles_string(triangles, labels)
    sky_string = light_string(lights)

    caribu = Caribu(canfile=can_string,
                    skyfile=sky_string,
                    optfiles=opt_strings.values(),
                    optnames=opt_strings.keys(),
                    patternfile=None,
                    direct=False,
                    infinitise=False,
                    sphere_diameter=-1,
                    projection_image_size=screen_size,
                    resdir=None, resfile=None)
    caribu.run()
    out = {k: v['data'] for k, v in caribu.nrj.iteritems()}
    for band in out:
        out[band]['Ei'] = get_incident(out[band]['Eabs'], x_materials[band])

    return out
def test_case_1_projection_non_toric_scene(debug=False):
    can = data_path('filterT.can')
    sky = data_path('zenith.light')
    opts = [data_path('par.opt'), data_path('nir.opt')]

    sim = Caribu(canfile=can, skyfile=sky,
                 optfiles=opts, resdir=None, resfile=None, debug=debug)

    sim.infinity = False
    sim.direct = True  # direct light only
    sim.nb_layers = None
    sim.can_height = None
    sim.sphere_diameter = -1
    sim.pattern = None
    sim.run()
    return sim.nrj
示例#5
0
def test_case_1_projection_non_toric_scene(debug=False):
    can = data_path('filterT.can')
    sky = data_path('zenith.light')
    opts = [data_path('par.opt'), data_path('nir.opt')]

    sim = Caribu(canfile=can,
                 skyfile=sky,
                 optfiles=opts,
                 resdir=None,
                 resfile=None,
                 debug=debug)

    sim.infinity = False
    sim.direct = True  # direct light only
    sim.nb_layers = None
    sim.can_height = None
    sim.sphere_diameter = -1
    sim.pattern = None
    sim.run()
    return sim.nrj
def test_case_5_nested_radiosity_toric_scene(debug=False):
    can = data_path('filterT.can')
    sky = data_path('zenith.light')
    opts = [data_path('par.opt'), data_path('nir.opt')]
    opts = data_path('par.opt')
    sim = Caribu(canfile=can, skyfile=sky,
                 optfiles=opts, resdir=None, resfile=None, debug=debug)

    sim.infinity = True
    sim.direct = False  # NOT direct light only
    sim.sphere_diameter = 1  # 1, 2, 5, 10, 20 make canestra crash !!!
    sim.nb_layers = 6
    sim.can_height = 21
    sim.pattern = data_path('filter.8')

    sim.run()
    return sim.nrj
def test_sensor(debug=False):
    can = data_path('filterT.can')
    sky = data_path('zenith.light')
    opts = [data_path('par.opt'), data_path('nir.opt')]
    sensor = data_path('sensor.can')

    sim = Caribu(canfile=can, skyfile=sky,
                 optfiles=opts, sensorfile=sensor, resdir=None, resfile=None, debug=debug)

    sim.infinity = False
    sim.direct = True  # direct light only
    sim.nb_layers = None
    sim.can_height = None
    sim.sphere_diameter = -1
    sim.pattern = None
    sim.run()
    return sim.measures
示例#8
0
def test_case_5_nested_radiosity_toric_scene(debug=False):
    can = data_path('filterT.can')
    sky = data_path('zenith.light')
    opts = [data_path('par.opt'), data_path('nir.opt')]
    opts = data_path('par.opt')
    sim = Caribu(canfile=can,
                 skyfile=sky,
                 optfiles=opts,
                 resdir=None,
                 resfile=None,
                 debug=debug)

    sim.infinity = True
    sim.direct = False  # NOT direct light only
    sim.sphere_diameter = 1  # 1, 2, 5, 10, 20 make canestra crash !!!
    sim.nb_layers = 6
    sim.can_height = 21
    sim.pattern = data_path('filter.8')

    sim.run()
    return sim.nrj
示例#9
0
def test_sensor(debug=False):
    can = data_path('filterT.can')
    sky = data_path('zenith.light')
    opts = [data_path('par.opt'), data_path('nir.opt')]
    sensor = data_path('sensor.can')

    sim = Caribu(canfile=can,
                 skyfile=sky,
                 optfiles=opts,
                 sensorfile=sensor,
                 resdir=None,
                 resfile=None,
                 debug=debug)

    sim.infinity = False
    sim.direct = True  # direct light only
    sim.nb_layers = None
    sim.can_height = None
    sim.sphere_diameter = -1
    sim.pattern = None
    sim.run()
    return sim.measures
示例#10
0
def x_mixed_radiosity(triangles, materials, lights, domain, soil_reflectance,
                      diameter, layers, height, sensors=None, screen_size=1536):
    """Compute multi-chromatic illumination of triangles using mixed-radiosity model.

    Args:
        triangles: (list of list of tuples) a list of triangles, each being defined
                    by an ordered triplet of 3-tuple points coordinates.
        materials: (dict of list of tuple) a {band_name: [materials]} dict defining optical properties of triangles
                    for different band/wavelength
                    A material is a 1-, 2- or 4-tuple depending on its optical behavior.
                    A 1-tuple encode an opaque material characterised by its reflectance
                    A 2-tuple encode a symmetric translucent material defined by a reflectance and a transmittance
                    A 4-tuple encode an asymmetric translucent material defined the reflectance and transmittance
                    of the upper and lower side respectively
        lights: (list of tuples) a list of (Energy, (vx, vy, vz)) tuples defining light sources
                Energy is light flux passing through a unit area (scene unit) horizontal plane.
        domain: (tuple of floats) 2D Coordinates of the domain bounding the scene for its replication.
                 (xmin, ymin, xmax, ymax) scene is not bounded along z axis
        soil_reflectance: (dict of float) a {band_name: reflectance} dict for the reflectances of the soil
        diameter: diameter (scene unit) of the sphere defining the close neighbourhood for local radiosity.
        layers: vertical subdivisions of scene used for approximation of far contribution
        height: upper limit of canopy layers (scene unit)
        screen_size: (int) buffer size for projection images (pixels)
        sensors: (list of list of tuples) a list of triangles defining virtual sensors

    Returns:
       a ({band_name: {property_name:property_values} } dict of dict) with  properties:
          - index(int) : the indices of the input triangles present in outputs ?
          - label(str) : the internal barcode (canlabel) used by caribu (for debugging)
          - area (float): the individual areas of triangles
          - Eabs (float): the surfacic density of energy absorbed by the triangles (absorbed_energy / area)
          - Ei (float): the surfacic density of energy incoming on the triangles
          - Ei_inf (float): the surfacic density of energy incoming on the inferior face of the triangle
          - Ei_sup (float): the surfacic density of energy incoming on the superior face of the triangle
          - sensor (dict): a dict with id, area, surfacic density of incoming
            direct energy and surfacic density of incoming total energy of sensors, if any
   """

    if len(triangles) <= 1:
        raise ValueError('Radiosity method needs at least two primitives')

    opt_strings, labels = x_opt_strings_and_labels(materials, soil_reflectance)
    can_string = triangles_string(triangles, labels)
    sky_string = light_string(lights)
    pattern_str = pattern_string(domain)
    if sensors is None:
        sensor_str = None
    else:
        sensor_str = sensor_string(sensors)
        raise NotImplementedError(
            'virtual sensors are not operational for mixed_radiosity')

    caribu = Caribu(canfile=can_string,
                    skyfile=sky_string,
                    optfiles=opt_strings.values(),
                    optnames=opt_strings.keys(),
                    patternfile=pattern_str,
                    sensorfile=sensor_str,
                    direct=False,
                    infinitise=True,
                    nb_layers=layers,
                    can_height=height,
                    sphere_diameter=diameter,
                    projection_image_size=screen_size,
                    resdir=None, resfile=None)
    caribu.run()
    out = {k: v['data'] for k, v in caribu.nrj.iteritems()}
    for band in out:
        out[band]['Ei'] = get_incident(out[band]['Eabs'], materials[band])

    return out
示例#11
0
def radiosity(triangles, materials, lights=(default_light,), screen_size=1536,
              sensors=None):
    """Compute monochromatic illumination of triangles using radiosity method.

    Args:
        triangles: (list of list of tuples) a list of triangles, each being defined
                    by an ordered triplet of 3-tuple points coordinates.
        materials: (list of tuple) a list of materials defining optical properties of triangles
                    A material is a 1-, 2- or 4-tuple depending on its optical behavior.
                    A 1-tuple encode an opaque material characterised by its reflectance
                    A 2-tuple encode a symmetric translucent material defined by a reflectance and a transmittance
                    A 4-tuple encode an asymmetric translucent material defined the reflectance and transmittance
                    of the upper and lower side respectively
        lights: (list of tuples) a list of (Energy, (vx, vy, vz)) tuples defining ligh sources
                By default a normalised zenital light is used.
                Energy is ligth flux passing throuh a unit area (scene unit) horizontal plane.
        screen_size: (int) buffer size for projection images (pixels)
        sensors: (list of list of tuples) a list of triangles defining virtual sensors


    Returns:
        (dict of str:property) properties computed:
          - index(int) : the indices of the input triangles present in outputs ?
          - label(str) : the internal barcode (canlabel) used by caribu (for debuging)
          - area (float): the individual areas of triangles
          - Eabs (float): the surfacic density of energy absorbed by the triangles (absorbed_energy / area)
          - Ei (float): the surfacic density of energy incoming on the triangles
          - Ei_inf (float): the surfacic density of energy incoming on the inferior face of the triangle
          - Ei_sup (float): the surfacic density of energy incoming on the superior face of the triangle
          - sensor (dict): a dict with id, area, surfacic density of incoming
            direct energy and surfacic density of incoming total energy of sensors, if any
    """

    if len(triangles) <= 1:
        raise ValueError('Radiosity method needs at least two primitives')

    o_string, labels = opt_string_and_labels(materials)
    can_string = triangles_string(triangles, labels)
    sky_string = light_string(lights)

    if sensors is None:
        sensor_str = None
    else:
        sensor_str = sensor_string(sensors)

    algo = Caribu(canfile=can_string,
                  skyfile=sky_string,
                  optfiles=o_string,
                  sensorfile=sensor_str,
                  patternfile=None,
                  direct=False,
                  infinitise=False,
                  sphere_diameter=-1,
                  projection_image_size=screen_size,
                  resdir=None, resfile=None)
    algo.run()
    out = algo.nrj['band0']['data']
    out['Ei'] = get_incident(out['Eabs'], materials)
    if sensors is not None:
        out['sensors'] = algo.measures['band0']

    return out
def test_caribu_inconsistent_case():
    can = data_path('filterT.can')
    sky = data_path('zenith.light')
    opts = [data_path('par.opt'), data_path('nir.opt')]

    sim = Caribu(canfile=can, skyfile=sky,
                 optfiles=opts, resdir=None, resfile=None)

    sim.direct = False  # NOT direct light only
    sim.nb_layers = None
    sim.can_height = None
    sim.sphere_diameter = -1
    sim.pattern = None

    # radiosity toric scene
    sim.infinity = True
    sim.pattern = data_path('filter.8')
    try:
        sim.run()
        assert False, "This test uses inconsistent options, it should raise an CaribuOptionError"
    except CaribuOptionError:
        assert True

    # nested radiosity non toric scene
    sim.infinity = False
    sim.pattern = None
    sim.sphere_diameter = 1
    sim.nb_layers = 6
    sim.can_height = 21
    try:
        sim.run()
        assert False, "This test uses inconsistent options, it should raise an CaribuOptionError"
    except CaribuOptionError:
        assert True
示例#13
0
def test_caribu_inconsistent_case():
    can = data_path('filterT.can')
    sky = data_path('zenith.light')
    opts = [data_path('par.opt'), data_path('nir.opt')]

    sim = Caribu(canfile=can,
                 skyfile=sky,
                 optfiles=opts,
                 resdir=None,
                 resfile=None)

    sim.direct = False  # NOT direct light only
    sim.nb_layers = None
    sim.can_height = None
    sim.sphere_diameter = -1
    sim.pattern = None

    # radiosity toric scene
    sim.infinity = True
    sim.pattern = data_path('filter.8')
    try:
        sim.run()
        assert False, "This test uses inconsistent options, it should raise an CaribuOptionError"
    except CaribuOptionError:
        assert True

    # nested radiosity non toric scene
    sim.infinity = False
    sim.pattern = None
    sim.sphere_diameter = 1
    sim.nb_layers = 6
    sim.can_height = 21
    try:
        sim.run()
        assert False, "This test uses inconsistent options, it should raise an CaribuOptionError"
    except CaribuOptionError:
        assert True
示例#14
0
def x_mixed_radiosity(triangles,
                      materials,
                      lights,
                      domain,
                      soil_reflectance,
                      diameter,
                      layers,
                      height,
                      sensors=None,
                      screen_size=1536,
                      debug=False):
    """Compute multi-chromatic illumination of triangles using mixed-radiosity model.

    Args:
        triangles: (list of list of tuples) a list of triangles, each being defined
                    by an ordered triplet of 3-tuple points coordinates.
        materials: (dict of list of tuple) a {band_name: [materials]} dict defining optical properties of triangles
                    for different band/wavelength
                    A material is a 1-, 2- or 4-tuple depending on its optical behavior.
                    A 1-tuple encode an opaque material characterised by its reflectance
                    A 2-tuple encode a symmetric translucent material defined by a reflectance and a transmittance
                    A 4-tuple encode an asymmetric translucent material defined the reflectance and transmittance
                    of the upper and lower side respectively
        lights: (list of tuples) a list of (Energy, (vx, vy, vz)) tuples defining light sources
                Energy is light flux passing through a unit area (scene unit) horizontal plane.
        domain: (tuple of floats) 2D Coordinates of the domain bounding the scene for its replication.
                 (xmin, ymin, xmax, ymax) scene is not bounded along z axis
        soil_reflectance: (dict of float) a {band_name: reflectance} dict for the reflectances of the soil
        diameter: diameter (scene unit) of the sphere defining the close neighbourhood for local radiosity.
        layers: vertical subdivisions of scene used for approximation of far contribution
        height: upper limit of canopy layers (scene unit)
        screen_size: (int) buffer size for projection images (pixels)
        sensors: (list of list of tuples) a list of triangles defining virtual sensors

    Returns:
       a ({band_name: {property_name:property_values} } dict of dict) with  properties:
          - index(int) : the indices of the input triangles present in outputs ?
          - label(str) : the internal barcode (canlabel) used by caribu (for debugging)
          - area (float): the individual areas of triangles
          - Eabs (float): the surfacic density of energy absorbed by the triangles (absorbed_energy / area)
          - Ei (float): the surfacic density of energy incoming on the triangles
          - Ei_inf (float): the surfacic density of energy incoming on the inferior face of the triangle
          - Ei_sup (float): the surfacic density of energy incoming on the superior face of the triangle
          - sensor (dict): a dict with id, area, surfacic density of incoming
            direct energy and surfacic density of incoming total energy of sensors, if any
   """

    if len(triangles) <= 1:
        raise ValueError('Radiosity method needs at least two primitives')

    opt_strings, labels = x_opt_strings_and_labels(materials, soil_reflectance)
    can_string = triangles_string(triangles, labels)
    sky_string = light_string(lights)
    pattern_str = pattern_string(domain)
    if sensors is None:
        sensor_str = None
    else:
        sensor_str = sensor_string(sensors)
        raise NotImplementedError(
            'virtual sensors are not operational for mixed_radiosity')

    caribu = Caribu(canfile=can_string,
                    skyfile=sky_string,
                    optfiles=list(opt_strings.values()),
                    optnames=list(opt_strings.keys()),
                    patternfile=pattern_str,
                    sensorfile=sensor_str,
                    direct=False,
                    infinitise=True,
                    nb_layers=layers,
                    can_height=height,
                    sphere_diameter=diameter,
                    projection_image_size=screen_size,
                    resdir=None,
                    resfile=None,
                    debug=debug)
    caribu.run()
    out = {k: v['data'] for k, v in caribu.nrj.items()}
    for band in out:
        out[band]['Ei'] = get_incident(out[band]['Eabs'], materials[band])

    return out
示例#15
0
def x_radiosity(triangles,
                x_materials,
                lights=(default_light, ),
                screen_size=1536,
                sensors=None,
                debug=False):
    """Compute multi-chromatic illumination of triangles using radiosity method.

    Args:
        triangles: (list of list of tuples) a list of triangles, each being defined
                    by an ordered triplet of 3-tuple points coordinates.
        x_materials: (dict of list of tuple) a {band_name: [materials]} dict defining optical properties of triangles
                    for different band/wavelength
                    A material is a 1-, 2- or 4-tuple depending on its optical behavior.
                    A 1-tuple encode an opaque material characterised by its reflectance
                    A 2-tuple encode a symmetric translucent material defined by a reflectance and a transmittance
                    A 4-tuple encode an asymmetric translucent material defined the reflectance and transmittance
                    of the upper and lower side respectively
        lights: (list of tuples) a list of (Energy, (vx, vy, vz)) tuples defining ligh sources
                By default a normalised zenital light is used.
                Energy is ligth flux passing throuh a unit area (scene unit) horizontal plane.
        screen_size: (int) buffer size for projection images (pixels)
        sensors: (list of list of tuples) a list of triangles defining virtual sensors

    Returns:
        a {band_name: {property_name:property_values} } dict of dict) with  properties:
          - index(int) : the indices of the input triangles present in outputs ?
          - label(str) : the internal barcode (canlabel) used by caribu (for debuging)
          - area (float): the individual areas of triangles
          - Eabs (float): the surfacic density of energy absorbed by the triangles (absorbed_energy / area)
          - Ei (float): the surfacic density of energy incoming on the triangles
          - Ei_inf (float): the surfacic density of energy incoming on the inferior face of the triangle
          - Ei_sup (float): the surfacic density of energy incoming on the superior face of the triangle
          - sensor (dict): a dict with id, area, surfacic density of incoming
            direct energy and surfacic density of incoming total energy of sensors, if any
    """

    if len(triangles) <= 1:
        raise ValueError('Radiosity method needs at least two primitives')

    no_soil = {band: -1 for band in x_materials}
    opt_strings, labels = x_opt_strings_and_labels(x_materials, no_soil)
    can_string = triangles_string(triangles, labels)
    sky_string = light_string(lights)

    if sensors is None:
        sensor_str = None
    else:
        sensor_str = sensor_string(sensors)

    caribu = Caribu(canfile=can_string,
                    skyfile=sky_string,
                    optfiles=list(opt_strings.values()),
                    optnames=list(opt_strings.keys()),
                    patternfile=None,
                    sensorfile=sensor_str,
                    direct=False,
                    infinitise=False,
                    sphere_diameter=-1,
                    projection_image_size=screen_size,
                    resdir=None,
                    resfile=None,
                    debug=debug)
    caribu.run()
    out = {k: v['data'] for k, v in caribu.nrj.items()}
    for band in out:
        out[band]['Ei'] = get_incident(out[band]['Eabs'], x_materials[band])
        if sensors is not None:
            out[band]['sensors'] = caribu.measures[band]

    return out
示例#16
0
def raycasting(triangles,
               materials,
               lights=(default_light, ),
               domain=None,
               screen_size=1536,
               sensors=None,
               debug=False,
               canfile=None,
               optfile=None):
    """Compute monochrome illumination of triangles using caribu raycasting mode.

    Args:
        triangles: (list of list of tuples) a list of triangles, each being defined
                    by an ordered triplet of 3-tuple points coordinates.
        materials: (list of tuple) a list of materials defining optical properties of triangles
                    A material is a 1-, 2- or 4-tuple depending on its optical behavior.
                    A 1-tuple encode the reflectance of an opaque material
                    A 2-tuple encode the reflectance and transmittance of a symmetric translucent material
                    A 4-tuple encode the reflectance and transmittance
                    of the upper and lower side of an asymmetric translucent material
        lights: (list of tuples) a list of (Energy, (vx, vy, vz)) tuples defining ligh sources
                By default a normalised zenithal light is used.
                Energy is light flux passing through a unit area (scene unit) horizontal plane.
        domain: (tuple of floats) 2D Coordinates of the domain bounding the scene for its replication.
                 (xmin, ymin, xmax, ymax) scene is not bounded along z axis
                 if None (default), scene is not repeated
        screen_size: (int) buffer size for projection images (pixels)
        sensors: (list of list of tuples) a list of triangles defining virtual sensors

    Returns:
        (dict of str:property) properties computed:
          - index(int) : the indices of the input triangles present in outputs ?
          - label(str) : the internal barcode (canlabel) used by caribu (for debugging)
          - area (float): the individual areas of triangles
          - Eabs (float): the surfacic density of energy absorbed by the triangles (absorbed_energy / area)
          - Ei (float): the surfacic density of energy incoming on the triangles
          - Ei_inf (float): the surfacic density of energy incoming on the inferior face of the triangle.
          - Ei_sup (float): the surfacic density of energy incoming on the superior face of the triangle
          - sensor (dict): a dict with id, area, surfacic density of incoming
            direct energy and surfacic density of incoming total energy of sensors, if any
    """

    if canfile is None or optfile is None:
        o_string, labels = opt_string_and_labels(materials)
        can_string = triangles_string(triangles, labels)
    else:
        if len(triangles) != len(materials):
            raise ValueError(len(triangles), len(materials))
        o_string = optfile
        can_string = canfile
    sky_string = light_string(lights)

    if domain is None:
        infinite = False
        pattern_str = None
    else:
        infinite = True
        pattern_str = pattern_string(domain)

    if sensors is None:
        sensor_str = None
    else:
        sensor_str = sensor_string(sensors)

    algo = Caribu(canfile=can_string,
                  skyfile=sky_string,
                  optfiles=o_string,
                  patternfile=pattern_str,
                  sensorfile=sensor_str,
                  direct=True,
                  infinitise=infinite,
                  projection_image_size=screen_size,
                  resdir=None,
                  resfile=None,
                  debug=debug)
    algo.run()
    out = algo.nrj['band0']['data']
    out['Ei'] = get_incident(out['Eabs'], materials)
    if sensors is not None:
        out['sensors'] = algo.measures['band0']

    return out