Exemple #1
0
 def attach(self, neighbor):
     if isinstance(neighbor, Dense):
         draw.line(*self.top_right, *neighbor.top_left, stroke="gray")
         draw.line(*self.bot_right, *neighbor.bot_left, stroke="gray")
     if isinstance(neighbor, Conv):
         x, y = self.bot_left
         draw.rect(x + 4, y - 12, 8, 8, stroke="gray")
         draw.line(x + 4, y - 12, *neighbor.center, stroke="gray")
         draw.line(x + 12, y - 4, *neighbor.center, stroke="gray")
Exemple #2
0
 def attach(self, neighbor):
     if neighbor.top_left is not None and neighbor.bot_left is not None:
         draw.line(*self.top_right, *neighbor.top_left, stroke="gray")
         draw.line(*self.bot_right, *neighbor.bot_left, stroke="gray")
Exemple #3
0
 def attach(self, neighbor):
     if isinstance(neighbor, Dense):
         if not self.simple and not neighbor.simple:
             # Connect every node with dots
             for cp in self.circle_positions:
                 for cp2 in neighbor.circle_positions:
                     draw.line(*cp, *cp2, stroke="gray")
             # Fill in white circles (lines should be behind)
             for cp in self.circle_positions:
                 draw.circle(*cp, 4, fill="white")
             for cp in neighbor.circle_positions:
                 draw.circle(*cp, 4, fill="white")
         else:
             draw.line(*self.top_right, *neighbor.top_left, stroke="gray")
             draw.line(*self.bot_right, *neighbor.bot_left, stroke="gray")
     if isinstance(neighbor, Image):
         if not self.simple:
             # Connect every node with dots
             for cp in self.circle_positions:
                 draw.line(*cp, *neighbor.top_left, stroke="gray")
                 draw.line(*cp, *neighbor.top_right, stroke="gray")
             # Fill in white circles (lines should be behind)
             for cp in self.circle_positions:
                 draw.circle(*cp, 4, fill="white")
         else:
             draw.line(*self.top_right, *neighbor.top_left, stroke="gray")
             draw.line(*self.bot_right, *neighbor.bot_left, stroke="gray")
     if isinstance(neighbor, Arrow):
         if not self.simple:
             # Connect every node with dots
             for cp in self.circle_positions:
                 draw.line(*cp, *neighbor.left, stroke="gray")
             # Fill in white circles (lines should be behind)
             for cp in self.circle_positions:
                 draw.circle(*cp, 4, fill="white")
         else:
             draw.line(*self.top_right, *neighbor.left, stroke="gray")
             draw.line(*self.bot_right, *neighbor.left, stroke="gray")
     if isinstance(neighbor, Conv):
         draw.line(*self.top_right, *neighbor.top_left, stroke="gray")
         draw.line(*self.bot_right, *neighbor.bot_left, stroke="gray")
Exemple #4
0
    def _draw(self, debug=False):

        self._width = 0
        self._height = 0
        GRAPH_POSITIONS = [[(0, 0, 0, 0) for _ in range(10)]
                           for _ in range(10)]

        for y in range(10):
            self._step_draw_position = 0
            for x in range(10):
                graph = self._graphs[x][y]
                # Draw at correct position
                if graph is None:
                    continue

                draw.begin(self._figure)
                gw = graph._draw(debug)

                # Calculate translation
                x_translate = self._PADDING + self._H_SPACING * x
                x_translate += self._step_draw_position
                y_translate = (draw.height() +
                               self._V_SPACING) * y + self._PADDING / 2

                if self.title is not None:
                    y_translate += 30
                if self.author is not None:
                    y_translate += 10

                # Add to group and translate in figure
                group = self._figure.g()
                draw.add_all(group)
                group.translate(x_translate, y_translate)
                self._figure.add(group)

                GRAPH_POSITIONS[x][y] = (x_translate, y_translate, gw)

                self._step_draw_position += gw

                self._width = max(self._width,
                                  self._step_draw_position + self._PADDING)
                self._height = max(self._height,
                                   y_translate + draw.height() + self._PADDING)

        self._width += self._PADDING / 4

        # Draw connections
        draw.begin(self._figure)
        for con in self._connections:

            x, y, x2, y2, position, offset = con

            from_x, from_y, from_w = GRAPH_POSITIONS[x][y]
            to_x, to_y, to_w = GRAPH_POSITIONS[x2][y2]

            from_x += from_w - 16
            from_y += draw.height() / 2
            to_y += draw.height() / 2

            # First out
            draw.line(from_x - 16, from_y, from_x + 12, from_y, stroke="gray")
            # Arrowhead
            draw.line(to_x - 6, to_y - 5, to_x - 1, to_y, stroke="gray")
            draw.line(to_x - 6, to_y + 5, to_x - 1, to_y, stroke="gray")

            if y < y2:
                mid = to_y - draw.height() / 2 - self._V_SPACING / 2
            else:
                mid = to_y + draw.height() / 2 + self._V_SPACING / 2

            if position is not None:
                mid = (draw.height() + self._V_SPACING
                       ) * position + self._PADDING / 2 - self._V_SPACING / 2
                if self.title is not None:
                    mid += 30
                if self.author is not None:
                    mid += 10
            if offset is not None:
                mid += offset

            draw.line(from_x + 12, from_y, from_x + 12, mid, stroke="gray")
            draw.line(from_x + 12, mid, to_x - 16, mid, stroke="gray")
            draw.line(to_x - 16, mid, to_x - 16, to_y, stroke="gray")
            draw.line(to_x - 16, to_y, to_x - 1, to_y, stroke="gray")

        draw.add_all(self._figure)