def draw(self, painter): labeled_so_far = 0 self.label_mask[:] = False label_indices = [self.luminoso.selected_index] + [self.order[i] for i in self.whichlabels] for (i, lindex) in enumerate(label_indices): if lindex is None: continue x, y = self.luminoso.screenpts[lindex] if not self.luminoso.is_on_screen(x, y) or self.label_mask[x, y]: continue r, g, b = self.luminoso.colors[lindex] + 25 # Make currently selected point white. if i == 0: b = g = r = 255 text = self.luminoso.labels[lindex] if text is None: continue # Mask out areas that already have label text. dist = self.distances[lindex] width = int(dist/8) + 9 height = int(dist/16) + 3 xmin = max(x-width, 0) xmax = min(x+width, self.luminoso.width) ymin = max(y-height, 0) ymax = min(y+height, self.luminoso.height) self.label_mask[xmin:xmax, ymin:ymax] = True painter.setPen(QColor(0, 0, 0)) painter.drawText(Point(x+5, y+5), unicode(text)) painter.setPen(QColor(r, g, b)) painter.drawText(Point(x+4, y+4), unicode(text)) labeled_so_far += 1 if labeled_so_far >= self.nlabels: break
def draw(self, painter): painter.setPen(Qt.NoPen) whichpoints = self.luminoso.is_point_on_screen(self.luminoso.screenpts) pointlist = np.flatnonzero(whichpoints) subsizes = self.sizes[pointlist] sub_order = np.argsort(-subsizes) order = pointlist[sub_order] pixelsize = self.luminoso.pixel_size() # draw the origin if self.luminoso.is_point_on_screen(np.zeros((2,))): x, y = self.luminoso.projection_to_screen(np.zeros((2,))) painter.setBrush(QColor(100, 100, 100)) painter.drawEllipse(Point(x, y), 6, 6) painter.setBrush(QColor(255, 255, 255)) painter.drawEllipse(Point(x, y), 2, 2) for i in xrange(min(len(order), self.npoints)): coords = self.luminoso.screenpts[order[i]] x, y = coords r, g, b = self.luminoso.colors[order[i]] if i <= 1: b = g = r = 230 size = self.sizes[order[i]] / pixelsize if size >= 1 and self.luminoso.is_on_screen(x, y): painter.setBrush(QColor(r, g, b)) painter.drawEllipse(Point(x, y), size, size)
def draw(self, painter): if self.root: lines_to_draw = [] for (source, target) in self.lines: source_pt = Point(*self.luminoso.components_to_screen(self.luminoso.array[source])) target_pt = Point(*self.luminoso.components_to_screen(self.luminoso.array[target])) lines_to_draw.append(Line(source_pt, target_pt)) painter.setPen(QColor(255, 255, 255, 100)) painter.drawLines(lines_to_draw)
def draw(self, painter): if self.source: source_pt = Point(*self.luminoso.components_to_screen(self.luminoso.array[self.source])) target_pts = [Point(*p) for p in self.luminoso.components_to_screen(self.luminoso.array[self.connections])] lines = [Line(source_pt, target_pt) for target_pt in target_pts] painter.setPen(QColor(0, 100, 200, 160)) painter.drawLines(lines) target_pts = [Point(*p) for p in self.luminoso.components_to_screen(self.luminoso.array[self.anti_connections])] lines = [Line(source_pt, target_pt) for target_pt in target_pts] painter.setPen(QColor(200, 0, 0, 160)) painter.drawLines(lines)
def draw(self, painter): if self.luminoso.selected_index is not None: painter.setPen(QColor(255, 255, 255)) painter.setBrush(QColor(255, 255, 0)) vec = self.luminoso.selected_vector() text = self.luminoso.selected_label() if text is None: # The selection was deleted in real-time data. Bail out. return x, y = self.luminoso.components_to_screen(vec) painter.drawEllipse(Point(x, y), 3, 3) painter.setPen(Qt.NoPen) painter.drawText(Point(x+4, y+4), unicode(text))
def draw(self, painter): origin = np.zeros((2,)) origin_pt = Point(*self.luminoso.projection_to_screen(origin)) #painter.setCompositionMode(QPainter.CompositionMode_Screen) #for axis in xrange(self.luminoso.k): # projpoint = self.luminoso.projection.matrix[axis]/2 # x, y = self.luminoso.projection_to_screen(projpoint) # target_pt = Point(x, y) # painter.setPen(QColor(100, 100, 100)) # painter.drawLine(Line(origin_pt, target_pt)) # painter.setPen(QColor(180, 180, 180)) # painter.drawText(Point(x+2, y+2), str(axis)) painter.setPen(QColor(200, 200, 0)) for canon in self.canonical: index = self.luminoso.labels.index(canon) components = self.luminoso.array[index] target_pt = Point(*self.luminoso.components_to_screen(components)) # draw a yellowish line from the origin to the canonical doc painter.drawLine(Line(origin_pt, target_pt))
def mouseDragEvent(self, ev, axis=None): ## if axis is specified, event will only affect that axis. ev.accept() ## we accept all buttons pos = ev.pos() lastPos = ev.lastPos() dif = pos - lastPos dif = dif * -1 if ev.isStart(): self.roistart = (self.parent.cursorx, self.parent.cursory) ## Ignore axes if mouse is disabled mouseEnabled = np.array(self.state['mouseEnabled'], dtype=np.float) mask = mouseEnabled.copy() if axis is not None: mask[1 - axis] = 0.0 ## Scale or translate based on mouse button if ev.button() & (QtCore.Qt.MidButton | QtCore.Qt.LeftButton): if ev.modifiers() == QtCore.Qt.ShiftModifier: if ev.isFinish(): self.roistop = (self.parent.cursorx, self.parent.cursory) if self.roi is not None: self.removeItem(self.roi) self.addROI(self.roistart, self.roistop) self.updatePlot() #if self.state['mouseMode'] == self.RectMode: # if ev.isFinish(): ## This is the final move in the drag; change the view scale now # #print "finish" # self.rbScaleBox.hide() # #ax = QtCore.QRectF(Point(self.pressPos), Point(self.mousePos)) # ax = QtCore.QRectF(Point(ev.buttonDownPos(ev.button())), Point(pos)) # ax = self.childGroup.mapRectFromParent(ax) # self.showAxRect(ax) # self.axHistoryPointer += 1 # self.axHistory = self.axHistory[:self.axHistoryPointer] + [ax] # else: # ## update shape of scale box # self.updateScaleBox(ev.buttonDownPos(), ev.pos()) else: tr = dif * mask tr = self.mapToView(tr) - self.mapToView(Point(0, 0)) x = tr.x() if mask[0] == 1 else None y = tr.y() if mask[1] == 1 else None self.translateBy(x=x, y=y) self.sigRangeChangedManually.emit(self.state['mouseEnabled'])