Skip to main content

Extract spatial metadata

The Treble SDK enables simulations in complex environments as well as placing sources and receivers in arbitrary, random or pseudo random positions in the room.

For various purposes it can be helpful to be able to extract spatial information after a simulation has been run. One popular use of this data is as metadata for machine learning models.

The examples below will build on top of the my first simulation example.

Basic examples

Distance to a layer

This method works on the ModelObj and can give the distance between any point and any named layer. The example below draws a room from the classroom dataset and computes the distance between a suggested position and the ceiling:

# The below three lines can be left out if you have just run the simulation
project = tsdk.get_or_create_project("My Unique Project Name")
model = project.get_model_by_name("example room")
simulation = project.get_simulation_by_name('Simulation_1')

my_receiver_location = simulation.receivers[0].location
model.get_distance_to_layer_m(my_receiver_location,"shoebox_walls")

Distance between points

Calculate the distance between two points — for example, between a source and a receiver:

# The below three lines can be left out if you have just run the simulation
project = tsdk.get_or_create_project("My Unique Project Name")
model = project.get_model_by_name("example room")
simulation = project.get_simulation_by_name('Simulation_1')

my_receiver_location = simulation.receivers[0].location
my_source_location = simulation.sources[0].location
my_source_location.euclidean_distance(my_receiver_location)

Line of sight between two points

Call has_line_of_sight() to check whether there is line of sight between two points — for example, between a source and a receiver:

# The below three lines can be left out if you have just run the simulation
project = tsdk.get_or_create_project("My Unique Project Name")
model = project.get_model_by_name("example room")
simulation = project.get_simulation_by_name('Simulation_1')

my_receiver_location = simulation.receivers[0].location
my_source_location = simulation.sources[0].location
model.has_line_of_sight(my_source_location,my_receiver_location)