diff --git a/amworkflow/src/geometries/composite_geometry.py b/amworkflow/src/geometries/composite_geometry.py index 787ab11..e0b4ebc 100644 --- a/amworkflow/src/geometries/composite_geometry.py +++ b/amworkflow/src/geometries/composite_geometry.py @@ -837,7 +837,6 @@ def visualize(self, plot_type: str) -> None: class CreateWallByPointsUpdate(): def __init__(self, coords: list, th: float, height: float): - # self.coords = [np.array(list(i.Coord())) if isinstance(i, gp_Pnt) else np.array(i) for i in coords] self.coords = Pnt(coords).coords self.height = height self.R = None @@ -853,8 +852,10 @@ def __init__(self, coords: list, th: float, height: float): self.create_sides() self.pnts = Segments(self.side_coords) self.G = nx.from_dict_of_lists(self.pnts.pts_digraph, create_using=nx.DiGraph) - self.all_loops = list(nx.simple_cycles(self.G)) - self.loops = self.get_loops() + # self.all_loops = list(nx.simple_cycles(self.G)) + self.self_loops = nx.selfloop_edges(self.G) + # self.all_loops = list(nx.simple_cycles(self.H)) # Dangerous! Ran out of memory. + self.loop_generator = nx.simple_cycles(self.G) def create_sides(self): if self.R is not None: @@ -913,7 +914,7 @@ def create_sides(self): self.rgt_coords = self.rgt_coords[::-1] self.side_coords = self.lft_coords + self.rgt_coords + self.lft_coords[0] - def visualize(self): + def visualize(self, display_polygon: bool = True): # Extract the x and y coordinates and IDs a = self.pnts.pts_index x = [coord[0] for coord in a.values()] @@ -921,24 +922,34 @@ def visualize(self): ids = list(a.keys()) # Get the point IDs # Create a scatter plot in 2D - plt.figure() + plt.subplot(1,2,1) + # plt.figure() plt.scatter(x, y) # Annotate points with IDs for i, (xi, yi) in enumerate(zip(x, y)): plt.annotate(f'{ids[i]}', (xi, yi), fontsize=12, ha='right') - - for lp in self.loops: - coords = [self.pnts.pts_index[i] for i in lp] - x = [point[0] for point in coords] - y = [point[1] for point in coords] - plt.plot(x + [x[0]], y + [y[0]], linestyle='-', marker='o') + + if display_polygon: + for lp in self.loop_generator: + if len(lp) > 2: + coords = [self.pnts.pts_index[i] for i in lp] + x = [point[0] for point in coords] + y = [point[1] for point in coords] + plt.plot(x + [x[0]], y + [y[0]], linestyle='-', marker='o') # Set labels and title plt.xlabel('X-axis') plt.ylabel('Y-axis') - plt.title('2D Scatter Plot with Annotations') + plt.title('Points With Polygons detected') + plt.subplot(1,2,2) + # layout = nx.spring_layout(self.G) + layout = nx.circular_layout(self.G) + # Draw the nodes and edges + nx.draw(self.G, pos=layout, with_labels=True, node_color='skyblue', font_size=10, node_size=300) + plt.title("Multi-Digraph") + plt.tight_layout() # Show the plot plt.show() diff --git a/some_thoughts_20230822_new/try_new_thought/trail_3.py b/some_thoughts_20230822_new/try_new_thought/trail_3.py index bd80fb7..2c10c21 100644 --- a/some_thoughts_20230822_new/try_new_thought/trail_3.py +++ b/some_thoughts_20230822_new/try_new_thought/trail_3.py @@ -59,6 +59,6 @@ # plot_digraph(wall.pnts.pts_digraph) # wall.visualize() -print(wall.loops) -wall.visualize_graph() +# print(wall.loops) +# wall.visualize_graph() wall.visualize() \ No newline at end of file diff --git a/some_thoughts_20230822_new/try_new_thought/trail_4.py b/some_thoughts_20230822_new/try_new_thought/trail_4.py index 8aa4bce..b0df52c 100644 --- a/some_thoughts_20230822_new/try_new_thought/trail_4.py +++ b/some_thoughts_20230822_new/try_new_thought/trail_4.py @@ -19,5 +19,5 @@ g = aw.geom wall = CreateWallByPointsUpdate(pmfo, 8, 12) # print(wall.loops) -wall.visualize_graph() -wall.visualize() +# wall.visualize_graph() +wall.visualize(display_polygon=False) diff --git a/some_thoughts_20230822_new/try_new_thought/trail_5.py b/some_thoughts_20230822_new/try_new_thought/trail_5.py index a1d4280..6031d97 100644 --- a/some_thoughts_20230822_new/try_new_thought/trail_5.py +++ b/some_thoughts_20230822_new/try_new_thought/trail_5.py @@ -5,5 +5,5 @@ points = [[],[0,2],[2,4],[5,4],[8,4],[8,6],[3,6],[3,1]] wall = CreateWallByPointsUpdate(points,1,2) print(wall.loops) -wall.visualize_graph() +# wall.visualize_graph() wall.visualize() \ No newline at end of file