semantic_digital_twin.adapters.procthor.procthor_parser#

Classes#

ProcthorDoor

Processes a door dictionary from Procthor, extracting the door's hole polygon and computing its scale and

ProcthorWall

Processes a wall dictionary from Procthor, extracting the wall's polygon and computing its scale and

ProcthorRoom

Processes a room dictionary from Procthor, extracting the room's floor polygon and computing its center.

ProcthorObject

Processes an object dictionary from Procthor, extracting the object's position and rotation,

ProcTHORParser

Parses a Procthor JSON file into a semantic digital twin World.

Functions#

unity_to_semantic_digital_twin_transform(...)

Convert a left-handed Y-up, Z-forward Unity transform to the right-handed Z-up, X-forward convention used in the

get_world_by_asset_id(...)

Queries the database for a WorldMapping with the given asset_id provided by the procthor file.

Module Contents#

class semantic_digital_twin.adapters.procthor.procthor_parser.ProcthorDoor#

Processes a door dictionary from Procthor, extracting the door’s hole polygon and computing its scale and transformation matrix relative to the parent wall’s horizontal center.

door_dict: dict#

Dictionary representing a door from Procthors’ JSON format

parent_wall_width: float#

Width of the parent wall, since we define the door relative to the wall’s horizontal center.

thickness: float = 0.02#

Thickness of the door, since the door dictionary only provides a 2d polygon.

name: semantic_digital_twin.datastructures.prefixed_name.PrefixedName#

Name of the door, constructed from the assetId and room numbers.

min_x: float#

Minimum x-coordinate of the door’s hole polygon.

min_y: float#

Minimum y-coordinate of the door’s hole polygon.

max_x: float#

Maximum x-coordinate of the door’s hole polygon.

max_y: float#

Maximum y-coordinate of the door’s hole polygon.

property scale: semantic_digital_twin.world_description.geometry.Scale#

Computes the door scale from the door’s hole polygon. Converts the scale from Unity’s left-handed Y-up, Z-forward convention to the semantic digital twin’s right-handed Z-up, X-forward convention.

Returns:

Scale representing the door’s geometry.

property wall_T_door: semantic_digital_twin.spatial_types.spatial_types.TransformationMatrix#

Computes the door position from the wall’s horizontal center. Converts the Unity’s left-handed Y-up, Z-forward convention to the semantic digital twin’s right-handed Z-up, X-forward convention.

Returns:

TransformationMatrix representing the door’s transform from the wall’s perspective.

get_factory() semantic_digital_twin.semantic_annotations.factories.DoorFactory | semantic_digital_twin.semantic_annotations.factories.DoubleDoorFactory#

Returns a Factory for the door, either a DoorFactory or a DoubleDoorFactory, depending on its name. If the door’s name contains “double”, it is treated as a double door.

class semantic_digital_twin.adapters.procthor.procthor_parser.ProcthorWall#

Processes a wall dictionary from Procthor, extracting the wall’s polygon and computing its scale and transformation matrix. Its center will be at the horizontal center of its polygon, at height 0.

It also processes any doors associated with the wall, creating ProcthorDoor instances for each door.

The wall is defined by two polygons, one for each side of the physical wall, and the door is defined as a hole in the wall polygon.

wall_dicts: List[dict] = []#

List of dictionaries, where each dictionary represents one wall polygon in procthor

door_dicts: List[dict] = []#

List of dictionaries, where each dictionary represents one door hole in the wall polygon

wall_thickness: float = 0.02#

Thickness of the wall, since the wall dictionary only provides a 2d polygon.

name: semantic_digital_twin.datastructures.prefixed_name.PrefixedName#

Name of the wall, constructed from the corners of the wall polygon and the room numbers associated with the wall.

x_coords: List[float]#

List of unique X-coordinates of the wall polygon, extracted in order from the wall dictionary.

y_coords: List[float]#

List of unique Y-coordinates of the wall polygon, extracted in order from the wall dictionary.

z_coords: List[float]#

List of unique Z-coordinates of the wall polygon, extracted in order from the wall dictionary.

delta_x: float#

Difference between the first and last X-coordinates of the wall polygon.

delta_z: float#

Difference between the first and last Z-coordinates of the wall polygon.

property scale: semantic_digital_twin.world_description.geometry.Scale#

Computes the wall scale from the first wall polygon. Converts the scale from Unity’s left-handed Y-up, Z-forward convention to the semantic digital twin’s right-handed Z-up, X-forward convention.

Returns:

Scale representing the wall’s geometry.

