[vtkusers] [EXTERNAL] format file algorithm

Meehan, Bernard MEEHANBT at nv.doe.gov
Wed Oct 4 10:43:03 EDT 2017


There are a many sources on the internet that explain the format:
https://www.vtk.org/doc/nightly/html/IOLegacyInformationFormat.html
https://www.vtk.org/wp-content/uploads/2015/04/file-formats.pdf
http://www.cacr.caltech.edu/~slombey/asci/vtk/vtk_formats.simple.html
https://www.vtk.org/Wiki/VTK/Writing_VTK_files_using_python#.22legacy.22

The reason that the lines and vertices are recorded the way they are is probably to save space. In your small example it may not be readily apparent, but once you start to get a semi-large dataset, such as a 3D CFD mesh, it will make much more sense why it is done that way. Just as an example of how you might do this in something like python, here is a script that writes out a circle:


#!/usr/bin/env python3

# -*- coding: utf-8 -*-


from math import *

N = 20


points   = []

vertices = []

segments = []


for i in range(N):

  points.append((0., cos(i*2.*pi/N), sin(i*2.*pi/N)))

  vertices.append((1, i))

  segments.append((2, i, (i + 1) % N))


print("""# vtk DataFile Version 3.0

vtk output

ASCII

DATASET POLYDATA\n""")


print("POINTS {} float".format(N))

for point in points:

  print("{} {} {}".format(*point))

print()


print("LINES {} {}".format(N, 3*N))

for segment in segments:

  print("{} {} {}".format(*segment))

print()


print("VERTICES {} {}".format(N, 2*N))

for vert in vertices:

  print("{} {}".format(*vert))

print()


From: vtkusers <vtkusers-bounces at vtk.org<mailto:vtkusers-bounces at vtk.org>> on behalf of Marco Ghiani <marcog.ghiani at gmail.com<mailto:marcog.ghiani at gmail.com>>
Date: Wednesday, October 4, 2017 at 1:29 AM
To: "vtkusers at vtk.org<mailto:vtkusers at vtk.org>" <vtkusers at vtk.org<mailto:vtkusers at vtk.org>>
Subject: [EXTERNAL] [vtkusers] format file algorithm


I'm Marco I've just started my phD last week , about computational fluid dynamics of polymeric turbulent flow , I would really understand the algorithm for write a generic script that given a set of point x,y,z construct a file in this format :

# vtk DataFile Version 3.0
vtk output
ASCII
DATASET POLYDATA

POINTS 3 float
1.0 0.5 1.5
0.2 0.1 0.8
0.4 0.2 2.3

LINES 2 6
2 0 1
2 0 2

VERTICES 3 6
1 0
1 1
1 2

POINT_DATA 3
SCALARS element float
LOOKUP_TABLE default
8 1 1
SCALARS somefield float
LOOKUP_TABLE default
0.687 0.262 0.185


I have no idea how to set the LINES and VERTICES starting from only a number of spatial point ! could somebody help me please ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20171004/43db27a1/attachment.html>


More information about the vtkusers mailing list