def get_plot_average_y_section(obj, apply_lut=False): """ Return cross section along y-axis, averaged on ROI defined by 'obj' 'obj' is an AbstractShape object supporting the 'get_rect' method (RectangleShape, AnnotatedRectangle, etc.) """ x0, y0, x1, y1 = obj.get_rect() xc0, yc0 = axes_to_canvas(obj, x0, y0) xc1, yc1 = axes_to_canvas(obj, x1, y1) invert = False ydir = obj.plot().get_axis_direction("left") if (ydir and yc0 > yc1) or (not ydir and yc0 < yc1): invert = True yc1, yc0 = yc0, yc1 if xc0 > xc1: xc1, xc0 = xc0, xc1 try: data = get_image_from_qrect(obj.plot(), QPointF(xc0, yc0), QPointF(xc1, yc1), apply_lut=apply_lut, apply_interpolation=False) except (ValueError, ZeroDivisionError, TypeError): return np.array([]), np.array([]) y = data.mean(axis=1) x = np.linspace(y0, y1, len(y)) if invert: x = x[::-1] return x, y
def get_plot_y_section(obj, apply_lut=False): """ Return plot cross section along y-axis, at the x value defined by 'obj', a Marker/AnnotatedPoint object """ x0, _y0 = get_object_coordinates(obj) plot = obj.plot() ymap = plot.canvasMap(plot.Y_LEFT) yc0, yc1 = ymap.p1(), ymap.p2() if plot.get_axis_direction("left"): yc1, yc0 = yc0, yc1 xc0, _yc0 = axes_to_canvas(obj, x0, 0) xc1 = xc0 + 1 try: data = get_image_from_qrect(plot, QPointF(xc0, yc0), QPointF(xc1, yc1), apply_lut=apply_lut, add_images=True, apply_interpolation=False) except (ValueError, ZeroDivisionError, TypeError): return np.array([]), np.array([]) y = data.mean(axis=1) _x0, y0 = canvas_to_axes(obj, QPointF(xc0, yc0)) _x1, y1 = canvas_to_axes(obj, QPointF(xc1, yc1)) x = np.linspace(y0, y1, len(y)) return x, y
def get_plot_x_section(obj, apply_lut=False): """ Return plot cross section along x-axis, at the y value defined by 'obj', a Marker/AnnotatedPoint object """ _x0, y0 = get_object_coordinates(obj) plot = obj.plot() xmap = plot.canvasMap(plot.X_BOTTOM) xc0, xc1 = xmap.p1(), xmap.p2() _xc0, yc0 = axes_to_canvas(obj, 0, y0) if plot.get_axis_direction("left"): yc1 = yc0 + 1 else: yc1 = yc0 - 3 try: #TODO: eventually add an option to apply interpolation algorithm data = get_image_from_qrect(plot, QPointF(xc0, yc0), QPointF(xc1, yc1), apply_lut=apply_lut, add_images=True, apply_interpolation=False) except (ValueError, ZeroDivisionError, TypeError): return np.array([]), np.array([]) y = data.mean(axis=0) x0, _y0 = canvas_to_axes(obj, QPointF(xc0, yc0)) x1, _y1 = canvas_to_axes(obj, QPointF(xc1, yc1)) x = np.linspace(x0, x1, len(y)) return x, y
def start_moving(self, filter, event): self.shape.attach(filter.plot) self.shape.setZ(filter.plot.get_max_z() + 1) if self.avoid_null_shape: self.start -= QPointF(1, 1) self.shape.move_local_point_to(self.shape_h0, self.start) self.shape.move_local_point_to(self.shape_h1, event.pos()) self.start_moving_action(filter, event) if self.setup_shape_cb is not None: self.setup_shape_cb(self.shape) self.shape.show() filter.plot.replot()
def draw(self, painter, xMap, yMap, canvasRect): self.update_text() x, y = self.get_top_left(xMap, yMap, canvasRect) x0, y0 = self.get_origin(xMap, yMap, canvasRect) painter.save() self.marker.drawSymbols(painter, [QPointF(x0, y0)]) painter.restore() sz = self.text.size() self.draw_frame(painter, x, y, sz.width(), sz.height()) painter.setPen(QPen(QColor(self.labelparam.color))) painter.translate(x, y) self.text.drawContents(painter)
def move(self, filter, event): if self.active is None: return self.unselection_pending = False if self.inside: self.active.move_local_shape(self.last_pos, event.pos()) self.undo_action = UndoMoveObject(self.active, event.pos(), self.first_pos) else: ctrl = event.modifiers() & Qt.ControlModifier == Qt.ControlModifier self.active.move_local_point_to(self.handle, event.pos(), ctrl) self.undo_action = UndoMovePoint(self.active, self.first_pos, event.pos(), self.handle, ctrl) self.last_pos = QPointF(event.pos()) filter.plot.replot()
def draw(self, painter, xMap, yMap, canvasRect): items = self.get_legend_items() TW, TH, _width, height = self.get_legend_size(items) x, y = self.get_top_left(xMap, yMap, canvasRect) self.draw_frame(painter, x, y, TW, TH) y0 = y+LEGEND_SPACEV x0 = x+LEGEND_SPACEH for text, ipen, ibrush, isymbol in items: isymbol.drawSymbols(painter, [QPointF(x0+LEGEND_WIDTH/2, y0+height/2)]) painter.save() painter.setPen(ipen) painter.setBrush(ibrush) painter.drawLine( x0, y0+height/2, x0+LEGEND_WIDTH, y0+height/2) x1 = x0+LEGEND_SPACEH+LEGEND_WIDTH painter.translate(x1, y0) text.drawContents(painter) painter.restore() y0 += height+LEGEND_SPACEV
def start_tracking(self, filter, event): self.start = self.last = QPointF(event.pos())
def start_tracking(self, filter, event): plot = filter.plot self.inside = False self.active = None self.handle = None self.first_pos = pos = event.pos() self.last_pos = QPointF(pos) selected = plot.get_active_item() distance = CONF.get("plot", "selection/distance", 6) (nearest, nearest_dist, nearest_handle, nearest_inside) = plot.get_nearest_object(pos, distance) if nearest is not None: # Is the nearest object the real deal? if not nearest.can_select() or nearest_dist >= distance: # Looking for the nearest object in z containing cursor position (nearest, nearest_dist, nearest_handle, nearest_inside) = plot.get_nearest_object_in_z(pos) # This will unselect active item only if it's not moved afterwards: self.unselection_pending = selected is nearest if selected and not self.multiselection: # An item is selected self.active = selected (dist, self.handle, self.inside, other_object) = self.active.hit_test(pos) if other_object is not None: # e.g. LegendBoxItem: 'other_object' is the selected curve plot.set_active_item(other_object) return if dist >= distance and not self.inside: # The following allows to move together selected items by # clicking inside any of them (instead of active item only) other_selitems = [ _it for _it in plot.get_selected_items() if _it is not self.active and _it.can_move() ] for selitem in other_selitems: dist, handle, inside, _other = selitem.hit_test(pos) if dist < distance or inside: self.inside = inside break else: self.__unselect_objects(filter) filter.set_state(self.start_state, event) return else: # No item is selected self.active = nearest self.handle = nearest_handle self.inside = nearest_inside dist = nearest_dist if nearest is not None: plot.set_active_item(nearest) if not nearest.selected: if not self.multiselection: plot.unselect_all() plot.select_item(nearest) # Eventually move or resize selected object: self.__move_or_resize_object(dist, distance, event, filter) plot.replot()
def compute_positions(self): from guiqwt.baseplot import axes_to_canvas pos1 = QPointF(*axes_to_canvas(self.obj, *self.coords1)) pos2 = QPointF(*axes_to_canvas(self.obj, *self.coords2)) return pos1, pos2
def get_move_state(self, filter, pos): rct = filter.plot.contentsRect() dx = (pos.x(), self.last.x(), self.start.x(), rct.width()) dy = (pos.y(), self.last.y(), self.start.y(), rct.height()) self.last = QPointF(pos) return dx, dy
def __init__(self, xmin, xmax, ymin, ymax): super(MandelItem, self).__init__(np.zeros((1, 1), np.uint8)) self.bounds = QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax)) self.update_border() self.IMAX = 80 self.set_lut_range([0, self.IMAX])