我正在为一些数据构建一个可视化工具,并希望使用在pyqtGraphs3D OpenGL组件中绘制的3D球面来表示在所提供的数据中标识的目标。
我能够生成球并使用GLMeshItem.translate()
命令移动它们,但是,如果不首先通过调用.transform()获得所述球的当前位置,然后从它的当前位置生成一个转换命令到我希望将其移动到的新的绝对坐标,我就无法找到一种方便的方法来设置球面的坐标。这可能是唯一的方法来完成这一点,我只是怀疑有一个更直接的设置网格项目绝对坐标,我只是似乎无法确定。
下面的代码展示了我正在做的事情的基本框架,以及当前用于移动球体的方法。
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph as pg
import pyqtgraph.opengl as gl
import numpy as np
app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.showMaximized()
w.setWindowTitle('pyqtgraph example: GLMeshItem')
w.setCameraPosition(distance=40)
g = gl.GLGridItem()
g.scale(2,2,1)
w.addItem(g)
verts = np.array([
[0, 0, 0],
[2, 0, 0],
[1, 2, 0],
[1, 1, 1],
])
faces = np.array([
[0, 1, 2],
[0, 1, 3],
[0, 2, 3],
[1, 2, 3]
])
colors = np.array([
[1, 0, 0, 0.3],
[0, 1, 0, 0.3],
[0, 0, 1, 0.3],
[1, 1, 0, 0.3]
])
md = gl.MeshData.sphere(rows=4, cols=4)
colors = np.ones((md.faceCount(), 4), dtype=float)
colors[::2,0] = 0
colors[:,1] = np.linspace(0, 1, colors.shape[0])
md.setFaceColors(colors)
m3 = gl.GLMeshItem(meshdata=md, smooth=False)#, shader='balloon')
w.addItem(m3)
target = gl.MeshData.sphere(4,4,10)
targetMI = gl.GLMeshItem(meshdata = target, drawFaces = True,smooth = False)
w.addItem(targetMI)
while(1):
targetMI.translate(0.1,0,0)
app.processEvents()
## Start Qt event loop unless running in interactive mode.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
如本例所示。对于相对于当前位置的移动来说,翻译工作很好。我只是好奇是否有一种方法可以在GLMeshItem
上进行绝对位置移动(在本例中是targetMI
),这样我就可以使它移动到一个坐标,而无需首先得到转换,然后计算移动到所需坐标所需的转换。
发布于 2019-10-24 15:22:33
一个选项是在按身份设置绝对位置之前,通过resetTransform()
将项的转换重置为translate()
转换。例如:
targetMI.resetTransform()
targetMI.translate(10, 0, 0)
https://stackoverflow.com/questions/58531651
复制相似问题