Skip to content

Commit 7086187

Browse files
committed
🌧️ Update _get_pts_voxel and _get_pts_ray functions to accept fill parameter without default value for improved clarity and consistency.
1 parent 67e1c4f commit 7086187

2 files changed

Lines changed: 9 additions & 41 deletions

File tree

src/discretization/_polygon.jl

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,7 @@
44
| - _get_pts |
55
+==========================================================================================#
66

7-
"""
8-
_get_pts(polygon::QueryPolygon, h::Real; fill::Bool=true)
9-
10-
Description:
11-
---
12-
Get points inside a polygon at a specified grid resolution `h`. The input `polygon` is an
13-
instance of `QueryPolygon`, and `h` is the grid resolution. If `fill` is set to true, it
14-
returns the points in a filled grid pattern; otherwise, it returns the center points of the
15-
grid cells.
16-
17-
Example:
18-
---
19-
```julia
20-
polygon_xy = [0 0; 1 0; 1 1; 0 1]' # 2xN array
21-
poly = _get_polygon(polygon_xy, ratio=1) # poly.polygon to visualize
22-
pts = get_pts(poly, 0.1; fill=true) # returns points in a filled grid pattern
23-
```
24-
"""
25-
function _get_pts(polygon::QueryPolygon, h::Real; fill::Bool=true)
7+
function _get_pts(polygon::QueryPolygon, h::Real, fill::Bool, edge::Bool)
268
h > 0 || error("h must be positive")
279
pypoly = polygon.polygon
2810
minx, miny, maxx, maxy = pypoly.bounds
@@ -36,7 +18,8 @@ function _get_pts(polygon::QueryPolygon, h::Real; fill::Bool=true)
3618
out_shape=(height, width),
3719
transform=transform,
3820
fill=0,
39-
dtype=np.uint8
21+
dtype=np.uint8,
22+
all_touched=edge
4023
)
4124
rows, cols = np.where(mask == 1)
4225
xs, ys = rasterio.transform.xy(transform, rows, cols, offset="center")
@@ -53,28 +36,11 @@ function _get_pts(polygon::QueryPolygon, h::Real; fill::Bool=true)
5336
end
5437
end
5538

56-
"""
57-
_get_pts(stl_data::STLInfo2D, h::Real; fill::Bool=true)
58-
59-
Description:
60-
---
61-
Get points inside a 2D STL model at a specified grid resolution `h`. The input `stl_data` is
62-
an instance of `STLInfo2D`, which contains the mesh, vertices, and triangles of the STL
63-
model. If `fill` is set to true, it returns the points in a filled grid pattern; otherwise,
64-
it returns the center points of the grid cells.
65-
66-
Example:
67-
---
68-
```julia
69-
stl_data = readSTL2D("path/to/your/file.stl")
70-
pts = _get_pts(stl_data, 0.1; fill=true) # returns points in a filled grid pattern
71-
```
72-
"""
73-
function _get_pts(stl_data::STLInfo2D, h::Real; fill::Bool=true)
39+
function _get_pts(stl_data::STLInfo2D, h::Real, fill::Bool, edge::Bool)
7440
h > 0 || error("h must be positive")
7541
triangle_coords_2d = stl_data.py_vertices[stl_data.py_triangles]
7642
tris2d = shapely.polygons(triangle_coords_2d)
7743
region = shapely.unary_union(tris2d)
7844
polygon = QueryPolygon(region)
79-
return get_pts(polygon, h; fill=fill)
45+
return _get_pts(polygon, h, fill, edge)
8046
end

src/discretization/_polyhedron.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
| - _get_pts_ray |
66
+==========================================================================================#
77

8-
function _get_pts_voxel(stl_model::STLInfo3D, h::Real; fill::Bool=true)
8+
function _get_pts_voxel(stl_model::STLInfo3D, h::Real, fill::Bool)
99
# inputs check
1010
h > 0 || error("h must be a positive number")
1111
step = h * 0.25
@@ -30,7 +30,9 @@ function _get_pts_voxel(stl_model::STLInfo3D, h::Real; fill::Bool=true)
3030
end
3131
end
3232

33-
function _get_pts_ray(stl_model::STLInfo3D, h::Real; fill::Bool=true, ϵ::String="FP32")
33+
function _get_pts_ray(stl_model::STLInfo3D, h::Real, fill::Bool, ϵ::String)
34+
# inputs check
35+
h > 0 || error("h must be a positive number")
3436
points, pts2 = prepareprojection(stl_model, h, ϵ)
3537
@info "generating pts at h = $h"
3638
edges = projectionlist(stl_model, points)

0 commit comments

Comments
 (0)