Skip to content

Commit a289bdd

Browse files
committed
♦️ Add support for reading and saving .xy and .xyz files in the FastPointQuery module.
1 parent d909389 commit a289bdd

3 files changed

Lines changed: 77 additions & 7 deletions

File tree

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ version = "0.1.4"
55

66
[deps]
77
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
8+
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
89
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
910
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
1011
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
1112
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
1213

1314
[compat]
1415
CondaPkg = "0.2"
16+
DelimitedFiles = "1.9"
1517
PythonCall = "0.9"
1618
PrecompileTools = "1.2"
1719
julia = "1.11"

src/FastPointQuery.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module FastPointQuery
22

3-
using CondaPkg, Downloads, Logging, PrecompileTools, PythonCall
3+
using CondaPkg, DelimitedFiles, Downloads, Logging, PrecompileTools, PythonCall
44

55
# Python packages
66
const np = PythonCall.pynew()
@@ -39,14 +39,15 @@ function __init__()
3939
end
4040
end
4141

42-
include(joinpath(@__DIR__, "fileio/asc.jl" ))
42+
include(joinpath(@__DIR__, "fileio/asc.jl"))
4343
include(joinpath(@__DIR__, "fileio/geojson.jl"))
44-
include(joinpath(@__DIR__, "fileio/ply.jl" ))
45-
include(joinpath(@__DIR__, "fileio/stl.jl" ))
46-
include(joinpath(@__DIR__, "fileio/tiff.jl" ))
44+
include(joinpath(@__DIR__, "fileio/ply.jl"))
45+
include(joinpath(@__DIR__, "fileio/stl.jl"))
46+
include(joinpath(@__DIR__, "fileio/tiff.jl"))
47+
include(joinpath(@__DIR__, "fileio/xyz.jl"))
4748

48-
include(joinpath(@__DIR__, "utils.jl" ))
49-
include(joinpath(@__DIR__, "polygon.jl" ))
49+
include(joinpath(@__DIR__, "utils.jl"))
50+
include(joinpath(@__DIR__, "polygon.jl"))
5051
include(joinpath(@__DIR__, "polyhedron.jl"))
5152

5253
export get_resource, res_dir

src/fileio/xyz.jl

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#==========================================================================================+
2+
| TABLE OF CONTENTS: |
3+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4+
| - readxy |
5+
| - readxyz |
6+
| - savexy |
7+
| - savexyz |
8+
+==========================================================================================#
9+
10+
export readxy
11+
export readxyz
12+
export savexy
13+
export savexyz
14+
15+
"""
16+
readxy(file_dir::P) where P <: String
17+
18+
Description:
19+
---
20+
Read the 2D `.xy` file from `file_dir`.
21+
"""
22+
function readxy(file_dir::P) where P <: String
23+
xy = readdlm(file_dir, ' ')[:, 1:2]
24+
return Array{Float64}(xy)
25+
end
26+
27+
"""
28+
readxyz(file_dir::P) where P <: String
29+
30+
Description:
31+
---
32+
Read the 3D `.xyz` file from `file_dir`.
33+
"""
34+
function readxyz(file_dir::P) where P <: String
35+
xyz = readdlm(file_dir, ' ')[:, 1:3]
36+
return Array{Float64}(xyz)
37+
end
38+
39+
"""
40+
savexy(file_dir::P, pts::T) where {P <: String, T <: AbstractMatrix}
41+
42+
Description:
43+
---
44+
Save the 2D points `pts` to the `.xy` file (`file_dir`).
45+
"""
46+
function savexy(file_dir::P, pts::T) where {P <: String, T <: AbstractMatrix}
47+
size(pts, 2) == 2 || throw(ArgumentError("The input points should have 2 columns."))
48+
open(file_dir, "w") do io
49+
writedlm(io, pts, ' ')
50+
end
51+
end
52+
savexy(pts::T, file_dir::P) where {P <: String, T <: AbstractMatrix} = savexy(file_dir, pts)
53+
54+
"""
55+
savexyz(file_dir::P, pts::T) where {P <: String, T <: AbstractMatrix}
56+
57+
Description:
58+
---
59+
Save the 3D points `pts` to the `.xyz` file (`file_dir`).
60+
"""
61+
function savexyz(file_dir::P, pts::T) where {P <: String, T <: AbstractMatrix}
62+
size(pts, 2) == 3 || throw(ArgumentError("The input points should have 3 columns."))
63+
open(file_dir, "w") do io
64+
writedlm(io, pts, ' ')
65+
end
66+
end
67+
savexyz(pts::T, file_dir::P) where {P <: String, T <: AbstractMatrix} = savexyz(file_dir, pts)

0 commit comments

Comments
 (0)