如何解决在Pyqtgraph上绘制3D横截面时填充正面和背面
我有一个1D表面水模型。 目的是使用横截面数据以3D形式显示模型。
每个剖面的横截面都有x坐标,每个x坐标的高度和沿河的站点编号。
在此处输入代码
例如
X = [-5,-2,2,5] #Cross-section points along the x direction
Z = [121.5,120,119,121.5] #Heights on the coordinates
Y = 500 #Station number in m
我当前的代码:
# -*- coding: utf-8 -*-
from fbs_runtime.application_context.PyQt5 import ApplicationContext
#system modules
import sys
import numpy as np
import pyqtgraph as pg
import pyqtgraph.opengl as gl
from PyQt5.QtWidgets import QMainWindow
from PyQt5 import uic
Gradients = {
'blue_to_red':[(0,(0,1)),(0.25,1,(0.5,0)),(0.75,(1,0))]
}
__version__ = '1.3.2'
class MainW(QMainWindow):
def __init__(self,__version__):
QMainWindow.__init__(self)
#path to the ui file (QOpenGL container)
uic.loadUi(os.path.join(self.src_path,'ui','hydretUI.ui'),self)
self.initiate3D()
def initiate3D(self):
#plotting just one cross-section for example
#connecting the first and last point to make a loop
x = np.array([ -5,-5,5,-5])
zi = np.array([118,121.5,118,118])
y = np.array([10,0]) #station numbers
colors = np.full((len(y),len(x),4),0.05)
#color levels
levels = np.linspace(118,10)
grad = np.array(Gradients['blue_to_red'])
rgb = np.array([[*rgbt] for rgbt in grad[:,1]])
ticks = np.linspace(0,10)
r = np.interp(ticks,grad[:,0].astype(np.float32),rgb[:,0])
g = np.interp(ticks,1])
b = np.interp(ticks,2])
kst_cd = {n: (r[n],g[n],b[n]) for n,i in enumerate(ticks)}
for k,l in enumerate(levels[:-1]):
ix = np.logical_and(z>=l,z<levels[k+1])
colors[...,0][ix] = kst_cd[k][0]
colors[...,1][ix] = kst_cd[k][1]
colors[...,2][ix] = kst_cd[k][2]
sp = gl.GLSurfacePlotItem(y,x,z,colors=colors,drawEdges=True,shader=None,glOptions='opaque')
self.viewer3d.addItem(sp) #add item to OpenGl Container
if __name__ == '__main__':
appctxt = ApplicationContext()
myapp = MainW(__version__)
myapp.show()
exit_code = appctxt.app.exec_()
sys.exit(exit_code)
我应该如何填补空心的脸? 我玩过不同的着色器设置,但无济于事。 理想情况下,我想显示横截面的块。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。