Example #1
0
def drawedge(u, v, w=False):
    w = w or ""
    x1, y1 = pos[u]
    x2, y2 = pos[v]
    draw_line(x1, y1, x2, y2)
    x, y = (x1 + x2) / 2 + 10, (y1 + y2) / 2 + 10
    draw_label(str(w), x, y)
Example #2
0
 def render(self, canvas: tk.Canvas):
     drawing.draw_rect(canvas,
                       self.position,
                       self.size,
                       self.heading,
                       fill="blue")
     for _, sensor in self.sensors:
         drawing.draw_line(canvas, sensor)
     for point in self.detected_obstacles:
         drawing.draw_dot(canvas, point)
Example #3
0
    def draw_terrain(self):
        return
        for point in self.outer_points:
            drawing.draw_dot(self.canvas, point, fill="black")

        for wall in self.outer_walls():
            drawing.draw_line(self.canvas, wall, fill="black")

        for point in self.inner_points:
            drawing.draw_dot(self.canvas, point, fill="red")

        for wall in self.inner_walls():
            drawing.draw_line(self.canvas, wall, fill="red")
def draw_projection(pixels, camera, figures):
    lines = []
    triangles = []

    for figure in figures:
        transform_options = figure.get_transform_options()

        for triangle in figure.triangles:
            tr = triangle.transform(transform_options, camera)
            triangles.append(tr)

        for edge in figure.edges:
            lines.append(edge.transform(transform_options, camera))

    for line in lines:
        draw_line(pixels, line, GREEN, WHITE, triangles)
Example #5
0
def drawing_code(points, sparse=False):
    for p, color in points:
        if (not sparse) or p[0] in [1, -1]:
            for line in plane_drawing(p):
                c = draw_line(*line, color=color)
                yield c
        for point in antipodes(p):
            c = draw_point(point, color=color)
            yield c
Example #6
0
def draw_all(_points, _f, f_line, g_line, g_line_2=None):
    draw.draw_board()
    draw.draw_line(f_line, 'g--')
    draw.draw_points(_points, _f)
    draw.draw_line(g_line, 'r--')
    if g_line_2:
        draw.draw_line(g_line_2, 'b--')
    plt.show()
Example #7
0
def test_regression_n_times(number_of_points, number_of_tests):
    e_in_avg = 0
    e_out_avg = 0
    for _test_ in range(number_of_tests):
        _e_in, _e_out, _line, _px, _py, _points, _f, _g_ = test_regression(number_of_points)
        # print 'E_in:', _e_in, '   E_out:', _e_out
        e_in_avg += _e_in
        #
        #  Sanity check
        if _e_in > 30:
            print ' break at test ', _test_
            break
        e_out_avg += _e_out
    print ''
    print ' In-Sample      Freq:', e_in_avg, '// Error: ', float(e_in_avg) / (number_of_points * number_of_tests)
    print ' Out-of-Sample  Freq:', e_out_avg, '// Error: ',  float(e_out_avg) / (number_of_tests*1000)
    #
    # Draw last try.
    draw.draw_board()
    draw.draw_line(_line, 'g--')
    draw.draw_points(_points, _f)
    draw.draw_line(_g_, 'r--')
    plt.show()
Example #8
0
    def drawoutline(self, image, color):
        """Draws the outline of the cell over a color image."""
        if self._needs_refresh:
            self._refresh()

        draw_line(image, int(self._tail_left.x), int(self._tail_left.y),
                  int(self._head_left.x), int(self._head_left.y), color)
        draw_line(image, int(self._tail_right.x), int(self._tail_right.y),
                  int(self._head_right.x), int(self._head_right.y), color)

        r0 = self._head_right - self._head_center
        r1 = self._head_left - self._head_center
        t1 = atan2(r0.y, r0.x)
        t0 = atan2(r1.y, r1.x)
        draw_arc(image, self._head_center.x, self._head_center.y,
                 self._width / 2, t0, t1, color)

        r0 = self._tail_right - self._tail_center
        r1 = self._tail_left - self._tail_center
        t0 = atan2(r0.y, r0.x)
        t1 = atan2(r1.y, r1.x)
        draw_arc(image, self._tail_center.x, self._tail_center.y,
                 self._width / 2, t0, t1, color)
