Skip to content

Commit 3cfb136

Browse files
committed
👈🏿 Not following column-major layout
1 parent 06e5413 commit 3cfb136

14 files changed

Lines changed: 135 additions & 90 deletions

File tree

example/2d.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using FastPointQuery
22
using WGLMakie
33

4-
points = rand(2, 100)
4+
points = rand(100, 2)
55
poly = get_polygon(points, ratio=0.1)
66
stl_file = joinpath(@__DIR__, "2d_hole.stl")
77
stl_model = readSTL2D(stl_file)
@@ -14,9 +14,9 @@ write_polygon(poly, joinpath(@__DIR__, "polygon.geojson"))
1414
write_polygon(joinpath(@__DIR__, "polygon.geojson"), poly)
1515
poly2 = read_polygon(joinpath(@__DIR__, "polygon.geojson"))
1616

17-
pts1 = get_pts(poly, 0.1)
18-
pts2 = get_pts(poly, 0.1; fill=false)
19-
pts3 = get_pts(stl_model, 0.01, fill=false)
17+
pts1 = FastPointQuery._get_pts(poly, 0.1, true, true)
18+
pts2 = FastPointQuery._get_pts(poly, 0.1, false, false)
19+
pts3 = FastPointQuery._get_pts(stl_model, 0.01, false, true)
2020

2121
let
2222
fig = Figure()

example/3d.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using WGLMakie
44
stl_path1 = get_resource().dragon_phoenix
55
stl_path2 = get_resource().wheel
66

7-
points = rand(3, 10000)
7+
points = rand(10000, 3)
88
stl_model1 = readSTL3D(stl_path1)
99
stl_model2 = readSTL3D(stl_path2)
1010

@@ -13,7 +13,7 @@ pip_query(stl_model2, points; nsamples=5)
1313

1414
let
1515
h = 1
16-
pts = FastPointQuery._get_pts_voxel(stl_model1, h)
16+
pts = FastPointQuery._get_pts_voxel(stl_model1, h, true)
1717
fig = Figure()
1818
ax = LScene(fig[1, 1])
1919
scatter!(ax, pts, markersize=1)
@@ -22,7 +22,7 @@ end
2222

2323
let
2424
h = 5
25-
pts = FastPointQuery._get_pts_voxel(stl_model2, h; fill=true)
25+
pts = FastPointQuery._get_pts_voxel(stl_model2, h, true)
2626
fig = Figure()
2727
ax = LScene(fig[1, 1])
2828
scatter!(ax, pts, markersize=1)

example/fileio.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using FastPointQuery
22
using WGLMakie
33

4-
points = rand(2, 100)
4+
points = rand(100, 2)
55
saveply(points, joinpath(@__DIR__, "pointcloud.ply"))
66
readply(joinpath(@__DIR__, "pointcloud.ply"), xy=true)
77

example/getpts.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using WGLMakie
44
stl_model = readSTL3D(joinpath(@__DIR__, "wheel.stl"))
55

66
h = 3
7-
pts = FastPointQuery._get_pts_ray(stl_model, h, ϵ="FP32")
7+
pts = FastPointQuery._get_pts_ray(stl_model, h, true)
88

99
saveply(joinpath(@__DIR__, "wheel.ply"), pts)
1010

src/FastPointQuery.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const pyfun = PythonCall.pybuiltins
2323
const res_dir = joinpath(@__DIR__, "../example")
2424

2525
function __init__()
26-
@info "initializing environment..."
2726
try # import Python modules
2827
PythonCall.pycopy!(np , PythonCall.pyimport("numpy" ))
2928
PythonCall.pycopy!(shapely , PythonCall.pyimport("shapely" ))

