Skip to content

Commit

Permalink
update fix
Browse files Browse the repository at this point in the history
  • Loading branch information
YuXHe15 committed Sep 6, 2023
1 parent 2a5c782 commit daff73c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
35 changes: 23 additions & 12 deletions amworkflow/src/geometries/composite_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -913,32 +914,42 @@ 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()]
y = [coord[1] for coord in a.values()]
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()

Expand Down
4 changes: 2 additions & 2 deletions some_thoughts_20230822_new/try_new_thought/trail_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 2 additions & 2 deletions some_thoughts_20230822_new/try_new_thought/trail_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion some_thoughts_20230822_new/try_new_thought/trail_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit daff73c

Please sign in to comment.