Example #9
0
 def on_draw(self):
     self._sprite.draw()
     if DEBUG:
         draw_line(self._sprite.x,self._sprite.y,self._target._sprite.x,self._target._sprite.y,(0,0,1))
Example #10
0
 def test_basic_line(self):
     x = (0, 1)
     z = (1, 0.5)
     draw_code = draw_line(x, z)
     self.assertEqual(draw_code,
                      "    \draw[black] (0.00,1.00) -- (1.00,0.50);")
Example #11
0
 def test_basic_line_with_star(self):
     line = [(0, 1), (1, 0.5)]
     draw_code = draw_line(*line, color="red")
     self.assertEqual(draw_code,
                      "    \draw[red] (0.00,1.00) -- (1.00,0.50);")
Example #12
0
    def run(self, as_script=True):
        if self.invisible:
            cv2.namedWindow("Control")

        prev_gray = None
        prev_points = None
        
        while True:
            ret, frame = self.cam.read()
            if not ret:
                break

            fg_mask = self.operator.apply(frame)
            fg_mask = ((fg_mask == 255) * 255).astype(np.uint8)
            fg_mask = morph_openclose(fg_mask)

            frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

            if prev_gray is not None and prev_points is not None:
                p0 = np.float32([point for point in prev_points]).reshape(-1, 1, 2)
                if drawing.draw_prev_points(frame, prev_points):
                    # p1, st, err = cv2.calcOpticalFlowPyrLK(prev_gray, frame_gray, p0, None, **lk_params)
                    frame_gray[fg_mask == 0] = 255
                    p1, st, err = cv2.calcOpticalFlowPyrLK(prev_gray, frame_gray, p0, None, **lk_params)
                    for p_i, p_f in zip(p0.reshape(-1, 2), p1.reshape(-1, 2)):
                        result = cross(ROI, ROI_W, ROI_H, p_i, p_f)
                        if result is 1:
                            self.arrivals += 1
                            if not self.quiet:
                                print("Arrival")
                        elif result is -1:
                            self.departures += 1
                            if not self.quiet:
                                print("Departure")

                        if self.drawTracks:
                            drawing.draw_line(frame, tuple(p_i), tuple(p_f))

            prev_gray = frame_gray
            contours, hier = drawing.draw_contours(frame, fg_mask)
            
            areas, prev_points = drawing.draw_min_ellipse(contours, frame, MIN_AREA, MAX_AREA)
            self.areas += areas

            self.frame_idx += 1
            if not self.invisible:
                self.draw_overlays(frame, fg_mask)
                cv2.imshow("Fas", frame_gray)
                cv2.imshow('Tracking', frame)
                cv2.imshow("Mask", fg_mask)
                delay = 33
            else:
                delay = 1
            if handle_keys(delay) == 1:
                break
            
            # Should we continue running or yield some information about the current frame
            if as_script: continue
            else: pass

        return self.areas
