Hi, I generated the following VTK file from a simulation in FiPy
and reading it in Paraview doesnt seem to be working. I am only able to view the points as a Point Gaussian
and the colours are not suitably reflected. 50.0_output.vtk (24.7 KB)
I would appreciate any insight on this and is it possible to modify the VTK files in a scripted fashion so I could run a postprocessing pipeline to correct the VTK files if there is an error or are there certain buttons in Paraview that I need to click.
Thanks for your help.
It is because of the cell type used in your dataset.
In your file, from line 557 to 956 (i.e the ‘CELL_TYPES’ part) try replacing 41
(convex point set) by 9
(Quad). See here https://vtk.org/doc/nightly/html/vtkCellType_8h.html for available values, and check vtkCell subclasses (https://vtk.org/doc/nightly/html/classvtkCell.html) to get more informations.
more details
ParaView (and VTK) does not display points directly but only cells. ParaView does not handle every kind of VTK cells. The Point Gaussian
is a workaround to display a geometry at each point, whatever the cell type of the dataset.
1 Like
Hi! For future reference if anyone comes across a similar problem, here is a crude script in python to quickly modify the .vtk file. I know its not the most elegant, but it does the trick. I essentially do a text replacement of the 41
to 9
.
import glob
from tempfile import mkstemp
from shutil import move
from os import remove
# Obtain list of VTK files in directory
vtk_list = glob.glob("*.vtk")
# Rename the extensions to .txt files to process
for vtk in vtk_list:
# Access the last four characters in the path and replace them with .txt
os.rename(vtk, vtk[:-4] + ".txt")
txt_list = glob.glob("*output.txt")
def replace(source_file_path, pattern, substring):
fh, target_file_path = mkstemp()
with open(target_file_path, 'w') as target_file:
with open(source_file_path, 'r') as source_file:
for line in source_file:
if line.strip() == pattern:
lineout = f"{substring}\n"
target_file.write(lineout)
else:
target_file.write(line)
remove(source_file_path)
move(target_file_path, source_file_path)
for text in txt_list:
replace(text, "41", "9")
os.rename(text, text[:-4] + ".vtk")
On the command line, there are some powerful tools to do such replacements, as sed
:
$ sed -i 's/^41$/9/' 50.0_output.vtk