Ejemplo n.º 1
0
 def __init__(self):
     super(mctrack3D, self).__init__()
     self._productName = 'mctrack3D'
     self._process = evd.DrawMCTrack3D()
     self.init()
     self._mesh = gl.MeshData()
Ejemplo n.º 2
0
    # Qt Setup
    app = QtGui.QApplication([])
    w = gl.GLViewWidget()
    w.show()
    w.setWindowTitle('pyqtgraph example: GLIsosurface')

    w.setCameraPosition(azimuth=0, distance=30)

    g = gl.GLGridItem()
    g.scale(0.5, 0.5, 1)
    w.addItem(g)

    # Plot a the wavefunction isosurface
    verts, faces = pg.isosurface(prob, prob.max() / level)
    md = gl.MeshData(vertexes=verts, faces=faces)
    colors = np.ones((md.faceCount(), 4), dtype=float)
    colors[:, 3] = 0.2
    colors[:, 2] = np.linspace(1, 1, 1)
    md.setFaceColors(colors)

    m1 = gl.GLMeshItem(meshdata=md, smooth=True, shader='balloon')
    m1.setGLOptions('additive')
    w.addItem(m1)
    m1.translate(-L / (2 * dx), -L / (2 * dx), -L / (2 * dx))

    #Plot the potential sphere
    verts, faces = pg.isosurface(V, V.max())
    md = gl.MeshData(vertexes=verts, faces=faces)
    colors = np.ones((md.faceCount(), 4), dtype=float)
    colors[:, 3] = 0.2
print(mask_diastole.shape)

# Create an PyQT4 application object.
app = QtGui.QApplication(sys.argv)

# Create a window object.
window = gl.GLViewWidget()
window.resize(500, 500)
window.setCameraPosition(distance=100)
window.setWindowTitle('pyqtgraph : GLIsosurface')
window.show()

# uniform_filter() is equivalent to smooth3() in matlab.
mask_diastole = scipy.ndimage.uniform_filter(mask_diastole, [5, 5, 20], mode='nearest')

# Using marching cubes algorithm to get a polygonal mesh of an isosurface
verts, faces = measure.marching_cubes(mask_diastole, 0.1)
meshdata = gl.MeshData(vertexes=verts, faces=faces)
mesh = gl.GLMeshItem(meshdata=meshdata, smooth=True, color=(1.0, 0.0, 0.0, 0.2), shader='balloon', glOptions='additive')

# Translation
[avgX, avgY, avgZ] = map(np.mean, zip(*verts))
mesh.translate(-avgX, -avgY, -avgZ)
window.addItem(mesh)

sys.exit(app.exec_())

plt.show()

sys.exit()
Ejemplo n.º 4
0
    def SiPM_QT(self,position,phi,name,photons,max_photons,id=False,
                show_photons=True, MU_LIN=True, TH=0, color2=[0,0,0]):
        s = np.array(self.sipm,dtype=float)
        p = np.array([[s[0]/2,s[1]/2,s[2]/2],
                      [s[0]/2,s[1]/2,-s[2]/2],
                      [-s[0]/2,s[1]/2,s[2]/2],
                      [-s[0]/2,s[1]/2,-s[2]/2],
                      [s[0]/2,-s[1]/2,s[2]/2],
                      [s[0]/2,-s[1]/2,-s[2]/2],
                      [-s[0]/2,-s[1]/2,s[2]/2],
                      [-s[0]/2,-s[1]/2,-s[2]/2]])

        p=self.rot_cyl(p,phi)
        position3d = np.array([position for i in range(p.shape[0])])
        p = p + position3d

        #plt = gl.GLScatterPlotItem(pos=p, color=pg.glColor('w'),size=1)
        MU=25
        if (max_photons == 0):
            color = 0
        else:
            if MU_LIN==True:
                color = int(np.log(1+MU*photons/max_photons)/np.log(1+MU)*200.0)
            else:
                color = int(photons/max_photons*200)

        rgb=np.array([0.75*color+55,color+55,0.25*color+55])
        color  = pg.glColor(*rgb)
        color2 = pg.glColor(*(np.array(color2)))

        meshdata = gl.MeshData(vertexes=p,
                               faces=np.array([ [0,1,4], [5,4,1],
                                                [2,0,6], [4,6,0],
                                                [0,2,3], [1,0,3],
                                                [6,2,3], [7,3,6],
                                                [7,3,5], [1,3,5]]),
                          faceColors=np.array([ color,     color,
                                                color2,    color2,
                                                color2,    color2,
                                                color,     color,
                                                color2,    color2]))

        plt = gl.GLMeshItem(meshdata=meshdata, color = None,
                            edgeColor=pg.glColor('w'),
                            drawEdges=False,
                            smooth=False,
                            drawFaces=True,
                            #shader= 'shaded',#'balloon',#None, #'shaded',
                            glOptions='opaque',
                            computeNormals='False')

        #plt.setGLOptions('additive')
        self.w.addItem(plt)

        if (id==True): #and (int(name)==3512 or int(name)==1000 or int(name)==3511)):
            t = GLTextItem( X=position[0],
                            Y=position[1],
                            Z=position[2],
                            text=str(int(name)),size=8,color=np.array([255,0,0]))

            t.setGLViewWidget(self.w)
            self.w.addItem(t)


        text_color = (np.array([rgb[0],255,255])-rgb)*0.75
        text_size = self.w.opts['distance']

        if (show_photons==True and photons>TH) :
            t = GLTextItem( X=position[0],
                            Y=position[1],
                            Z=position[2],
                            text=str(int(photons)),size=8,
                            color=text_color)

            t.setGLViewWidget(self.w)
            self.w.addItem(t)
Ejemplo n.º 5
0
 def create_mesh_data(self):
     return gl.MeshData(vertexes=self.verts, faces=self.faces)
