Skip to content

Commit 6fc17f2

Browse files
committed
Fix some build issues
1 parent ede3eaa commit 6fc17f2

File tree

4 files changed

+88
-80
lines changed

4 files changed

+88
-80
lines changed

mesh_model/mesh_analysis/old_files/old_mesh_analysis.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from mesh_model.mesh_analysis.trimesh_analysis import TriMeshAnalysis
2+
from mesh_model.mesh_analysis.global_mesh_analysis import NodeAnalysis
23
from mesh_model.mesh_struct.mesh import Mesh
3-
from mesh_model.mesh_struct.mesh_elements import Dart
4+
from mesh_model.mesh_struct.mesh_elements import Dart, Face
45
from math import sqrt, degrees
56

67
FLIP = 0

mesh_model/mesh_analysis/quadmesh_analysis.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
import math
2+
13
import numpy as np
4+
import matplotlib.pyplot as plt
5+
from shapely.geometry import Polygon, Point, LineString
6+
from shapely import affinity
27

38
from mesh_model.mesh_struct.mesh_elements import Dart, Node, Face
49
from mesh_model.mesh_struct.mesh import Mesh
@@ -88,8 +93,7 @@ def get_dart_geometric_quality(self, d: Dart, m=None) -> int:
8893
np.linalg.norm(u3) < 1e-8 or
8994
np.linalg.norm(u4) < 1e-8 or
9095
np.linalg.norm(u5) < 1e-8):
91-
plot_mesh(self.mesh)
92-
#raise ValueError("near zero vector") # Quad invalid because one side is almost zero
96+
raise ValueError("near zero vector") # Quad invalid because one side is almost zero
9397

9498
# Calculate cross product at each node
9599
cp_A = self.cross_product(-1 * u3, u4)
@@ -285,8 +289,7 @@ def __init__(self, mesh: Mesh):
285289

