gcode_reader.emulate.additive_part ================================== .. py:module:: gcode_reader.emulate.additive_part Classes ------- .. autoapisummary:: gcode_reader.emulate.additive_part.AdditivePart gcode_reader.emulate.additive_part.Bead gcode_reader.emulate.additive_part.BeadShape gcode_reader.emulate.additive_part.Filament gcode_reader.emulate.additive_part.Layer gcode_reader.emulate.additive_part.Segment Module Contents --------------- .. py:class:: AdditivePart Represents an additively manufactured part, the result of an operation. .. attribute:: operation The source operation whose process data describes the toolpath. .. attribute:: 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. .. attribute:: bead The cross-sectional bead model used for volume, mass, and inertia calculations. .. attribute:: layer_normal A unit vector (x, y, z) normal to the build plane, used to partition process data into discrete layers. .. py:method:: calc_center_of_gravity(centroids_masses=None, use_process_data=True) Calculates the center of gravity of the part. :param centroids_masses: 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. :type centroids_masses: np.ndarray, optional :param use_process_data: Forwarded to ``_calc_segment_centroids_masses()`` when ``centroids_masses`` is None. See that method for details. :type use_process_data: bool :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. :rtype: np.ndarray .. py:method:: calc_deposition_bounds() 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 .. py:method:: calc_moment_of_inertia(centroids_masses=None, use_process_data=True) 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. :param centroids_masses: 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. :type centroids_masses: np.ndarray, optional :param use_process_data: Forwarded to ``_calc_segment_centroids_masses()`` when ``centroids_masses`` is None. See that method for details. :type use_process_data: bool :returns: A 3x3 inertia tensor. Returns a zero matrix if the part has no mass. :rtype: np.ndarray .. py:method:: from_operation(operation: gcode_reader.emulate.operations.AdditiveOperation, bead: Bead, layer_normal: Tuple[float, float, float] = None) :classmethod: Creates an AdditivePart from an operation. :param operation: An emulated operation containing process data. :type operation: AdditiveOperation :param bead: The geometric bead model to apply to all extruded filaments. :type bead: Bead :param layer_normal: The constant plane normal direction to identify layers. :type layer_normal: Tuple :returns: A new instance containing the structured layers. :rtype: AdditivePart :raises Warning: If ``operation`` has not been processed by a Machine. .. py:method:: from_process_data(process_data: List[gcode_reader.emulate.operations.AdditiveProcessData], bead: Bead, layer_normal: Tuple[float, float, float] = None) :classmethod: Creates an AdditivePart from a list of granular process data. :param process_data: A list of data objects, where each represents a discrete step in the process. :type process_data: List[AdditiveProcessData] :param bead: The geometric bead model to apply to all extruded filaments. :type bead: Bead :param layer_normal: The constant plane normal direction to identify layers. :type layer_normal: Tuple[float, float, float] :returns: A new instance containing the structured layers. :rtype: AdditivePart :raises TypeError: If process_data is not a list-like object. :raises ValueError: If bead is not a valid Bead instance. .. py:method:: generate_deposition_paths() Generates deposition paths (filaments) as lists of coordinates. :Yields: *list* -- A list of coordinate tuples `[(x, y, z), ...]` representing a single, continuous deposition path. .. py:method:: generate_layers(layer_range: tuple = None) Generates Layer objects for the part, one by one. :param layer_range: A (min, max) tuple of layer indices to filter which layers are generated. Defaults to all layers if None. :type layer_range: tuple, optional :Yields: *Layer* -- A `Layer` object containing all filaments for a given layer. .. py:method:: get_statistics() 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. :rtype: dict .. py:attribute:: bead :type: Bead .. py:attribute:: dataframe :type: pandas.DataFrame .. py:property:: deposition_dataframe Filters the part dataframe to rows where material is being deposited. :returns: A subset of ``self.dataframe`` where ``is_depositing`` is True, or None if ``self.dataframe`` is None. :rtype: pd.DataFrame .. py:property:: deposition_length Calculates the total length of all deposited material. .. py:property:: deposition_times :type: dict Gets the total elapsed time per deposition movement. .. py:attribute:: layer_normal :type: Tuple[float, float, float] .. py:property:: layer_times :type: dict Gets the total elapsed time per layer (deposition and travel). .. py:property:: mass Calculates the total mass of deposited material. .. py:property:: n_layers Calculates the total number of layers. .. py:attribute:: operation :type: gcode_reader.emulate.operations.AdditiveOperation .. py:property:: volume Calculates the total volume of deposited material. .. py:class:: Bead The cross-sectional properties of an extruded material .. py:method:: from_area(area: float, density: 1000.0, aspect_ratio: float = 4) :classmethod: .. py:property:: area .. py:attribute:: density :type: float :value: 1000.0 .. py:attribute:: height :type: float :value: 1.0 .. py:attribute:: shape :type: BeadShape .. py:attribute:: width :type: float :value: 1.0 .. py:class:: BeadShape Bases: :py:obj:`enum.Enum` Generic enumeration. Derive from this class to define new enumerations. .. py:attribute:: RECTANGLE :value: 'rectangle' .. py:attribute:: ROUNDED_RECTANGLE :value: 'rounded_rectangle' .. py:class:: Filament Collection of segments forming a continuous extrusion path .. py:method:: calc_bounds() Calculates the axis-aligned bounding box of all segment locations. .. py:method:: calc_center_of_gravity() Calculates the center of gravity of the filament. :returns: A 3-element array representing the center of gravity. :rtype: np.ndarray .. py:method:: from_process_data(process_data: List[gcode_reader.emulate.operations.AdditiveProcessData], bead: Bead) :classmethod: Creates a Filament from a list of process data points. :param process_data: A list containing sequential process data. :type process_data: List[AdditiveProcessData] :param bead: The bead model to apply to each generated segment. :type bead: Bead :returns: A new Filament instance. :rtype: Filament .. py:method:: from_process_dataframe(df: pandas.DataFrame, bead: Bead) :classmethod: Creates a Filament from a DataFrame of process data points. :param df: A DataFrame containing sequential process data, with columns matching the AdditiveProcessData schema. :type df: pd.DataFrame :param bead: The bead model to apply to each generated segment. :type bead: Bead :returns: A new Filament instance. :rtype: Filament :raises TypeError: If input arguments are of the wrong type. :raises KeyError: If the DataFrame is missing required columns. .. py:property:: deposition_time Calculates the total deposition time of all segments in the filament. :returns: The cumulative deposition time for all segments. :rtype: float .. py:property:: length Calculates the total length of all segments in the filament. :returns: The total length of all segments. :rtype: float .. py: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. :rtype: np.ndarray .. py:property:: mass Calculates the total mass of all segments in the filament. :returns: The total mass of all segments. :rtype: float .. py:attribute:: segments :type: List[Segment] :value: [] .. py:property:: volume Calculates the total volume of all segments in the filament. :returns: The total volume of all segments. :rtype: float .. py:class:: Layer .. py:method:: calc_bounds() 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. :rtype: Tuple .. py:method:: calc_center_of_gravity() Calculates the center of gravity of the layer. :returns: A 3-element array representing the center of gravity. :rtype: np.ndarray .. py:method:: filament_is_on_layer(filament: Filament, tol: float = ZERO_TOLERANCE) -> bool 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. .. py:property:: deposition_time Calculates the cumulative deposition time of all filaments in the layer. .. py:property:: filament_locations :type: 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) :rtype: np.ndarray .. py:attribute:: filaments :type: List[Filament] :value: [] .. py:property:: length Calculates the cumulative length of all filaments in the layer. .. py:property:: mass Calculates the cumulative mass of all filaments in the layer. .. py:attribute:: plane_location :type: Tuple[float, float, float] :value: (0.0, 0.0, 0.0) .. py:attribute:: plane_normal :type: Tuple[float, float, float] :value: (0.0, 0.0, 1.0) .. py:attribute:: time :type: float :value: 0.0 .. py:property:: volume Calculates the cumulative volume of all filaments in the layer. .. py:class:: Segment A linear movement containing extruded material .. py:attribute:: bead :type: Bead .. py:property:: centroid .. py:property:: deposition_time .. py:attribute:: end_location :type: Tuple[float, float, float] .. py:attribute:: id :type: int :value: None .. py:property:: length .. py:property:: mass .. py:attribute:: process_data :type: gcode_reader.emulate.operations.AdditiveProcessData .. py:attribute:: start_location :type: Tuple[float, float, float] .. py:property:: volume