Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/MeshIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ include("io/2dm.jl")
include("io/msh.jl")
include("io/gts.jl")
include("io/ifs.jl")
include("io/inp.jl")

"""
load(fn::File{MeshFormat}; pointtype=Point3f, uvtype=Vec2f,
Expand Down
36 changes: 36 additions & 0 deletions src/io/inp.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# read .inp files
function load(fs::Stream{format"INP"}; facetype=GLTriangleFace, pointtype=Point3f)
#INP file format
io = stream(fs)

points = pointtype[]
faces = facetype[]
node_idx = Int[]

# read the first 3 lines if there is the "*heading" keyword
line = readline(io)
contains(line,"*heading") && (line = readline(io))
BlockType = contains(line,"*NODE") ? Val{:NodeBlock}() : Val{:DataBlock}()

# read the file
while !eof(io)
line = readline(io)
BlockType, line = parse_blocktype!(BlockType, io, line)
if BlockType == Val{:NodeBlock}()
push!(node_idx, parse(Int,split(line,",")[1])) # keep track of the node index of the inp file
push!(points, pointtype(parse.(eltype(pointtype),split(line,",")[2:4])))
elseif BlockType == Val{:ElementBlock}()
nodes = parse.(Int,split(line,",")[2:end])
push!(faces, TriangleFace{Int}(facetype([findfirst(==(node),node_idx) for node in nodes])...)) # parse the face
else
continue
end
end

return Mesh(points, faces)
end
function parse_blocktype!(block, io, line)
contains(line,"*NODE") && return block=Val{:NodeBlock}(),readline(io)
contains(line,"*ELEMENT") && return block=Val{:ElementBlock}(),readline(io)
return block, line
end
2 changes: 2 additions & 0 deletions src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function _precompile_()
@warnpcfail precompile(load, (File{format"PLY_BINARY",IOStream},))
@warnpcfail precompile(load, (File{format"STL_ASCII",IOStream},))
@warnpcfail precompile(load, (File{format"STL_BINARY",IOStream},))
@warnpcfail precompile(load, (File{format"INP",IOStream},))
else
@warnpcfail precompile(load, (File{format"2DM"},))
@warnpcfail precompile(load, (File{format"MSH"},))
Expand All @@ -30,6 +31,7 @@ function _precompile_()
@warnpcfail precompile(load, (File{format"PLY_BINARY"},))
@warnpcfail precompile(load, (File{format"STL_ASCII"},))
@warnpcfail precompile(load, (File{format"STL_BINARY"},))
@warnpcfail precompile(load, (File{format"INP"},))
end

end
14 changes: 11 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,8 @@ end
msh2 = expand_faceviews(Mesh(msh))
@test !(normals(msh2) isa FaceView)
@test length(faces(msh2)) == 1
@test coordinates(coordinates(msh2)[faces(msh2)[1]]) == (Vec3f(0), Vec3f(0.062805, 0.591207, 0.902102), Vec3f(0.058382, 0.577691, 0.904429))
@test normals(msh2)[faces(msh2)[1]] == (Vec3f(0.9134, 0.104, 0.3934), Vec3f(0.8079, 0.4428, 0.3887), Vec3f(0.8943, 0.4474, 0.0))

@test all(coordinates(coordinates(msh2)[faces(msh2)[1]]) .==[Point3f(0), Point3f(0.062805, 0.591207, 0.902102), Point3f(0.058382, 0.577691, 0.904429)])
@test all(normals(msh2)[faces(msh2)[1]] .== [Vec3f(0.9134, 0.104, 0.3934), Vec3f(0.8079, 0.4428, 0.3887), Vec3f(0.8943, 0.4474, 0.0)])
# test that save works with FaceViews
mktempdir() do tmpdir
save(joinpath(tmpdir, "test.obj"), msh)
Expand Down Expand Up @@ -264,5 +263,14 @@ end
@test material["diffuse map"] isa Dict{String, Any}
@test material["diffuse map"]["filename"] == replace(joinpath(tf, "mini sponza/SP_LUK.JPG"), '\\' => '/')
end

@testset "INP" begin
msh = load(joinpath(tf, "cube.inp"))

@test length(faces(msh)) == 24
@test length(coordinates(msh)) == 14
@test msh.views == []
@test test_face_indices(msh)
end
end
end
40 changes: 40 additions & 0 deletions test/testfiles/cube.inp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
*NODE
1, -0.5, -0.5, 0.5
2, -0.5, -0.5, -0.5
3, -0.5, 0.5, 0.5
4, -0.5, 0.5, -0.5
5, 0.5, -0.5, 0.5
6, 0.5, -0.5, -0.5
7, 0.5, 0.5, 0.5
8, 0.5, 0.5, -0.5
9, -0.5, 0.0, 0.0
10, 0.5, 0.0, 0.0
11, 0.0, -0.5, 0.0
12, 0.0, 0.5, 0.0
13, 0.0, 0.0, -0.5
14, 0.0, 0.0, 0.5
*ELEMENT, type=CPS3, ELSET=Surface1
21, 2, 1, 9
22, 1, 3, 9
23, 4, 2, 9
24, 3, 4, 9
25, 6, 10, 5
26, 5, 10, 7
27, 8, 10, 6
28, 7, 10, 8
29, 1, 2, 11
30, 5, 1, 11
31, 2, 6, 11
32, 6, 5, 11
33, 3, 12, 4
34, 7, 12, 3
35, 4, 12, 8
36, 8, 12, 7
37, 2, 4, 13
38, 6, 2, 13
39, 4, 8, 13
40, 8, 6, 13
41, 1, 14, 3
42, 5, 14, 1
43, 3, 14, 7
44, 7, 14, 5
Loading