Ejemplo n.º 6
0
    def __init__(self, filename, filename_r):
        self.filename = filename
        self.flight = ReadData(self.filename)
        self.flight_data = self.flight.read_data();
        self.app = QtGui.QApplication([])
        self.win = QtGui.QMainWindow()
        self.area = DockArea()
        self.win.setCentralWidget(self.area)
        self.win.showMaximized()
        self.win.setWindowTitle('MPU Simulation')
        self.win.setGeometry(10, 25, 1920, 1024)

        #Reference Data
        self.filename_r = filename_r
        self.reference = ReadData(self.filename_r)
        self.reference_data = self.reference.read_data();


        # Create docks, place them into the window one at a time.
        self.d_a = Dock("Animation", size=(500, 400))
        self.d_n = Dock("North (Xn)", size=(500, 200))
        self.d_e = Dock("East (Yn)", size=(500, 200))
        self.d_h = Dock("Height (h)", size=(500, 200))
        self.d_v = Dock("Velocity V", size=(500, 200))
        self.d_u_ = Dock("Velocity u", size=(500, 200))
        self.d_v_ = Dock("Velocity v", size=(500, 200))
        self.d_w_ = Dock("Velocity w", size=(500, 200))
        self.d_p = Dock("Velocity p", size=(500, 200))
        self.d_q = Dock("Velocity q", size=(500, 200))
        self.d_r = Dock("Velocity r", size=(500, 200))
        self.d_phi = Dock("Roll", size=(500, 200))
        self.d_theta = Dock("Pitch", size=(500,200))
        self.d_psi = Dock("Yaw", size=(500,200))
        self.d_w = Dock("Motors Rotation", size=(500, 200))
        self.d_t = Dock("Motors Angle", size=(500,200))
        self.d_deltae = Dock("Elevons", size=(500,200))
        self.area.addDock(self.d_a, 'left')
        self.area.addDock(self.d_n, 'right')
        self.area.addDock(self.d_e, 'below', self.d_n)
        self.area.addDock(self.d_h, 'below', self.d_e)
        self.area.addDock(self.d_v, 'below', self.d_h)
        self.area.addDock(self.d_u_, 'below', self.d_v)
        self.area.addDock(self.d_v_, 'below', self.d_u_)
        self.area.addDock(self.d_w_, 'below', self.d_v_)
        self.area.addDock(self.d_phi, 'bottom', self.d_n)
        self.area.addDock(self.d_theta, 'below', self.d_phi)
        self.area.addDock(self.d_psi, 'below', self.d_theta)
        self.area.addDock(self.d_p, 'below', self.d_psi)
        self.area.addDock(self.d_q, 'below', self.d_p)
        self.area.addDock(self.d_r, 'below', self.d_q)
        self.area.addDock(self.d_w, 'bottom', self.d_phi)
        self.area.addDock(self.d_t, 'below', self.d_w)
        self.area.addDock(self.d_deltae, 'below', self.d_t)

        #Animation Window
        self.d_a.hideTitleBar()
        self.w = gl.GLViewWidget()
        self.zgrid = gl.GLGridItem()
        self.w.addItem(self.zgrid)
        self.w.setWindowTitle('Animation')
        self.w.setCameraPosition(distance=20, azimuth=90, elevation=60)
        self.x0 = self.flight_data[self.flight.i_north][0]
        self.y0 = -self.flight_data[self.flight.i_east][0]
        self.h0 = self.flight_data[self.flight.i_height][0]

        #Fuselage Model
        self.model_fus = Model("./obj_files/MPUFuselage.obj")
        self.md_fus = gl.MeshData(vertexes=self.model_fus.returnMesh())
        self.fuselage = gl.GLMeshItem(meshdata=self.md_fus, color=(1, 1, 1, 1),
            smooth=False, shader='shaded', glOptions='opaque')
        self.d_a.addWidget(self.w)

        #Waypoint Model
        self.model_wayp = Model("./obj_files/wayp.obj")
        self.md_wayp = gl.MeshData(vertexes=self.model_wayp.returnMesh())
        self.waypoint = gl.GLMeshItem(meshdata=self.md_wayp, color=(1, 1, 1, 1),
            smooth=False, shader='shaded', glOptions='opaque')
        self.d_a.addWidget(self.w)

        #Plots Setup
        #North Displacement
        self.w_n = pg.PlotWidget(title="North Displacement")
        self.w_n.setDownsampling(mode='peak')
        self.w_n.setClipToView(True)
        self.curve_x = self.w_n.plot()
        self.curve_x_r = self.w_n.plot()
        self.w_n.setLabel('bottom', 'Time', 's')
        self.w_n.setLabel('left', 'Xn', 'm')
        self.d_n.addWidget(self.w_n)

        #East Displacement
        self.w_e = pg.PlotWidget(title="East Displacement")
        self.w_e.setDownsampling(mode='peak')
        self.w_e.setClipToView(True)
        self.curve_y = self.w_e.plot()
        self.w_e.setLabel('bottom', 'Time', 's')
        self.w_e.setLabel('left', 'Yn', 'm')
        self.d_e.addWidget(self.w_e)

        #Height
        self.w_h = pg.PlotWidget(title="Height Displacement")
        self.w_h.setDownsampling(mode='peak')
        self.w_h.setClipToView(True)
        self.curve_h = self.w_h.plot()
        self.w_h.setLabel('bottom', 'Time', 's')
        self.w_h.setLabel('left', 'h', 'm')
        self.d_h.addWidget(self.w_h)

        #Velocity V
        self.w_v = pg.PlotWidget(title="Total Velocity")
        self.w_v.setDownsampling(mode='peak')
        self.w_v.setClipToView(True)
        self.curve_V = self.w_v.plot()
        self.w_v.setLabel('bottom', 'Time', 's')
        self.w_v.setLabel('left', 'V', 'm/s')
        self.d_v.addWidget(self.w_v)

        #Velocity u
        self.w_u_ = pg.PlotWidget(title="Velocity u")
        self.w_u_.setDownsampling(mode='peak')
        self.w_u_.setClipToView(True)
        self.curve_u_ = self.w_u_.plot()
        self.w_u_.setLabel('bottom', 'Time', 's')
        self.w_u_.setLabel('left', 'u', 'm/s')
        self.d_u_.addWidget(self.w_u_)

        #Velocity v
        self.w_v_ = pg.PlotWidget(title="Velocity v")
        self.w_v_.setDownsampling(mode='peak')
        self.w_v_.setClipToView(True)
        self.curve_v_ = self.w_v_.plot()
        self.w_v_.setLabel('bottom', 'Time', 's')
        self.w_v_.setLabel('left', 'v', 'm/s')
        self.d_v_.addWidget(self.w_v_)

        #Velocity w
        self.w_w_ = pg.PlotWidget(title="Velocity w")
        self.w_w_.setDownsampling(mode='peak')
        self.w_w_.setClipToView(True)
        self.curve_w_ = self.w_w_.plot()
        self.w_w_.setLabel('bottom', 'Time', 's')
        self.w_w_.setLabel('left', 'w', 'm/s')
        self.d_w_.addWidget(self.w_w_)

        #Velocity p
        self.w_p = pg.PlotWidget(title="Rotational Velocity p")
        self.w_p.setDownsampling(mode='peak')
        self.w_p.setClipToView(True)
        self.curve_p = self.w_p.plot()
        self.w_p.setLabel('bottom', 'Time', 's')
        self.w_p.setLabel('left', 'p', 'rad/s')
        self.d_p.addWidget(self.w_p)

        #Velocity q
        self.w_q = pg.PlotWidget(title="Rotational Velocity q")
        self.w_q.setDownsampling(mode='peak')
        self.w_q.setClipToView(True)
        self.curve_q = self.w_q.plot()
        self.w_q.setLabel('bottom', 'Time', 's')
        self.w_q.setLabel('left', 'q', 'rad/s')
        self.d_q.addWidget(self.w_q)

        #Velocity q
        self.w_r = pg.PlotWidget(title="Rotational Velocity r")
        self.w_r.setDownsampling(mode='peak')
        self.w_r.setClipToView(True)
        self.curve_r = self.w_r.plot()
        self.w_r.setLabel('bottom', 'Time', 's')
        self.w_r.setLabel('left', 'r', 'rad/s')
        self.d_r.addWidget(self.w_r)

        #Roll
        self.w_phi = pg.PlotWidget(title="Roll Angle")
        self.w_phi.setDownsampling(mode='peak')
        self.w_phi.setClipToView(True)
        self.curve_phi = self.w_phi.plot()
        self.w_phi.setLabel('bottom', 'Time', 's')
        self.w_phi.setLabel('left', 'Roll Anlge', 'rad')
        self.d_phi.addWidget(self.w_phi)

        #Pitch
        self.w_theta = pg.PlotWidget(title="Pitch Angle")
        self.w_theta.setDownsampling(mode='peak')
        self.w_theta.setClipToView(True)
        self.curve_theta = self.w_theta.plot()
        self.w_theta.setLabel('bottom', 'Time', 's')
        self.w_theta.setLabel('left', 'Pitch Angle', 'rad')
        self.d_theta.addWidget(self.w_theta)

        #Yaw
        self.w_psi = pg.PlotWidget(title="Yaw Angle")
        self.w_psi.setDownsampling(mode='peak')
        self.w_psi.setClipToView(True)
        self.curve_psi = self.w_psi.plot()
        self.w_psi.setLabel('bottom', 'Time', 's')
        self.w_psi.setLabel('left', 'Yaw Angle', 'rad')
        self.d_psi.addWidget(self.w_psi)

        #Motors Rotation
        self.w_w = pg.PlotWidget(title="Motors Rotational Velocity")
        self.w_w.setDownsampling(mode='peak')
        self.w_w.setClipToView(True)
        self.curve_wl = self.w_w.plot(pen = (255,0,0))
        self.curve_wr = self.w_w.plot(pen = (0,255,0))
        self.curve_wb = self.w_w.plot(pen = (0,0,255))
        self.w_w.setLabel('bottom', 'Time', 's')
        self.w_w.setLabel('left', 'Rotational Velocity', 'rpm')
        self.w_w.addLegend()
        self.l_w = self.w_w.plotItem.legend
        self.l_w.addItem(self.curve_wl, "Left Motor")
        self.l_w.addItem(self.curve_wr, "Right Motor")
        self.l_w.addItem(self.curve_wb, "Rear Motor")
        self.d_w.addWidget(self.w_w)

        #Motors Angle
        self.w_t = pg.PlotWidget(title="Motors Angle")
        self.w_t.setDownsampling(mode='peak')
        self.w_t.setClipToView(True)
        self.curve_tl = self.w_t.plot(pen = (255,0,0))
        self.curve_tr = self.w_t.plot(pen = (0,255,0))
        self.w_t.setLabel('bottom', 'Time', 's')
        self.w_t.setLabel('left', 'Motors Angle', 'deg')
        self.d_t.addWidget(self.w_t)
        self.w_t.addLegend()
        self.l_t = self.w_t.plotItem.legend
        self.l_t.addItem(self.curve_tl, "Left Motor")
        self.l_t.addItem(self.curve_tr, "Right Motor")
        self.d_t.addWidget(self.w_t)

        #Elevons Angle
        self.w_deltae = pg.PlotWidget(title="Elevons Angle")
        self.w_deltae.setDownsampling(mode='peak')
        self.w_deltae.setClipToView(True)
        self.curve_deltael = self.w_deltae.plot(pen = (255,0,0))
        self.curve_deltaer = self.w_deltae.plot(pen = (0,255,0))
        self.w_deltae.setLabel('bottom', 'Time', 's')
        self.w_deltae.setLabel('left', 'Elevons Angle', 'deg')
        self.d_deltae.addWidget(self.w_deltae)
        self.w_deltae.addLegend()
        self.l_deltae = self.w_deltae.plotItem.legend
        self.l_deltae.addItem(self.curve_deltael, "Left Elevon")
        self.l_deltae.addItem(self.curve_deltaer, "Right Elevon")
        self.d_deltae.addWidget(self.w_deltae)

        #Data Animation
        self.pts = np.vstack([self.flight_data[self.flight.i_north],
            -self.flight_data[self.flight.i_east],
            self.flight_data[self.flight.i_height]]).transpose()
        self.plt = gl.GLLinePlotItem(pos=self.pts, color=pg.glColor(('b')),
            width=1, antialias=True)
        self.w.addItem(self.plt)

        #Reference
        self.pts_r = np.stack([self.reference_data[self.reference.i_north_r],
            -self.reference_data[self.reference.i_east_r],
            self.reference_data[self.reference.i_height_r]]).transpose()
        self.plt_r = gl.GLLinePlotItem(pos=self.pts_r, color=pg.glColor(('r')),
            width=1, antialias=True)
        # print(self.pts_r[0])
        self.w.addItem(self.plt_r)

        #Add Geometry
        self.w.addItem(self.fuselage)
        self.w.addItem(self.waypoint)
        self.ti_in = 0
