How to make a simple 2D contour plot in VTK?
I'm cramming VTK examples to find out how to make a simple contour plot of the data I've created. Suppose I have solved a simple PDE in a 71x71 domain, on a structured rectangular grid, in which nodes are aligned with equal distances between them.
I've examined the example of filledContours which tells how to visualize a data coming from a *.vtp file. I'm fine with this as long as I can write .vtp files. The problem is that I don't know how to create a .vtp data file which is suitable for contour plotting. I managed to create .vtp files from embedded actors such as spheres or cones, 开发者_如何学Cbut I don't know how to do it with my 2D data array.
Since you need an equally spaced mesh, I'd use the vtk xml-based ImageData format (*.vti).
From http://www.cacr.caltech.edu/~slombey/asci/vtk/vtk_formats.simple.html :
"� ImageData — Each ImageData piece specifies its extent within the dataset's whole extent. The points and cells ... are described implicitly by the extent, origin, and spacing. Note that the origin and spacing are constant across all pieces, so they are specified as attributes of the ImageData XML element as follows.
<VTKFile type=" ImageData" ...>
<ImageData WholeExtent=" x1 x2 y1 y2 z1 z2"
Origin=" x0 y0 z0" Spacing=" dx dy dz">
<Piece Extent=" x1 x2 y1 y2 z1 z2">
<PointData>...</ PointData>
<CellData>...</ CellData>
</ Piece>
</ ImageData>
</ VTKFile>
-End of link info" Notice that only x0 y0 z0 and dx dy dz are real, WholeExtent and PieceExtent refer to pixel indices.
This example will show you a 10x10-pixel map with temperatures going from the lower-left corner to the upper corner-right corner. Values are associated with each cell. You can adjust this format to your 2D data. The file contents (notice I only use CellData):example.vti :
<VTKFile type="ImageData" version="0.1" byte_order="LittleEndian">
<ImageData WholeExtent=" 0 10 0 10 0 1" Origin=" 0 0 0" Spacing=" 1 1 0">
<Piece Extent=" 0 10 0 10 0 1">
<CellData Scalars="scalars">
<DataArray type="Float32" Name="Temperature[C]" format="ascii">
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100
</DataArray>
</CellData>
</Piece>
</ImageData>
</VTKFile>
A simple way would be to output your data in CSV format with a new line for each grid square, i.e.
....
grid_idx_i, grid_idx_j, grid_idx_k, val_ijk
....
then if you load this into paraview you can apply the filter TableToPoints
to get it in a form paraview can handle. Then apply the filter Delaunay2D
to convert it from points to cells. Once you've done this the Contour
filter should work fine.
Also it might be possible somehow to load the data if it is stored as a straight grid in CSV but I'm not sure.
EDIT: Sorry I implicitly assumed you were trying to visualise data in paraview. Is this the case?
精彩评论