gcoordinator package
Submodules
gcoordinator.gcode_generator module
gcoordinator.gui_export module
- gcoordinator.gui_export.gui_export(full_object)[source]
Exports the given object to a pickle file. This method is called from the GUI editor. The generated full_object is saved as a pickle file in the buffer directory for processing in the G-coordinator (GUI).
- Parameters:
full_object – A list of Path or PathList objects.
- Returns:
None
gcoordinator.infill_generator module
This module provides functions for generating infill paths for 3D printing.
Infill patterns fall into two categories with different generation strategies:
- Category 1 – Implicit surface (TPMS):
gyroid_infill, schwartz_p_infill Defined by a 3D equation f(X, Y, Z) = 0. The layer cross-section is obtained by extracting iso-contour lines of f sampled on the print-plane grid.
- Category 2 – Line pattern:
line_infill, grid_infill, triangle_infill Defined as families of parallel straight lines. Each line is clipped against the boundary polygon using a scanline algorithm, guaranteeing that every returned Path is a true straight segment.
- class gcoordinator.infill_generator.Infill[source]
Bases:
objectNamespace class for infill pattern generation, mirroring the Transform API.
Usage:
import gcoordinator as gc import numpy as np infill = gc.Infill.gyroid(wall, infill_distance=2) infill = gc.Infill.schwartz_p(wall, infill_distance=2) infill = gc.Infill.line(wall, infill_distance=2, angle=np.pi/4) infill = gc.Infill.grid(wall, infill_distance=2) infill = gc.Infill.triangle(wall, infill_distance=2) # Custom implicit surface: def my_equation(X, Y, z_height): p = 2 * np.pi / 3.0 return np.sin(X * p) + np.cos(Y * p) * np.sin(z_height * p) infill = gc.Infill.custom_implicit(wall, my_equation)
- static custom_implicit(path, equation_fn, resolution=0.4) PathList[source]
Infill defined by a user-supplied implicit surface equation.
The zero iso-contour of
equation_fnon the print plane becomes the infill pattern, clipped to the boundary.- Parameters:
equation_fn (callable) – A function with signature
(X: np.ndarray, Y: np.ndarray, z_height: float) -> np.ndarraythat returns the scalar field evaluated on the meshgrid. The iso-contour at level 0 is used as the infill.resolution (float) – Grid sampling step in mm. Smaller values give finer contours but take longer. Default: 0.4.
- Returns:
Generated infill paths.
- Return type:
Example:
import numpy as np import gcoordinator as gc def lidinoid(X, Y, z): p = 2 * np.pi / 3.0 return ( np.sin(2*X*p) * np.cos(Y*p) * np.sin(z*p) + np.sin(2*Y*p) * np.cos(z*p) * np.sin(X*p) + np.sin(2*z*p) * np.cos(X*p) * np.sin(Y*p) - 0.3 ) infill = gc.Infill.custom_implicit(wall, lidinoid, resolution=0.3)
- static gyroid(path, infill_distance=1, value=0) PathList[source]
Gyroid (TPMS) infill. Pattern varies with layer height.
- static line(path, infill_distance=1, angle=0.7853981633974483) PathList[source]
Parallel-line infill at a given angle.
- static schwartz_p(path, infill_distance=1, value=0) PathList[source]
Schwartz P (TPMS) infill. Pattern varies with layer height.
gcoordinator.path_generator module
- class gcoordinator.path_generator.Path(x, y, z, rot=None, tilt=None, **kwargs)[source]
Bases:
objectA class representing a path in 3D space.
Attributes:
- xnumpy.ndarray
The x-coordinates of the path points.
- ynumpy.ndarray
The y-coordinates of the path points.
- znumpy.ndarray
The z-coordinates of the path points.
- rotnumpy.ndarray
The rotation at each point in the path, in radians.
- tiltnumpy.ndarray
The tilt at each point in the path, in radians.
- kinematicsstr
The kinematics of the printer. One of ‘Cartesian’, ‘BedRotate’, ‘BedTiltBC’, or ‘NozzleTilt’.
- coordsnumpy.ndarray
A 2D array of shape (n_points, 3) containing the (x, y, z) coordinates of the path points.
- normsnumpy.ndarray
A 2D array of shape (n_points, 3) containing the (x, y, z) components of the normals at each point in the path.
- centernumpy.ndarray
The center of the path, calculated as the mean of the path points.
- start_coordnumpy.ndarray
The coordinates of the first point in the path.
- end_coordnumpy.ndarray
The coordinates of the last point in the path.
- nozzle_diameterfloat
The diameter of the printer nozzle, in millimeters.
- filament_diameterfloat
The diameter of the printer filament, in millimeters.
- layer_heightfloat
The height of each printed layer, in millimeters.
- print_speedfloat
The speed at which the printer extrudes filament, in millimeters per second.
- travel_speedfloat
The speed at which the printer moves between points, in millimeters per second.
- x_originfloat
The x-coordinate of the origin of the printer’s coordinate system, in millimeters.
- y_originfloat
The y-coordinate of the origin of the printer’s coordinate system, in millimeters.
- fan_speedfloat
The speed of the printer’s cooling fan, as a percentage of its maximum speed.
- nozzle_temperaturefloat
The temperature of the printer nozzle, in degrees Celsius.
- bed_temperaturefloat
The temperature of the printer bed, in degrees Celsius.
- retractionbool
Whether to retract the filament between moves.
- retraction_distancefloat
The distance by which to retract the filament, in millimeters.
- unretraction_distancefloat
The distance by which to unretract the filament, in millimeters.
- z_hopbool
Whether to perform a Z-hop between moves.
- z_hop_distancefloat
The distance by which to Z-hop, in millimeters.
- extrusion_multiplierfloat
A multiplier for the amount of filament extruded, used to adjust for filament diameter variations.
- segment_extrusion_multipliernumpy.ndarray or None
Per-segment multiplier for filament extrusion. An array of the same length as x and y. For segment i (from point i to i+1), the value at index i is used. When both extrusion_multiplier and segment_extrusion_multiplier are specified, segment_extrusion_multiplier takes precedence.
- segment_print_speednumpy.ndarray or None
Per-segment print speed. An array of the same length as x and y. For segment i (from point i to i+1), the value at index i is used. When both print_speed and segment_print_speed are specified, segment_print_speed takes precedence.
Methods:
- apply_default_settings()
Applies the default settings to the object.
- apply_optional_settings()
Applies the optional settings to the object.
- class gcoordinator.path_generator.PathList(paths)[source]
Bases:
objectA class representing a list of paths. This class has the same attributes of Path class. The attributes are applied to all paths in the PathList.
- paths
A list of Path objects.
- Type:
list
- all attributes of Path class
gcoordinator.path_transformer module
- class gcoordinator.path_transformer.Transform[source]
Bases:
object- static move(arg, x=0.0, y=0.0, z=0.0, roll=0.0, pitch=0.0, yaw=0.0)[source]
Moves a Path or PathList object in 3D space by the specified amounts of translation and rotation.
- Parameters:
arg (Path or PathList) – The Path or PathList object to be transformed.
x (float) – The amount of translation along the x-axis.
y (float) – The amount of translation along the y-axis.
z (float) – The amount of translation along the z-axis.
roll (float) – The amount of rotation around the x-axis, in radians.
pitch (float) – The amount of rotation around the y-axis, in radians.
yaw (float) – The amount of rotation around the z-axis, in radians.
- Returns:
The transformed Path or PathList object.
- Return type:
- static move_path(path, x=0.0, y=0.0, z=0.0, roll=0.0, pitch=0.0, yaw=0.0)[source]
Moves a given path by a specified translation vector and rotation angles.
- Parameters:
path (Path) – The path to be moved.
x (float) – The x-component of the translation vector. Defaults to 0.
y (float) – The y-component of the translation vector. Defaults to 0.
z (float) – The z-component of the translation vector. Defaults to 0.
roll (float) – The roll angle in radians. Defaults to 0.
pitch (float) – The pitch angle in radians. Defaults to 0.
yaw (float) – The yaw angle in radians. Defaults to 0.
- Returns:
The moved path.
- Return type:
- static move_pathlist(pathlist, x=0, y=0, z=0, roll=0, pitch=0, yaw=0)[source]
Moves a list of paths in 3D space according to the specified translation and rotation values.
- Parameters:
pathlist (PathList) – The list of paths to be transformed.
x (float) – The amount to translate the paths along the x-axis.
y (float) – The amount to translate the paths along the y-axis.
z (float) – The amount to translate the paths along the z-axis.
roll (float) – The amount to rotate the paths around the x-axis.
pitch (float) – The amount to rotate the paths around the y-axis.
yaw (float) – The amount to rotate the paths around the z-axis.
- Returns:
A new PathList instance containing the transformed paths.
- Return type:
- static offset(path, offset_distance)[source]
Computes the offset polygon of a given path by moving each vertex along its normal vector by the offset_distance.
- static stretch(path, x_stretch_ratio, y_stretch_ratio, z_stretch_ratio)[source]
Stretches a given path by the specified ratios along each axis.
- Parameters:
path (Path) – The path to be stretched.
x_stretch_ratio (float) – The ratio by which to stretch the path along the x-axis.
y_stretch_ratio (float) – The ratio by which to stretch the path along the y-axis.
z_stretch_ratio (float) – The ratio by which to stretch the path along the z-axis.
- Returns:
The stretched path.
- Return type:
gcoordinator.settings module
- gcoordinator.settings.get_default_settings(settings)[source]
This function loads the default settings for a 3D printer from a JSON file and retunrs them as a dictionary.
The following constants are defined: - ‘nozzle_diameter’ : the diameter of the printer’s nozzle in millimeters - ‘layer_height’ : the height of each printed layer in millimeters - ‘filament_diameter’ : the diameter of the filament used by the printer in millimeters - ‘print_speed’ : the speed at which the printer extrudes filament during printing in millimeters per minute - ‘travel_speed’ : the speed at which the printer moves between printing locations in millimeters per minute - ‘x_origin’ : the X coordinate of the printer’s origin in millimeters - ‘y_origin’ : the Y coordinate of the printer’s origin in millimeters - ‘fan_speed’ : the speed of the printer’s fan in percent of maximum speed - ‘nozzle_temperature’ : the temperature of the printer’s nozzle in degrees Celsius - ‘bed_temperature’ : the temperature of the printer’s bed in degrees Celsius - ‘retraction’ : a boolean indicating whether the printer should retract filament during travel moves - ‘retraction_distance’ : the distance by which the printer should retract filament during travel moves in millimeters - ‘unretraction_distance’: the distance by which the printer should unretract filament after travel moves in millimeters - ‘z_hop’ : a boolean indicating whether the printer should raise the nozzle during travel moves - ‘z_hop_distance’ : the height by which the printer should raise the nozzle during travel moves in millimeters - ‘extrusion_multiplier’ : a scaling factor for the amount of filament extruded by the printer
- gcoordinator.settings.load_settings(config_path)[source]
Loads the settings from a JSON config file. The format of the JSON file is as follows: https://gcoordinator.readthedocs.io/en/latest/tutorials/tutorial_4.html
- Parameters:
config_path (str) – The path to the JSON config file.
- Returns:
None
- Raises:
json.JSONDecodeError – If the config file has an invalid JSON format.