Ejemplo n.º 7
0
    def show(self):
        """
        Generate an display widget based on the plot settings and display it.

        ----

        Example:

        ``app1 = qg.QApplication(sys.argv)``

        ``plot1 = Plot(mesh1)``

        ``plot1.show()``

        ``app1.processEvents()``

        ``app1.exec_()``

        ----

        :return: None
        """
        mesh_data = pgo.MeshData(vertexes=self.mesh.verts, faces=self.mesh.tris, vertexColors=self.mesh.colors, faceColors=None)
        mesh_item = pgo.GLMeshItem(meshdata=mesh_data, shader='balloon', drawEdges=self.drawEdges, edgeColor=self.edgeColor,
                                   smooth=False, computeNormals=False, glOptions='translucent')
        # mesh_item = pgo.GLMeshItem(meshdata = mesh_data, shader='shaded', drawEdges=False, smooth=True, computeNormals = True, glOptions='opaque')

        widget = pgo.GLViewWidget()
        widget.setBackgroundColor('w')
        widget.addItem(mesh_item)

        if self.grids:
            # Add grids
            gx = pgo.GLGridItem()
            gx.setSize(x=50, y=50, z=50)
            gx.rotate(90, 0, 1, 0)
            gx.translate(-0.5, 24.5, 24.5)
            widget.addItem(gx)
            gy = pgo.GLGridItem()
            gy.setSize(x=50, y=50, z=50)
            gy.rotate(90, 1, 0, 0)
            gy.translate(24.5, -0.5, 24.5)
            widget.addItem(gy)
            gz = pgo.GLGridItem()
            gz.setSize(x=50, y=50, z=50)
            gz.translate(24.5, 24.5, -0.5)
            widget.addItem(gz)

            # Add axes
            ptsx = np.array([[-0.5, -0.5, -0.5], [50, -0.5, -0.5]])
            pltx = pgo.GLLinePlotItem(pos=ptsx, color=(1, 0, 0, 1), width=1, antialias=True)
            widget.addItem(pltx)
            ptsy = np.array([[-0.5, -0.5, -0.5], [-0.5, 50, -0.5]])
            plty = pgo.GLLinePlotItem(pos=ptsy, color=(0, 1, 0, 1), width=1, antialias=True)
            widget.addItem(plty)
            ptsz = np.array([[-0.5, -0.5, -0.5], [-0.5, -0.5, 50]])
            pltz = pgo.GLLinePlotItem(pos=ptsz, color=(0, 0, 1, 1), width=1, antialias=True)
            widget.addItem(pltz)

        # Set plot options
        widget.opts['center'] = qg.QVector3D(((self.mesh.model.shape[0]/self.mesh.res)/2)+self.pos[0], ((self.mesh.model.shape[1]/self.mesh.res)/2)+self.pos[1], ((self.mesh.model.shape[2]/self.mesh.res)/2)+self.pos[2])
        widget.opts['elevation'] = self.angle[0]
        widget.opts['azimuth'] = self.angle[1]
        widget.opts['distance'] = self.angle[2]
        widget.resize(self.res[0], self.res[1])

        # Show plot
        widget.setWindowTitle(str(self.name))
        widget.show()

        self.widget = widget
Ejemplo n.º 8
0
#ax = gl.GLAxisItem()
#ax.setSize(5,5,5)
#w.addItem(ax)

# compute isosurface for positive and negative isovalues
isovals = [+0.2 * data.max(), -0.2 * data.max()]
colors = [(1, 0.2, 0.2), (0.2, 0.2, 1)]

for isoval, color in zip(isovals, colors):
    # compute vertices and faces and center around origin
    verts, faces = pg.isosurface(data, isoval)
    verts[:, 0] = verts[:, 0] - nx / 2
    verts[:, 1] = verts[:, 1] - ny / 2
    verts[:, 2] = verts[:, 2] - nz / 2

    isosurface = gl.MeshData(vertexes=verts, faces=faces)
    rgbt = np.zeros((isosurface.faceCount(), 4), dtype=float)
    for c in range(3):
        rgbt[:, c] = color[c]
    rgbt[:, 3] = 1  # transparency (I guess)
    isosurface.setFaceColors(rgbt)

    p = gl.GLMeshItem(
        meshdata=isosurface, smooth=True, shader='edgeHilight'
    )  # shader options: 'balloon', 'shaded', 'normalColor', 'edgeHilight'
    p.setGLOptions(
        'translucent')  # choose between 'opaque', 'translucent' or 'additive'
    w.addItem(p)

# add hemisphere for a given kinetic energy
E_kin = 35.0
Ejemplo n.º 9
0
d3.hideTitleBar()

w = gl.GLViewWidget()

#w.setBackgroundColor('b')
w.show()
w.setWindowTitle('Visualizacion del Quadrotor')
w.setCameraPosition(distance=8, azimuth=-45, elevation=30)

g = gl.GLGridItem()
g.scale(3, 3, 1)
w.addItem(g)
h0 = 0

model = Model("ardrone1.obj")
md = gl.MeshData(vertexes=model.returnMesh())
quadr = gl.GLMeshItem(meshdata=md,
                      color=(0.7, 0.7, 1, 1),
                      smooth=False,
                      shader='shaded',
                      glOptions='opaque')
quadr.translate(0, 0, h0)

arriba = False

ardrone = quad()

ts = ardrone.ts

clog = Control_log(ts)
Ejemplo n.º 10
0
# TODO label sensor by nearest aparc name

# on EEG cap and MEG helmet, avg pos and vtx norm to get sensor positions and normals
eegpo = sens_xyz_ori(vc * eeg_scl, fc, vcl)
megpo = sens_xyz_ori(vc * meg_scl, fc, vcl)

# write sensor files for OpenMEEG
np.savetxt(eeg_fname, eegpo[:3])
np.savetxt(meg_fname, megpo)

# visualize results
if plot:
    from pyqtgraph import mkQApp
    app = mkQApp()
    import pyqtgraph.opengl as gl
    gvw = gl.GLViewWidget()
    hs = gl.GLMeshItem(meshdata=gl.MeshData(vl, fl, vertexColors=xyz2rgb(vl)), drawEdges=True)
    cap = gl.GLMeshItem(meshdata=gl.MeshData(vc*eeg_scl, fc), color=(0, 0, 1.0, 1.0), drawEdges=True)
    hc = np.c_[np.random.rand(n_sens, 3), np.ones((n_sens, 1))][vcl]
    helmet = gl.GLMeshItem(meshdata=gl.MeshData(vc*meg_scl, fc, vertexColors=hc), #color=(1, 0, 0.0, 1.0),
            drawEdges=True)
    lh = gl.GLMeshItem(meshdata=gl.MeshData(*read_geometry(ctx)), drawEdges=True, drawFaces=False)
    for item in [hs, cap, helmet, lh]:
        gvw.addItem(item)
    for po in (megpo, eegpo):
        gvw.addItem(gl.GLScatterPlotItem(pos=po[:, :3], size=7))
        gvw.addItem(gl.GLScatterPlotItem(pos=po[:, :3] + 8*po[:, 3:], size=4, color=(1, 0, 0, 1)))
    gvw.show()
    gvw.readQImage().save('head_sensors.png')
    app.exec_()
Ejemplo n.º 11
0
    #wireplane_volumes=[('volTPCPlane_PV0x7f868ac5ef50',add_wireplane_surface)],
    acrylic_detect=True,
    acrylic_wls=False,
    read_bvh_cache=True,
    cache_dir="./../uboone/uboone_cache",
    dump_node_info=False)
sim = Simulation(geom,
                 geant4_processes=0,
                 nthreads_per_block=nthreads_per_block,
                 max_blocks=max_blocks)
geom.mesh.vertices
geom.mesh.triangles

# ============================================
# DRAWING DATA
detector_meshdata = gl.MeshData(vertexes=geom.mesh.vertices,
                                faces=geom.mesh.triangles)
detector_meshitem = gl.GLMeshItem(meshdata=detector_meshdata,
                                  drawFaces=False,
                                  drawEdges=True)
detector_meshitem.rotate(90, 1, 0, 0)
w.addItem(detector_meshitem)
detector_angle = 0.0

new_data = [1]
nphotons = 10
photon_end_pos = np.zeros((nphotons, 3), dtype=np.float)
photon_colors = np.zeros((nphotons, 4), dtype=np.float)
pos_plot = gl.GLScatterPlotItem(pos=photon_end_pos,
                                color=photon_colors,
                                size=2.0,
                                pxMode=True)
Ejemplo n.º 12
0
from matplotlib import cm
from matplotlib import colors as mcolors

data_path = sample.data_path()
filename_inv = data_path + '/MEG/sample/sample_audvis-meg-oct-6-meg-inv.fif'
inverse_operator = read_inverse_operator(filename_inv)

left_hemi, right_hemi = inverse_operator['src']
vertexes = np.r_[left_hemi['rr'], right_hemi['rr']]
lh_vertex_cnt = left_hemi['rr'].shape[0]
faces = np.r_[left_hemi['use_tris'], lh_vertex_cnt + right_hemi['use_tris']]
submesh_verrtex_idx = np.unique(faces)
vertex_idx = np.r_[left_hemi['vertno'], lh_vertex_cnt + right_hemi['vertno']]
vertex_cnt = vertex_idx.shape[0]

cortex_mesh_data = gl.MeshData(vertexes=vertexes, faces=faces)
cortex_mesh_data.setVertexColors(np.ones((vertexes.shape[0], 4)))

app = QtGui.QApplication([])
widget = gl.GLViewWidget()
widget.show()
widget.setWindowTitle('My first pyqtgraph brain mesh')
# The largest brain dimension
max_dim = max(np.ptp(vertexes, axis=0))
widget.setCameraPosition(distance=2 * max_dim)

grid = gl.GLGridItem()
grid.scale(2, 2, 1)
widget.addItem(grid)

# m1 = gl.GLMeshItem(vertexes=vertices, faces=faces,
    def init_ui(self):
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.setMinimumSize(250, 250)
        layout = QGridLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)

        positions = np.vstack([self.x_points, self.y_points,
                               self.z_points]).transpose()

        self.view = GLViewWidgetFix.GLViewWidgetFix()
        self.view.setBackgroundColor(119, 181, 254)
        self.view.setCameraPosition(distance=1950, elevation=90, azimuth=0)

        self.plot = opengl.GLLinePlotItem(pos=positions,
                                          color=[1, 0, 0, 1],
                                          width=3)
        self.plot.setGLOptions("opaque")
        self.view.addItem(self.plot)

        # self.grid = opengl.GLGridItem(color="white")
        # self.grid.setSize(x=(self.lon_max-self.lon_min)*self.meters_per_lon,
        #                   y=(self.lat_max-self.lat_min)*self.meters_per_lat)
        # self.grid.setSpacing(x=100, y=100)
        # self.view.addItem(self.grid)

        self.image_file = Image.open(self.image_name)
        self.image = opengl.GLImageItem(np.asarray(self.image_file))
        self.view.addItem(self.image)
        self.image.scale((self.lat_max - self.lat_min) * self.meters_per_lat /
                         self.image_file.size[1],
                         (self.lon_max - self.lon_min) * self.meters_per_lon /
                         self.image_file.size[0], 1)
        self.image.translate(
            -(self.lat_max - self.lat_min) * self.meters_per_lat / 2,
            -(self.lon_max - self.lon_min) * self.meters_per_lon / 2, 0)

        flat_earth = opengl.GLMeshItem(meshdata=opengl.MeshData.cylinder(
            1, 64, [6371000, 0], 0),
                                       color=[84 / 255, 89 / 255, 72 / 255, 1],
                                       smooth=True)
        flat_earth.translate(0, 0, -10000)
        flat_earth.setGLOptions("opaque")
        self.view.addItem(flat_earth)

        crosshair_mesh = mesh.Mesh.from_file("DisplayModels/Crosshairs.stl")
        crosshair_mesh_data = opengl.MeshData(vertexes=crosshair_mesh.vectors)
        self.crosshair = opengl.GLMeshItem(meshdata=crosshair_mesh_data,
                                           color=[1, 0, 0, 1])
        self.set_crosshair_pos(0, 0, 0)
        self.view.addItem(self.crosshair)

        self.view_btn = QPushButton("2D")
        self.view_btn.clicked.connect(self.switch_3d)
        self.view_btn.setMaximumWidth(30)

        self.coords_label = QLineEdit("0,0")
        self.coords_label.setAlignment(Qt.AlignCenter)
        self.coords_label.setReadOnly(True)

        self.clear_btn = QPushButton("CLR")
        self.clear_btn.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.clear_btn.setToolTip("Clear Data")
        self.clear_btn.setFixedWidth(35)
        self.clear_btn.setParent(self.view)
        self.clear_btn.clicked.connect(self.clear_plot)

        self.sats_label = QLineEdit("0")
        self.sats_label.setAlignment(Qt.AlignCenter)
        self.sats_label.setReadOnly(True)
        self.sats_label.setToolTip("Number of Satellites")
        self.sats_label.setMaximumWidth(50)

        layout.addWidget(self.view, 0, 0, 1, 4)
        layout.addWidget(self.clear_btn, 1, 3)
        layout.addWidget(self.view_btn, 1, 0)
        layout.addWidget(self.coords_label, 1, 1)
        layout.addWidget(self.sats_label, 1, 2)
# reduce to 30000 triangles:
points_dec, triangles_dec = decimate_surface(points,
                                             triangles,
                                             n_triangles=30000)

from mayavi import mlab  # noqa

head_col = (0.95, 0.83, 0.83)  # light pink

p, t = points_dec, triangles_dec

w = gl.GLViewWidget()
w.setGeometry(0, 0, 1000, 1000)
w.setWindowTitle('Terrain')
w.setCameraPosition(distance=50, elevation=8)

# s = gl.GLScatterPlotItem(pos=p)
mesh_data = gl.MeshData(p, t)
mesh_item = gl.GLMeshItem(meshdata=mesh_data,
                          computeNormals=True,
                          shader='viewNormalColor',
                          glOptions='translucent')
# mesh_item.translate(i*0.2, j*0.3, 0)
mesh_item.setColor([0, 0, 1, 0.6])
# s.setData(=p)
w.addItem(mesh_item)
w.show()
# mlab.triangular_mesh(p[:, 0], p[:, 1], p[:, 2], t, color=head_col)
# mlab.showif __name__ == '__main__':
if __name__ == '__main__':
    QtGui.QApplication.instance().exec_()()
    def init_ui(self):
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.setMinimumSize(250, 250)
        layout = QGridLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)

        positions = np.vstack([self.x_points, self.y_points, self.z_points]).transpose()

        self.view = GLViewWidgetFix.GLViewWidgetFix()
        self.view.setBackgroundColor(119, 181, 254)
        self.view.setCameraPosition(distance=2, elevation=45, azimuth=45)
        self.view.pan(0, 0, 0.73)

        self.plot = opengl.GLLinePlotItem(pos=positions)
        self.plot.setGLOptions("opaque")
        self.view.addItem(self.plot)

        self.image_file = Image.open(self.image_name)
        self.image = opengl.GLImageItem(np.asarray(self.image_file))
        self.view.addItem(self.image)
        self.image.scale((self.lat_max - self.lat_min) * self.meters_per_lat / self.image_file.size[1],
                         (self.lon_max - self.lon_min) * self.meters_per_lon / self.image_file.size[0],
                         1)
        self.image.translate(-(self.lat_max - self.lat_min) * self.meters_per_lat / 2,
                             -(self.lon_max - self.lon_min) * self.meters_per_lon / 2,
                             0)

        flat_earth = opengl.GLMeshItem(meshdata=opengl.MeshData.cylinder(1, 64, [6371000, 0], 0),
                                            color=[84/255, 89/255, 72/255, 1],
                                            smooth=True)
        flat_earth.translate(0, 0, -1000)
        flat_earth.setGLOptions("opaque")
        self.view.addItem(flat_earth)

        rocket_mesh = mesh.Mesh.from_file("DisplayModels/Rocket.stl")
        rocket_mesh_data = opengl.MeshData(vertexes=rocket_mesh.vectors)
        self.rocket = opengl.GLMeshItem(meshdata=rocket_mesh_data, color=[235 / 255, 193 / 255, 153 / 255, 1], smooth=True)
        self.rocket.scale(1/1000, 1/1000, 1/1000)
        self.rocket.rotate(180, 1, 0, 0, local=False)
        self.rocket.translate(0, 0, 1.5)
        self.rocket.setShader(self.shader)
        self.view.addItem(self.rocket)

        payload_mesh = mesh.Mesh.from_file("DisplayModels/PayloadSection.stl")
        payload_mesh_data = opengl.MeshData(vertexes=payload_mesh.vectors)
        self.payload = opengl.GLMeshItem(meshdata=payload_mesh_data, color=[235 / 255, 193 / 255, 153 / 255, 50 / 255])
        self.payload.setParentItem(self.rocket)
        self.payload.setShader(self.shader)
        self.payload.setGLOptions("additive")
        self.view.addItem(self.payload)

        nose_mesh = mesh.Mesh.from_file("DisplayModels/Nosecone.stl")
        nose_mesh_data = opengl.MeshData(vertexes=nose_mesh.vectors)
        self.nose = opengl.GLMeshItem(meshdata=nose_mesh_data, color=[240 / 255, 240 / 255, 240 / 255, 1], smooth=True)
        self.nose.setParentItem(self.rocket)
        self.nose.setShader(self.shader)
        self.view.addItem(self.nose)

        body_mesh = mesh.Mesh.from_file("DisplayModels/Body.stl")
        body_mesh_data = opengl.MeshData(vertexes=body_mesh.vectors)
        self.body = opengl.GLMeshItem(meshdata=body_mesh_data, color=[240 / 255, 20 / 255, 20 / 255, 1], smooth=False)
        self.body.scale(1 / 1000, 1 / 1000, 1 / 1000)
        self.body.setShader(self.shader)
        self.view.addItem(self.body)
        self.body.translate(0, 0, 0.6)

        rotor_mesh = mesh.Mesh.from_file("DisplayModels/Rotor.stl")
        rotor_mesh_data = opengl.MeshData(vertexes=rotor_mesh.vectors)
        self.rotor = opengl.GLMeshItem(meshdata=rotor_mesh_data, color=[200 / 255, 200 / 255, 200 / 255, 1], smooth=False)
        self.rotor.setParentItem(self.body)
        self.rotor.setShader(self.shader)
        self.view.addItem(self.rotor)
        self.rotor.translate(0, 0, 0.6)

        blade_mesh = mesh.Mesh.from_file("DisplayModels/Blade.stl")
        blade_mesh_data = opengl.MeshData(vertexes=blade_mesh.vectors)
        self.blades = [0]*4
        for n in range(0, 4):
            self.blades[n] = opengl.GLMeshItem(meshdata=blade_mesh_data, color=[200 / 255, 200 / 255, 200 / 255, 1], smooth=False)
            self.blades[n].setParentItem(self.rotor)
            self.blades[n].setShader(self.shader)
            self.view.addItem(self.blades[n])
            self.blades[n].rotate(n*90, 0, 0, 1)
            self.blades[n].translate(0, 0, 0.6)
            self.blades[n].translate(45, 0, 255, local=True)
            self.blades[n].rotate(90, 0, 1, 0, local=True)
            self.blades[n].translate(-45, 0, -255, local=True)

        self.blades[-1].setColor([50 / 255, 50 / 255, 50 / 255, 1])

        fin_holder_mesh = mesh.Mesh.from_file("DisplayModels/FinHolder.stl")
        fin_holder_mesh_data = opengl.MeshData(vertexes=fin_holder_mesh.vectors)

        fin_mesh = mesh.Mesh.from_file("DisplayModels/Fin.stl")
        fin_mesh_data = opengl.MeshData(vertexes=fin_mesh.vectors)

        self.fins = [0] * 2
        self.fin_holders = [0] * 2
        for n in range(0, 2):
            self.fin_holders[n] = opengl.GLMeshItem(meshdata=fin_holder_mesh_data,
                                                    color=[200 / 255, 200 / 255, 200 / 255, 1],
                                                    smooth=False)
            self.fin_holders[n].setParentItem(self.body)
            self.fin_holders[n].setShader(self.shader)
            self.view.addItem(self.fin_holders[n])
            self.fin_holders[n].rotate(n * 180, 0, 0, 1)

            self.fins[n] = opengl.GLMeshItem(meshdata=fin_mesh_data, color=[200 / 255, 200 / 255, 200 / 255, 1],
                                               smooth=False)
            self.fins[n].setParentItem(self.fin_holders[n])
            self.fins[n].setShader(self.shader)
            self.view.addItem(self.fins[n])
            self.fins[n].translate(0, 0, 0.6)
            self.fins[n].translate(41.3, 0, 126.5, local=True)
            self.fins[n].rotate(-90, 0, 1, 0, local=True)
            self.fins[n].translate(-41.3, 0, -126.5, local=True)

        can_mesh = mesh.Mesh.from_file("DisplayModels/Container.stl")
        can_mesh_data = opengl.MeshData(vertexes=can_mesh.vectors)
        self.can = opengl.GLMeshItem(meshdata=can_mesh_data, color=[255 / 255, 20 / 255, 147 / 255, 50 / 255],
                                       smooth=True)
        self.can.setShader(self.shader)
        self.can.setGLOptions("additive")
        self.view.addItem(self.can)
        self.can.scale(1 / 1000, 1 / 1000, 1 / 1000)
        self.can.translate(0, 0, 0.6)

        can_roof_mesh = mesh.Mesh.from_file("DisplayModels/ContainerRoof.stl")
        can_roof_mesh_data = opengl.MeshData(vertexes=can_roof_mesh.vectors)
        self.can_roof = opengl.GLMeshItem(meshdata=can_roof_mesh_data, color=[240 / 255, 20 / 255, 20 / 255, 1],
                                     smooth=False)
        self.can_roof.setParentItem(self.can)
        self.can_roof.setShader(self.shader)
        self.view.addItem(self.can_roof)
        self.can_roof.translate(0, 0, 0.6)

        chute_mesh = mesh.Mesh.from_file("DisplayModels/Chute.stl")
        chute_mesh_data = opengl.MeshData(vertexes=chute_mesh.vectors)
        self.chute = opengl.GLMeshItem(meshdata=chute_mesh_data, color=[255 / 255, 20 / 255, 147 / 255, 50 / 255],
                                          smooth=False)
        self.chute.setParentItem(self.can)
        self.chute.setShader(self.shader)
        self.view.addItem(self.chute)
        self.chute.translate(0, 0, 0.6)
        self.chute.hide()

        layout.addWidget(self.view)
        self.view.double_clicked.connect(self.change_speed)

        self.timer.start(16)
