如何根据 txt 文件中的信息构建 vtkPolyData
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,你有一系列规则的网格点,对吗?如果是这样,vtkImageData 可能是更好的选择。如果您确实需要的话,您可以随时使用几何过滤器来转换为多数据。
如果是 C++,
如果使用其他语言 (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.
If in C++,
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.
这些示例有用吗?特别是,这会生成点和多边形,所以应该可以适应。核心似乎是(有很多遗漏):
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):