src/discretization/_polygon.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ function _get_pts(polygon::QueryPolygon, h::Real, fill::Bool, edge::Bool)
3030
ur = pts_cen + np.array([ dx, dy])
3131
dl = pts_cen + np.array([-dx, -dy])
3232
dr = pts_cen + np.array([ dx, -dy])
33-
return PythonCall.PyArray(np.vstack([ul, ur, dl, dr]).T, copy=false)
33+
return PythonCall.PyArray(np.vstack([ul, ur, dl, dr]), copy=false)
3434
else
35-
return PythonCall.PyArray(pts_cen.T, copy=false)
35+
return PythonCall.PyArray(pts_cen, copy=false)
3636
end
3737
end
3838

src/discretization/_polyhedron.jl

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
function _get_pts_voxel(stl_model::STLInfo3D, h::Real, fill::Bool)
99
# inputs check
1010
h > 0 || error("h must be a positive number")
11-
step = h * 0.25
12-
offsets = np.array([-1 1 1; -1 1 -1; 1 1 1; 1 1 -1
13-
-1 -1 1; -1 -1 -1; 1 -1 1; 1 -1 -1]) * step
14-
py_all = pyslice(nothing, nothing, nothing)
11+
# step = h * 0.25
12+
# offsets = np.array([-1 1 1; -1 1 -1; 1 1 1; 1 1 -1
13+
# -1 -1 1; -1 -1 -1; 1 -1 1; 1 -1 -1]) * step
14+
# py_all = pyslice(nothing, nothing, nothing)
1515

1616
# convert to trimesh
1717
vertices = stl_model.py_vertices
@@ -23,17 +23,18 @@ function _get_pts_voxel(stl_model::STLInfo3D, h::Real, fill::Bool)
2323
pts_cen = filled_vox.points
2424

2525
if fill # filling mode
26-
expanded = pts_cen[py_all, np.newaxis, py_all] + offsets[np.newaxis, py_all, py_all]
27-
return PyArray(expanded.reshape(-1, 3))
26+
# expanded = pts_cen[py_all, np.newaxis, py_all] + offsets[np.newaxis, py_all, py_all]
27+
# PyArray(expanded.reshape(-1, 3))
28+
return filling_pts(PyArray(pts_cen), h)
2829
else
2930
return PyArray(pts_cen)
3031
end
3132
end
3233

33-
function _get_pts_ray(stl_model::STLInfo3D, h::Real, fill::Bool, ϵ::String)
34+
function _get_pts_ray(stl_model::STLInfo3D, h::Real, fill::Bool)
3435
# inputs check
3536
h > 0 || error("h must be a positive number")
36-
points, pts2 = prepareprojection(stl_model, h, ϵ)
37+
points, pts2 = prepareprojection(stl_model, h)
3738
@info "generating pts at h = $h"
3839
edges = projectionlist(stl_model, points)
3940
pts_cen = fill_particles(edges, pts2, h)
@@ -44,19 +45,19 @@ function _get_pts_ray(stl_model::STLInfo3D, h::Real, fill::Bool, ϵ::String)
4445
end
4546
end
4647

47-
function prepareprojection(stl_model::STLInfo3D, h::Real, ϵ)
48-
T = ϵ == "FP32" ? Float32 : Float64
48+
function prepareprojection(stl_model::STLInfo3D, h::Real)
49+
T = Float64
4950
pts2 = meshbuilder(stl_model.vmin[1]-1.5h : h : stl_model.vmax[1]+1.5h,
50-
stl_model.vmin[2]-1.5h : h : stl_model.vmax[2]+1.5h, ϵ=ϵ)
51+
stl_model.vmin[2]-1.5h : h : stl_model.vmax[2]+1.5h)
5152
vzlimit = T(stl_model.vmin[3] - 10h)
52-
points = vcat(pts2, vzlimit .* ones(T, 1, size(pts2, 2)))
53+
points = hcat(pts2, vzlimit .* ones(T, size(pts2, 1)))
5354
return points, pts2
5455
end
5556

5657
function projectionlist(stl_model::STLInfo3D, points::AbstractArray{T}) where T
5758
# inputs check
58-
pts = points'; n, m = size(pts)
59-
m == 3 || error("points must be a 3xN array")
59+
pts = points; n, m = size(pts)
60+
m == 3 || error("points must be a Nx3 array")
6061

