如何在pyqtgraph中设置绘图距离?

时间:2018-04-18 13:54:23

标签: python pyqtgraph

我的GLMeshItem中有很多GLViewWidget s,当我平移或缩放时,这会让我的情节变得很慢。

有没有办法限制pyqtgraph中的绘制距离?

1 个答案:

答案 0 :(得分:0)

我自己找到了它,在GLViewWidget.projectionMatrix()中有一个局部变量farClip

def projectionMatrix(self, region=None):
    if region is None:
        region = (0, 0, self.width(), self.height())

    x0, y0, w, h = self.getViewport()
    dist = self.opts['distance']
    fov = self.opts['fov']
    nearClip = dist * 0.001
    farClip = dist * 1000.

    r = nearClip * np.tan(fov * 0.5 * np.pi / 180.)
    t = r * h / w

    left  = r * ((region[0]-x0) * (2.0/w) - 1)
    right = r * ((region[0]+region[2]-x0) * (2.0/w) - 1)
    bottom = t * ((region[1]-y0) * (2.0/h) - 1)
    top    = t * ((region[1]+region[3]-y0) * (2.0/h) - 1)

    tr = QtGui.QMatrix4x4()
    tr.frustum(left, right, bottom, top, nearClip, farClip)
    return tr

所以答案是继承GLViewWidget并更改farClip

class MyView(GLViewWidget):
    def __init__(self):
        super().__init__()

    def projectionMatrix(self, region=None):
        ...
        farClip = 42.
        ...