property world_T_wall: semantic_digital_twin.spatial_types.spatial_types.TransformationMatrix#

Computes the wall’s world position matrix from the wall’s x and z coordinates. Calculates the yaw angle using the atan2 function based on the wall’s width and depth. The wall is artificially set to height=0, because 1. as of now, procthor house floors have the same floor value at 0 2. Since doors origins are in 3d center, positioning the door correctly at the floor given potentially varying

wall heights is unnecessarily complex given the assumption stated in 1.

get_world() semantic_digital_twin.world.World#

Returns a World instance with this wall at its root.

class semantic_digital_twin.adapters.procthor.procthor_parser.ProcthorRoom#

Processes a room dictionary from Procthor, extracting the room’s floor polygon and computing its center.

room_dict: dict#

Dictionary representing a room from Procthor’s JSON format.

name: semantic_digital_twin.datastructures.prefixed_name.PrefixedName#

Name of the room, constructed from the room type and room ID.

centered_polytope: List[semantic_digital_twin.spatial_types.spatial_types.Point3]#

Polytope representing the room’s floor polygon, centered around its local 0, 0, 0 coordinate

property world_T_room: semantic_digital_twin.spatial_types.spatial_types.TransformationMatrix#

Computes the room’s world transform

get_world() semantic_digital_twin.world.World#

Returns a World instance with this room as a Region at its root.

class semantic_digital_twin.adapters.procthor.procthor_parser.ProcthorObject#

Processes an object dictionary from Procthor, extracting the object’s position and rotation, and computing its world transformation matrix. It also handles the import of child objects recursively.

object_dict: dict#

Dictionary representing an object from Procthor’s JSON format.

session: sqlalchemy.orm.Session#

SQLAlchemy session to interact with the database to import objects.

property world_T_obj: semantic_digital_twin.spatial_types.spatial_types.TransformationMatrix#

Computes the object’s world transformation matrix from its position and rotation. Converts Unity’s left-handed Y-up, Z-forward convention to the right-handed Z-up, X-forward convention.

get_world() semantic_digital_twin.world.World | None#

Returns a World instance with this object at its root, importing it from the database using its assetId. If the object has children, they are imported recursively and connected to the parent object. If the object cannot be found in the database, it’s children are skipped as well.

semantic_digital_twin.adapters.procthor.procthor_parser.unity_to_semantic_digital_twin_transform(unity_transform_matrix: semantic_digital_twin.spatial_types.spatial_types.TransformationMatrix) semantic_digital_twin.spatial_types.spatial_types.TransformationMatrix#

Convert a left-handed Y-up, Z-forward Unity transform to the right-handed Z-up, X-forward convention used in the semantic digital twin.

Parameters:

unity_transform_matrix – The transformation matrix in Unity coordinates.

Returns:

TransformationMatrix in semantic digital twin coordinates.

class semantic_digital_twin.adapters.procthor.procthor_parser.ProcTHORParser#

Parses a Procthor JSON file into a semantic digital twin World.

file_path: str#

File path to the Procthor JSON file.

session: sqlalchemy.orm.Session | None = None#

SQLAlchemy session to interact with the database to import objects.

parse() semantic_digital_twin.world.World#

Parses a JSON file from procthor into a world. Room floor areas are constructed from the supplied polygons Walls and doors are constructed from the supplied polygons Objects are imported from the database

static import_rooms(world: semantic_digital_twin.world.World, rooms: List[Dict])#

Imports rooms from the Procthor JSON file into ProcthorRoom instances.

Parameters:
  • world – The World instance to which the rooms will be added.

  • rooms – List of room dictionaries from the Procthor JSON file.

import_objects(world: semantic_digital_twin.world.World, objects: List[Dict])#

Imports objects from the Procthor JSON file into ProcthorObject instances.

Parameters:
  • world – The World instance to which the objects will be added.

  • objects – List of object dictionaries from the Procthor JSON file.

import_walls_and_doors(world: semantic_digital_twin.world.World, walls: List[Dict], doors: List[Dict])#

Imports walls from the Procthor JSON file into ProcthorWall instances.

Parameters:
  • world – The World instance to which the walls will be added.

  • walls – List of wall dictionaries from the Procthor JSON file.

  • doors – List of door dictionaries from the Procthor JSON file.

semantic_digital_twin.adapters.procthor.procthor_parser.get_world_by_asset_id(session: sqlalchemy.orm.Session, asset_id: str) semantic_digital_twin.world.World | None#

Queries the database for a WorldMapping with the given asset_id provided by the procthor file.