Example #13
0
def draw_population_structure_graph(output_file_name,
                                    data,
                                    genotypes_ordering,
                                    struct_plot_settings):
    """ Draws a structure plot from the splicing data, broken up by genotype

    output_file_name is the file path where the plot will be written
    data is a pandas.DataFrame object representing the splicing data
    width is the width of the plot
    height is the height of the plot
    left_margin is the amount of white space on the left side of the plot
    right_margin is the amount of white space on the right side of the plot
    bottom_margin is the amount of white space below the plot
    top_margin is the amount of white space above the plot
    colors is a list of RGB objects which determine the colors of the bars in the structure plot
    axis_color is an RGB object representing the color of the axes, labels, and tick marks
    axis_thickness is the thickness of the axes and ticks
    tick_length is the length of the tick marks
    horiz_label_size is the font size of the labels along the horizontal (x) axis
    horiz_label_spacing represents the distance from the horizontal axis labels are drawn below the horizontal axis
    horiz_axis_title_size is the font size of the label for the horizontal axis
    horiz_axis_title_spacing is the distance from the horizontal axis that the title is drawn below the horizontal axis
    use_vertical_ticks is a boolean determining whether or not tick marks are drawn for the vertical (y) axis
    vertical_tick_spacing represents the scale for the tick marks on the vertical axis. Must be between 0 and 1
    vert_label_size is the font size of the vertical axis tick mark labels
    vert_label_spacing represents the distance from which the vertical axis labels are drawn to the left of the vertical axis
    include_key is a boolean determining whether or not a key should be drawn
    key_position is an array representing the cartesian coordinates of the key. [0,0] refers to the bottom left corner of the plot
    key_font_size is the font size of each entry in the key
    key_text_color is an RGB object which represents the color of the text in the key
    """

    # parse settings
    width=struct_plot_settings['plot_width']
    height=struct_plot_settings['plot_height']
    left_margin=struct_plot_settings['left_margin']
    right_margin=struct_plot_settings['right_margin']
    bottom_margin=struct_plot_settings['bottom_margin']
    top_margin=struct_plot_settings['top_margin']
    colors=struct_plot_settings['colors']
    axis_color=struct_plot_settings['axis_color']
    axis_thickness =struct_plot_settings['axis_thickness']
    tick_length=struct_plot_settings['tick_length']
    horiz_label_size=struct_plot_settings['horiz_label_size']
    horiz_label_spacing=struct_plot_settings['horiz_label_spacing']
    horiz_axis_title_size=struct_plot_settings['horiz_axis_title_size']
    horiz_axis_title_spacing=struct_plot_settings['horiz_axis_title_spacing']
    use_vertical_ticks=struct_plot_settings['use_vertical_ticks']
    vertical_tick_spacing=struct_plot_settings['vertical_tick_spacing']
    vert_label_size=struct_plot_settings['vert_label_size']
    vert_label_spacing=struct_plot_settings['vert_label_spacing']
    include_key=struct_plot_settings['include_key']
    key_position=struct_plot_settings['key_position']
    key_font_size=struct_plot_settings['key_font_size']
    key_text_color=struct_plot_settings['key_text_color']


    # sort the data frame so that homozygous reference is first, heterozygous is in the middle, etc
    indiv_and_genotypes = data.iloc[:,0]
    indivs_by_genotype = {}
    for indiv_id, genotype in indiv_and_genotypes.iteritems():
        if genotype not in indivs_by_genotype:
            indivs_by_genotype[genotype] = []
        indivs_by_genotype[genotype].append(indiv_id)

    new_index_order = []
    for genotype in genotypes_ordering:
        new_index_order.extend(indivs_by_genotype[genotype])
    sorted_data = data.reindex(index=new_index_order)

    # assign colors for each junction
    color_lookup = {}
    all_junctions = list(sorted_data.columns[1:])
    for i in range(len(all_junctions)):
        color_lookup[all_junctions[i]] = colors[i]

    width_per_individual = (width - (left_margin + right_margin)) / len(sorted_data.index)

    
    # create svg file
    f1 = open(output_file_name,'w+')

    # set up svg
    f1.write('<?xml version="1.0"?>\n')
    f1.write('<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n')
    f1.write('<svg width="{0}in" height="{1}in" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 {0} {1}">\n'.format(width,height))

    # flip to cartesian coordinates, (0,0) is at bottom left corner
    f1.write('<g transform="translate(0,{0}) scale(1,-1)">\n'.format(height))

    # draw the rectangles. also draw vertical separators and horizontal axis labels
    previous_width = left_margin
    current_width = left_margin
    current_genotype = sorted_data.iloc[0,0]
    for row_number in range(sorted_data.shape[0]):
        individual = sorted_data.iloc[row_number]

        # draw rectangles
        expression_total_value = 0
        for junction in all_junctions:

            junction_color = color_lookup[junction]

            current_junction_expression = individual[junction]
            start_y, rect_height = (height - top_margin - bottom_margin) * expression_total_value + bottom_margin, (height - top_margin - bottom_margin) * current_junction_expression            
            drawing.draw_rectangle(f1,current_width,start_y,width_per_individual,rect_height,junction_color)
            expression_total_value += current_junction_expression

        # draw separators and horizontal axis labels
        if individual.iloc[0] != current_genotype or row_number == sorted_data.shape[0] - 1:
            if individual.iloc[0] != current_genotype:
                drawing.draw_line(f1,current_width,bottom_margin-tick_length*0.5,current_width,height-top_margin,axis_thickness,axis_color)

            if horiz_label_size:
                drawing.draw_text(f1,current_genotype,previous_width+(current_width-previous_width)*0.5,bottom_margin-horiz_label_spacing,horiz_label_size,angle=0,color=axis_color)

            previous_width = current_width
            current_genotype = individual.iloc[0]

        current_width += width_per_individual


    # draw vertical tick marks
    if use_vertical_ticks:
        i = vertical_tick_spacing
        while i <= 1:
            y_coordinate = (height - top_margin - bottom_margin) * i + bottom_margin
            x_coordinate = left_margin - vert_label_spacing

            drawing.draw_line(f1,left_margin-tick_length*0.5,y_coordinate,left_margin+tick_length*0.5,y_coordinate,axis_thickness,axis_color)
            drawing.draw_text(f1,i,x_coordinate,y_coordinate-vert_label_size*0.25,vert_label_size,angle=0,color=axis_color)

            drawing.draw_line
            i += vertical_tick_spacing


    # draw the plot border
    left_x, right_x = left_margin, current_width
    top_y, bottom_y = height - top_margin, bottom_margin

    drawing.draw_line(f1,left_x-axis_thickness/2,top_y,right_x+axis_thickness/2,top_y,axis_thickness,axis_color)
    drawing.draw_line(f1,left_x,top_y+axis_thickness/2,left_x,bottom_y-axis_thickness/2,axis_thickness,axis_color)
    drawing.draw_line(f1,right_x,bottom_y-axis_thickness/2,right_x,top_y+axis_thickness/2,axis_thickness,axis_color)
    drawing.draw_line(f1,right_x+axis_thickness/2,bottom_y,left_x-axis_thickness/2,bottom_y,axis_thickness,axis_color)


    # draw horizontal axis title, if desired
    if horiz_axis_title_size != 0:
        drawing.draw_text(f1,data.columns[0],(left_margin+current_width)*0.5,bottom_margin-horiz_axis_title_spacing,horiz_axis_title_size,angle=0,color=axis_color)


    # draw the key if desired
    if include_key:

        spacing = key_font_size * 2

        for i in range(len(all_junctions)):
            junction_name = all_junctions[i]
            color = color_lookup[junction_name]

            drawing.draw_rectangle(f1,key_position[0],key_position[1] - i * spacing,key_font_size,key_font_size,color)
            drawing.draw_text_left(f1,data.columns[i+1],key_position[0]+spacing,key_position[1] - i * spacing,key_font_size,color=key_text_color)
    
            
    f1.write('</g>\n')
    f1.write('</svg>\n')

    f1.close()
