GPU Acceleration API
Optional WebGPU (wgpu) runtime detection, orthographic projection cameras, B-Rep tessellation, technical-illustration shading, visibility-buffer HLR, and 2D distance-field (SDF) layout.
Runtime Detection & Device Management
build123d_techdraw.gpu.runtime
Opt-in wgpu runtime detection, adapter/device caching, and diagnostics.
All wgpu imports are deferred so build123d-techdraw remains 100% usable
without GPU dependencies installed. When build123d-techdraw[gpu] is
installed, GPU acceleration is auto-enabled whenever a compatible hardware or
software (e.g. Mesa Lavapipe) adapter can be initialized, unless overridden by
an explicit gpu=False argument or BUILD123D_TECHDRAW_GPU=0.
GPU_ENV_VAR = 'BUILD123D_TECHDRAW_GPU'
module-attribute
is_gpu_installed()
is_gpu_available(*, allow_software=True)
Return True if a usable wgpu adapter and device can be initialized.
Hardware adapters are preferred. When allow_software=True (the default),
software Vulkan/WebGPU drivers such as Mesa Lavapipe are accepted as a
fallback so headless CI environments work seamlessly.
Source code in src/build123d_techdraw/gpu/runtime.py
is_gpu_enabled(gpu=None)
Resolve whether GPU acceleration should be used for an operation.
Resolution order:
gpu=False-> always returnsFalsewithout probing adapters.gpu=True-> requireswgpuand a working adapter; raisesImportErrorifwgpuis not installed orRuntimeErrorif no adapter is available.-
gpu=None-> consultsBUILD123D_TECHDRAW_GPU:"0"/"false"/"off"/"no"->False"1"/"true"/"on"/"yes"-> require GPU (same asgpu=True)- unset / empty /
"auto"->Trueiffis_gpu_installed()andis_gpu_available().
Source code in src/build123d_techdraw/gpu/runtime.py
get_gpu_device(*, allow_software=True, force_fallback=False)
Return the cached (adapter, device) pair for wgpu execution.
Raises:
| Type | Description |
|---|---|
ImportError
|
If |
RuntimeError
|
If no compatible wgpu adapter/device could be created. |
Source code in src/build123d_techdraw/gpu/runtime.py
gpu_info(*, allow_software=True)
Return diagnostic metadata describing the active wgpu runtime environment.
Source code in src/build123d_techdraw/gpu/runtime.py
Tessellation & Edge Sampling
build123d_techdraw.gpu.mesh
OCCT-to-GPU triangle mesh tessellation and B-Rep/silhouette edge sampling.
Both tessellate_shape and sample_shape_edges traverse assembly parts
and faces in the exact same deterministic order so 1-based face_ids in
TessellatedMesh match face_id_a / face_id_b in SampledEdge
1-to-1 for GPU hidden-line removal (HLR) depth/ID buffer lookups.
TessellatedMesh
dataclass
GPU-ready triangle mesh extracted from a build123d / OCCT B-Rep shape.
Source code in src/build123d_techdraw/gpu/mesh.py
num_vertices
property
Number of vertices in the mesh.
num_triangles
property
Number of triangles in the mesh.
SampledEdge
dataclass
A discretized 3D B-Rep edge or analytic silhouette polyline.
Source code in src/build123d_techdraw/gpu/mesh.py
SampledEdgeSet
dataclass
Collection of discretized 3D edges and optional analytic silhouettes for a shape.
Source code in src/build123d_techdraw/gpu/mesh.py
total_points
property
Total number of 3D polyline sample points across all edges.
total_segments
property
Total number of polyline line segments across all edges.
pack_segments()
Pack all polyline segments into flat GPU-ready arrays.
Returns:
| Type | Description |
|---|---|
NDArray[float32]
|
|
NDArray[float32]
|
( |
NDArray[uint32]
|
|
tuple[NDArray[float32], NDArray[float32], NDArray[uint32]]
|
|
Source code in src/build123d_techdraw/gpu/mesh.py
tessellate_shape(shape, *, linear_deflection=0.05, angular_deflection=0.2, split_sharp_edges_deg=35.0)
Tessellate a build123d or OCCT shape into a GPU-ready TessellatedMesh.
Uses BRepMesh_IncrementalMesh + BRep_Tool.Triangulation_s with analytical
OCCT surface normals (falling back to area-weighted triangle normals at degenerate
poles) and optional sharp-edge preservation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Shape[Any] | TopoDS_Shape | Any
|
build123d |
required |
linear_deflection
|
float
|
Maximum chordal deviation in model units (mm). |
0.05
|
angular_deflection
|
float
|
Maximum angular deviation in radians. |
0.2
|
split_sharp_edges_deg
|
float | None
|
Dihedral angle threshold in degrees above which edges
remain sharp (split normals). Default |
35.0
|
Source code in src/build123d_techdraw/gpu/mesh.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | |
sample_shape_edges(shape, *, deflection=0.05, look_from=None)
Extract discretized B-Rep edges and optional analytic silhouettes for GPU HLR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Shape[Any] | TopoDS_Shape | Any
|
build123d |
required |
deflection
|
float
|
Chordal discretization tolerance in model units (mm). |
0.05
|
look_from
|
Vec3 | None
|
Optional orthographic camera direction |
None
|
Source code in src/build123d_techdraw/gpu/mesh.py
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 | |
Orthographic Camera
build123d_techdraw.gpu.camera
Orthographic camera math aligned pixel-for-pixel with build123d.Drawing and SheetView.
Coordinate conventions
Given (look_from, look_up) matching build123d_techdraw.core.view.VIEW_VECTORS:
eye_dir = normalize(look_from)points from the model toward the camera.forward = -eye_diris the camera viewing direction (into the scene).right = normalize(cross(normalize(look_up), eye_dir))matchesgp_Ax2X direction.up = normalize(cross(eye_dir, right))matchesgp_Ax2Y direction.
Matrices use standard mathematical row-major layout in NumPy (clip = view_proj @ p)
with WebGPU/Vulkan clip-space depth z in [0, 1] (0 at z_near, 1 at z_far)
and +y upward in NDC (mapping +up to the top of rendered raster images, matching
SVG <image> top-down pixel coordinates). Use OrthoCamera.uniform_view_proj
when uploading mat4x4<f32> uniforms to WGSL (column-major memory order).
OrthoCamera
dataclass
Orthographic WebGPU camera matching SheetView / build123d.Drawing projection.
Source code in src/build123d_techdraw/gpu/camera.py
uniform_view_proj()
Return view_proj in contiguous column-major layout for WGSL mat4x4<f32>.
uniform_view_matrix()
Return view_matrix in contiguous column-major layout for WGSL mat4x4<f32>.
project_points_ndc(points_3d)
Project (N, 3) world points into WebGPU NDC (x_ndc, y_ndc, z_ndc).
Source code in src/build123d_techdraw/gpu/camera.py
project_points_px(points_3d)
Project (N, 3) world points into top-left image pixels (px, py, z_ndc).
Source code in src/build123d_techdraw/gpu/camera.py
project_points_2d(points_3d, *, origin=(0.0, 0.0, 0.0))
Project (N, 3) world points onto the view (right, up) plane around origin.
When origin equals shape.center(), the resulting (u, v) coordinates
match build123d.Drawing(..., look_from=..., look_up=...) directly.
Source code in src/build123d_techdraw/gpu/camera.py
compute_ortho_camera(bbox_min, bbox_max, look_from, look_up, width_px, height_px, *, padding_mm=0.0)
Compute an orthographic WebGPU camera framing the 3D AABB [bbox_min, bbox_max].
The camera basis matches build123d.Drawing(shape, look_from=..., look_up=...) and
build123d_techdraw.core.view.VIEW_VECTORS so rasterized GPU views align
pixel-for-pixel with projected vector views.
Source code in src/build123d_techdraw/gpu/camera.py
compute_ortho_camera_for_points(points_3d, look_from, look_up, width_px, height_px, *, padding_mm=0.0)
Compute an orthographic WebGPU camera tightly framing a (N, 3) 3D point cloud.
Prefer this over compute_ortho_camera for isometric or angled views of
non-box shapes (cylinders, L-brackets, assemblies) when exact tight alignment
with build123d.Drawing.visible_lines.bounding_box() is required.
Source code in src/build123d_techdraw/gpu/camera.py
Technical Shading
build123d_techdraw.gpu.shading
WGSL technical-illustration shading for raster layers drawn under exact vector edges.
A shaded view is rendered offscreen with wgpu in three passes:
- Geometry G-buffer: the tessellated B-Rep is rasterized orthographically with the
OrthoCamerabasis used bybuild123d.Drawing, writing per-part albedo (rgba8unorm), view-space normals (rgba16float) anddepth32float. X-ray views instead accumulate Fresnel-weighted coverage of every surface layer with additive blending, so internal bores show through. - Screen-space ambient occlusion: a hemisphere-kernel pass over depth + normals darkens bores, fillets, counterbores and contact seams so 3D form reads on a 2D sheet.
- Composite: one style-specific lighting pass per theme (Gooch, toon, blueprint, ...).
The frame is supersampled and box-filtered (premultiplied alpha) into a transparent RGBA
PIL.Image.Image. ShadedRender.to_svg places it in the view's local
build123d.Drawing coordinates, so it can be drawn before #layer_visible and the exact
vector outlines stay sharp on top. wgpu is imported lazily: this module stays importable
without the gpu extra.
ENGINEERING_BOM_PALETTE = ('#8A9BB0', '#4C8DD6', '#D4A24C', '#C0704F', '#6FAE8B', '#A58BD0', '#D7D9D2', '#E07A7A')
module-attribute
ViewStyle
Bases: Enum
How a projected view is drawn: exact vectors only, or a GPU-shaded raster layer.
Source code in src/build123d_techdraw/gpu/shading.py
WIREFRAME = 'wireframe'
class-attribute
instance-attribute
Classic exact vector drawing (default, no GPU work).
SHADED = 'shaded'
class-attribute
instance-attribute
Smooth technical shading without a vector edge overlay.
SHADED_WITH_EDGES = 'shaded_with_edges'
class-attribute
instance-attribute
Smooth technical shading underneath the exact vector edges.
GOOCH = 'gooch'
class-attribute
instance-attribute
Gooch cool-to-warm technical illustration shading + subtle SSAO + vector edges.
TOON = 'toon'
class-attribute
instance-attribute
Quantized cel bands + vector edges.
BLUEPRINT_SHADED = 'blueprint_shaded'
class-attribute
instance-attribute
Holographic blueprint shading (cyan in dark theme, gray-blue in white) + vector edges.
XRAY = 'xray'
class-attribute
instance-attribute
Fresnel translucent shading revealing internal features + vector edges.
coerce(value)
classmethod
Return value as a ViewStyle, accepting its case-insensitive string value.
Source code in src/build123d_techdraw/gpu/shading.py
ShadedRender
dataclass
Result of render_shaded_view: one transparent raster per requested theme.
rect is (u_min, v_min, u_max, v_max) in model millimetres on the
build123d.Drawing projection plane (u along the view's right axis, v along its
up axis, both relative to the projection origin), i.e. the exact frame the vector edges of
the matching SheetView are expressed in.
Source code in src/build123d_techdraw/gpu/shading.py
to_svg()
Return a <g class="shaded-view"> of <image> layers in Drawing coordinates.
With more than one theme each image carries shaded-layer-dark /
shaded-layer-white so the sheet CSS shows only the layer matching the active
theme; a single-theme render is always visible.
Source code in src/build123d_techdraw/gpu/shading.py
render_shaded_view(shape, look_from, look_up, *, style=ViewStyle.SHADED_WITH_EDGES, shading_dpi=300, color_by_part=False, part_colors=None, ssao=True, gpu=None, shading_theme=None, scale=1.0, origin=None, max_size_px=2048)
Render a transparent technical-illustration raster of shape with wgpu.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Shape[Any] | TessellatedMesh
|
build123d shape ( |
required |
look_from, look_up
|
Camera vectors, as in |
required | |
style
|
ViewStyle | str
|
Any shaded |
SHADED_WITH_EDGES
|
shading_dpi
|
int
|
Raster resolution in pixels per inch of paper; the longest side is
capped at |
300
|
color_by_part
|
bool
|
Colour each solid of an assembly from |
False
|
part_colors
|
PartColors | None
|
Explicit colours per part, by index (sequence) or part label (mapping). |
None
|
ssao
|
bool
|
Enable screen-space ambient occlusion (ignored by |
True
|
gpu
|
bool | None
|
|
None
|
shading_theme
|
Theme | str | None
|
Render one theme only; |
None
|
scale
|
float
|
View scale (paper mm per model mm), used to convert |
1.0
|
origin
|
Vec3 | None
|
Projection origin; defaults to |
None
|
max_size_px
|
int
|
Maximum output size in pixels along either axis. |
2048
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If |
RuntimeError
|
If GPU rendering is disabled ( |
ValueError
|
For |
Source code in src/build123d_techdraw/gpu/shading.py
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 | |
Visibility-Buffer HLR
build123d_techdraw.gpu.hlr
GPU visibility-buffer hidden-line removal (HLR) producing crisp vector output.
The engine replaces OCCT HLRBRep_Algo with a three-pass wgpu pipeline:
- Raster pass - the tessellated shape is drawn orthographically into an offscreen
depth32floatattachment plus two colour targets: anr32floatcopy of the fragment depth and anr32uint1-based B-Rep face ID per pixel. - Compute pass - every B-Rep edge, analytic silhouette and mesh silhouette is cut into ~1 px sample intervals. A WGSL compute shader projects each interval midpoint and inspects the 3x3 pixel neighbourhood: the sample is visible if any neighbour shows background, a surface behind it, or one of the edge's own adjacent faces at (nearly) the edge depth; otherwise it is hidden.
- Vector pass - the per-sample flags are de-speckled, hidden runs coinciding with
visible lines (and duplicate visible lines) are removed, contiguous runs are stitched
into polylines, simplified with Ramer-Douglas-Peucker and emitted with the exact SVG
DOM structure of
build123d.ExportSVGused by the OCCT path, so every downstream consumer (views, breaks, details, PDF/DXF renderers, themes) works unchanged.
Model-space output coordinates match build123d.Drawing: (u, v) on the view plane
around shape.center(), +u right and +v up (SVG flips with scale(1,-1)).
HLRMode = Literal['exact', 'gpu', 'auto']
module-attribute
Hidden-line removal backend: OCCT HLRBRep_Algo, GPU visibility buffer, or automatic.
HLROptions
Bases: TypedDict
Hidden-line removal keyword options accepted by view factories (**hlr_options).
Source code in src/build123d_techdraw/gpu/hlr.py
GPUHLRStats
dataclass
Problem size and wall-clock timings (seconds) of one GPU HLR projection.
Source code in src/build123d_techdraw/gpu/hlr.py
GPUHLRResult
dataclass
Vector output of project_shape_gpu_hlr in build123d.Drawing coordinates.
Source code in src/build123d_techdraw/gpu/hlr.py
count_shape_faces(shape)
Return the number of distinct B-Rep faces of shape.
Source code in src/build123d_techdraw/gpu/hlr.py
resolve_hlr_backend(shape, hlr, *, gpu=None, face_threshold=250)
Return True if shape should be projected with GPU HLR rather than OCCT.
"exact": always OCCTHLRBRep_Algo."gpu": always GPU; raises ifgpu=Falseor no wgpu adapter is available (gpu=Noneis treated as an explicit GPU request)."auto": GPU whenis_gpu_enabled(gpu/BUILD123D_TECHDRAW_GPU) and the shape has at leastface_thresholdfaces; otherwise OCCT.
Source code in src/build123d_techdraw/gpu/hlr.py
project_shape_gpu_hlr(shape, look_from, look_up, *, show_hidden=True, resolution=2048, deflection=None, gpu=None)
Project shape with GPU visibility-buffer hidden-line removal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
Any
|
build123d shape ( |
required |
look_from
|
Vec3
|
Direction from the model toward the camera ( |
required |
look_up
|
Vec3
|
Up direction of the view. |
required |
show_hidden
|
bool
|
Emit hidden lines (dashed |
True
|
resolution
|
int
|
Long side, in pixels, of the depth / face-ID visibility buffer. Visibility transitions are located to about one pixel of this raster. |
2048
|
deflection
|
float | None
|
Tessellation / edge discretisation tolerance in model units;
defaults to |
None
|
gpu
|
bool | None
|
|
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ImportError
|
If |
RuntimeError
|
If no wgpu adapter can be initialised. |
Source code in src/build123d_techdraw/gpu/hlr.py
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 | |
Distance-Field (SDF / JFA)
build123d_techdraw.gpu.sdf
2D Euclidean Distance-Field (SDF) sheet occupancy and Jump Flooding Algorithm (JFA).
Rasterizes a DrawingSheet into a high-resolution binary obstacle mask — including exact
projected 2D view geometry contours (so concave L/C/T-shaped parts expose true whitespace
pockets instead of coarse AABBs), margins, ISO 7200 title block, revision/BOM tables,
view labels, and existing annotations — and computes an exact millimeter clearance field
via a WebGPU (WGSL) Jump Flooding Algorithm (JFA+1) compute shader, with automatic exact
CPU fallback via scipy.ndimage.distance_transform_edt.
SheetDistanceField
2D Euclidean Signed/Unsigned Distance Field (clearance in mm) over a DrawingSheet.
Attributes:
| Name | Type | Description |
|---|---|---|
distance_mm |
NDArray[float32]
|
|
obstacle_mask |
NDArray[bool_]
|
|
resolution_px_per_mm |
float
|
Raster resolution in pixels per sheet millimetre. |
backend |
BackendName
|
Execution backend that computed the field ( |
width_mm |
float
|
Sheet width in millimetres. |
height_mm |
float
|
Sheet height in millimetres. |
Source code in src/build123d_techdraw/gpu/sdf.py
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 | |
height_px
property
Raster height in pixels.
width_px
property
Raster width in pixels.
query_clearance(x_mm, y_mm)
Return the Euclidean clearance in millimetres at sheet coordinate (x_mm, y_mm).
Source code in src/build123d_techdraw/gpu/sdf.py
box_min_clearance(min_x, min_y, max_x, max_y)
Return the minimum SDF clearance (mm) anywhere inside the given sheet-mm rectangle.
Source code in src/build123d_techdraw/gpu/sdf.py
mark_occupied_box(bbox, pad_mm=1.0)
Mark bbox (expanded by pad_mm) occupied and update distance_mm exactly.
Uses the exact analytical Euclidean distance to an axis-aligned pixel rectangle
D_new = min(D_old, d_rect), which is mathematically identical to re-running a
full EDT/JFA transform over the updated mask while completing in sub-millisecond time.
Source code in src/build123d_techdraw/gpu/sdf.py
register_leader_segment(start_xy, end_xy)
Record a placed leader line segment so future callouts avoid crossing it.
Source code in src/build123d_techdraw/gpu/sdf.py
find_best_callout_position(target_xy, box_size_mm, *, min_dist_mm=10.0, max_dist_mm=55.0, preferred_angles_deg=None, avoid_leader_crossings=True, validator=None)
Find the highest-clearance collision-free center (cx, cy) for a callout box.
Evaluates candidate rings around target_xy using exact SDF box clearance,
leader-line obstacle sampling, leader-crossing detection, and distance/angle
preferences so callouts naturally discover concave part pockets while keeping
leaders short and unobstructed.
Source code in src/build123d_techdraw/gpu/sdf.py
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 | |
find_best_leader_elbow(target_xy, shelf_length_mm, text_height_mm=8.0, *, min_dist_mm=12.0, max_dist_mm=60.0, preferred_angles_deg=None, avoid_leader_crossings=True, validator=None)
Find an optimal (elbow_dx, elbow_dy) offset for a LeaderNote / HoleCallout.
Scores each candidate elbow by the SDF clearance of its horizontal text shelf,
leader obstacle/crossing avoidance, and optional linter-compatibility validator.
Source code in src/build123d_techdraw/gpu/sdf.py
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 | |
render_heatmap_image(*, theme=None, placed_boxes=None, max_clearance_mm=40.0, contour_step_mm=5.0)
Render a blueprint-styled 2D clearance heatmap PNG for visualization and CI diffs.
Displays the continuous Euclidean clearance field with iso-distance contour rings, occupied margins/title-block/tables, crisp projected part geometry silhouettes, and highlighted placed annotation boxes.
Source code in src/build123d_techdraw/gpu/sdf.py
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 | |
compute_distance_field_from_mask(obstacle_mask, *, resolution_px_per_mm=2.0, gpu=None)
Compute a 2D millimeter distance field from a boolean (H, W) obstacle mask.
Uses the WebGPU JFA+1 compute shader when is_gpu_enabled returns True
and falls back to exact CPU scipy.ndimage.distance_transform_edt otherwise.
Source code in src/build123d_techdraw/gpu/sdf.py
compute_sheet_sdf(sheet, *, resolution_px_per_mm=2.0, gpu=None, include_annotations=True, include_labels=True, include_notes=True, geometry_stroke_mm=0.8)
Build a 2D Euclidean clearance field (SheetDistanceField) for sheet.
Rasterizes:
- Sheet border / margin exclusion bands,
- ISO 7200 title block, revision table, BOM table, and general notes block,
- Exact projected 2D geometry contours and solid silhouettes of every
SheetView, - View title labels and existing annotations' bounding boxes.
Computes Euclidean millimeter clearance on GPU via WGSL Jump Flooding (JFA+1) when
is_gpu_enabled(gpu) is True, seamlessly falling back to exact CPU SciPy EDT
when gpu=False or [gpu] is unavailable.
Source code in src/build123d_techdraw/gpu/sdf.py
1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 | |