Reputation: 2000
############points (108 ea)##################
[[362. 437. 0.]
[418. 124. 0.]
[452. 64. 0.]
...
[256. 512. 0.]
[ 0. 256. 0.]
[512. 256. 0.]]
##########triangles (205 ea)#################
[[ 86 106 100]
[104 95 100]
[ 41 104 101]
...
[ 0 84 36]
[ 84 6 36]
[ 6 84 0]]
################triangle_colours (205 ea)##############
[[0.69140625 0.2734375 0.3203125 1. ]
[0.8046875 0.37109375 0.36328125 1. ]
[0.83203125 0.48046875 0.40234375 1. ]
...
[0.46875 0.13671875 0.26171875 1. ]
[0.49609375 0.1796875 0.28515625 1. ]
[0.91796875 0.796875 0.71484375 1. ]]
Code:
import meshio
cells = [
("triangle", triangles)
]
mesh = meshio.Mesh(
points,
cells,
cell_data={"a": triangle_colours},
)
mesh.write(
"foo.vtk",
)
Above code gives
ValueError: Incompatible cell data. 1 cell blocks, but 'a' has 205 blocks.
I just want to add colors to triangles. triangle_colours array has the same size as triangles as per the example in here: https://github.com/nschloe/meshio .(Both has 205 elements) How can I correct this error?
Upvotes: 1
Views: 738
Reputation: 58821
cell_data
corresponds to cells
, so it needs to have the same "blocked" structure.
import meshio
cells = [("triangle", triangles)]
mesh = meshio.Mesh(
points,
cells,
cell_data={"a": [triangle_colours]},
)
mesh.write("foo.vtk")
Upvotes: 2