Ejemplo n.º 16
0
    def viewer(self,
               grids: bool = False,
               drawEdges: bool = True,
               edgeColor: Tuple[float, float, float, float] = (0, 0, 0, 0.5),
               positionOffset: Tuple[int, int, int] = (0, 0, 0),
               viewAngle: Tuple[int, int, int] = (40, 30, 300),
               resolution: Tuple[int, int] = (1280, 720),
               name: str = 'Plot 1',
               export: bool = False):
        """
        Display the mesh in a 3D viewer window.

        This function will block program execution until viewer window is closed

        Args:
            grids: Enable/disable display of XYZ axes and grids
            drawEdges: Enable/disable display of voxel edges
            edgeColor: Set display color of voxel edges
            positionOffset: Offset of the camera target from the center of the model in voxels
            viewAngle: Elevation, Azimuth, and Distance of the camera
            resolution: Window resolution in px
            name: Plot window name
            export: Enable/disable exporting a screenshot of the plot
        
        Returns:
            None
        """
        app = qtw.QApplication(sys.argv)

        mesh_data = pgo.MeshData(vertexes=self.verts,
                                 faces=self.tris,
                                 vertexColors=self.colors,
                                 faceColors=None)
        mesh_item = pgo.GLMeshItem(meshdata=mesh_data,
                                   shader='balloon',
                                   drawEdges=drawEdges,
                                   edgeColor=edgeColor,
                                   smooth=False,
                                   computeNormals=False,
                                   glOptions='translucent')

        widget = pgo.GLViewWidget()
        widget.setBackgroundColor('w')
        widget.addItem(mesh_item)

        if grids:
            # Add grids
            gx = pgo.GLGridItem()
            gx.setSize(x=50, y=50, z=50)
            gx.rotate(90, 0, 1, 0)
            gx.translate(-0.5, 24.5, 24.5)
            widget.addItem(gx)
            gy = pgo.GLGridItem()
            gy.setSize(x=50, y=50, z=50)
            gy.rotate(90, 1, 0, 0)
            gy.translate(24.5, -0.5, 24.5)
            widget.addItem(gy)
            gz = pgo.GLGridItem()
            gz.setSize(x=50, y=50, z=50)
            gz.translate(24.5, 24.5, -0.5)
            widget.addItem(gz)

            # Add axes
            ptsx = np.array([[-0.5, -0.5, -0.5], [50, -0.5, -0.5]])
            pltx = pgo.GLLinePlotItem(pos=ptsx,
                                      color=(1, 0, 0, 1),
                                      width=1,
                                      antialias=True)
            widget.addItem(pltx)
            ptsy = np.array([[-0.5, -0.5, -0.5], [-0.5, 50, -0.5]])
            plty = pgo.GLLinePlotItem(pos=ptsy,
                                      color=(0, 1, 0, 1),
                                      width=1,
                                      antialias=True)
            widget.addItem(plty)
            ptsz = np.array([[-0.5, -0.5, -0.5], [-0.5, -0.5, 50]])
            pltz = pgo.GLLinePlotItem(pos=ptsz,
                                      color=(0, 0, 1, 1),
                                      width=1,
                                      antialias=True)
            widget.addItem(pltz)

        # Set plot options
        widget.opts['center'] = qg.QVector3D(
            ((self.model.shape[0] / self.res) / 2) + positionOffset[0],
            ((self.model.shape[1] / self.res) / 2) + positionOffset[1],
            ((self.model.shape[2] / self.res) / 2) + positionOffset[2])
        widget.opts['elevation'] = viewAngle[0]
        widget.opts['azimuth'] = viewAngle[1]
        widget.opts['distance'] = viewAngle[2]
        widget.resize(resolution[0], resolution[1])

        # Show plot
        widget.setWindowTitle(str(name))
        widget.show()

        app.processEvents()

        # if export: # TODO: Fix export code
        #     widget.paintGL()
        #     widget.grabFrameBuffer().save(str(name) + '.png')

        print('Close viewer to resume program')
        app.exec_()
        app.quit()