如何在 meshio 中将颜色数组添加到网格?
How to add color array to mesh in meshio?
############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. ]]
代码:
import meshio
cells = [
("triangle", triangles)
]
mesh = meshio.Mesh(
points,
cells,
cell_data={"a": triangle_colours},
)
mesh.write(
"foo.vtk",
)
以上代码给出
ValueError: Incompatible cell data. 1 cell blocks, but 'a' has 205 blocks.
我只想给三角形添加颜色。 triangle_colours 数组的大小与此处示例中的三角形相同:https://github.com/nschloe/meshio。(两者都有 205 个元素)如何更正此错误?
cell_data
对应cells
,所以需要有相同的“阻塞”结构。
import meshio
cells = [("triangle", triangles)]
mesh = meshio.Mesh(
points,
cells,
cell_data={"a": [triangle_colours]},
)
mesh.write("foo.vtk")
############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. ]]
代码:
import meshio
cells = [
("triangle", triangles)
]
mesh = meshio.Mesh(
points,
cells,
cell_data={"a": triangle_colours},
)
mesh.write(
"foo.vtk",
)
以上代码给出
ValueError: Incompatible cell data. 1 cell blocks, but 'a' has 205 blocks.
我只想给三角形添加颜色。 triangle_colours 数组的大小与此处示例中的三角形相同:https://github.com/nschloe/meshio。(两者都有 205 个元素)如何更正此错误?
cell_data
对应cells
,所以需要有相同的“阻塞”结构。
import meshio
cells = [("triangle", triangles)]
mesh = meshio.Mesh(
points,
cells,
cell_data={"a": [triangle_colours]},
)
mesh.write("foo.vtk")