简体   繁体   English

如何在VTK中制作简单的2D等高线图?

[英]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. 我正在填入VTK示例,以了解如何对所创建的数据进行简单的轮廓图绘制。 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. 假设我已经在一个结构化的矩形网格上的71x71域中解决了一个简单的PDE,其中节点之间的间距相等。

I've examined the example of filledContours which tells how to visualize a data coming from a *.vtp file. 我检查了filledContours的示例,该示例告诉您如何可视化来自* .vtp文件的数据。 I'm fine with this as long as I can write .vtp files. 只要可以编写.vtp文件,我就可以接受。 The problem is that I don't know how to create a .vtp data file which is suitable for contour plotting. 问题是我不知道如何创建适合轮廓绘制的.vtp数据文件。 I managed to create .vtp files from embedded actors such as spheres or cones, but I don't know how to do it with my 2D data array. 我设法从嵌入式参与者(例如球体或圆锥体)创建.vtp文件,但是我不知道如何使用2D数据数组来执行此操作。

Since you need an equally spaced mesh, I'd use the vtk xml-based ImageData format (*.vti). 由于您需要等距的网格,因此我将使用基于vtk xml的ImageData格式(* .vti)。

From http://www.cacr.caltech.edu/~slombey/asci/vtk/vtk_formats.simple.html : 来自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. “ ImageData-每个ImageData块都指定其在数据集整个范围内的范围。点和单元格由范围,原点和间距隐式描述。请注意,在所有块上,原点和间距都是恒定的,因此它们是指定为ImageData XML元素的属性,如下所示。

<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. -“链接信息末尾”。请注意,只有x0 y0 z0和dx dy dz是实数,WholeExtent和PieceExtent引用像素索引。

在Paraview上可视化具有10x10像素的2D地图 This example will show you a 10x10-pixel map with temperatures going from the lower-left corner to the upper corner-right corner. 本示例将向您显示一个10x10像素的地图,其温度从左下角到右上角。 Values are associated with each cell. 值与每个单元格关联。 You can adjust this format to your 2D data. 您可以将此格式调整为2D数据。 The file contents (notice I only use CellData): 文件内容(注意,我仅使用CellData):

example.vti : 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, ie 一种简单的方法是以CSV格式输出数据,并为每个网格正方形添加新行,即

....
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. 然后,如果将其加载到paraview中,则可以应用过滤器TableToPoints使其以paraview可以处理的形式获取。 Then apply the filter Delaunay2D to convert it from points to cells. 然后应用过滤器Delaunay2D将其从点转换为像元。 Once you've done this the Contour filter should work fine. 完成此操作后, Contour过滤器应该可以正常工作。

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. 如果将数据存储为CSV中的直线网格,也可能以某种方式加载数据,但是我不确定。

EDIT: Sorry I implicitly assumed you were trying to visualise data in paraview. 编辑:对不起,我隐式地假设您正在尝试可视化paraview中的数据。 Is this the case? 是这样吗

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM