Creating Mesh Out of Mesh

51 views
Skip to first unread message

Soo Rin Park

unread,
Jul 22, 2016, 6:57:04 PM7/22/16
to pyqtgraph
I'm fairly new to all this, so I was hoping you guys might be able to help with this. Here's my code to start with:

from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph as pg
import pyqtgraph.opengl as gl
import numpy as np
import matplotlib.cm

app
= QtGui.QApplication([])

view
= gl.GLViewWidget()
view
.show()

grid
= gl.GLGridItem()
grid
.scale(1,1,1)
view
.addItem(grid)

# verts and faces to create a cube
verts
= np.array([
[0, 0, 0], #0
[0, 0, 1], #1
[0, 1, 0], #2
[0, 1, 1], #3
[1, 0, 0], #4
[1, 0, 1], #5
[1, 1, 0], #6
[1, 1, 1] #7
])

faces
= np.array([
[0, 4, 6],
[0, 6, 2],
[1, 5, 7],
[1, 7, 3],
[2, 6, 3],
[3, 7, 6],
[0, 4, 1],
[1, 5, 4],
[4, 5, 7],
[4, 6, 7],
[0, 1, 3],
[0, 2, 3]
])

# data that contains [x, y, z, color]
data
= [[0, 0, 0, .123], [0, 0, 1, .234], [0, 1, 0, .345], [0, 1, 1, .456], [1, 0, 0, .567], [1, 0, 1, .678], [1, 1, 0, .789], [1, 1, 1, .890]]

for i in range(0, len(data)):
   
   
# use matplotlib to get rgb color
    colorData
= matplotlib.cm.hot(data[i][3])    
    colors
= np.tile(colorData, (12, 1))
   
    m1
= gl.GLMeshItem(vertexes=verts, faces=faces, faceColors=colors, smooth=False)
    m1
.translate(data[i][0], data[i][1], data[i][2]) # translate according to xyz data to "mesh" together
    m1
. setGLOptions('opaque')
    glview
.addItem(m1)

if __name__ == '__main__':
   
import sys
   
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
       
QtGui.QApplication.instance().exec_()

So I need to do a scatter plot but I need to use 3D Cubes, so I'm using a mesh to create the cube first then I'm stacking them on top of each other to imitate a mesh. The issue is, this is very slow and will only work for small amount of cubes. So How could I mesh all the cubes together that all each have different color values, and make it so that it will operate with big data as well? I know you could mesh the data together again, but I'm not really sure how to do that.


Reply all
Reply to author
Forward
0 new messages