Example #14
0
    def run(self, as_script=True):
        if self.invisible:
            cv2.namedWindow("Control")

        prev_gray = None
        prev_points = None

        while True:
            ret, frame = self.cam.read()
            if not ret:
                break

            fg_mask = self.operator.apply(frame)
            fg_mask = ((fg_mask == 255) * 255).astype(np.uint8)
            fg_mask = morph_openclose(fg_mask)

            frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

            if prev_gray is not None and prev_points is not None:
                p0 = np.float32([point
                                 for point in prev_points]).reshape(-1, 1, 2)
                if drawing.draw_prev_points(frame, prev_points):
                    # p1, st, err = cv2.calcOpticalFlowPyrLK(prev_gray, frame_gray, p0, None, **lk_params)
                    frame_gray[fg_mask == 0] = 255
                    p1, st, err = cv2.calcOpticalFlowPyrLK(
                        prev_gray, frame_gray, p0, None, **lk_params)
                    for p_i, p_f in zip(p0.reshape(-1, 2), p1.reshape(-1, 2)):
                        result = cross(ROI, ROI_W, ROI_H, p_i, p_f)
                        if result is 1:
                            self.arrivals += 1
                            if not self.quiet:
                                print("Arrival")
                        elif result is -1:
                            self.departures += 1
                            if not self.quiet:
                                print("Departure")

                        if self.drawTracks:
                            drawing.draw_line(frame, tuple(p_i), tuple(p_f))

            prev_gray = frame_gray
            contours, hier = drawing.draw_contours(frame, fg_mask)

            areas, prev_points = drawing.draw_min_ellipse(
                contours, frame, MIN_AREA, MAX_AREA)
            self.areas += areas

            self.frame_idx += 1
            if not self.invisible:
                self.draw_overlays(frame, fg_mask)
                cv2.imshow("Fas", frame_gray)
                cv2.imshow('Tracking', frame)
                cv2.imshow("Mask", fg_mask)
                delay = 33
            else:
                delay = 1
            if handle_keys(delay) == 1:
                break

            # Should we continue running or yield some information about the current frame
            if as_script: continue
            else: pass

        return self.areas