286290
def isValidAction(self, dart_id: int, action: int) -> (bool, bool):
287291
"""
288-
Test if an action is valid. You can select the ype of action between {flip clockwise, flip counterclockwise, split, collapse, cleanup, all action, one action no matter wich one}. :param mesh:
289-
:param mesh: a mesh
292+
Test if an action is valid. You can select the ype of action between {flip clockwise, flip counterclockwise, split, collapse, cleanup, all action, one action no matter wich one}.
290293
:param dart_id: a dart on which to test the action
291294
:param action: an action type
292295
:return:

mesh_model/mesh_analysis/trimesh_analysis.py

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -398,80 +398,80 @@ def is_star_vertex2(self, n1:Node, n2:Node, v):
398398
return False
399399
return True
400400

401-
def find_star_vertex2(self, n1:Node, n2:Node) -> (float, float):
402-
adj_nodes = []
403-
nodes_coord = []
404-
for d_info in self.mesh.active_darts():
405-
if d_info[3] == n1.id or d_info[3] == n2.id:
406-
d2 = Dart(self.mesh, d_info[2])
407-
if d2 is not None:
408-
n = d2.get_node()
409-
adj_nodes.append(n)
410-
nodes_coord.append([n.x(), n.y()])
411-
else:
412-
raise ValueError("Collapse action may not be done near boundary")
413-
nodes_coord = np.array(nodes_coord)
414-
415-
# Ordonner les voisins autour de v
416-
vectors = nodes_coord - v
417-
angles = np.arctan2(vectors[:, 1], vectors[:, 0])
418-
order = np.argsort(angles)
419-
neighbors_ordered = nodes_coord[order]
420-
421-
hull = ConvexHull(nodes_coord)
422-
delaunay = Delaunay(nodes_coord)
423-
plt.plot(nodes_coord[:, 0], nodes_coord[:, 1], 'o')
424-
425-
for simplex in hull.simplices:
426-
plt.plot(nodes_coord[simplex, 0], nodes_coord[simplex, 1], 'k-')
427-
plt.plot(nodes_coord[hull.vertices, 0], nodes_coord[hull.vertices, 1], 'r--', lw=2)
428-
plt.plot(nodes_coord[hull.vertices[0], 0], nodes_coord[hull.vertices[0], 1], 'ro')
429-
plt.show()
430-
431-
_ = scipy.spatial.delaunay_plot_2d(delaunay)
432-
plt.show()
433-
434-
mid = np.array([(n1.x() + n2.x()) / 2, (n1.y() + n2.y()) / 2])
435-
is_star_vertex = delaunay.find_simplex(mid) >=0
436-
437-
# Calcul des angles des voisins autour de v
438-
vectors = nodes_coord - mid
439-
angles = np.arctan2(vectors[:, 1], vectors[:, 0])
440-
order = np.argsort(angles)
441-
neighbors_ordered = nodes_coord[order]
442-
443-
# Construire le polygone
444-
poly = Polygon(neighbors_ordered)
445-
446-
# Vérifier si v est à l'intérieur ou sur la frontière
447-
point_v = Point(mid)
448-
is_star = poly.contains(point_v) or poly.touches(point_v)
449-
450-
plt.figure(figsize=(6, 6))
451-
# Polygone
452-
x, y = poly.exterior.xy
453-
plt.fill(x, y, alpha=0.3, edgecolor='red', facecolor='lightcoral', label='Polygone formé par les voisins')
454-
455-
# Voisins
456-
plt.scatter(nodes_coord[:, 0], nodes_coord[:, 1], color='blue', zorder=5, label='Voisins')
457-
458-
# Sommet testé
459-
plt.scatter(mid[0], mid[1], color='green', s=100, zorder=5, label='Sommet testé')
460-
461-
plt.legend()
462-
plt.gca().set_aspect('equal')
463-
plt.title(f"Le sommet est-il étoilé ? {is_star}")
464-
plt.show()
465-
466-
if is_star:
467-
return mid
468-
elif poly.contains(Point(n1.x(), n1.y())) or poly.touches(Point(n1.x(), n1.y())):
469-
return n1.x(), n1.y()
470-
elif poly.contains(Point(n2.x(), n2.y())) or poly.touches(Point(n2.x(), n2.y())):
471-
return n2.x(), n2.y()
472-
else:
473-
plot_mesh(self.mesh)
474-
raise ValueError("No star vertex was found")
401+
# def find_star_vertex2(self, n1:Node, n2:Node) -> (float, float):
402+
# adj_nodes = []
403+
# nodes_coord = []
404+
# for d_info in self.mesh.active_darts():
405+
# if d_info[3] == n1.id or d_info[3] == n2.id:
406+
# d2 = Dart(self.mesh, d_info[2])
407+
# if d2 is not None:
408+
# n = d2.get_node()
409+
# adj_nodes.append(n)
410+
# nodes_coord.append([n.x(), n.y()])
411+
# else:
412+
# raise ValueError("Collapse action may not be done near boundary")
413+
# nodes_coord = np.array(nodes_coord)
414+
#
415+
# # Ordonner les voisins autour de v
416+
# vectors = nodes_coord - v
417+
# angles = np.arctan2(vectors[:, 1], vectors[:, 0])
418+
# order = np.argsort(angles)
419+
# neighbors_ordered = nodes_coord[order]
420+
#
421+
# hull = ConvexHull(nodes_coord)
422+
# delaunay = Delaunay(nodes_coord)
423+
# plt.plot(nodes_coord[:, 0], nodes_coord[:, 1], 'o')
424+
#
425+
# for simplex in hull.simplices:
426+
# plt.plot(nodes_coord[simplex, 0], nodes_coord[simplex, 1], 'k-')
427+
# plt.plot(nodes_coord[hull.vertices, 0], nodes_coord[hull.vertices, 1], 'r--', lw=2)
428+
# plt.plot(nodes_coord[hull.vertices[0], 0], nodes_coord[hull.vertices[0], 1], 'ro')
429+
# plt.show()
430+
#
431+
# _ = scipy.spatial.delaunay_plot_2d(delaunay)
432+
# plt.show()
433+
#
434+
# mid = np.array([(n1.x() + n2.x()) / 2, (n1.y() + n2.y()) / 2])
435+
# is_star_vertex = delaunay.find_simplex(mid) >=0
436+
#
437+
# # Calcul des angles des voisins autour de v
438+
# vectors = nodes_coord - mid
439+
# angles = np.arctan2(vectors[:, 1], vectors[:, 0])
440+
# order = np.argsort(angles)
441+
# neighbors_ordered = nodes_coord[order]
442+
#
443+
# # Construire le polygone
444+
# poly = Polygon(neighbors_ordered)
445+
#
446+
# # Vérifier si v est à l'intérieur ou sur la frontière
447+
# point_v = Point(mid)
448+
# is_star = poly.contains(point_v) or poly.touches(point_v)
449+
#
450+
# plt.figure(figsize=(6, 6))
451+
# # Polygone
452+
# x, y = poly.exterior.xy
453+
# plt.fill(x, y, alpha=0.3, edgecolor='red', facecolor='lightcoral', label='Polygone formé par les voisins')
454+
#
455+
# # Voisins
456+
# plt.scatter(nodes_coord[:, 0], nodes_coord[:, 1], color='blue', zorder=5, label='Voisins')
457+
#
458+
# # Sommet testé
459+
# plt.scatter(mid[0], mid[1], color='green', s=100, zorder=5, label='Sommet testé')
460+
#
461+
# plt.legend()
462+
# plt.gca().set_aspect('equal')
463+
# plt.title(f"Le sommet est-il étoilé ? {is_star}")
464+
# plt.show()
465+
#
466+
# if is_star:
467+
# return mid
468+
# elif poly.contains(Point(n1.x(), n1.y())) or poly.touches(Point(n1.x(), n1.y())):
469+
# return n1.x(), n1.y()
470+
# elif poly.contains(Point(n2.x(), n2.y())) or poly.touches(Point(n2.x(), n2.y())):
471+
# return n2.x(), n2.y()
472+
# else:
473+
# plot_mesh(self.mesh)
474+
# raise ValueError("No star vertex was found")
475475

476476

477477
def get_adjacent_faces(self, n: Node, d_from: Dart, d_to: Dart) -> list:

model_RL/evaluate_model.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
from tqdm import tqdm
55

6+
from environment.old_files.trimesh_env import TriMesh
7+
from mesh_model.mesh_analysis.trimesh_analysis import TriMeshOldAnalysis
68
from mesh_model.mesh_struct.mesh import Mesh
79

810

@@ -58,7 +60,9 @@ def isBetterPolicy(actual_best_policy, policy_to_test):
5860

5961

6062
def isBetterMesh(best_mesh, actual_mesh):
61-
if best_mesh is None or global_score(best_mesh)[1] > global_score(actual_mesh)[1]:
63+
ma1 = TriMeshOldAnalysis(best_mesh)
64+
ma2 = TriMeshOldAnalysis(actual_mesh)
65+
if best_mesh is None or ma1.global_score()[1] > ma2.global_score()[1]:
6266
return True
6367
else:
6468
return False

0 commit comments

Comments
 (0)