vtk 数据格式错误 [英] vtk data format error

查看:38
本文介绍了vtk 数据格式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 VTK(绘制彩色等值面)将我存储在常规网格上的一些数据可视化.我编写了一些代码来以 vtk 旧格式转储数据,该格式适用于数据的低分辨率版本.我可以使用 ParaView 或 VTK 库提取和查看预期的等值面.当我将每个维度的分辨率提高 10 倍(nx 从大约 100 到 1000,与 ny、nz 相同)时,paraview 和我使用 VTK 库编写的查看器不正确.它们看起来像一组略微偏离轴的薄片,而不是单个斑点".我从其他测试中知道数据本身是正确的.

I'm trying to visualize some data I have stored on a regular grid using VTK (drawing a colored isosurface). I wrote some code to dump the data in the vtk legacy format which works for low resolution versions of the data. I can extract and view the expected isosurface with ParaView or the VTK library. When I increase the resolution by a factor of 10 in each dimension (nx goes from about 100 to 1000, same with ny, nz), paraview and a viewer I wrote using the VTK library are incorrect. They look like a set of slightly off-axis sheets instead of a single "blob". I know from other tests that the data itself is correct.

下面我的旧版 vtk 格式转储代码有问题吗?我不明白查找表的作用,但它似乎适用于低分辨率情况.

Is there something wrong with my legacy vtk format dumping code below? I don't understand what the lookup table does, but it seems to work fine for the low resolution case.

std::ofstream out(filename);

out << "# vtk DataFile Version 3.0" << std::endl;
out << "Signed distance/biharmonic visualizer" << std::endl;
out << "ASCII" << std::endl;
out << "DATASET STRUCTURED_POINTS" << std::endl;
out << "DIMENSIONS " << nx << " " << ny << " " << nz << std::endl;
out << "ORIGIN 0 0 0" << std::endl;
out << "SPACING " << h << " " << h << " " << h << std::endl;
out << "POINT_DATA " << nx*ny*nz << std::endl;
out << "SCALARS signedDistance double" << std::endl;
out << "LOOKUP_TABLE default" << std::endl;
for(size_t i = 0; i < nx; ++i)
  for(size_t j = 0; j < ny; ++j)
    for(size_t k = 0; k < nz; ++k)
      out << tempPhi(i,j,k) << std::endl;
out << "SCALARS biharmonic double" << std::endl;
out << "LOOKUP_TABLE default" << std::endl;
for(size_t i = 0; i < nx; ++i)
  for(size_t j = 0; j < ny; ++j)
    for(size_t k = 0; k < nz; ++k)
      out << biharmonic(i,j,k) << std::endl;
out.close();

推荐答案

在您提供的 VTK 文件中,出现了多次 1.79769e+308.要真正查看"您的数据,我必须用零替换这些数据.完成此操作并查看 VisIt 中的数据文件后,我猜您编写点数据不正确(您的三个嵌套 for 循环 - 将数据从 3D 展平为 1D 列表).

In the VTK file you provide there are a number of occurrences of 1.79769e+308. To actually 'see' your data I had to replace these with zeros. Having done this and looked at your data file in VisIt I would guess that your method of writing the point data is incorrect (your three nested for loops - which flatten the data from 3D to a 1D list).

我建议您使用 VTK 编写器和 this 简单的 C 代码,随 VisIt 一起提供,用于编写遗留的 VTK 文件.确保使用这两种方法编写的数据集完全一致(请注意,VisItWriterLib.c 编写的是版本 2 VTK 文件格式,而您使用的是版本 3 - 但这不会导致问题).

I would suggest that you you write some small test data sets with your VTK writer and also with this simple C code, which is supplied with VisIt to write legacy VTK files. Make sure that the data sets written with both methods agree exactly (note that VisItWriterLib.c writes version 2 VTK file formats, whereas you use version 3 - this shouldn't cause a problem however).

正如评论中所讨论的,问题在于嵌套 for 循环的排序,这些循环用于输出点数据并将其从 3D 展平为 1D 列表.代码

As discussed in the comments, the problem was the ordering of the nested for loops which were used to output the point data and flatten it from 3D to a 1D list. The code

for(size_t i = 0; i < nx; ++i)
  for(size_t j = 0; j < ny; ++j)
    for(size_t k = 0; k < nz; ++k)
      out << tempPhi(i,j,k) << std::endl;

其实应该读

for(size_t k = 0; k < nz; ++k)
  for(size_t j = 0; j < ny; ++j)
    for(size_t i = 0; i < nx; ++i)
      out << tempPhi(i,j,k) << std::endl;

即数据应按列主要顺序写入,而不是按行主要顺序写入.这是VTK文件格式文档所欠缺的一点.

i.e. the data should be written in column major order, not row major. This is a point in which the VTK file formats document is lacking.

这篇关于vtk 数据格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