我有一个vtk将温度映射为3维的文件。我想确定给定x,y,z点的温度。我将使用以下代码来加载vtk文件(读取.vtk文件):
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;
}
Run Code Online (Sandbox Code Playgroud)
但是,在库中搜索大量方法时,vtk我找不到合适的函数来提取特定位置的值。有什么建议么?
在给定位置检索标量值的正确方法取决于两个问题:
关于数据布局,主要有两种布局:
关于职位,您可以有两种情况:
与数据布局无关,要在示例位置(即原始数据集的示例)检索数据,可以使用vtkPointLocator类。使用以下类(未经测试):
// 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);
Run Code Online (Sandbox Code Playgroud)
这将为您提供最接近的数据样本的点值。 请注意,这不会为您提供该点在数据集中的明确位置,因为它是隐式编码在变量id中的。要检索最接近点的实际位置,可以编写:
double *dataPt = polyData->GetPoint(id);
Run Code Online (Sandbox Code Playgroud)
如果要在域的任意位置检索数据,则需要某种插值方式。在这里,数据布局很重要。
| 归档时间: |
|
| 查看次数: |
1826 次 |
| 最近记录: |