diff --git a/.gitignore b/.gitignore index f78340e..6359fd3 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ Manifest.toml *.vtr *.vts *.pvd +.CondaPkg/ diff --git a/CondaPkg.toml b/CondaPkg.toml new file mode 100644 index 0000000..e96a042 --- /dev/null +++ b/CondaPkg.toml @@ -0,0 +1,3 @@ +[deps] +vtk = "" +numpy = "" diff --git a/Project.toml b/Project.toml index c744a0d..431afb8 100644 --- a/Project.toml +++ b/Project.toml @@ -4,17 +4,21 @@ authors = ["mohamed82008 "] 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" diff --git a/src/PyVTK.jl b/src/PyVTK.jl index 3fdc4b0..a521373 100644 --- a/src/PyVTK.jl +++ b/src/PyVTK.jl @@ -1,4 +1,4 @@ -VTKClasses = Dict( +const VTKClasses = Dict( 0=>vtk.vtkEmptyCell, 1=>vtk.vtkVertex, 2=>vtk.vtkPolyVertex, @@ -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 @@ -337,7 +337,7 @@ function PyVTK(dataset::VTKMultiblockData) return mb end -function _VTKDataTypes(pyvtk::PyObject) +function _VTKDataTypes(pyvtk) if pyvtk.GetClassName() == "vtkMultiBlockDataSet" return extract_blocked_data(pyvtk) else @@ -345,7 +345,7 @@ function _VTKDataTypes(pyvtk::PyObject) 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() diff --git a/src/VTKDataIO.jl b/src/VTKDataIO.jl index 42facb2..7cdc490 100644 --- a/src/VTKDataIO.jl +++ b/src/VTKDataIO.jl @@ -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 diff --git a/src/stlIO.jl b/src/stlIO.jl index 88fe5f2..c65bfbb 100644 --- a/src/stlIO.jl +++ b/src/stlIO.jl @@ -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) diff --git a/src/vtkreaders.jl b/src/vtkreaders.jl index 72ee893..668c76d 100644 --- a/src/vtkreaders.jl +++ b/src/vtkreaders.jl @@ -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) @@ -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 diff --git a/src/vtpwriter.jl b/src/vtpwriter.jl index b75c213..517e51c 100644 --- a/src/vtpwriter.jl +++ b/src/vtpwriter.jl @@ -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()