def __init__(self, sys='TrueBeam'): """ Initialize the trajectory class. Units should stay be consistent for all dimensions. The default is cm though it could be changed if necessary. The trajectory will be built from a set of control points. The number of views will then be determined by the frame rate which is also in the system configuration file. Currently only the system configuration is the only parameter. Once the total trajectory is built, the time will be represented based on the velocities in the system configuration. There will also need to be some additional error checking to make sure that the positions that are specified are allowed. From the actual trajectory that can be imaged with the physical system, the trajectory can be downsampled much in the same way the few-view studies will be done with the real data. That way the simulations and the real data downsampling will both work in the same way in the reconstruction. .. todo:: If allowing different units, add flags. Keyword Arguments: sys -- (default 'TrueBeam') Imaging system. """ # Setup the system configuration self.sys = sys # a valid system configuration is needed to ensure that the # correct velocities are used to populate the trajectory if sys == 'TrueBeam': self.conf = system_config.TrueBeam() else: raise Exception("This system configuration has not been defined.") # control point object self.cpts = control_points.ControlPoints(self.conf) # position is paramaterized by time # # TODO this needs to be populated based on the velocities from # the system configuration self.t = [] # source self.r_src = coords.Coords() # det self.r_det = coords.Coords() # frame vectors # TODO populate this from the trajectory if necessary self.fvecs = [] # plots self.vis_traj = None
def connectVorNodes(nodes,radii): """Create connections between the voronoi nodes. Each of the nodes is connected with its closest neighbours. The input is an array of n nodes and an array of n corresponding radii. Two voronoi nodes are connected if the distance between these two nodes is smaller than the sum of their corresponding radii. The output is an array containing the connectivity information. """ connections = array([]).astype(int) v = 4 for i in range(nodes.shape[0]): t1 = (nodes[:] > (nodes[i]-v*radii[i])).all(axis=2) t2 = (nodes[:] < (nodes[i]+v*radii[i])).all(axis=2) t = t1*t2 t[i] = False w1 = where(t == 1)[0] c = coords.Coords(nodes[w1]) d =c.distanceFromPoint(nodes[i]).reshape(-1) w2 = d < radii[w1] + radii[i] w = w1[w2] for j in w: connections = append(connections,i) connections = append(connections,j) connections = connections.reshape(-1,2) connections = removeDoubles(connections) return connections.reshape(-1,2)
def test_coords(): for i in range(1000): lat = random.uniform(-90, 90) lon = random.uniform(-180, 180) cds = coords.Coords(lat, lon) assert cds.latitude == math.radians(lat) assert cds.longitude == math.radians(lon)
def test_distance(): c1 = coords.Coords(0, 0) c2 = coords.Coords(0, 90) c3 = coords.Coords(0, -90) assert int(c1.distance(c2)) == 10007 assert int(c2.distance(c1)) == 10007 assert int(c1.distance(c3)) == 10007 assert int(c3.distance(c1)) == 10007 c2 = coords.Coords(0, 180) c3 = coords.Coords(0, -180) assert int(c1.distance(c2)) == 20015 assert int(c2.distance(c1)) == 20015 assert int(c1.distance(c3)) == 20015 assert int(c3.distance(c1)) == 20015
def read_fvecs(self, filename, header=1, basis='iec'): """Read external fvecs file and populate the trajectory Keyword Arguments: filename -- csv file with the frame vectors header -- (default 1) number of lines to skip for the header basis -- (default 'iec') basis the frame vectors are in """ self.fvecs = np.genfromtxt(filename, delimiter=',', skip_header=header) # this part isn't right, it already assumes a basis when I # read in the frame vectors if basis == 'iec': self.r_src = coords.Coords(self.fvecs[:, 0], self.fvecs[:, 1], self.fvecs[:, 2], basis) elif basis == 'dicom': self.r_src = coords.Coords(self.fvecs[:, 0], self.fvecs[:, 2], self.fvecs[:, 1], basis) else: raise Exception('Unsupported basis.')
def test_customer(): auid = int(random.uniform(0, 1000)) alat = random.uniform(-90, 90) along = random.uniform(-180, 180) alice = customers.Customer(auid, 'Alice', coords.Coords(alat, along)) assert alice.user_id == auid assert alice.name == 'Alice' assert alice.coords.latitude == math.radians(alat) assert alice.coords.longitude == math.radians(along)
def read_customers(self, fname): # Clears previous configuration self.customers.clear() # Closes the file when f gets out of scope with open(fname, 'r') as f: for line in f: # I'm parsing the json here and converting the data to the types # expected by the internal apis. jsline = json.loads(line) coords = cd.Coords(float(jsline['latitude']), float(jsline['longitude'])) self.customers.append( cs.Customer(jsline['user_id'], jsline['name'], coords))
def __init__(self): self.office = cd.Coords(53.339428, -6.257664) self.customers = [] self.invited = []
def setCamera(self, bbox=None, angles=None): """Sets the camera looking under angles at bbox. This function sets the camera parameters to view the specified bbox volume from the specified viewing direction. Parameters: - `bbox`: the bbox of the volume looked at - `angles`: the camera angles specifying the viewing direction. It can also be a string, the key of one of the predefined camera directions If no angles are specified, the viewing direction remains constant. The scene center (camera focus point), camera distance, fovy and clipping planes are adjusted to make the whole bbox viewed from the specified direction fit into the screen. If no bbox is specified, the following remain constant: the center of the scene, the camera distance, the lens opening and aspect ratio, the clipping planes. In other words the camera is moving on a spherical surface and keeps focusing on the same point. If both are specified, then first the scene center is set, then the camera angles, and finally the camera distance. In the current implementation, the lens fovy and aspect are not changed by this function. Zoom adjusting is performed solely by changing the camera distance. """ # # TODO: we should add the rectangle (digital) zooming to # the docstring self.makeCurrent() # set scene center if bbox is not None: pf.debug("SETTING BBOX: %s" % self.bbox, pf.DEBUG.DRAW) self.setBbox(bbox) X0, X1 = self.bbox self.camera.focus = 0.5 * (X0 + X1) # set camera angles if type(angles) is str: angles = self.view_angles.get(angles) if angles is not None: try: self.camera.setAngles(angles) except: raise ValueError, 'Invalid view angles specified' # set camera distance and clipping planes if bbox is not None: # Currently, we keep the default fovy/aspect # and change the camera distance to focus fovy = self.camera.fovy #pf.debug("FOVY: %s" % fovy,pf.DEBUG.DRAW) self.camera.setLens(fovy, self.aspect) # Default correction is sqrt(3) correction = float(pf.cfg.get('gui/autozoomfactor', 1.732)) tf = coords.tand(fovy / 2.) import simple bbix = simple.regularGrid(X0, X1, [1, 1, 1]) bbix = dot(bbix, self.camera.rot[:3, :3]) bbox = coords.Coords(bbix).bbox() dx, dy, dz = bbox[1] - bbox[0] vsize = max(dx / self.aspect, dy) dsize = bbox.dsize() offset = dz dist = (vsize / tf + offset) / correction if dist == nan or dist == inf: pf.debug("DIST: %s" % dist, pf.DEBUG.DRAW) return if dist <= 0.0: dist = 1.0 self.camera.dist = dist ## print "vsize,dist = %s, %s" % (vsize,dist) ## near,far = 0.01*dist,100.*dist ## print "near,far = %s, %s" % (near,far) #near,far = dist-1.2*offset/correction,dist+1.2*offset/correction near, far = dist - 1.0 * dsize, dist + 1.0 * dsize # print "near,far = %s, %s" % (near,far) #print (0.0001*vsize,0.01*dist,near) # make sure near is positive near = max(near, 0.0001 * vsize, 0.01 * dist, finfo(coords.Float).tiny) # make sure far > near if far <= near: far += finfo(coords.Float).eps #print "near,far = %s, %s" % (near,far) self.camera.setClip(near, far) self.camera.resetArea()
self): # starts one QThread and refresh proper gui elements if self.isRunning and len(coords.getCoords()) > 0: setIsRunningTextStarted(True) setIsReplayingStarted(True) self.replayRec.setText('◼') self.startTextThread.start() self.startReplayingThread.start() self.isRunning = False else: setIsRunningTextStarted(False) setIsReplayingStarted(False) self.replayRec.setText('⏵') self.isRunning = True app = QApplication(sys.argv) appid = 'mycompany.myproduct.subproduct.version' # arbitrary string (for taskbar icon) ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(appid) window = Window() window.setWindowTitle('Kísérletező felhasználói felületet') window.setWindowIcon( QIcon(os.path.join(os.getcwd() + '/datas/images/logo.png'))) window.show() coords = coords.Coords() circle = Circle(window.circle) circle.getCircle().setPixmap( QPixmap(os.path.join(os.getcwd() + "/datas/images/gaussianBlur.png"))) circle.getCircle().hide() sys.exit(app.exec_())