def _refresh_axis(self): if self.axis is not None: for item in self.axis: self.removeItem(item) self.axis = None axes_items = [] colors = [(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1)] end_points = [[40,0,0], [0,40,0], [0,0,40]] for color, end_point in zip(colors, end_points): pos = np.array([[0,0,0],end_point]) axis = GLLinePlotItem( pos=pos, color=color, width=3, antialias=True) axis.setGLOptions('translucent') axes_items.append(axis) self.axis = axes_items for item in axes_items: self.addItem(item)
def _refresh_bonds(self): if self.bonds: for bond in self.bonds: self.removeItem(bond) self.bonds = [] if self.orbital is None or not self.options.is_show_bonds(): return color = (0.8, 0.8, 0.8, 1) # light gray for bond in self.orbital.get_bonds(): new_bond = GLLinePlotItem(pos=bond, color=color, width=5, antialias=True) self.bonds.append(new_bond) self.addItem(new_bond)
def _refresh_photon(self): # Couldn't find the bug without second part of if so I removed # it for now if self.photon: self.removeItem(self.photon) self.photon = None polarization, alpha, beta = self.photon_parameters if self.orbital is None or not self.options.is_show_photon(): return color = (1, 1, 0.0, 1) # color for wavy light ray (yellow) ray_length = 50 # length of wavy light ray amplitude = 5 # amplitude of oscillation wavelength = 5 # wavelength of oscillation n_points = 200 # number of points along wavy light ray alpha = alpha * np.pi / 180 beta = (180 + beta) * np.pi / 180 direction = [ np.sin(alpha) * np.cos(beta), np.sin(alpha) * np.sin(beta), np.cos(alpha) ] x0 = np.linspace(0, ray_length * direction[0], n_points) y0 = np.linspace(0, ray_length * direction[1], n_points) z0 = np.linspace(0, ray_length * direction[2], n_points) t = np.linspace(0, ray_length, n_points) if polarization == 's': pol_1 = [np.sin(beta), -np.cos(beta), 0] pol_2 = [0, 0, 0] elif polarization == 'p': pol_1 = [0, 0, 0] pol_2 = [ np.cos(alpha) * np.cos(beta), np.cos(alpha) * np.sin(beta), -np.sin(alpha) ] # ... to be updated ... elif polarization == 'unpolarized': pol_1 = [0, 0, 0] pol_2 = [ np.sin(beta) + np.cos(alpha) * np.cos(beta), -np.cos(beta) + np.cos(alpha) * np.sin(beta), -np.sin(alpha) ] elif polarization == 'C+': pol_1 = [np.sin(beta), -np.cos(beta), 0] pol_2 = [ np.cos(alpha) * np.cos(beta), np.cos(alpha) * np.sin(beta), -np.sin(alpha) ] elif polarization == 'C-': pol_1 = [np.sin(beta), -np.cos(beta), 0] pol_2 = [ -np.cos(alpha) * np.cos(beta), -np.cos(alpha) * np.sin(beta), +np.sin(alpha) ] # show C+ spiral ... until I have a better idea ... elif polarization == 'CDAD': pol_1 = [np.sin(beta), -np.cos(beta), 0] pol_2 = [ np.cos(alpha) * np.cos(beta), np.cos(alpha) * np.sin(beta), -np.sin(alpha) ] dx = amplitude * pol_1[0] * np.cos(2 * np.pi * t / wavelength) + \ amplitude * pol_2[0] * np.sin(2 * np.pi * t / wavelength) dy = amplitude * pol_1[1] * np.cos(2 * np.pi * t / wavelength) + \ amplitude * pol_2[1] * np.sin(2 * np.pi * t / wavelength) dz = amplitude * pol_1[2] * np.cos(2 * np.pi * t / wavelength) + \ amplitude * pol_2[2] * np.sin(2 * np.pi * t / wavelength) pos = np.array([x0 + dx, y0 + dy, z0 + dz]).T photon_line = GLLinePlotItem(pos=pos, color=color, width=5, antialias=True) photon_line.setGLOptions('translucent') self.photon = photon_line self.addItem(photon_line)
def __init__(self, args, option='camera'): self.args = args self.fpsTime = 0 self.option = option self.app = QtGui.QApplication(sys.argv) self.window = GLViewWidget() self.window.setGeometry(0, 150, 1920, 1080) self.window.setCameraPosition(distance=50, elevation=8) self.window.setWindowTitle("3D Pose Estimation") self.window.show() gx = GLGridItem() gy = GLGridItem() gz = 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) self.lines = {} keypoints = [] 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]] self.w, self.h = model_wh(self.args.resize) if self.w > 0 and self.h > 0: self.e = TfPoseEstimator(get_graph_path(self.args.model), target_size=(self.w, self.h), trt_bool=str2bool(self.args.tensorrt)) else: self.e = TfPoseEstimator(get_graph_path(self.args.model), target_size=(432, 368), trt_bool=str2bool(self.args.tensorrt)) print(self.args.option) image, ret_val = PoseEstimation.getframe(self.args.option) self.poseLifting = Prob3dPose( 'lifting/prob_model/prob_model_params.mat') try: keypoints = self.mesh(image) except AssertionError: print("body not in image") keypoints = np.zeros((17, 3)) except Exception: print("General exception") keypoints = np.zeros((17, 3)) # self.lines = {} # self.connection = [ # [13, 16] # ] # p = [] # p.append(keypoints[13]) # p.append(keypoints[16]) # p = np.array(p) finally: self.points = GLScatterPlotItem( pos=np.array(np.array(keypoints)), color=glColor((12, 255, 0)), size=15, ) self.window.addItem(self.points) for n, pts in enumerate(self.connection): self.lines[n] = GLLinePlotItem(pos=np.array( [keypoints[p] for p in pts]), color=glColor((0, 0, 255)), width=3, antialias=True) self.window.addItem(self.lines[n])