如何根据 txt 文件中的信息构建 vtkPolyData

发布于 2024-10-02 15:29:54 字数 441 浏览 2 评论 0原文

我有一个 txt 文件,其中包含一组 3 维数据点,我想根据这些点创建一个 vtkPolyData。

在文件中,我在第一行有点数,在我的例子中它们是 6 x 6。之后是每个点的实际坐标。文件的内容是这样的。

6 6 
1 1 3
2 1 3.4
3 1 3.6
4 1 3.6
5 1 3.4
6 1 3
1 2 3
2 2 3.8
3 2 4.2
4 2 4.2
5 2 3.8
6 2 3
1 3 3
2 3 3
3 3 3
4 3 3
5 3 3
6 3 3
1 4 3
2 4 3
3 4 3
4 4 3
5 4 3
6 4 3
1 5 3
2 5 3.8
3 5 4.2
4 5 4.2
5 5 3.8
6 5 3
1 6 3
2 6 3.4
3 6 3.6
4 6 3.6
5 6 3.4
6 6 3

如何使用包含此数据的 txt 文件构建 vtkPolyData 结构?

I have a txt file which contains a set of 3 Dimensional data points and I would like to create a vtkPolyData based on those points.

In the file, I have the number of points on the first line, in my case they are 6 x 6. And after that the actual coordinates of each point. The content of the file is like this.

6 6 
1 1 3
2 1 3.4
3 1 3.6
4 1 3.6
5 1 3.4
6 1 3
1 2 3
2 2 3.8
3 2 4.2
4 2 4.2
5 2 3.8
6 2 3
1 3 3
2 3 3
3 3 3
4 3 3
5 3 3
6 3 3
1 4 3
2 4 3
3 4 3
4 4 3
5 4 3
6 4 3
1 5 3
2 5 3.8
3 5 4.2
4 5 4.2
5 5 3.8
6 5 3
1 6 3
2 6 3.4
3 6 3.6
4 6 3.6
5 6 3.4
6 6 3

How can I build a vtkPolyData structure with a txt file with this data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜雨飘雪 2024-10-09 15:29:54

在我看来,你有一系列规则的网格点,对吗?如果是这样,vtkImageData 可能是更好的选择。如果您确实需要的话,您可以随时使用几何过滤器来转换为多数据。

  1. 创建一个 vtkImageData 实例。
  2. 将其维度设置为 (6, 6, 1)(忽略第三个维度)。
  3. 将其数据类型设置为适当的类型(我猜是浮点型或双精度型)。
  4. 调用 AllocateScalars();
  5. 如果是 C++,

    1. 调用 GetScalarPointer() 并将其转换为 3 中设置的数据类型。
    2. 该指针将指向一个大小为 36 的数组。您可以像平常一样填充每个点。
  6. 如果使用其他语言 (TCL/Python/Java),则使用参数 (x, y, 0, 0, value) 对图像数据调用 SetScalarComponentFromFloat。第一个 0 是第三个维度,第二个是第一个分量。

这将为您提供一个网格,并且它比多数据具有更高的内存效率。

如果您只想可视化点,请使用 vtkDataSetMapper,并使用 SetRepresentationToPoints() 设置 actor 的属性,设置适当的点大小。这将完成一个简单的可视化工作。

It looks to me like you have a regularly gridded series of points, right? If so, vtkImageData might be a better choice. You can always use a geometry filter afterwards to convert to polydata if you really need it that way.

  1. Create a vtkImageData instance.
  2. Set its dimensions to (6, 6, 1) (the third dimension is ignored).
  3. Set its data type to an appropriate type (float or double, I guess).
  4. Call AllocateScalars();
  5. If in C++,

    1. call GetScalarPointer() and cast it to the data type set in 3.
    2. This pointer will point to an array of size 36. You can just fill each point as you would normally.
  6. If in another language (TCL/Python/Java), call SetScalarComponentFromFloat on the image data, with the arguments (x, y, 0, 0, value). The first 0 is the 3rd dimension and the second is for the first component.

This will give you a grid, and it'll be far more memory efficient than a polydata.

If you want to visualize only the points, use a vtkDataSetMapper, and setup the actor's property with SetRepresentationToPoints(), setting an appropriate point size. That will do a simple job of visualization.

情绪操控生活 2024-10-09 15:29:54

这些示例有用吗?特别是,会生成点和多边形,所以应该可以适应。核心似乎是(有很多遗漏):

# ...
vtkPolyData shell
vtkFloatPoints points
vtkCellArray strips

# Generate points...
loop {
   ...
   points InsertPoint $k $x0 $x1 $x2
}
shell SetPoints points
points Delete

# Generate triangles/polygons...
loop {
   strips InsertNextCell $NP2
   # ...
   strips InsertCellPoint [expr $kb +$ke ]
   # ...
   strips InsertCellPoint [expr $kb +$ke ]
}
shell SetStrips strips
strips Delete

# ...

Are these examples useful? In particular, this does generation of points and polygons, so it should be possible to adapt. The core seems to be (with lots left out):

# ...
vtkPolyData shell
vtkFloatPoints points
vtkCellArray strips

# Generate points...
loop {
   ...
   points InsertPoint $k $x0 $x1 $x2
}
shell SetPoints points
points Delete

# Generate triangles/polygons...
loop {
   strips InsertNextCell $NP2
   # ...
   strips InsertCellPoint [expr $kb +$ke ]
   # ...
   strips InsertCellPoint [expr $kb +$ke ]
}
shell SetStrips strips
strips Delete

# ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文