0

I have 3d points in file.I read them :

def points_to_array(pathIn):
    pointArray = []
    point = []
    in_file = open(pathIn, 'r')
    for line in in_file.readlines():
        split_line = line.strip('\n').split(' ')
        for i in range(0, 3):
            point.append(float(split_line[i]))
        pointArray.append(point)
        point = []
    return pointArray

And display them this way

import pyvista as pv
plotter = pv.Plotter(window_size=(1600, 1100))
points = points_to_array("C:\points.txt")
npPointArray = np.array(points)
plotter.add_points(npPointArray, color = 'r')

I want to add a line between some points (i.e from point to point as they appear in the file) Can I do this? how?

4

1 回答 1

2

这是一个应该有所帮助的简单示例。此示例所做的是使用描述单元格的格式(基本上是每个单元格的点数,然后是单元格连通性)创建一些由lines数组定义的线。vtk在此示例中,我们将创建两条简单的线,但您可以创建更多,并在每条线上包含任意数量的点。

import numpy as np
import pyvista as pv


points = np.array([[0, 0, 0],
                   [1, 0, 0],
                   [1, 1, 0],
                   [0, 1, 0]])

lines = np.hstack(([2, 0, 1],
                   [2, 1, 2]))

pdata = pv.PolyData(points)
pdata.lines = lines

pl = pv.Plotter()
pl.add_mesh(pdata)
pl.camera_position = 'xy'
pl.add_point_labels(points, range(4), font_size=20)
pl.show()

pyvista 图

于 2020-09-08T04:46:24.867 回答