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

Distance to a layer

This method works on the ModelObj and can give the distance between any point and any named layer. In the example below a room is drawn from the classroom dataset and the distance between a suggested position and the ceiling is computed.

# 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

The distance between two points can be calculated, for example the distance between a source and receiver pair.

# 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

A method can be called to check if 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)