Base Object Classes¶
This page groups the foundational scene objects used throughout DiscoPygal, including scene containers, obstacles, robots, and path-related classes.
These classes are imported through discopygal.solvers_infra and are shared by
solvers, geometry utilities, and GUI tooling.
- class discopygal.solvers_infra.Obstacle(data)¶
Bases:
objectAbstract class that represents the notion of an obstacle in the scene. The obstacle has some geometry.
- Parameters:
data (
object) – Any metadata appended to the obstacle (could be None)
- static from_dict(d)¶
Load json dict to object
- Parameters:
d (
dict) – dict representing json export
- to_dict()¶
Convert current object to json dict
- Returns:
dict representing json export
- Return type:
dict
- class discopygal.solvers_infra.ObstacleDisc(location, radius, data=None)¶
Bases:
ObstacleDisc obstacle in the scene. Its geometry is given as a location and radius.
- Parameters:
- static from_dict(d)¶
Load json dict to object
- Parameters:
d (
dict) – dict representing json export
- to_dict()¶
Convert current object to json dict
- Returns:
dict representing json export
- Return type:
dict
- class discopygal.solvers_infra.ObstaclePolygon(poly, data=None)¶
Bases:
ObstaclePolygon obstacle in the scene. Its geometry is given as a polygon.
- Parameters:
poly (
Polygon2) – Polygon obstacle geometry, as a CGAL polygon
- static from_dict(d)¶
Load json dict to object
- Parameters:
d (
dict) – dict representing json export
- to_dict()¶
Convert current object to json dict
- Returns:
dict representing json export
- Return type:
dict
- class discopygal.solvers_infra.Path(points: list[~discopygal.solvers_infra.PathPoint], metric=<class 'discopygal.solvers_infra.metrics.Metric_Euclidean'>)¶
Bases:
objectRepresentation of the path a single robot does
- Parameters:
points (list<
PathPoint>) – points along the path
- calculate_length()¶
Return the total length of the path (sum of length between each two points)
- Parameters:
metric (
Metric) – The metric to use for calculating the distance between two points- Returns:
The length of the path
- Return type:
FT
- class discopygal.solvers_infra.PathCollection(paths=None, metric=<class 'discopygal.solvers_infra.metrics.Metric_Euclidean'>, add_padding_to_paths=True)¶
Bases:
objectCollection of the paths of all the robots in the scene. This is the objects that is returned by a solver.
- add_padding_to_paths()¶
Add more points (end points) to the paths that are shorter than the maximum path so all paths will be at the same size
- add_robot_path(robot, path)¶
Add a robot’s path to the collection
- static from_dict(state, metric: ~discopygal.solvers_infra.metrics.Metric = <class 'discopygal.solvers_infra.metrics.Metric_Euclidean'>)¶
Load json dict to PathCollection object
- Parameters:
state (
dict) – dict representing json export- Returns:
PathCollection object
- Return type:
- to_dict()¶
Convert current object to json dict
- Returns:
dict representing json export
- Return type:
dict
- class discopygal.solvers_infra.PathPoint(location, data=None)¶
Bases:
objectA single point in the path (of some robot). Has a 2D location and additional data
- Parameters:
location (
Point_2) – location of pointdata (
dict) – attached data to point
- class discopygal.solvers_infra.Robot(start, end, data=None)¶
Bases:
objectAbstact class that represents the notion of a robot in a scene. Reference point is always the origin of the given geometry.
- Parameters:
- static from_dict(d)¶
Load json dict to object
- Parameters:
d (
dict) – dict representing json export
- to_dict()¶
Convert current object to json dict
- Returns:
dict representing json export
- Return type:
dict
- class discopygal.solvers_infra.RobotDisc(radius, start, end, data=None)¶
Bases:
RobotA disc robot. Its geometry is defined by its radius.
- Parameters:
- static from_dict(d)¶
Load json dict to object
- Parameters:
d (
dict) – dict representing json export
- to_dict()¶
Convert current object to json dict
- Returns:
dict representing json export
- Return type:
dict
- class discopygal.solvers_infra.RobotPolygon(poly, start, end, data=None)¶
Bases:
RobotA polygonal robot. Its geometry is given as a CGAL 2D polygon.
- Parameters:
- static from_dict(d)¶
Load json dict to object
- Parameters:
d (
dict) – dict representing json export
- to_dict()¶
Convert current object to json dict
- Returns:
dict representing json export
- Return type:
dict
- class discopygal.solvers_infra.RobotRod(length, start, end, data=None)¶
Bases:
RobotA rod robot. Its geometry is defined by its length.
- Parameters:
length (
FT) – The length of the rod, as a CGAL field typestart ((
Point_2,FT)) – The start location and angle of the robot, as a tuple of CGAL point and angleend ((
Point_2,FT)) – The end location and angle of the robot, as a tuple of CGAL point and angledata (
object) – Any metadata appended to the robot (could be None)
- static from_dict(d)¶
Load json dict to object
- Parameters:
d (
dict) – dict representing json export
- to_dict()¶
Convert current object to json dict
- Returns:
dict representing json export
- Return type:
dict
- class discopygal.solvers_infra.Scene(obstacles: list[Obstacle] = None, robots: list[Robot] = None, metadata: dict = None)¶
Bases:
objectThe notion of “scene” in DiscoPygal, which is the setting where we conduct motion planning. A scene has robots that can move inside it, and obstacles. Also the scene can have any metadata, saved as a dictionary.
- Parameters:
JSON Serialization Format:
Scenes are serialized to JSON with the following structure:
{ "__class__": "Scene", "obstacles": [ { "__class__": "ObstacleDisc", "location": [x, y], "radius": float_value, "data": { "color": "HSV h,s,v", "name": "obstacle_name", ... } }, { "__class__": "ObstaclePolygon", "poly": [[x1, y1], [x2, y2], ...], "data": {...} }, ... ], "robots": [ { "__class__": "RobotDisc", "radius": float_value, "start": [x, y], "end": [x, y], "data": { "color": "HSV h,s,v", "name": "robot_name", ... } }, { "__class__": "RobotRod", "length": float_value, "start": [[x, y], angle], "end": [[x, y], angle], "data": {...} }, { "__class__": "RobotPolygon", "poly": [[x1, y1], [x2, y2], ...], "start": [x, y], "end": [x, y], "data": {...} }, ... ], "metadata": { "version": "version_string", "solvers": "SolverName1, SolverName2", "scene_details": "Scene description", ... } }
Serialization Process:
Use
to_dict()to convert a Scene object to a dictionary suitable for JSON exportUse
from_dict()to reconstruct a Scene object from a dictionary (loaded from JSON)Use
from_file()to load a Scene directly from a JSON file
Key Points:
Each object (obstacle/robot) has a
"__class__"field indicating its typeAll coordinates are stored as [x, y] coordinate pairs (floats)
Rod robots store start/end as [[x, y], angle] tuples
The
datafield stores metadata like color, name, and custom user-defined valuesScene-level metadata is preserved in the
metadatadictionary
- add_obstacle(obstacle: Obstacle)¶
Add a obstacle to the scene
- Parameters:
obstacle (
Obstacle) – obstacle to add
- calc_max_robot_size() FT¶
Return the size of the largest robot in the scene For RobotDisc the is it’s diameter For RobotRod the size is it’s length
- create_single_robot_scene(robot: Robot) Scene¶
Create from the current a scene a new scene containing only the given robot. This means it creates a scene with the original obstacles and only the given robot
- static from_dict(d: dict) Scene¶
Load json dict to object
- Parameters:
d (
dict) – dict representing json export- Returns:
A scene object build from the given dict
- Return type:
- static from_file(scene_path: str) Scene¶
Load scene from json file
- Parameters:
scene_path (
str) – Path to scene json file- Returns:
A scene object build from the given file
- Return type:
- remove_obstacle(obstacle: Obstacle)¶
Remove a obstacle from the scene
- Parameters:
obstacle (
Obstacle) – obstacle to remove
- remove_robot(robot: Robot)¶
Remove a robot from the scene
- Parameters:
robot (
Robot) – Robot to remove
- to_dict() dict¶
Convert current object to json dict
- Returns:
dict representing json export
- Return type:
dict
- class discopygal.solvers_infra.SceneDrawer(gui, scene)¶
Bases:
objectObject for lookup tables and drawing scene objects
- Parameters:
gui (
discopygal.gui.gui.GUI) – the given guiscene (
Scene) – the given scene to draw
- clear_scene()¶
Clear (only) the DiscoPygal scene objects from the GUI
- deselect_entity(entity)¶
- draw_obstacle(obstacle, color_select=False)¶
Draw a single obstacle to the scene You can affect its color by having the data of the obstacle as a dict, and having “color” value (with a string confining to gui.gui.color).
- Parameters:
obstacle (
Obstacle) – obstacle to drawcolor_select (
bool) – if true override color to select color
- draw_robot(robot, color_select=False)¶
Draw a single robot to the scene You can affect its color by having the data of the robot as a dict, and having “color” value (with a string confining to gui.gui.color).
- Parameters:
obstacle (
Robot) – robot to drawcolor_select (
bool) – if true override color to select color
- draw_scene()¶
Draw the scene to the selected GUI
- select_entity(entity)¶
- discopygal.solvers_infra.load_object_from_dict(d)¶
Load a seriallized object from a dict In order for this to work, the dict should have a “__class__” property, which is equal to the exact python name of the class
- Parameters:
d (
dict) – dict describing an object- Returns:
the serialized object
- Return type:
object