easier visualization if verts have a point-cell

This commit is contained in:
Martin Diehl 2020-10-27 13:19:53 +01:00
parent 93a791abd1
commit 201a62d7c9
2 changed files with 17 additions and 9 deletions

View File

@ -108,11 +108,18 @@ class VTK:
Spatial position of the points. Spatial position of the points.
""" """
N = points.shape[0]
vtk_points = vtk.vtkPoints() vtk_points = vtk.vtkPoints()
vtk_points.SetData(np_to_vtk(points)) vtk_points.SetData(np_to_vtk(points))
vtk_cells = vtk.vtkCellArray()
vtk_cells.SetNumberOfCells(N)
vtk_cells.SetCells(N,np_to_vtkIdTypeArray(np.stack((np.ones (N,dtype=np.int64),
np.arange(N,dtype=np.int64)),axis=1).ravel(),deep=True))
vtk_data = vtk.vtkPolyData() vtk_data = vtk.vtkPolyData()
vtk_data.SetPoints(vtk_points) vtk_data.SetPoints(vtk_points)
vtk_data.SetVerts(vtk_cells)
return VTK(vtk_data) return VTK(vtk_data)
@ -164,6 +171,7 @@ class VTK:
return VTK(vtk_data) return VTK(vtk_data)
@staticmethod @staticmethod
def _write(writer): def _write(writer):
"""Wrapper for parallel writing.""" """Wrapper for parallel writing."""
@ -192,7 +200,7 @@ class VTK:
default_ext = writer.GetDefaultFileExtension() default_ext = writer.GetDefaultFileExtension()
ext = Path(fname).suffix ext = Path(fname).suffix
if ext and ext != '.'+default_ext: if ext and ext != '.'+default_ext:
raise ValueError(f'Given extension {ext} does not match default .{default_ext}') raise ValueError(f'Given extension "{ext}" does not match default ".{default_ext}"')
writer.SetFileName(str(Path(fname).with_suffix('.'+default_ext))) writer.SetFileName(str(Path(fname).with_suffix('.'+default_ext)))
if compress: if compress:
writer.SetCompressorTypeToZLib() writer.SetCompressorTypeToZLib()
@ -238,10 +246,10 @@ class VTK:
else data).reshape(N_data,-1),deep=True) # avoid large files else data).reshape(N_data,-1),deep=True) # avoid large files
d.SetName(label) d.SetName(label)
if N_data == N_cells: if N_data == N_points:
self.vtk_data.GetCellData().AddArray(d)
elif N_data == N_points:
self.vtk_data.GetPointData().AddArray(d) self.vtk_data.GetPointData().AddArray(d)
elif N_data == N_cells:
self.vtk_data.GetCellData().AddArray(d)
else: else:
raise ValueError(f'Cell / point count ({N_cells} / {N_points}) differs from data ({N_data}).') raise ValueError(f'Cell / point count ({N_cells} / {N_points}) differs from data ({N_data}).')
elif isinstance(data,pd.DataFrame): elif isinstance(data,pd.DataFrame):

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<VTKFile type="PolyData" version="0.1" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor"> <VTKFile type="PolyData" version="0.1" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor">
<PolyData> <PolyData>
<Piece NumberOfPoints="10" NumberOfVerts="0" NumberOfLines="0" NumberOfStrips="0" NumberOfPolys="0"> <Piece NumberOfPoints="10" NumberOfVerts="10" NumberOfLines="0" NumberOfStrips="0" NumberOfPolys="0">
<PointData> <PointData>
<DataArray type="Float32" Name="coordinates" NumberOfComponents="3" format="binary" RangeMin="0.7453560147132696" RangeMax="2.449489742783178"> <DataArray type="Float32" Name="coordinates" NumberOfComponents="3" format="binary" RangeMin="0.7453560147132696" RangeMax="2.449489742783178">
AQAAAACAAAB4AAAAVgAAAA==eF5jYICBhv2WfY9tLfuS7Ypk3PeDaCDf7okF3/7Vq1bZrV6lZQ+k94HEgHL2QHovUM7+iUUfiG0LlQdhkH77Ipnj9iB5qFp7kBjQDiBmcADRANsaLXM= AQAAAACAAAB4AAAAVgAAAA==eF5jYICBhv2WfY9tLfuS7Ypk3PeDaCDf7okF3/7Vq1bZrV6lZQ+k94HEgHL2QHovUM7+iUUfiG0LlQdhkH77Ipnj9iB5qFp7kBjQDiBmcADRANsaLXM=
@ -31,11 +31,11 @@
</DataArray> </DataArray>
</Points> </Points>
<Verts> <Verts>
<DataArray type="Int64" Name="connectivity" format="binary" RangeMin="1e+299" RangeMax="-1e+299"> <DataArray type="Int64" Name="connectivity" format="binary" RangeMin="0" RangeMax="9">
AAAAAACAAAAAAAAA AQAAAACAAABQAAAAIgAAAA==eF4txbcBACAIADAsiP7/sAPJkog2PL28nT4uXz9/BXgALg==
</DataArray> </DataArray>
<DataArray type="Int64" Name="offsets" format="binary" RangeMin="1e+299" RangeMax="-1e+299"> <DataArray type="Int64" Name="offsets" format="binary" RangeMin="1" RangeMax="10">
AAAAAACAAAAAAAAA AQAAAACAAABQAAAAIgAAAA==eF4txbcBACAIADA76v8HM5As6a0MTy9vH4evn78TBzAAOA==
</DataArray> </DataArray>
</Verts> </Verts>
<Lines> <Lines>