def fill_pixels_within_circle(self, clicked_x, clicked_y): """ Add 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, # add it to the highlighted pixels. # Set of points to color points_to_color = set() # 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) scaled_tool_radius = int(self.draw_tool_radius * ( float(self.rows) / DEFAULT_WINDOW_SIZE)) min_y_bound_square = math.floor(clicked_y) - scaled_tool_radius min_x_bound_square = math.floor(clicked_x) - scaled_tool_radius max_y_bound_square = math.floor(clicked_y) + scaled_tool_radius max_x_bound_square = math.floor(clicked_x) + scaled_tool_radius for y_coord in range( max(self.min_y, min_y_bound_square), min(self.max_y, max_y_bound_square)): for x_coord in range( max(self.min_x, min_x_bound_square), min(self.max_x, max_x_bound_square)): clicked_point = numpy.array((clicked_x, clicked_y)) point_to_check = numpy.array((x_coord, y_coord)) distance = numpy.linalg.norm( clicked_point - point_to_check) if (self.keep_empty_pixel or self.min_pixel <= self.pixel_array[y_coord][ x_coord] <= self.max_pixel) \ and distance <= scaled_tool_radius: temp = set() temp.add((x_coord, y_coord)) points = get_pixel_coords(temp, self.rows, self.cols) temp_2 = get_first_entry(points) c = self.q_image.pixel(temp_2[0], temp_2[1]) colors = QColor(c) if (x_coord, y_coord) not in self.according_color_dict: self.according_color_dict[ (x_coord, y_coord)] = colors.getRgbF() points_to_color.add((x_coord, y_coord)) self.target_pixel_coords.add((x_coord, y_coord)) # Color to draw color_to_draw = QtGui.QColor() color_to_draw.setRgb(90, 250, 175, 200) points = get_pixel_coords(points_to_color, self.rows, self.cols) for x_coord, y_coord in points: self.q_image.setPixelColor(x_coord, y_coord, color_to_draw) self.refresh_image()
def render(self): if not self._context: return self._window.beginExternalCommands() if self._request_stop: self._request_scene = None assert self._context.set_scene(None) == 0 self._t = 0.0 if self._request_scene: assert self._context.set_scene(self._request_scene) == 0 self._request_scene = None w, h = self._fbo.width(), self._fbo.height() self._context.gl_wrap_framebuffer(self._fbo.handle()) self._context.resize(w, h, (0, 0, w, h)) for live_id, ctl in self._livectls_changes.items(): node = ctl["node"] type_ = ctl["type"] value = ctl["val"] if type_ in ("range", "bool"): node.set_value(value) elif type_ == "color": node.set_value(*QColor.getRgbF(value)[:3]) elif type_ == "text": node.set_text(value) elif type_.startswith("vec") or type_.startswith("mat"): node.set_value(*value) self._livectls_changes = {} self._context.draw(self._t) if self._request_stop: del self._context self._context = None self._request_stop = False self._window.endExternalCommands()