gcode_reader.emulate.additive_part¶
Classes¶
Represents an additively manufactured part, the result of an operation. |
|
The cross-sectional properties of an extruded material |
|
Generic enumeration. |
|
Collection of segments forming a continuous extrusion path |
|
A linear movement containing extruded material |
Module Contents¶
- class gcode_reader.emulate.additive_part.AdditivePart[source]¶
Represents an additively manufactured part, the result of an operation.
- operation¶
The source operation whose process data describes the toolpath.
- dataframe¶
A per-deposition-segment summary DataFrame. Each row represents one continuous deposition or travel move, with columns for elapsed time, distance, start/end process-data indices, and layer annotations. Required columns are validated on construction.
- bead¶
The cross-sectional bead model used for volume, mass, and inertia calculations.
- layer_normal¶
A unit vector (x, y, z) normal to the build plane, used to partition process data into discrete layers.
- calc_center_of_gravity(centroids_masses=None, use_process_data=True)[source]¶
Calculates the center of gravity of the part.
- Parameters:
centroids_masses (np.ndarray, optional) – An (N, 4) array of [cx, cy, cz, mass] rows as returned by
_calc_segment_centroids_masses(). Pass a pre-computed value to avoid redundant computation when calling multiple physics methods. If None, the array is computed internally.use_process_data (bool) – Forwarded to
_calc_segment_centroids_masses()whencentroids_massesis None. See that method for details.
- Returns:
- A 3-element array [x, y, z] representing the center of
gravity, or an empty (0, 3) array if the part has no mass.
- Return type:
np.ndarray
- calc_deposition_bounds()[source]¶
Calculates the axis-aligned bounding box of all deposition locations in all layers. :returns: A nested tuple of ((min_x, min_y, min_z), (max_x, max_y, max_z)). If there are no locations, returns None. :rtype: Tuple
- calc_moment_of_inertia(centroids_masses=None, use_process_data=True)[source]¶
Calculates the moment of inertia of the part about its center of gravity.
Uses a point-mass approximation: each deposition segment is treated as a point mass located at its centroid. Rotational inertia of individual segments about their own axes is not included.
- Parameters:
centroids_masses (np.ndarray, optional) – An (N, 4) array of [cx, cy, cz, mass] rows as returned by
_calc_segment_centroids_masses(). Pass a pre-computed value to avoid redundant computation when calling multiple physics methods. If None, the array is computed internally.use_process_data (bool) – Forwarded to
_calc_segment_centroids_masses()whencentroids_massesis None. See that method for details.
- Returns:
- A 3x3 inertia tensor. Returns a zero matrix if the part
has no mass.
- Return type:
np.ndarray
- classmethod from_operation(operation: gcode_reader.emulate.operations.AdditiveOperation, bead: Bead, layer_normal: Tuple[float, float, float] = None)[source]¶
Creates an AdditivePart from an operation.
- Parameters:
operation (AdditiveOperation) – An emulated operation containing process data.
bead (Bead) – The geometric bead model to apply to all extruded filaments.
layer_normal (Tuple) – The constant plane normal direction to identify layers.
- Returns:
A new instance containing the structured layers.
- Return type:
- Raises:
Warning – If
operationhas not been processed by a Machine.
- classmethod from_process_data(process_data: List[gcode_reader.emulate.operations.AdditiveProcessData], bead: Bead, layer_normal: Tuple[float, float, float] = None)[source]¶
Creates an AdditivePart from a list of granular process data.
- Parameters:
process_data (List[AdditiveProcessData]) – A list of data objects, where each represents a discrete step in the process.
bead (Bead) – The geometric bead model to apply to all extruded filaments.
layer_normal (Tuple[float, float, float]) – The constant plane normal direction to identify layers.
- Returns:
A new instance containing the structured layers.
- Return type:
- Raises:
TypeError – If process_data is not a list-like object.
ValueError – If bead is not a valid Bead instance.
- generate_deposition_paths()[source]¶
Generates deposition paths (filaments) as lists of coordinates.
- Yields:
list –
- A list of coordinate tuples [(x, y, z), …] representing
a single, continuous deposition path.
- generate_layers(layer_range: tuple = None)[source]¶
Generates Layer objects for the part, one by one.
- Parameters:
layer_range (tuple, optional) – A (min, max) tuple of layer indices to filter which layers are generated. Defaults to all layers if None.
- Yields:
Layer – A Layer object containing all filaments for a given layer.
- get_statistics()[source]¶
Compiles a dictionary of statistics describing the part.
- Raises:
ValueError – If self.operation is not an AdditiveOperation.
- Returns:
A dictionary containing the part’s statistics.
- Return type:
- dataframe: pandas.DataFrame¶
- property deposition_dataframe¶
Filters the part dataframe to rows where material is being deposited.
- Returns:
- A subset of
self.dataframewhereis_depositing is True, or None if
self.dataframeis None.
- A subset of
- Return type:
pd.DataFrame
- property deposition_length¶
Calculates the total length of all deposited material.
- property mass¶
Calculates the total mass of deposited material.
- property n_layers¶
Calculates the total number of layers.
- property volume¶
Calculates the total volume of deposited material.
- class gcode_reader.emulate.additive_part.Bead[source]¶
The cross-sectional properties of an extruded material
- property area¶
- class gcode_reader.emulate.additive_part.BeadShape[source]¶
Bases:
enum.EnumGeneric enumeration.
Derive from this class to define new enumerations.
- RECTANGLE = 'rectangle'¶
- ROUNDED_RECTANGLE = 'rounded_rectangle'¶
- class gcode_reader.emulate.additive_part.Filament[source]¶
Collection of segments forming a continuous extrusion path
- calc_center_of_gravity()[source]¶
Calculates the center of gravity of the filament. :returns: A 3-element array representing the center of gravity. :rtype: np.ndarray
- classmethod from_process_data(process_data: List[gcode_reader.emulate.operations.AdditiveProcessData], bead: Bead)[source]¶
Creates a Filament from a list of process data points.
- Parameters:
process_data (List[AdditiveProcessData]) – A list containing sequential process data.
bead (Bead) – The bead model to apply to each generated segment.
- Returns:
A new Filament instance.
- Return type:
- classmethod from_process_dataframe(df: pandas.DataFrame, bead: Bead)[source]¶
Creates a Filament from a DataFrame of process data points.
- Parameters:
df (pd.DataFrame) – A DataFrame containing sequential process data, with columns matching the AdditiveProcessData schema.
bead (Bead) – The bead model to apply to each generated segment.
- Returns:
A new Filament instance.
- Return type:
- Raises:
- property deposition_time¶
Calculates the total deposition time of all segments in the filament.
- Returns:
The cumulative deposition time for all segments.
- Return type:
- property length¶
Calculates the total length of all segments in the filament.
- Returns:
The total length of all segments.
- Return type:
- property locations¶
Get all segment locations as an array.
- Returns:
An array of shape (N, 3) containing the start and end locations of each segment.
- Return type:
np.ndarray
- property mass¶
Calculates the total mass of all segments in the filament.
- Returns:
The total mass of all segments.
- Return type:
- class gcode_reader.emulate.additive_part.Layer[source]¶
- calc_bounds()[source]¶
Calculates the axis-aligned bounding box of all filament locations.
- Returns:
A nested tuple of ((min_x, min_y, min_z), (max_x, max_y, max_z)). If there are no locations, returns None.
- Return type:
Tuple
- calc_center_of_gravity()[source]¶
Calculates the center of gravity of the layer.
- Returns:
A 3-element array representing the center of gravity.
- Return type:
np.ndarray
- filament_is_on_layer(filament: Filament, tol: float = ZERO_TOLERANCE) bool[source]¶
Checks if all points in a filament are on the layer within a given tolerance. :param filament: The filament to check. :type filament: Filament :param tol: The tolerance for determining if the filament locations are on the layer. :type tol: float, optional :param Returns: bool: True if all points in the filament are on the layer within the tolerance, False otherwise.
- property deposition_time¶
Calculates the cumulative deposition time of all filaments in the layer.
- property filament_locations: numpy.ndarray¶
Concatenates all filament locations into a single NumPy array.
- Returns:
- An (N, 3) array of all points. If there are no
points, returns an empty array with shape (0, 3)
- Return type:
np.ndarray
- property length¶
Calculates the cumulative length of all filaments in the layer.
- property mass¶
Calculates the cumulative mass of all filaments in the layer.
- property volume¶
Calculates the cumulative volume of all filaments in the layer.