|
STAR
Cal STAR — firmware, DAQ server, and engine design
|
Functions | |
| np.ndarray | quantize_coordinates (np.ndarray pts, int precision=DXF_PRECISION) |
| np.ndarray | deduplicate_vertices (np.ndarray pts, float epsilon=VERTEX_EPSILON) |
| np.ndarray | remove_zero_length_segments (np.ndarray pts, float epsilon=VERTEX_EPSILON) |
| Tuple[bool, Optional[int], Optional[float]] | validate_continuity (np.ndarray pts, float max_gap=1e-6) |
| np.ndarray | ensure_shared_vertices (np.ndarray pts, int precision=DXF_PRECISION) |
| np.ndarray | prepare_polyline_points (np.ndarray pts, int precision=DXF_PRECISION, float epsilon=VERTEX_EPSILON) |
| None | export_chamber_dxf (np.ndarray chamber_pts, str export_path, bool add_centerline=True, bool add_mirrored=False, str layer_name="CONTOUR", str centerline_layer="CENTERLINE", int precision=DXF_PRECISION) |
| None | export_closed_contour_dxf (np.ndarray chamber_pts, str export_path, str layer_name="CONTOUR", int precision=DXF_PRECISION) |
Variables | |
| bool | HAS_EZDXF = True |
| int | DXF_PRECISION = 6 |
| int | VERTEX_EPSILON = 1e-9 |
| x = np.linspace(-0.1, 0.2, 100) | |
| y = np.where(x < 0, 0.05, 0.05 - x * 0.1) | |
| pts = np.column_stack([x, y]) | |
| np.ndarray | cleaned = prepare_polyline_points(pts) |
Robust DXF export utilities for chamber geometry. This module provides functions to export chamber contours as CAD-compatible DXF files with proper handling of: - Coordinate quantization (consistent precision) - Vertex deduplication (no overlapping points) - Zero-length segment removal - Endpoint continuity validation - Single closed LWPOLYLINE output
| np.ndarray engine.core.dxf_export.deduplicate_vertices | ( | np.ndarray | pts, |
| float | epsilon = VERTEX_EPSILON ) |
Remove duplicate/near-duplicate consecutive vertices.
This handles the case where segment boundaries have overlapping points,
ensuring each vertex appears exactly once in the output polyline.
Parameters:
-----------
pts : np.ndarray
Array of (x, y) points, shape (N, 2)
epsilon : float
Distance threshold - points closer than this are considered duplicates
Returns:
--------
np.ndarray
Deduplicated points array
Definition at line 53 of file dxf_export.py.
Referenced by ensure_shared_vertices(), prepare_polyline_points(), and remove_zero_length_segments().
| np.ndarray engine.core.dxf_export.ensure_shared_vertices | ( | np.ndarray | pts, |
| int | precision = DXF_PRECISION ) |
Ensure vertices at segment boundaries are properly shared.
After quantization, this ensures that connecting points between
segments (cylindrical->contraction->nozzle) are exactly the same.
Parameters:
-----------
pts : np.ndarray
Array of (x, y) points, shape (N, 2)
precision : int
Number of decimal places for coordinate quantization
Returns:
--------
np.ndarray
Points array with shared vertices at boundaries
Definition at line 155 of file dxf_export.py.
References deduplicate_vertices(), and quantize_coordinates().
| None engine.core.dxf_export.export_chamber_dxf | ( | np.ndarray | chamber_pts, |
| str | export_path, | ||
| bool | add_centerline = True, | ||
| bool | add_mirrored = False, | ||
| str | layer_name = "CONTOUR", | ||
| str | centerline_layer = "CENTERLINE", | ||
| int | precision = DXF_PRECISION ) |
Export chamber contour to a CAD-compatible DXF file.
Creates a single LWPOLYLINE with properly shared vertices,
quantized coordinates, and no duplicate or zero-length entities.
Parameters:
-----------
chamber_pts : np.ndarray
Array of (x, y) points representing the chamber contour
export_path : str
Path to save the DXF file
add_centerline : bool
If True, adds a centerline (y=0) as a reference line
add_mirrored : bool
If True, also adds the mirrored (lower half) contour
layer_name : str
DXF layer name for the contour
centerline_layer : str
DXF layer name for the centerline
precision : int
Decimal places for coordinate quantization
Definition at line 230 of file dxf_export.py.
References max, min, and prepare_polyline_points().
| None engine.core.dxf_export.export_closed_contour_dxf | ( | np.ndarray | chamber_pts, |
| str | export_path, | ||
| str | layer_name = "CONTOUR", | ||
| int | precision = DXF_PRECISION ) |
Export chamber contour as a closed LWPOLYLINE (full cross-section).
Creates a single closed polyline representing the full chamber
cross-section by mirroring the upper half contour.
Parameters:
-----------
chamber_pts : np.ndarray
Array of (x, y) points representing the upper half contour
export_path : str
Path to save the DXF file
layer_name : str
DXF layer name for the contour
precision : int
Decimal places for coordinate quantization
Definition at line 320 of file dxf_export.py.
References prepare_polyline_points().
| np.ndarray engine.core.dxf_export.prepare_polyline_points | ( | np.ndarray | pts, |
| int | precision = DXF_PRECISION, | ||
| float | epsilon = VERTEX_EPSILON ) |
Full preparation pipeline for polyline points.
Applies all cleaning steps in the correct order:
1. Quantize coordinates
2. Deduplicate vertices
3. Remove zero-length segments
4. Validate continuity
Parameters:
-----------
pts : np.ndarray
Raw array of (x, y) points, shape (N, 2)
precision : int
Decimal places for coordinate quantization
epsilon : float
Threshold for vertex deduplication
Returns:
--------
np.ndarray
Cleaned, validated points ready for DXF export
Definition at line 183 of file dxf_export.py.
References deduplicate_vertices(), quantize_coordinates(), remove_zero_length_segments(), and validate_continuity().
Referenced by export_chamber_dxf(), and export_closed_contour_dxf().
| np.ndarray engine.core.dxf_export.quantize_coordinates | ( | np.ndarray | pts, |
| int | precision = DXF_PRECISION ) |
Round coordinates to fixed decimal places for CAD compatibility.
This ensures consistent coordinate representation and eliminates
floating-point precision issues that cause gaps in CAD imports.
Parameters:
-----------
pts : np.ndarray
Array of (x, y) points, shape (N, 2)
precision : int
Number of decimal places to round to (default: 6)
Returns:
--------
np.ndarray
Quantized points array with same shape
Definition at line 31 of file dxf_export.py.
Referenced by ensure_shared_vertices(), and prepare_polyline_points().
| np.ndarray engine.core.dxf_export.remove_zero_length_segments | ( | np.ndarray | pts, |
| float | epsilon = VERTEX_EPSILON ) |
Remove points that would create zero-length line segments.
This is similar to deduplicate_vertices but specifically targets
zero-length segments that cause CAD import errors.
Parameters:
-----------
pts : np.ndarray
Array of (x, y) points, shape (N, 2)
epsilon : float
Length threshold - segments shorter than this are removed
Returns:
--------
np.ndarray
Cleaned points array with no zero-length segments
Definition at line 87 of file dxf_export.py.
References deduplicate_vertices().
Referenced by prepare_polyline_points().
| Tuple[bool, Optional[int], Optional[float]] engine.core.dxf_export.validate_continuity | ( | np.ndarray | pts, |
| float | max_gap = 1e-6 ) |
Validate that the polyline forms a continuous path.
Checks that there are no unexpected gaps between consecutive vertices.
Parameters:
-----------
pts : np.ndarray
Array of (x, y) points, shape (N, 2)
max_gap : float
Maximum allowed gap between consecutive points for typical geometry.
Gaps larger than this trigger a warning.
Returns:
--------
Tuple[bool, Optional[int], Optional[float]]
(is_valid, gap_index, gap_distance)
- is_valid: True if all consecutive points are reasonably close
- gap_index: Index of first large gap (if any)
- gap_distance: Distance of first large gap (if any)
Definition at line 111 of file dxf_export.py.
References max.
Referenced by prepare_polyline_points().
| np.ndarray engine.core.dxf_export.cleaned = prepare_polyline_points(pts) |
Definition at line 411 of file dxf_export.py.
| int engine.core.dxf_export.DXF_PRECISION = 6 |
Definition at line 25 of file dxf_export.py.
| bool engine.core.dxf_export.HAS_EZDXF = True |
Definition at line 19 of file dxf_export.py.
Definition at line 403 of file dxf_export.py.
| int engine.core.dxf_export.VERTEX_EPSILON = 1e-9 |
Definition at line 28 of file dxf_export.py.
| engine.core.dxf_export.x = np.linspace(-0.1, 0.2, 100) |
Definition at line 401 of file dxf_export.py.
Definition at line 402 of file dxf_export.py.