Skip to content

try PythonCall #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Manifest.toml
*.vtr
*.vts
*.pvd
.CondaPkg/
3 changes: 3 additions & 0 deletions CondaPkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
vtk = ""
numpy = ""
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ authors = ["mohamed82008 <[email protected]>"]
version = "0.1.0"

[deps]
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
LightXML = "9c8b4983-aa76-5018-a973-4c85ecc9e179"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
VTKDataTypes = "10d27dd1-1d0f-5a4c-b178-bd2d0045a217"
WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192"

[compat]
CondaPkg = "0.2"
IterTools = "1"
LightXML = "0.9"
PyCall = "1.92"
PythonCall = "0.9"
VTKDataTypes = "0.1"
WriteVTK = "1.11"
julia = "1"
Expand Down
8 changes: 4 additions & 4 deletions src/PyVTK.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VTKClasses = Dict(
const VTKClasses = Dict(
0=>vtk.vtkEmptyCell,
1=>vtk.vtkVertex,
2=>vtk.vtkPolyVertex,
Expand Down Expand Up @@ -302,7 +302,7 @@ function PyVTK(dataset::VTKUniformRectilinearData)
return grid
end

function add_structured_data_to_grid!(grid::PyObject, dataset::AbstractVTKStructuredData)
function add_structured_data_to_grid!(grid, dataset::AbstractVTKStructuredData)
for m in keys(dataset.point_data)
_var_dim = var_dim(dataset, m, "Point")
if _var_dim == 1
Expand Down Expand Up @@ -337,15 +337,15 @@ function PyVTK(dataset::VTKMultiblockData)
return mb
end

function _VTKDataTypes(pyvtk::PyObject)
function _VTKDataTypes(pyvtk)
if pyvtk.GetClassName() == "vtkMultiBlockDataSet"
return extract_blocked_data(pyvtk)
else
return extract_simple_data(pyvtk)
end
end

function write_vtk(pyvtk::PyObject, filepath_noext::String)
function write_vtk(pyvtk, filepath_noext::String)
classname = pyvtk.GetClassName()
if classname == "vtkUnstructuredGrid"
writer = vtk.vtkXMLUnstructuredGridWriter()
Expand Down
37 changes: 19 additions & 18 deletions src/VTKDataIO.jl
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
module VTKDataIO

__precompile__(false)
# __precompile__(false)

using VTKDataTypes
using WriteVTK
using PyCall
using PythonCall
using LightXML
using IterTools
using Printf

if get(ENV, "JULIA_REGISTRYCI_AUTOMERGE", "false") == "false"
@eval begin
const vtkns = pyimport_conda("vtk.util.numpy_support", "vtk")
const vtk = pyimport_conda("vtk", "vtk")
const np = pyimport_conda("numpy", "numpy")
const vtk = PythonCall.pynew() # initially NULL
const vtkns = PythonCall.pynew() # initially NULL
const np = PythonCall.pynew() # initially NULL
function __init__()
PythonCall.pycopy!(vtk, pyimport("vtk"))
PythonCall.pycopy!(vtkns, pyimport("vtk.util.numpy_support"))
PythonCall.pycopy!(np, pyimport("numpy"))
end

include("vtkreaders.jl")
include("vtkwriters.jl")
include("vtpwriter.jl")
include("stlIO.jl")
include("extra_readers.jl")
include("PyVTK.jl")
include("visualize.jl")
include("vtkreaders.jl")
include("vtkwriters.jl")
include("vtpwriter.jl")
include("stlIO.jl")
include("extra_readers.jl")
include("PyVTK.jl")
include("visualize.jl")

export read_vtk, write_vtk, read_stl, write_stl, valid_to_write, PyVTK,
_VTKDataTypes, visualize, write_x3d, write_ply, read_obj, read_ply, visualize_3ds
end
end
export read_vtk, write_vtk, read_stl, write_stl, valid_to_write, PyVTK,
_VTKDataTypes, visualize, write_x3d, write_ply, read_obj, read_ply, visualize_3ds

end
2 changes: 1 addition & 1 deletion src/stlIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function write_stl(dataset::AbstractStaticVTKData, filepath_no_ext::String)
return write_stl(polydata, filepath_no_ext)
end

function write_stl(polydata::PyCall.PyObject, filepath_no_ext::String)
function write_stl(polydata, filepath_no_ext::String)
writer = vtk.vtkSTLWriter()
writer.SetFileName(string(filepath_no_ext, ".stl"))
writer.SetInputData(polydata)
Expand Down
6 changes: 3 additions & 3 deletions src/vtkreaders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ vtk_to_julia(x::Vector, T) = convert.(T, x)
vtk_to_julia(x::Matrix, T) = convert.(T, copy(x'))

function julia_to_vtk(x::Matrix, args...)
return @pycall vtkns.numpy_to_vtk(PyReverseDims(x), args...)::PyObject
return vtkns.numpy_to_vtk(PyReverseDims(x), args...)
end
function julia_to_vtk(x::Vector, args...)
return @pycall vtkns.numpy_to_vtk(np.array(x), args...)::PyObject
return vtkns.numpy_to_vtk(np.array(x), args...)
end

function pytype_as_string(x)
Expand All @@ -18,7 +18,7 @@ function pytype_as_string(x)
end
end

function read_vtk(reader::PyCall.PyObject)
function read_vtk(reader)
if in(reader.GetFileName(), readdir())
reader.Update()
else
Expand Down
2 changes: 1 addition & 1 deletion src/vtpwriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function write_vtp(dataset::VTKPolyData, filepath_no_ext::String)
return write_vtp(polydata, filepath_no_ext)
end

function write_vtp(polydata::PyObject, filepath_no_ext::String)
function write_vtp(polydata, filepath_no_ext::String)
writer = vtk.vtkXMLPolyDataWriter()
writer.SetFileName(string(filepath_no_ext, ".vtp"))
writer.SetDataModeToBinary()
Expand Down