def createRenderer(self): self._renderer = _NodeGLRenderer(self.window()) livectls = ngl.get_livectls(self._scene) if livectls: model_data = [] for label, ctl in livectls.items(): data = dict( type=self._NODE_TYPES_MODEL_MAP.get( ctl["node_type"], "range"), label=label, val=ctl["val"], node=ctl["node"], ) if data["type"] not in ("bool", "text"): data["min"] = ctl["min"] data["max"] = ctl["max"] if data["type"] == "color": data["val"] = QColor.fromRgbF(*ctl["val"]) model_data.append(data) self.livectls_changes = {} self.livectls_changed.emit(model_data) self.request_scene = self._scene return self._renderer
def remove_pixels_within_circle(self, clicked_x, clicked_y): """ Removes all highlighted pixels within the selected circle and updates the image. :param clicked_x: the current x coordinate :param clicked_y: the current y coordinate """ # Calculate euclidean distance between each highlighted point and # the clicked point. If the distance is less than the radius, # remove it from the highlighted pixels. # The roi drawn on current slice is changed after several pixels are # modified self.slice_changed = True clicked_x, clicked_y = linear_transform( clicked_x, clicked_y, self.rows, self.cols) according_color_dict_key_list = list(self.according_color_dict.keys()) color_to_draw = QtGui.QColor() color_to_draw.setRgb(90, 250, 175, 200) for x, y in according_color_dict_key_list: colors = self.according_color_dict[(x, y)] clicked_point = numpy.array((clicked_x, clicked_y)) point_to_check = numpy.array((x, y)) distance = numpy.linalg.norm(clicked_point - point_to_check) if distance <= self.draw_tool_radius * ( float(self.rows) / DEFAULT_WINDOW_SIZE): temp = set() temp.add((x, y)) points = get_pixel_coords(temp, self.rows, self.cols) for x_t, y_t in points: self.q_image.setPixelColor(x_t, y_t, QColor.fromRgbF( colors[0], colors[1], colors[2], colors[3])) self.target_pixel_coords.remove((x, y)) self.according_color_dict.pop((x, y)) # The roi drawn on current slice is changed after several # pixels are modified self.slice_changed = True self.refresh_image()