def from_(self, off_pts): """Reverse of :meth:`to_`.""" off_pts = np.asarray(off_pts, dtype=np.float) has_z = (off_pts.shape[-1] > 2) t_ = self.viewer.t_ # rotate if t_['rot_deg'] != 0: thetas = [-t_['rot_deg']] offset = [0.0, 0.0] if has_z: offset.append(0.0) off_pts = trcalc.rotate_coord(off_pts, thetas, offset) # swap if t_['swap_xy']: p = list(off_pts.T) off_pts = np.asarray([p[1], p[0]] + list(p[2:])).T # flip flip_pt = [1.0, 1.0] if t_['flip_x']: flip_pt[0] = -1.0 if t_['flip_y']: flip_pt[1] = -1.0 if has_z: # no flip_z at the moment flip_pt.append(1.0) off_pts = np.multiply(off_pts, flip_pt) return off_pts
def from_(self, off_pts): """Reverse of :meth:`to_`.""" off_pts = np.asarray(off_pts, dtype=np.float) has_z = (off_pts.shape[-1] > 2) t_ = self.viewer.t_ # rotate if t_['rot_deg'] != 0: thetas = [- t_['rot_deg']] offset = [0.0, 0.0] if has_z: offset.append(0.0) off_pts = trcalc.rotate_coord(off_pts, thetas, offset) # swap if t_['swap_xy']: p = list(off_pts.T) off_pts = np.asarray([p[1], p[0]] + list(p[2:])).T # flip flip_pt = [1.0, 1.0] if t_['flip_x']: flip_pt[0] = -1.0 if t_['flip_y']: flip_pt[1] = -1.0 if has_z: # no flip_z at the moment flip_pt.append(1.0) off_pts = np.multiply(off_pts, flip_pt) return off_pts
def get_cpoints(self, viewer, points=None, no_rotate=False): # If points are passed, they are assumed to be in data space if points is None: points = self.get_points() if (not no_rotate) and hasattr(self, 'rot_deg') and self.rot_deg != 0.0: # rotate vertices according to rotation ctr_x, ctr_y = self.get_center_pt() points = trcalc.rotate_coord(points, [self.rot_deg], (ctr_x, ctr_y)) crdmap = viewer.get_coordmap('native') return crdmap.data_to(points)
def get_cpoints(self, viewer, points=None, no_rotate=False): if points is None: points = self.get_points() points = numpy.asarray(points) if (not no_rotate) and hasattr(self, 'rot_deg') and self.rot_deg != 0.0: # rotate vertices according to rotation ctr_x, ctr_y = self.get_center_pt() points = trcalc.rotate_coord(points, self.rot_deg, (ctr_x, ctr_y)) cpoints = tuple(map(lambda p: self.canvascoords(viewer, p[0], p[1]), points)) return cpoints
def get_pt(self, viewer, points, pt, canvas_radius=None): """Takes an array of points `points` and a target point `pt`. Returns the first index of the point that is within the radius of the target point. If none of the points are within the radius, returns None. """ if canvas_radius is None: canvas_radius = self.cap_radius if hasattr(self, 'rot_deg'): # rotate point back to cartesian alignment for test ctr_pt = self.get_center_pt() pt = trcalc.rotate_coord(pt, [-self.rot_deg], ctr_pt) res = self.within_radius(viewer, points, pt, canvas_radius) return np.flatnonzero(res)
def get_llur(self): points = (self.crdmap.offset_pt((self.x, self.y), (-self.xradius, -self.yradius)), self.crdmap.offset_pt((self.x, self.y), (self.xradius, -self.yradius)), self.crdmap.offset_pt((self.x, self.y), (self.xradius, self.yradius)), self.crdmap.offset_pt((self.x, self.y), (-self.xradius, self.yradius))) mpts = np.asarray(self.get_data_points(points=points)) if hasattr(self, 'rot_deg'): xd, yd = self.crdmap.to_data((self.x, self.y)) mpts = trcalc.rotate_coord(mpts, [self.rot_deg], [xd, yd]) a, b = trcalc.get_bounds(mpts) return (a[0], a[1], b[0], b[1])
def get_llur(self): points = (self.crdmap.offset_pt((self.x, self.y), -self.xradius, -self.yradius), self.crdmap.offset_pt((self.x, self.y), self.xradius, -self.yradius), self.crdmap.offset_pt((self.x, self.y), self.xradius, self.yradius), self.crdmap.offset_pt((self.x, self.y), -self.xradius, self.yradius)) mpts = numpy.asarray(self.get_data_points(points=points)) if hasattr(self, 'rot_deg'): xd, yd = self.crdmap.to_data(self.x, self.y) mpts = trcalc.rotate_coord(mpts, self.rot_deg, [xd, yd]) t_ = mpts.T x1, y1 = t_[0].min(), t_[1].min() x2, y2 = t_[0].max(), t_[1].max() return (x1, y1, x2, y2)
def rerotate_by(self, theta_deg, detail): ref_x, ref_y = detail.center_pos points = numpy.asarray(detail.points) points = trcalc.rotate_coord(points, theta_deg, [ref_x, ref_y]) self.set_data_points(points)
def rotate(self, theta_deg, xoff=0, yoff=0): points = numpy.asarray(self.get_data_points()) points = trcalc.rotate_coord(points, theta_deg, [xoff, yoff]) self.set_data_points(points)
def rerotate_by_deg(self, thetas, detail): ref_pt = detail.center_pos points = np.asarray(detail.points, dtype=np.double) points = trcalc.rotate_coord(points, thetas, ref_pt) self.set_data_points(points)
def rotate(self, theta_deg, xoff=0, yoff=0): points = numpy.asarray(self.get_data_points(), dtype=numpy.double) points = trcalc.rotate_coord(points, theta_deg, [xoff, yoff]) self.set_data_points(points)
def rotate_deg(self, thetas, offset): points = np.asarray(self.get_data_points(), dtype=np.double) points = trcalc.rotate_coord(points, thetas, offset) self.set_data_points(points)
def rerotate_by(self, theta_deg, detail): ref_x, ref_y = detail.center_pos points = numpy.asarray(detail.points, dtype=numpy.double) points = trcalc.rotate_coord(points, theta_deg, [ref_x, ref_y]) self.set_data_points(points)