Model Module
This model module contains classes for creating a scene with nodes and edges.
- class ModelSphere(geometry: Sphere, depiction: Depiction)[source]
Sphere shaped node in a scene.
Used as node in a scene.
Create a sphere shaped node in a scene.
- class ModelCylinder(geometry: Cylinder, depiction: Depiction)[source]
Cylinder shaped node in a scene.
Used as edge between two nodes.
Create a cylinder shaped node in a scene.
- class ModelWire(geometry: Line3D, color: Color, width: float, opacity: float)[source]
Wire shaped node in a scene.
Used as edge between two nodes.
Create a wire shaped node in a scene.
- get_node_polygon_vertices(this: ModelSphere | ModelCylinder | ModelWire, others: List[ModelSphere | ModelCylinder | ModelWire], resolution: int, focal_length: float | None = None) List[Point2D][source]
Get the vertices of the polygon that represents the visible part of the node.
- Parameters:
this (ty.Union[ModelSphere, ModelCylinder, ModelWire]) – The node to get the vertices of.
others (ty.List[ty.Union[ModelSphere, ModelCylinder, ModelWire]]) – The other nodes in the scene.
resolution (int) – The resolution of the polygon.
focal_length (ty.Optional[float]) – The scaling factor of the polygon.
- Returns:
The vertices of the polygon.
- Return type:
ty.List[Point2D]
- prepare_nodes_for_intersecting(nodes_to_sort: List[ModelSphere | ModelCylinder | ModelWire], include_spheres: bool, include_cylinders: bool, include_wires: bool, rotation_over_x_axis: float = 0.0, rotation_over_y_axis: float = 0.0, rotation_over_z_axis: float = 0.0, scale: float | None = None) List[ModelSphere | ModelCylinder | ModelWire][source]
Filter, rotate, and scale nodes based on what to include in the scene.
- Parameters:
nodes_to_sort (ty.List[ty.Union[ModelSphere, ModelCylinder, ModelWire]]) – The nodes to filter.
include_spheres (bool) – Whether to include spheres in the scene.
include_cylinders (bool) – Whether to include cylinders in the scene.
include_wires (bool) – Whether to include wires in the scene.
rotation_over_x_axis (float) – The rotation over the x-axis.
rotation_over_y_axis (float) – The rotation over the y-axis.
rotation_over_z_axis (float) – The rotation over the z-axis.
scale (ty.Optional[float]) – The scale of the scene.
- Returns:
The filtered nodes.
- Return type:
ty.List[ty.Union[ModelSphere, ModelCylinder, ModelWire]]
- create_fill(node: ModelSphere | ModelCylinder | ModelWire, reference: str) Fill | None[source]
Create a fill for a node.
- Parameters:
node (ty.Union[ModelSphere, ModelCylinder, ModelWire]) – The node to create a fill for.
reference (str) – The reference of the fill.
- Returns:
The fill.
- Return type:
ty.Optional[Fill]
- Raises:
AssertionError – If the geometry of the node is not appropriate for the node type.
- calculate_intersecting_nodes(node: ModelSphere | ModelCylinder | ModelWire, other_nodes: List[ModelSphere | ModelCylinder | ModelWire], calculate_sphere_sphere_intersections: bool, calculate_sphere_cylinder_intersections: bool, calculate_cylinder_sphere_intersections: bool, calculate_cylinder_cylinder_intersections: bool, filter_nodes_for_intersecting: bool) List[ModelSphere | ModelCylinder | ModelWire][source]
Calculate which of the previous nodes intersect with the current node.
- Parameters:
node (ty.Union[ModelSphere, ModelCylinder, ModelWire]) – The current node.
other_nodes (ty.List[ty.Union[ModelSphere, ModelCylinder, ModelWire]]) – The previous nodes.
calculate_sphere_sphere_intersections (bool) – Whether to calculate intersections between spheres.
calculate_sphere_cylinder_intersections (bool) – Whether to calculate intersections between spheres and cylinders.
calculate_cylinder_sphere_intersections (bool) – Whether to calculate intersections between cylinders and spheres.
calculate_cylinder_cylinder_intersections (bool) – Whether to calculate intersections between cylinders.
filter_nodes_for_intersecting (bool) – Whether to filter nodes for intersecting nodes.
- Returns:
The previous nodes that intersect with the current node.
- Return type:
ty.List[ty.Union[ModelSphere, ModelCylinder, ModelWire]]
- class Scene(nodes: List[ModelSphere | ModelCylinder | ModelWire] | None = None)[source]
A scene contains a list of nodes.
Create a scene with nodes.
- Parameters:
nodes (ty.List[ty.Union[ModelSphere, ModelCylinder, ModelWire]]) – The nodes in the scene.
- add_node(node: ModelSphere | ModelCylinder | ModelWire) None[source]
Add a node to the scene.
- Parameters:
node (ty.Union[ModelSphere, ModelCylinder, ModelWire]) – The node to add.
- calculate_view_box(points: List[Point2D], margin: float) ViewBox[source]
Calculate the view box of the scene.
- draw(resolution: int, window: Tuple[float, float] | None = None, view_box: ViewBox | None = None, rotation_over_x_axis: float = 0.0, rotation_over_y_axis: float = 0.0, rotation_over_z_axis: float = 0.0, include_spheres: bool = True, include_cylinders: bool = True, include_wires: bool = True, calculate_sphere_sphere_intersections: bool = True, calculate_sphere_cylinder_intersections: bool = True, calculate_cylinder_sphere_intersections: bool = True, calculate_cylinder_cylinder_intersections: bool = True, filter_nodes_for_intersecting: bool = True, scale: float = 1.0, focal_length: float | None = None) Svg[source]
Draw the scene.
- Parameters:
resolution (int) – The resolution of the scene.
window (ty.Optional[ty.Tuple[float, float]]) – The window of the scene.
view_box (ty.Optional[ViewBox]) – The view box of the scene.
rotation_over_x_axis (float) – The rotation over the x-axis.
rotation_over_y_axis (float) – The rotation over the y-axis.
rotation_over_z_axis (float) – The rotation over the z-axis.
include_spheres (bool) – Whether to include spheres in the scene.
include_cylinders (bool) – Whether to include cylinders in the scene.
include_wires (bool) – Whether to include wires in the scene.
calculate_sphere_sphere_intersections (bool) – Whether to calculate intersections between spheres.
calculate_sphere_cylinder_intersections (bool) – Whether to calculate intersections between spheres and cylinders.
calculate_cylinder_sphere_intersections (bool) – Whether to calculate intersections between cylinders and spheres.
calculate_cylinder_cylinder_intersections (bool) – Whether to calculate intersections between cylinders.
filter_nodes_for_intersecting (bool) – Whether to filter nodes for intersecting nodes.
scale (float) – The scale of the scene.
focal_length (ty.Optional[float]) – The focal length of the depiction. If None, the focal length is calculated based on the dimensions of the scene.
- Returns:
The scene as Svg.
- Return type: