Skip to content

Commit 3d2ee56

Browse files
committed
Add documentation for triangular actions
1 parent 8f7c865 commit 3d2ee56

File tree

8 files changed

+311
-67
lines changed

8 files changed

+311
-67
lines changed

environment/actions/triangular_actions.py

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import copy
4-
4+
import numpy as np
55
from mesh_model.mesh_analysis.global_mesh_analysis import NodeAnalysis
66
from mesh_model.mesh_analysis.trimesh_analysis import TriMeshQualityAnalysis
77
from mesh_model.mesh_struct.mesh_elements import Node, Dart
@@ -168,20 +168,15 @@ def collapse_edge(mesh_analysis, n1: Node, n2: Node) -> True:
168168

169169
d2, d1, d11, d21, d211, n1, n2, n3, n4 = mesh.active_triangles(d)
170170

171-
d212 = d21.get_beta(2) #T1
172-
d2112 = d211.get_beta(2) #T2
173-
d12 = d1.get_beta(2) #T3
171+
d212 = d21.get_beta(2) # T1
172+
d2112 = d211.get_beta(2) # T2
173+
d12 = d1.get_beta(2) # T3
174174
if not mesh.is_dart_active(d12):
175175
print("error")
176-
d112 = d11.get_beta(2) #T4
177-
178-
#Delete the darts around selected dart
176+
d112 = d11.get_beta(2) # T4
177+
# Delete the darts around selected dart
179178
mesh_analysis.mesh.del_adj_triangles(d)
180179

181-
#Move n1 node in the middle of [n1, n2]
182-
n1.set_xy((n1.x() + n2.x()) / 2, (n1.y() + n2.y()) / 2)
183-
i = 0
184-
185180
#Check if nodes n3 and n4 are not linked to deleted dart
186181

187182
if n3.get_dart().id == d11.id:
@@ -212,6 +207,11 @@ def collapse_edge(mesh_analysis, n1: Node, n2: Node) -> True:
212207
d2112.set_beta(2, d212)
213208

214209
n2_score = n2.get_score()
210+
n2x = n2.x()
211+
n2y =n2.y()
212+
mid = np.array([(n1.x() + n2x) / 2, (n1.y() + n2y) / 2])
213+
near_n1 = np.array([(n1.x() * 0.9 + n2x * 0.1), (n1.y() * 0.9 + n2y * 0.1)])
214+
near_n2 = np.array([(n1.x() * 0.1 + n2x * 0.9), (n1.y() * 0.1 + n2y * 0.9)])
215215
#delete n2 node
216216
mesh_analysis.mesh.del_node(n2)
217217

@@ -223,7 +223,8 @@ def collapse_edge(mesh_analysis, n1: Node, n2: Node) -> True:
223223
# d12.set_quality(mesh_analysis.get_dart_geometric_quality(d12))
224224
# d212.set_quality(mesh_analysis.get_dart_geometric_quality(d212, mesh_before))
225225

226-
# Update node relations and dart quality of old n2 side
226+
# Update node relations
227+
i = 0
227228
if mesh.is_dart_active(d12):
228229
d121 = d12.get_beta(1)
229230
d121.set_node(n1)
@@ -253,6 +254,20 @@ def collapse_edge(mesh_analysis, n1: Node, n2: Node) -> True:
253254
plot_mesh(mesh_analysis.mesh)
254255
raise ValueError("Potential infinite loop in action collapse")
255256

257+
258+
if mesh_analysis.is_star_vertex(n1, mid):
259+
n1.set_xy(mid[0], mid[1])
260+
elif mesh_analysis.is_star_vertex(n1, near_n1):
261+
n1.set_xy(near_n1[0], near_n1[1])
262+
elif mesh_analysis.is_star_vertex(n1, near_n2):
263+
n1.set_xy(near_n2[0], near_n2[1])
264+
elif mesh_analysis.is_star_vertex(n1, np.array([n1.x(), n1.y()])):
265+
pass
266+
elif mesh_analysis.is_star_vertex(n1, np.array([n2x, n2y])):
267+
n1.set_xy(n2x, n2y)
268+
else:
269+
raise ValueError("No star vertex found")
270+
256271
# Update dart quality
257272
n1_analysis = NodeAnalysis(n1)
258273
adj_darts = n1_analysis.adjacent_darts()
@@ -265,17 +280,18 @@ def collapse_edge(mesh_analysis, n1: Node, n2: Node) -> True:
265280
_d112 = _d11.get_beta(2)
266281
# if d2, d12 or d112 is None, dart quality is -1 and was not modified by collapse action
267282
if _d2 is not None and _d2.id not in d_updated:
268-
_d.set_quality(mesh_analysis.get_dart_geometric_quality(_d))
283+
_d.set_quality(mesh_analysis.get_dart_geometric_quality(_d, mesh_before))
269284
d_updated.append(_d.id)
270285
if _d12 is not None and _d12.id not in d_updated:
271-
_d1.set_quality(mesh_analysis.get_dart_geometric_quality(_d1))
286+
_d1.set_quality(mesh_analysis.get_dart_geometric_quality(_d1, mesh_before))
272287
d_updated.append(_d1.id)
273288
if _d112 is not None and _d112.id not in d_updated:
274289
_d11.set_quality(mesh_analysis.get_dart_geometric_quality(_d11))
275290
d_updated.append(_d11.id)
276291

277292
after_check = check_mesh(mesh_analysis, mesh_before)
278293
if not after_check:
294+
mesh_analysis.is_star_vertex(n1, np.array([n1.x(), n1.y()]), True)
279295
raise ValueError("Some checks are missing")
280296
return True, topo, geo
281297

@@ -320,10 +336,10 @@ def check_mesh(mesh_analysis, m=None) -> bool:
320336
plot_mesh(m)
321337
plot_mesh(mesh_analysis.mesh)
322338
return False
323-
if dart_info[5] == 6:
324-
plot_mesh(m)
325-
plot_mesh(mesh_analysis.mesh)
326-
return False
339+
#if dart_info[5] not in [-1,0,1,2]:
340+
#plot_mesh(m)
341+
#plot_mesh(mesh_analysis.mesh)
342+
#return False
327343
return True
328344

329345

environment/gymnasium_envs/trimesh_full_env/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
id="Trimesh-v0",
66
entry_point="environment.gymnasium_envs.trimesh_full_env.envs:TriMeshEnvFull",
77
max_episode_steps=100,
8-
kwargs={"mesh": None, "mesh_size": 7, "n_darts_selected": 20, "deep": 6, "with_quality_obs": False, "action_restriction": False},
8+
kwargs={"mesh": None, "mesh_size": 7, "n_darts_selected": 7, "deep": 6, "with_quality_obs": True, "action_restriction": False},
99
)

mesh_model/mesh_analysis/global_mesh_analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def cross_product(self, vect_AB, vect_AC):
298298
return val
299299

300300
def signe(self, a: int):
301-
if a <= 1e-5:
301+
if a <= 1e-8:
302302
return 0
303303
else:
304304
return 1

0 commit comments

Comments
 (0)