在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)

从上面的代码生成图将产生以下输出:

Top-View

Front-View

我应该如何填补空心的脸? 我玩过不同的着色器设置,但无济于事。 理想情况下,我想显示横截面的块。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...