x,y,z 点的 vtk 值 [英] vtk value at x,y,z point

查看:31
本文介绍了x,y,z 点的 vtk 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 vtk 文件,它在 3 个维度上映射温度.我想确定给定 x、y、z 点的温度.我将使用以下代码来加载 vtk 文件(阅读 .vtk 文件):

I have a vtk file which maps temperature in 3 dimensions. I would like to determine the temperature at a given x, y, z point. I will use the following code in order to load the vtk file (Reading .vtk file):

int main(int argc, char *argv[]) 
{
  // simply set filename here (oh static joy)
  std::string inputFilename = "setYourPathToVtkFileHere";

  // Get all data from the file
  vtkSmartPointer<vtkGenericDataObjectReader> reader =
        vtkSmartPointer<vtkGenericDataObjectReader>::New();
  reader->SetFileName(inputFilename.c_str());
  reader->Update();

  // All of the standard data types can be checked and obtained like this:
  if (reader->IsFilePolyData()) 
  {
    std::cout << "output is a polydata" << std::endl;
    vtkPolyData* output = reader->GetPolyDataOutput();
    std::cout << "output has " << output->GetNumberOfPoints() << "     points." << std::endl;
  }

  return EXIT_SUCCESS;
}

但是,当在 vtk 库中搜索大量方法时,我找不到合适的函数来提取特定位置的值.有什么建议吗?

However, when searching through the extensive list of methods in the vtk library I cant find the appropriate function to extract a value at a specific location. Any suggestions?

推荐答案

在给定位置检索标量值的正确方法取决于两个问题:

The proper way to retrieve a scalar value at a given position depends on two questions:

  1. 您的数据是如何布局的,
  2. 您想从哪个位置检索属性

关于数据布局,主要有两种布局:

Concerning the data layout there are two main layouts:

  • 结构化:数据驻留在统一的网格中
  • 非结构化:点样本是任意的

关于位置,您可以有两种情况:

Concerning the position you can have two situations:

  • 在样本位置查询:您要求的点直接是数据集中的样本
  • 在任意位置查询:您请求一个位于您域中某个位置但不一定与您的数据样本重合的点.

独立于数据布局,要在样本位置(即原始数据集的样本)检索数据,您可以使用 vtkPointLocator 类.按如下方式使用该类(未经测试):

Independent of the data layout, to retrieve the data at a sample position (i.e. a sample of your original data set) you can use the vtkPointLocator class. Use the class as follows (untested):

// Build locator object
vtkSmartPointer<vtkPointLocator> locator = vtkPointLocator::New();
locator->SetDataSet(polyData);
locator->BuildLocator();
// Define query position
double pt[3] = {0.1, 0.2, 0.3};
// Get the ID of the point that is closest to the query position
vtkIdType id = locator->FindClosestPoint(pt);
// Retrieve the first attribute value from this point
double value = polyData->GetPointData()->GetScalars()->GetTuple(id, 0);

这将为您提供最接近数据样本的点值.请注意,这不会为您提供数据集中点的显式位置,因为它隐式编码在变量 id 中.要检索最近点的实际位置,您可以编写:

This will give you the point value of the closest sample of your data. Note that this will not give you the explicit position of the point in the data set as this is implicitly encoded in the variable id. To retrieve the actual position of the closest point, you can write:

double *dataPt = polyData->GetPoint(id);

如果您想在域的任意位置检索数据,您将需要某种插值方法.在这里,数据布局很重要.

If you want to retrieve data at an arbitrary position of your domain you will need some way of interpolation. Here, the data layout is important.

  • 对于结构化数据,您可以先将数据转换为 vtkImage,然后对其执行查询.如果要使用线性或三次方案检索插值属性,可以在过滤器链中添加 vtkImageInterpolator,然后使用 GetScalarComponentAsDouble 方法检索点.
  • 对于非结构化数据,您应该首先确定插值方案.vtk 有各种过滤器可以从数据样本中重建连续数据.选项包括 Delaunay 三角剖分/四面体化 (vtkDelaunay2D, vtkDelaunay3D) 以及 Shepard 方法 (vtkShepardMethod).这两种方法都将为您提供一个新的数据集,可以查询任意点.如果您想在不实际重建完整数据集的情况下检索(一批)点的标量属性,您还可以查看 vtkProbeFilter.

这篇关于x,y,z 点的 vtk 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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