Thanks!
I am trying to give it a go. My points have no connectivity, so I am trying to make the simplest file possible:
using HDF5
# Open or create a .vtkhdf file
h5file = h5open("mydata.vtkhdf", "w")
vtkhdf = create_group(h5file,"VTKHDF")
version = write_attribute(vtkhdf,"Version","2.1")
type = write_attribute(vtkhdf,"Type",8) #length of "PolyData"?
data = rand(Float32, 412, 3)
# Write the 'Points' dataset to the file
write(h5file, "VTKHDF/Points", data)
close(h5file)
It generates a file but it does not recognize the format / open in Paraview 5.12. If anyone has some pointers then it would be highly appreciated.
EDIT: In Python this produces something which works:
import h5py #Uses UTF-8 by default
import numpy as np
with h5py.File("wtf.hdf",'w') as hdffile:
# write support data
vtkhdf_group = hdffile.create_group("VTKHDF")
vtkhdf_group.attrs.create("Version", [1, 0])
vtkhdf_group.attrs.create("Type",np.string_("ImageData")) # ascii fixed length string
whole_extent = (0, 3, 0, 1, 0, 0)
vtkhdf_group.attrs.create("WholeExtent", whole_extent)
vtkhdf_group.attrs.create("Origin", (0.0, 0.0, 0.0))
vtkhdf_group.attrs.create("Spacing", (1.0, 1.0, 1.0))
vtkhdf_group.attrs.create("Direction", (1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0))
# create the pointdata group and the dataset inside it
field_data_group = vtkhdf_group.create_group("PointData")
field_data_group.attrs.create('Scalars', "PNGImage") ## UTF-8 seems to work here
dset = field_data_group.create_dataset('PNGImage',dtype=np.uint8,shape=(2,4))
dset[:, :] = np.reshape([1.0,2.3,3.1,4.5,\
1.0,2.3,3.1,4.5],(2, 4))
Taken from: Paraview VTKHDF Reader can not read utf8 strings (#22135) · Issues · ParaView / ParaView · GitLab
I would love if someone could get it to work in Julia. I have the following Julia code:
using HDF5
# Open an HDF5 file
filename = "wtf.hdf"
h5open(filename, "w") do file
# Create the top-level group 'VTKHDF' and set its attributes
vtkhdf_group = create_group(file, "VTKHDF")
write_attribute(vtkhdf_group, "Version", [1, 0]) # Julia HDF5 handles arrays as attributes natively
# For ASCII fixed-length strings, Julia's HDF5 doesn't require special handling like np.string_
# Direct assignment is typically sufficient, as HDF5.jl manages string encoding
attrs(vtkhdf_group)["Type"] = codeunits("ImageData") # This is inherently UTF-8, and HDF5.jl handles it correctly
whole_extent = [0, 3, 0, 1, 0, 0]
write_attribute(vtkhdf_group,"WholeExtent", whole_extent)
write_attribute(vtkhdf_group, "Origin", [0.0, 0.0, 0.0])
write_attribute(vtkhdf_group, "Spacing", [1.0, 1.0, 1.0])
write_attribute(vtkhdf_group, "Direction", [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0])
# Create the PointData group and the dataset inside it
field_data_group = create_group(vtkhdf_group, "PointData")
write_attribute(field_data_group, "Scalars", "PNGImage")
dset = create_dataset(field_data_group, "PNGImage", datatype(UInt8), dataspace(2, 4))
write(dset, UInt8[1 2 3 4; 5 6 7 8]) # Adjusted for UInt8
end
# Path to the file for reference
filename
Which runs but produces a file which is non openable in Paraview.