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
5437end
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 )
8046end
0 commit comments