def __init__(self): self.traces = dict() self.app = QtGui.QApplication(sys.argv) self.w = gl.GLViewWidget() self.w.opts['distance'] = 40 self.w.setWindowTitle('pyqtgraph example: GLLinePlotItem') self.w.setGeometry(0, 110, 1920, 1080) self.w.show() self.phase = 0 self.lines = 50 self.points = 1000 self.y = np.linspace(-10, 10, self.lines) self.x = np.linspace(-10, 10, self.points) for i, line in enumerate(self.y): y = np.array([line] * self.points) d = np.sqrt(self.x ** 2 + y ** 2) sine = 10 * np.sin(d + self.phase) pts = np.vstack([self.x, y, sine]).transpose() self.traces[i] = gl.GLLinePlotItem( pos=pts, color=pg.glColor((i, self.lines * 1.3)), width=(i + 1) / 10, antialias=True ) self.w.addItem(self.traces[i])
def gl_line3(w, pts, c=None, size=None, color=None, cmap=None): pts = np.array(pts) if size is None: size = 1 if color is None: color = np.ones((pts.shape[0], 4)) if cmap is None: r, g, b = 0.3, 0.6, 1.0 elif cmap == 'random': r, g, b = np.random.rand(3) elif cmap == 'red': r, g, b = 1, 0.3, 0.3 elif cmap == 'green': r, g, b = 0.3, 1, 0.3 elif cmap == 'blue': r, g, b = 0.3, 0.3, 1 if c is not None: color = [] # c is a 0-1 valued 'scale' for coloring per point for i in range(len(c)): color.append((r, g * c[i], b * c[i], 1)) color = np.array(color) line = gl.GLLinePlotItem(pos=pts, width=size, color=color, antialias=False) w.addItem(line) return line
def __init__(self): self.traces = dict() self.app = QtGui.QApplication(sys.argv) self.w = gl.GLViewWidget() self.w.opts['distance'] = 100 # Distance to view from self.w.setWindowTitle('pyqtgraph : OPENGL Line Plot') # Title self.w.setGeometry(0, 110, 1920, 1080) # Viewing box geometery self.w.show() self.phase = 0 # Phase offset initial Value self.lines = 50 # Number of lines self.points = 1000 # Number of points to be displayed self.y = np.linspace(-10, 10, self.lines) self.x = np.linspace(-10, 10, self.points) for i, line in enumerate(self.y): y = np.array([line] * self.points) d = np.sqrt(self.x ** 2 + y ** 2) sine = 10 * np.sin(d + self.phase) pts = np.vstack([self.x, y, sine]).transpose() self.traces[i] = gl.GLLinePlotItem( pos=pts, color=pg.glColor((i, self.lines * 1.3)), width=(i + 1) / 10, antialias=True ) self.w.addItem(self.traces[i])
def show_path(self, cur_agent=None, cur_path=None): self.erase_path(cur_path) cur_path = None points = [] for node in self.paths[cur_agent]: point = [ node[1] - self.map.rows // 2, node[0] - self.map.cols // 2, self.map.grid[node[1]][node[0]] ] points.append(point) points = np.array(points).reshape((-1, 3)) path_line = gl.GLLinePlotItem(pos=points, width=4, mode='line_strip', antialias=True) cur_path = path_line self.w.addItem(path_line) self.app.processEvents() return cur_path
def gen_path(self): if self.mesh_info.mesh == None: return self.view_slice.items = [] self.update_var() self.mesh_info.first_layer_thicknes = self.conf.get( "first_layer_thickness") self.mesh_info.layer_thickness = self.conf.get("layer_thickness") # self.mesh_info.init(self.mesh_info.pixel_size, # self.mesh_info.first_layer_thickness, self.mesh_info.layer_thickness) self.message(self.mesh_info.get_info()) curdir = os.getcwd() if(path.isdir("images")): # remove all files in images filelist = [f for f in os.listdir( "./images") if f.endswith(".png")] for f in filelist: os.remove(os.path.join(curdir + "/images", f)) else: os.mkdir("images") self.out_path = os.path.join(curdir, "images") self.path_verts = mkspiral.gen_continuous_path( self.mesh_info, self.out_path, 20000, self.conf.get("infill_offset")) # self.path_verts = # mkspiral.gen_continuous_path_with_constraint(self.mesh_info, # self.out_path, 2000, 60,self.conf.get("infill_offset")) plt = gl.GLLinePlotItem(pos=self.path_verts, color=pg.glColor('r'), width=1, antialias=True) self.view_slice.addItem(plt) self.view_slice.setBackgroundColor(pg.mkColor('w')) return
def straight_line_plot(self, path): points = np.array([[ path.line_origin.item(0), path.line_origin.item(1), path.line_origin.item(2) ], [ path.line_origin.item(0) + self.scale * path.line_direction.item(0), path.line_origin.item(1) + self.scale * path.line_direction.item(1), path.line_origin.item(2) + self.scale * path.line_direction.item(2) ]]) # convert North-East Down to East-North-Up for rendering R = np.array([[0, 1, 0], [1, 0, 0], [0, 0, -1]]) points = points @ R.T red = np.array([[1., 0., 0., 1]]) path_color = np.concatenate((red, red), axis=0) object = gl.GLLinePlotItem(pos=points, color=path_color, width=2, antialias=True, mode='lines') return object
def addLine(self): a = np.array([-0.42814296, -0.34476757, -0.2380489]) b = np.array([0.42814296, 0.34476757, 0.2380489]) c = np.array([0.11085646, -0.0391669, -1.7693107]) d = np.array([0.4818, 0.0441, -1.3064]) pts = np.array([[0.4818, 0.0441, -1.3064], [-5.216978, -5.6464047, 1.279653], [0.11085646, -0.0391669, -1.7693107], list(c + a), [1, 1, 1], [-1, -1, 1], [1, 1, -1]]) ptss = np.array([[-0.2336967, -0.01164758, -1.4284158], [-0.08075887, 0.33305264, -1.4650047], [0.605029, 0.01541734, -1.5908893], [0.45209116, -0.32928282, -1.5543004], [-0.34442478, -0.02340117, -2.0019777], [-0.19148695, 0.32129902, -2.0385666], [0.4943009, 0.00366375, -2.1644514], [0.34136307, -0.34103644, -2.1278625]]) color = np.full((8, 4), [0, 0.9, 0, 0.5]) self.linePlot = gl.GLLinePlotItem(pos=ptss, color=color, width=5.0, mode='lines') self.addItem(self.linePlot) md = gl.MeshData.sphere(rows=10, cols=10) self.m2 = gl.GLMeshItem(meshdata=md, smooth=True, shader='normalColor', glOptions='opaque') self.m2.translate(c[0], c[1], c[2]) self.m2.scale(0.1, 0.1, 0.1) # m3 = gl.GLMeshItem(meshdata=md, smooth=True, shader='normalColor', glOptions='opaque') # m3.translate(0.306,-0.397,-1.33) # m3.scale(0.1, 0.1, 0.1) self.addItem(self.m2)
def __init__(self): self.traces = dict() self.app = QtGui.QApplication(sys.argv) self.w = gl.GLViewWidget() self.w.opts['distance'] = 60 self.w.setWindowTitle('pyqtgraph example: GLLinePlotItem') self.w.setGeometry(0, 110, 1920, 1080) self.w.show() gx = gl.GLGridItem() gx.rotate(90, 0, 1, 0) gx.translate(-10, 0, 0) self.w.addItem(gx) gy = gl.GLGridItem() gy.rotate(90, 1, 0, 0) gy.translate(0, -10, 0) self.w.addItem(gy) gz = gl.GLGridItem() gz.translate(0, 0, -10) self.w.addItem(gz) m1 = gl.GLMeshItem(vertexes=verts, faces=faces, faceColors=colors, smooth=False) m1.translate(0, 0.1, 0) m1.setGLOptions('additive') self.w.addItem(m1) self.n = new_particle_source.N for i in range(self.n): pts = np.vstack([x_cords[i], y_cords[i], z_cords[i]]).transpose() self.traces[i] = gl.GLLinePlotItem(pos=pts, antialias=True) self.w.addItem(self.traces[i])
def drawinputs3d (cell,clr,widg,width=2.0): for lsrc in [cell.ncfrom_L2Pyr, cell.ncfrom_L2Basket, cell.ncfrom_L5Pyr, cell.ncfrom_L5Basket]: for src in lsrc: precell = src.precell() pts = np.vstack([[precell.pos[0]*100,cell.pos[0]*100],[precell.pos[2],cell.pos[2]],[precell.pos[1]*100,cell.pos[1]*100]]).transpose() plt = gl.GLLinePlotItem(pos=pts, color=clr, width=width, antialias=True, mode='lines') widg.addItem(plt)
def __init__(self, layout): self.w = gl.GLViewWidget() self.w.opts['distance'] = 1.0 # self.w.show() # self.w.setWindowTitle('pyqtgraph example: GLLinePlotItem') gx = gl.GLGridItem() gx.rotate(90, 0, 0.1, 0) gx.translate(-10, 0, 0) self.w.addItem(gx) gy = gl.GLGridItem() gy.rotate(90, 0.1, 0, 0) gy.translate(0, -10, 0) self.w.addItem(gy) gz = gl.GLGridItem() gz.translate(0, 0, -10) self.w.addItem(gz) axis = gl.GLAxisItem() axis.setSize(0.2, 0.2, 0.2) self.w.addItem(axis) self.x_text = gl.GLTextItem(pos=(0.2,0,0), text="x", font=QtGui.QFont('Helvetica', 7)) self.w.addItem(self.x_text) self.y_text = gl.GLTextItem(pos=(0,0.2,0), text="y", font=QtGui.QFont('Helvetica', 7)) self.w.addItem(self.y_text) self.z_text = gl.GLTextItem(pos=(0,0,0.2), text="z", font=QtGui.QFont('Helvetica', 7)) self.w.addItem(self.z_text) self.hfov = 90.0 self.vfov = 60.0 self.cam_rotmat = Rotation.from_rotvec([0., 0., 0.]) self.cam_t = np.array([0., 0., 0.]) self.max_depth = 0.01 # 相机深度 self.imlt = [-0.01, -0.005, 0.01] self.imrt = [0.01, -0.005, 0.01] self.imlb = [-0.01, 0.005, 0.01] self.imrb = [0.01, 0.005, 0.01] self.oc = [0.0, 0.0, 0.0] self.cal_cam_fov() self.lines = [] pos = np.empty((TIME_LENGTH, 3)) size = np.empty((TIME_LENGTH)) color = np.empty((TIME_LENGTH, 4)) self.fix_points = None self.points = None self.currentSTL = None self.showSTL('./res/helmat.stl') self.head_last_rot = Rotation.from_quat([0,0,0,1]) self.head_last_trans = np.array([0., 0., 0.]) for i in range(TIME_LENGTH): pos[i] = (0, 0, 0) size[i] = 0.005 color[i] = (i * 1.0 / TIME_LENGTH, 0.0, 0.0, 1.0) self.history = gl.GLScatterPlotItem(pos=pos, size=size, color=color, pxMode=False) self.w.addItem(self.history) for i in range(8): self.lines.append(gl.GLLinePlotItem(antialias=True)) self.w.addItem(self.lines[i]) layout.addWidget(self.w)
def lines(self, name, lines, colors, alphas=1.0, width=1.0, antialias=True): if lines is None: return colors = _extend_color_if_necessary(colors, lines.shape[0], alphas) if name not in self._named_items: w_gl_item = gl.GLLinePlotItem(pos=lines, color=colors, width=width, antialias=antialias, mode='lines') self._named_items[name] = w_gl_item self.addItem(w_gl_item) else: self._named_items[name].setData(pos=lines, color=colors, width=width, antialias=antialias, mode='lines')
def updateRRT(self, iteration, rrt_pts): if iteration != self.RRT_iteration: self.initialized_RRT = False self.RRT_iteration = iteration if not self.initialized_RRT: """ vm_all_pts = self.voronoi.E_inf self.vm_all = gl.GLLinePlotItem(pos=vm_all_pts,color=pg.glColor('w'),width=1.0,mode='lines') self.w.addItem(self.vm_all) """ # allows repeated colors while iteration > len(self.RRT_colors) - 1: iteration -= len(self.RRT_colors) rrt_color = self.RRT_colors[iteration] self.rrt_line = gl.GLLinePlotItem(pos=rrt_pts, color=rrt_color, width=1, antialias=True, mode='lines') self.window.addItem(self.rrt_line) self.initialized_RRT = True else: self.rrt_line.setData(pos=rrt_pts) self.app.processEvents()
def draw_3d_bboxlines_in_pyqt_v1(widget, bboxes, colors=(0.0, 1.0, 0.0, 1.0), width=1.0, labels=None, label_color='r'): if not isinstance(colors, list): colors = [colors for i in range(len(bboxes))] if not isinstance(labels, list): labels = [labels for i in range(len(bboxes))] for box, facecolor, label in zip(bboxes, colors, labels): lines = np.array([ box[0], box[1], box[1], box[2], box[2], box[3], box[3], box[0], box[1], box[5], box[5], box[4], box[4], box[0], box[2], box[6], box[6], box[7], box[7], box[3], box[5], box[6], box[4], box[7] ]) color = np.array([list(facecolor) for i in range(len(lines))]) plt = gl.GLLinePlotItem(pos=lines, color=color, width=width, antialias=True, mode='lines') widget.addItem(plt) if label is not None: label_color_qt = _pltcolor_to_qtcolor(label_color) t = GLTextItem(X=box[0, 0], Y=box[0, 1], Z=box[0, 2], text=label, color=label_color_qt) t.setGLViewWidget(widget) widget.addItem(t) return widget
def show_strokes_3d(key, strokes, mean_stroke): view = gl.GLViewWidget() view.orbit(75, -15) view.show() # view.readQImage().save('%s-r.png'%key) # view.setBackgroundColor([255, 255, 255, 0]) ## create three grids, add each to the view # xgrid = gl.GLGridItem(color=(0,0,0,255)) # ygrid = gl.GLGridItem() zgrid = gl.GLGridItem() # color = np.array([0, 0, 1, 0.2]) # for stroke in strokes: # pos = stroke['data'] # colors = np.tile(color, (pos.shape[0], 1)) # line = gl.GLLinePlotItem(pos=pos, color=colors, width=5) # view.addItem(line) pos = mean_stroke[:, :3] color1 = np.array([0, 1, 0, 1]) color2 = np.array([1, 0, 0, 1]) steps = np.linspace(0, 1, pos.shape[0]) R = np.interp(steps, np.array([0, 1]), np.array([color1[0], color2[0]])) G = np.interp(steps, np.array([0, 1]), np.array([color1[1], color2[1]])) B = np.interp(steps, np.array([0, 1]), np.array([color1[2], color2[2]])) A = np.interp(steps, np.array([0, 1]), np.array([color1[3], color2[3]])) colors = np.vstack((R, G, B, A)).T line = gl.GLLinePlotItem(pos=pos, color=colors, width=40, mode='line_strip') view.addItem(line) # view.addItem(xgrid) # view.addItem(ygrid) view.addItem(zgrid) ## rotate x and y grids to face the correct direction # xgrid.rotate(90, 0, 1, 0) # ygrid.rotate(90, 1, 0, 0) print 'var geometry = new THREE.Geometry();\ngeometry.vertices.push(\n' for point in pos: print 'new THREE.Vector3(%f, %f, %f),' % (point[0], point[1], point[2]) print ');\ngeometry.colors.push(\n' for color in colors: hexc = hex( int(color[0] * 255) * 65536 + int(color[1] * 255) * 256 + int(color[2] * 255)) print 'new THREE.Color( %s ),' % hexc print ');'
def drawObjects(self, view_manager, io_manager, meta): event_particle = io_manager.get_data(self._product_name, str(self._producerName)) # # This section draws voxels onto the environment: for particle in event_particle.as_vector(): box = particle.boundingbox_3d() # Can create a 3D box using line plots. pts = self._box_template.copy() pts[:, 0] *= box.width() pts[:, 1] *= box.height() pts[:, 2] *= box.depth() pts[:, 0] += box.center_x() - meta.min_x() - 0.5 * box.width() pts[:, 1] += box.center_y() - meta.min_y() - 0.5 * box.height() pts[:, 2] += box.center_z() - meta.min_z() - 0.5 * box.depth() line = gl.GLLinePlotItem(pos=pts, color=(1.0, 1.0, 1.0, 1.0), width=3) view_manager.getView().addItem(line) self._drawnObjects.append(line)
def update(self): """Function called on each animation iteration """ if self.play: self.index = (self.index + 1) % len(self.df) i = self.index if i == 0: print("... loop animation ...") time00 = self.df["time0_s"].iloc[0] time0_s = self.df["time0_s"].iloc[i] time_simu = i * self.step_interval diff_time = time_simu - time0_s + time00 pitch = self.df["pitch"].iloc[i] roll = self.df["roll"].iloc[i] nb_g = self.df["nbG_tot"].iloc[i] yaw = self.df["yaw"].iloc[i] lat = self.df["lat_m"].iloc[i] lon = self.df["lon_m"].iloc[i] alt = self.df["alt_m"].iloc[i] #Update Text data self.data_info_text.setText(f'i: \t {i} \n' + f'time simu: \t {time_simu:.2f} \n' + f'time0_s: \t {time0_s:.2f} \n' + f'time diff: \t {diff_time:.2f} \n\n' + f'pitch: \t {pitch:.1f} \n' + f'roll: \t {roll:.1f} \n' + f'yaw: \t {yaw:.1f} \n\n' + f'x: \t {lat:.1f} \n' + f'y: \t {lon:.1f} \n' + f'z: \t {alt:.1f} \n\n') #Update arrow: self.custom['arrow_alt'].setPos(time0_s, alt) self.custom['arrow_pitch'].setPos(time0_s, pitch) self.custom['arrow_nb_g'].setPos(time0_s, nb_g) self.custom['arrow_yaw'].setPos(time0_s, yaw) #Update 3D body self.geom.resetTransform() # Important to rotate before translated self.geom.rotate(pitch, 0, 1, 0) self.geom.rotate(roll, 1, 0, 0) self.geom.rotate(yaw, 0, 0, 1) self.geom.translate(lat, lon, alt) self.geom.update() # Add track if exist: if self.track is not None and not self.track_is_ploted: print("ploting track") plt = gl.GLLinePlotItem(pos=self.track, antialias=True) self.w.addItem(plt) self.track_is_ploted = True
def __initUpperPlots(self): # set layout self.setLayout(self.layoutgb) self.videoViewer.sizeHint = lambda: pg.QtCore.QSize(100, 100) self.glvw.sizeHint = lambda: pg.QtCore.QSize(100, 100) self.glvw.setSizePolicy(self.videoViewer.sizePolicy()) #colorMap colormap = matplotlib.cm.get_cmap('jet') numMarkers = np.size(self.marker_data.marker_pos, 2) color_idx = np.linspace(0, 1, numMarkers) self.cmap = colormap(color_idx) #initilize scatterPlot startPos = self.marker_data.marker_pos[0, :, :] startPos_plot = prep_data(startPos) self.scatterPlot = gl.GLScatterPlotItem(pos=startPos_plot, size=20, color=self.cmap) self.glvw.addItem(self.scatterPlot) #initilize linePlots bone_lines = get_bone_lines(startPos, self.marker_data.marker_names, self.marker_data.connections) bone_lines = bone_lines / 100 self.bones = gl.GLLinePlotItem(pos=bone_lines, width=1, mode='lines') self.glvw.addItem(self.bones) #initilize video plot self.videoViewer.set_frame(0) #connect the slider self.dataSlider.slider.valueChanged.connect(self.slider_update_plots) self.resize(1600, 1000)
def orbit_plot(self, path): N = 100 red = np.array([[1., 0., 0., 1]]) theta = 0 points = np.array([[ path.orbit_center.item(0) + path.orbit_radius, path.orbit_center.item(1), path.orbit_center.item(2) ]]) path_color = red for i in range(0, N): theta += 2 * np.pi / N new_point = np.array([[ path.orbit_center.item(0) + path.orbit_radius * np.cos(theta), path.orbit_center.item(1) + path.orbit_radius * np.sin(theta), path.orbit_center.item(2) ]]) points = np.concatenate((points, new_point), axis=0) path_color = np.concatenate((path_color, red), axis=0) # convert North-East Down to East-North-Up for rendering R = np.array([[0, 1, 0], [1, 0, 0], [0, 0, -1]]) points = points @ R.T object = gl.GLLinePlotItem(pos=points, color=path_color, width=2, antialias=True, mode='line_strip') return object
def drawObjects(self, view_manager): geom = view_manager._geometry view = view_manager.getView() seeds = self._process.getData() # Each flash is drawn as an oval in Y/Z/X for i in range(len(seeds)): thisSeed = seeds[i] # Each seed just needs two points, the start and end point x = np.zeros(2) y = np.zeros(2) z = np.zeros(2) x[0] = thisSeed.point().X() x[1] = thisSeed.point().X() \ + thisSeed.direction().X()*thisSeed.length() y[0] = thisSeed.point().Y() y[1] = thisSeed.point().Y() \ + thisSeed.direction().Y()*thisSeed.length() z[0] = thisSeed.point().Z() z[1] = thisSeed.point().Z() \ + thisSeed.direction().Z()*thisSeed.length() pts = np.vstack([x, y, z]).transpose() pen = pg.mkPen((255, 0, 0), width=2) line = gl.GLLinePlotItem(pos=pts, color=(255, 255, 0, 255)) view.addItem(line) self._drawnObjects.append(line)
def drawObjects(self, view_manager): geom = view_manager._geometry view = view_manager.getView() print 't0 ------------------------------------------------' self tracks = self._process.getData() trkctr = 0 for track in tracks: # construct a line for this track: points = track.track() x = np.zeros(points.size()) y = np.zeros(points.size()) z = np.zeros(points.size()) # x = numpy.ndarray() # x = numpy.ndarray() i = 0 for point in points: x[i] = point.X() y[i] = point.Y() z[i] = point.Z() i+= 1 pts = np.vstack([x,y,z]).transpose() pen = pg.mkPen((255,255,0), width=2) # Track Color print trkctr , " ----------------------------------- " line = gl.GLLinePlotItem(pos=pts,color=self._trackColors[ trkctr % len(self._trackColors) ], width=4) view.addItem(line) self._drawnObjects.append(line) trkctr += 1
def update_plots(): global acc_curve, acc_data, gyro_curve, gyro_data, origin, cube, view try: ser_line = ser.readline() message = json.loads(bytes(ser_line).decode()) except Exception as e: if hasattr(e, 'message'): print('plot:', e.message) else: print('plot:', e) return if message.get('meas') == 'acc': val = message.get('values') new_data = np.array([val.get('x'), val.get('y'), val.get('z')]) acc_data[:-1, :] = acc_data[1:, :] acc_data[-1, :] = new_data for i, curve in enumerate(acc_curve): curve.setData(acc_data[:, i]) elif message.get('meas') == 'gyro': val = message.get('values') new_data = np.array([val.get('x'), val.get('y'), val.get('z')]) gyro_data[:-1, :] = gyro_data[1:, :] gyro_data[-1, :] = new_data for i, curve in enumerate(gyro_curve): curve.setData(gyro_data[:, i]) elif message.get('meas') == 'angle': val = message.get('values') view.removeItem(origin) view.removeItem(cube) origin = gl.GLLinePlotItem(pos=origin_coord, mode='lines', color=origin_colors, width=8, antialias=True) origin.rotate(val.get('x'), 1, 0, 0) origin.rotate(val.get('y'), 0, 1, 0) origin.rotate(val.get('z'), 0, 0, 1) cube = gl.GLLinePlotItem(pos=cube_coord, mode='line_strip', width=2, antialias=True) cube.rotate(val.get('x'), 1, 0, 0) cube.rotate(val.get('y'), 0, 1, 0) cube.rotate(val.get('z'), 0, 0, 1) view.addItem(cube) view.addItem(origin)
def __init__(self,N,clusters): self.clusters = clusters self.w = gl.GLViewWidget() self.w.opts['distance'] = 100 self.w.setWindowTitle('RGB space') self.w.setGeometry(100, 100, 500, 500) self.w.show() # create the background grids gx = gl.GLGridItem() gx.rotate(90, 0, 1, 0) gx.translate(0, 10, 10) self.w.addItem(gx) gy = gl.GLGridItem() gy.rotate(90, 1, 0, 0) gy.translate(10, 0, 10) self.w.addItem(gy) gz = gl.GLGridItem() gz.translate(10, 10, 0) self.w.addItem(gz) self.curve1 = gl.GLLinePlotItem() self.curve2 = gl.GLLinePlotItem() self.curve3 = gl.GLLinePlotItem() self.w.addItem(self.curve1) self.w.addItem(self.curve2) self.w.addItem(self.curve3) self.pca = decomposition.PCA(n_components=3) self.centers = [None for _ in range(clusters)] for i in range(clusters): pts = np.array([0, 0, 0])/14 self.centers[i] = gl.GLScatterPlotItem(pos=pts, color=pg.glColor(0,0,255,255)) self.w.addItem(self.centers[i]) self.cyl=[] for i in range(clusters): CYL = gl.MeshData.cylinder(rows=10, cols=20, radius=[1., 1.0], length=5.) self.cyl.append(gl.GLMeshItem(meshdata=CYL, smooth=True, drawEdges=True, edgeColor=(1, 0, 0, 0.1), shader='balloon')) self.cyl[-1].setGLOptions('additive') self.w.addItem(self.cyl[-1]) self.traces = dict() for i in range(N): pts = np.array([0, 0, 0])/14 self.traces[i] = gl.GLScatterPlotItem(pos=pts, color=pg.glColor(100,100,100,100)) self.w.addItem(self.traces[i])
def plot_line(x, y, z, color='w'): # first line p = np.array([z, x, y]) p = p.transpose() C = pg.glColor(color) #plt = gl.GLScatterPlotItem(pos=p, color=C, size =2.5) plt = gl.GLLinePlotItem(pos=p, color=C, width=1.5, antialias=True) return plt
def create_axis(pos, axes_scale=10, axes_width=10): x_axis = gl.GLLinePlotItem(pos=np.array([[0, 0, 0], [1, 0, 0]]) * axes_scale, color=[1, 0, 0, 1], width=axes_width) y_axis = gl.GLLinePlotItem(pos=np.array([[0, 0, 0], [0, 1, 0]]) * axes_scale, color=[0, 1, 0, 1], width=axes_width) z_axis = gl.GLLinePlotItem(pos=np.array([[0, 0, 0], [0, 0, 1]]) * axes_scale, color=[0, 0, 1, 1], width=axes_width) x_axis.translate(pos[0], pos[1], pos[2]) y_axis.translate(pos[0], pos[1], pos[2]) z_axis.translate(pos[0], pos[1], pos[2]) return x_axis, y_axis, z_axis
def addLine(self,ch1_x,ch1_y,ch1_z,ch2_x,ch2_y,ch2_z,name=''): item = gl.GLLinePlotItem() item.setVisible(True) item.setData(pos=np.array([[ch1_x,ch1_y,ch1_z], [ch2_x,ch2_y,ch2_z]]), color=(1, 1, 1, 1)) item.__name__ = name self.addItem(item) return
def add_line(self, p1, p2, color, width=3): lines = np.array([[p1[0], p1[1], p1[2]], [p2[0], p2[1], p2[2]]]) lines_item = gl.GLLinePlotItem(pos=lines, mode='lines', color=color, width=width, antialias=True) self.add_item(lines_item)
def drawcells3dgl (ty,widget,width=2.2): for cell in net.cells: if type(cell) != ty: continue lx,ly,lz = getshapecoords(h,cell.get_sections()) pts = np.vstack([lx,ly,lz]).transpose() plt = gl.GLLinePlotItem(pos=pts, color=dclr[type(cell)], width=width, antialias=True, mode='lines') #plt.showGrid(x=True,y=True) widget.addItem(plt)
def add_line(self, p1, p2): lines = np.array([[p1[0], p1[1], p1[2]], [p2[0], p2[1], p2[2]]]) lines_item = gl.GLLinePlotItem(pos=lines, mode='lines', color=(1, 0, 0, 1), width=3, antialias=True) self.view.addItem(lines_item)
def __init__(self): """ Initialize the graphics window and mesh surface """ # setup the view window self.app = QtGui.QApplication(sys.argv) self.window = gl.GLViewWidget() self.window.setWindowTitle('Terrain') self.window.setGeometry(0, 110, 1920, 1080) self.window.setCameraPosition(distance=30, elevation=12) self.window.show() gx = gl.GLGridItem() gy = gl.GLGridItem() gz = gl.GLGridItem() gx.rotate(90, 0, 1, 0) gy.rotate(90, 1, 0, 0) gx.translate(-10, 0, 0) gy.translate(0, -10, 0) gz.translate(0, 0, -10) self.window.addItem(gx) self.window.addItem(gy) self.window.addItem(gz) modeln = 'mobilenet_thin' modelr = '432x368' camera = 0 self.lines = {} self.connection = [ [0, 1], [1, 2], [2, 3], [0, 4], [4, 5], [5, 6], [0, 7], [7, 8], [8, 9], [9, 10], [8, 11], [11, 12], [12, 13], [8, 14], [14, 15], [15, 16] ] w, h = model_wh(modelr) self.e = TfPoseEstimator(get_graph_path(modeln), target_size=(w, h)) self.cam = cv2.VideoCapture(camera) ret_val, image = self.cam.read() self.poseLifting = Prob3dPose('./skeleton_humanactivity/lifting/models/prob_model_params.mat') keypoints = self.mesh(image) self.points = gl.GLScatterPlotItem( pos=keypoints, color=pg.glColor((0, 255, 0)), size=15 ) self.window.addItem(self.points) for n, pts in enumerate(self.connection): self.lines[n] = gl.GLLinePlotItem( pos=np.array([keypoints[p] for p in pts]), color=pg.glColor((0, 0, 255)), width=3, antialias=True ) self.window.addItem(self.lines[n])
def setup_view_box(self, view_widget, line_width, V_FoV, H_FoV, depth): line_color = (1.0, 1.0, 1.0, 1.0) # color = (r,g,b,a) x_pos = depth * math.sin(H_FoV / 2.0) y_pos = depth * math.sin(V_FoV / 2.0) # create the line data top_right_line_data = np.array([[0.0, 0.0, 0.0], [x_pos * INVERT, y_pos, depth]]) top_left_line_data = np.array([[0.0, 0.0, 0.0], [-x_pos * INVERT, y_pos, depth]]) bottom_right_line_data = np.array([[0.0, 0.0, 0.0], [x_pos * INVERT, -y_pos, depth]]) bottom_left_line_data = np.array([[0.0, 0.0, 0.0], [-x_pos * INVERT, -y_pos, depth]]) # connecting lines box_data = np.array([[x_pos * INVERT, y_pos, depth], [-x_pos * INVERT, y_pos, depth], [-x_pos * INVERT, -y_pos, depth], [x_pos * INVERT, -y_pos, depth], [x_pos * INVERT, y_pos, depth]]) # create the lines top_right_line = gl.GLLinePlotItem(pos=top_right_line_data, width=line_width, color=line_color) top_left_line = gl.GLLinePlotItem(pos=top_left_line_data, width=line_width, color=line_color) bottom_right_line = gl.GLLinePlotItem(pos=bottom_right_line_data, width=line_width, color=line_color) bottom_left_line = gl.GLLinePlotItem(pos=bottom_left_line_data, width=line_width, color=line_color) box = gl.GLLinePlotItem(pos=box_data, width=line_width, color=line_color) # add the lines to the view view_widget.addItem(top_right_line) view_widget.addItem(top_left_line) view_widget.addItem(bottom_right_line) view_widget.addItem(bottom_left_line) view_widget.addItem(box)