6162
mesh = stl_model.mesh
6263
pts = np.asarray(pts, dtype=np.float32)
@@ -88,7 +89,7 @@ function fill_particles(edges::AbstractArray, pts::AbstractMatrix{T}, h::Real) w
8889
@inbounds for i in eachindex(edges)
8990
v = edges[i]
9091
if !isempty(v) && iseven(length(v)) && any(!iszero, v)
91-
sort!(v); xi, yi = pts[1, i], pts[2, i]
92+
sort!(v); xi, yi = pts[i, 1], pts[i, 2]
9293
for j in 1:2:(length(v) - 1)
9394
for z in v[j]:h:v[j + 1]
9495
push!(x_all, xi)
@@ -98,9 +99,9 @@ function fill_particles(edges::AbstractArray, pts::AbstractMatrix{T}, h::Real) w
9899
end
99100
end
100101
end
101-
xyz = Matrix{T}(undef, 3, length(x_all))
102-
xyz[1, :] .= x_all
103-
xyz[2, :] .= y_all
104-
xyz[3, :] .= z_all
102+
xyz = Matrix{T}(undef, length(x_all), 3)
103+
xyz[:, 1] .= x_all
104+
xyz[:, 2] .= y_all
105+
xyz[:, 3] .= z_all
105106
return xyz
106107
end

src/fileio/asc.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function readasc(filename::String)
4949
5050
# 拼成 (N, 3) 的数组
5151
xyz = np.column_stack([xs, ys, zs])
52-
return xyz.T
52+
return xyz
5353
""" => py_tmp
5454

5555
return py2ju(Array, py_tmp(filename, rasterio, np))

src/fileio/geojson.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Write the polygon to a GeoJSON file. The `polygon` is an instance of `QueryPolyg
4343
Example:
4444
---
4545
```julia
46-
polygon_xy = [0 0; 1 0; 1 1; 0 1]' # 2xN array
46+
polygon_xy = [0 0; 1 0; 1 1; 0 1] # Nx2 array
4747
poly = get_polygon(polygon_xy, ratio=1) # poly.polygon to visualize
4848
write_polygon(poly, "/path/to/polygon.geojson")
4949
# or

src/fileio/ply.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,26 @@ Saves a point cloud to a PLY file.
1717
Example:
1818
---
1919
```julia
20-
points = rand(3, 1000) # 3D points
20+
points = rand(1000, 3) # 3D points
2121
saveply(points, "pointcloud.ply")
2222
# or
2323
saveply("pointcloud", points) # add .ply extension automatically
2424
25-
points = rand(2, 1000) # 2D points
25+
points = rand(1000, 2) # 2D points
2626
saveply("pointcloud.ply", points)
2727
```
2828
"""
2929
function saveply(points::AbstractArray, filename::String)
3030
# input check
31-
n, m = size(points)
32-
n in [2, 3] || throw(ArgumentError("points must be a 2D array with 2 or 3 rows"))
31+
m, n = size(points)
32+
n in [2, 3] || throw(ArgumentError("points must be a 2D array with 2 or 3 columns"))
3333
if !endswith(filename, ".ply")
3434
filename *= ".ply"
3535
end
3636
if n == 2
37-
pts = vcat(points, zeros(1, m))'
37+
pts = hcat(points, zeros(m))
3838
else
39-
pts = points'
39+
pts = points
4040
end
4141

4242
cloud = trimesh.points.PointCloud(pts)
@@ -65,9 +65,9 @@ pc = readply("pointcloud.ply", xy=true) # returns only x and y
6565
"""
6666
function readply(filename::String; xy::Bool=false)
6767
isfile(filename) || throw(ArgumentError("file $(filename) does not exist"))
68-
pc = py2ju(Array, trimesh.load(filename).vertices.T)
68+
pc = py2ju(Array, trimesh.load(filename).vertices)
6969
if xy
70-
return Array(pc[1:2, :])
70+
return Array(pc[:, 1:2])
7171
else
7272
return pc
7373
end

0 commit comments

Comments
 (0)