fabex.utilities.chunk_utils#
Fabex ‘chunk_utils.py’ © 2012 Vilem Novak
Functions#
|
Add Extra Points in Between for Chunks |
|
Add Extra Points in Between for Chunks. for Medial Axis Strategy only! |
|
Converts CAM path chunks into Shapely Polygon |
|
Sets the Depth of CAM path chunks |
|
|
|
Extend chunks with 5-axis cutter start and end points. |
|
Find the closest chunk to a given position. |
|
Checks CAM path chunks for Stability for Pencil path |
|
Prevent excluded CAM path chunks from being Processed |
|
Sample chunks along a specified axis based on provided paths and layers. |
|
Generate a sample path between two channels. |
|
Sample chunks of paths based on the provided parameters. |
|
Connects chunks that are close to each other without lifting, sampling |
|
Sort a list of chunks based on a specified strategy. |
|
Convert sampled chunks into a mesh path for a given optimization object. |
Module Contents#
- chunks_refine_threshold(chunks, distance, limitdistance)[source]#
Add Extra Points in Between for Chunks. for Medial Axis Strategy only!
- chunk_to_shapely(chunk)[source]#
Converts CAM path chunks into Shapely Polygon
This function takes a CAM path chunk, uses the chunk points to create a Shapely Polygon, and returns the Polygon.
- set_chunks_z(chunks, z)[source]#
Sets the Depth of CAM path chunks
This function takes a group of CAM path chunks, and a depth setting, creates copies of the chunks, assigns the depth value and then returns the copied chunks as a new list.
- extend_chunks_5_axis(chunks, o)[source]#
Extend chunks with 5-axis cutter start and end points.
This function modifies the provided chunks by appending calculated start and end points for a cutter based on the specified orientation and movement parameters. It determines the starting position of the cutter based on the machine’s settings and the object’s movement constraints. The function iterates through each point in the chunks and updates their start and end points accordingly.
- Parameters:
chunks (list) – A list of chunk objects that will be modified.
o (object) – An object containing movement and orientation data.
- get_closest_chunk(o, pos, chunks)[source]#
Find the closest chunk to a given position.
This function iterates through a list of chunks and determines which chunk is closest to the specified position. It checks if each chunk’s children are sorted before calculating the distance. The chunk with the minimum distance to the given position is returned.
- Parameters:
o – An object representing the origin point.
pos – A position to which the closest chunk is calculated.
chunks (list) – A list of chunk objects to evaluate.
- Returns:
- The closest chunk object to the specified position, or None if no valid
chunk is found.
- Return type:
Chunk
- chunks_coherency(chunks)[source]#
Checks CAM path chunks for Stability for Pencil path
This function checks if the vectors direction doesn’t change too quickly, if this happens it splits the chunk at that point, and if the change is too great the chunk will be deleted. This prevents the router/spindle from slowing down too much, but also means that some parts detected by cavity algorithm won’t be milled.
- limit_chunks(chunks, o, force=False)[source]#
Prevent excluded CAM path chunks from being Processed
This function checks if there are limitations on the area to be milled, like limit curves, and rebuilds the chunk list without the excluded chunks.
- async sample_chunks_n_axis(o, pathSamples, layers)[source]#
Sample chunks along a specified axis based on provided paths and layers.
This function processes a set of path samples and organizes them into chunks according to specified layers. It prepares the collision world if necessary, updates the cutter’s rotation based on the path samples, and handles the sampling of points along the paths. The function also manages the relationships between the sampled points and their respective layers, ensuring that the correct points are added to each chunk. The resulting chunks can be used for further processing in a 3D environment.
- Parameters:
o (object) – An object containing properties such as min/max coordinates, cutter shape, and other relevant parameters.
pathSamples (list) – A list of path samples, each containing start points, end points, and rotations.
layers (list) – A list of layer definitions that specify the boundaries for sampling.
- Returns:
A list of sampled chunks organized by layers.
- Return type:
list
- sample_path_low(o, ch1, ch2, dosample)[source]#
Generate a sample path between two channels.
This function computes a series of points that form a path between two given channels. It calculates the direction vector from the end of the first channel to the start of the second channel and generates points along this vector up to a specified distance. If sampling is enabled, it modifies the z-coordinate of the generated points based on the cutter shape or image sampling, ensuring that the path accounts for any obstacles or features in the environment.
- Parameters:
o – An object containing optimization parameters and properties related to the path generation.
ch1 – The first channel object, which provides a point for the starting location of the path.
ch2 – The second channel object, which provides a point for the ending location of the path.
dosample (bool) – A flag indicating whether to perform sampling along the generated path.
- Returns:
An object representing the generated path points.
- Return type:
CamPathChunk
- async sample_chunks(o, pathSamples, layers)[source]#
Sample chunks of paths based on the provided parameters.
This function processes the given path samples and layers to generate chunks of points that represent the sampled paths. It takes into account various optimization settings and strategies to determine how the points are sampled and organized into layers. The function handles different scenarios based on the object’s properties and the specified layers, ensuring that the resulting chunks are correctly structured for further processing.
- Parameters:
o (object) – An object containing various properties and settings related to the sampling process.
pathSamples (list) – A list of path samples to be processed.
layers (list) – A list of layers defining the z-coordinate ranges for sampling.
- Returns:
- A list of sampled chunks, each containing points that represent
the sampled paths.
- Return type:
list
- async connect_chunks_low(chunks, o)[source]#
Connects chunks that are close to each other without lifting, sampling them ‘low’.
This function processes a list of chunks and connects those that are within a specified distance based on the provided options. It takes into account various strategies for connecting the chunks, including ‘CARVE’, ‘PENCIL’, and ‘MEDIAL_AXIS’, and adjusts the merging distance accordingly. The function also handles specific movement settings, such as whether to stay low or to merge distances, and may resample chunks if certain optimization conditions are met.
- Parameters:
chunks (list) – A list of chunk objects to be connected.
o (object) – An options object containing movement and strategy parameters.
- Returns:
A list of connected chunk objects.
- Return type:
list
- async sort_chunks(chunks, o, last_pos=None)[source]#
Sort a list of chunks based on a specified strategy.
This function sorts a list of chunks according to the provided options and the current position. It utilizes a recursive approach to find the closest chunk to the current position and adapts its distance if it has not been sorted before. The function also handles progress updates asynchronously and adjusts the recursion limit to accommodate deep recursion scenarios.
- Parameters:
chunks (list) – A list of chunk objects to be sorted.
o (object) – An options object that contains sorting strategy and other parameters.
last_pos (tuple?) – The last known position as a tuple of coordinates. Defaults to None, which initializes the position to (0, 0, 0).
- Returns:
A sorted list of chunk objects.
- Return type:
list
- chunks_to_mesh(chunks, o)[source]#
Convert sampled chunks into a mesh path for a given optimization object.
This function takes a list of sampled chunks and converts them into a mesh path based on the specified optimization parameters. It handles different machine axes configurations and applies optimizations as needed. The resulting mesh is created in the Blender context, and the function also manages the lifting and dropping of the cutter based on the chunk positions.
- Parameters:
chunks (list) – A list of chunk objects to be converted into a mesh.
o (object) – An object containing optimization parameters and settings.
- Returns:
- The function creates a mesh in the Blender context but does not return a
value.
- Return type:
None