Skip to content

Commit 6336525

Browse files
authored
Merge pull request #39 from zasexton/main
improving automated 3d mesh generation
2 parents 119e485 + af0fae2 commit 6336525

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

svv/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
__version__ = "0.0.35"
1+
__version__ = "0.0.36"
2+
23

34
# If the optional companion package with compiled accelerators is installed
45
# (svv-accelerated), prefer those modules transparently by aliasing them into

svv/simulation/simulation.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ def build_meshes(self, fluid=True, tissue=False, hausd=0.0001, hsize=None, minra
9292
extension_scale += 1.0
9393
root_extension = self.synthetic_object.data[0, 21] * extension_scale
9494
self.synthetic_object.data[0, 0:3] += root_extension * self.synthetic_object.data.get('w_basis', 0)
95+
print("Unioning water-tight model")
9596
fluid_surface_mesh = self.synthetic_object.export_solid(watertight=True)
97+
print("Finished Unioning water-tight model")
98+
print("Tetrahedralizing")
9699
tet_fluid = tetgen.TetGen(fluid_surface_mesh)
97100
try:
98101
tet_fluid.make_manifold(verbose=True)
@@ -182,7 +185,11 @@ def build_meshes(self, fluid=True, tissue=False, hausd=0.0001, hsize=None, minra
182185
else:
183186
fluid_surface_boolean_mesh = deepcopy(self.fluid_domain_wall_layers[-1])
184187
hsize = fluid_surface_boolean_mesh.cell_data["hsize"][0]
185-
tissue_domain = remesh_surface(self.synthetic_object.domain.boundary, hausd=hausd) # Check if this should be remeshed
188+
try:
189+
tissue_domain = remesh_surface(self.synthetic_object.domain.boundary, hausd=hausd) # Check if this should be remeshed
190+
except:
191+
print("REMESHING FAILS: CHECKING FOR TRIANGLE INTERSECTIONS")
192+
tmp_boundary = pymeshfix.MeshFix(self.synthetic_object.domain.boundary)
186193
area = tissue_domain.area
187194
tissue_domain = boolean(tissue_domain, fluid_surface_boolean_mesh, operation='difference')
188195
if fluid:

svv/tree/branch/bifurcation.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def add_vessel(tree, **kwargs):
9191
nonconvex_sampling = kwargs.pop('nonconvex_sampling', 10)
9292
homogeneous = kwargs.pop('homogeneous', True)
9393
use_brute = kwargs.pop('use_brute', False)
94-
max_iter = kwargs.pop('max_iter', 10)
94+
max_iter = kwargs.pop('max_iter', 100)
9595
return_cost = kwargs.pop('return_cost', False)
9696
#defualt_threshold = ((tree.domain.mesh.volume ** (1/3)) /
9797
# (tree.n_terminals ** threshold_exponent)) + tree.data[0, 21]*2.0
@@ -218,8 +218,8 @@ def callback(xk):
218218
#plt.colorbar(label='Function values')
219219
#plt.show()
220220
cons = [{"type": "ineq", "fun": lambda a: 1 - a[0] - a[1]}]
221-
result = minimize(cost, x0, bounds=[(0, 1.0), (0, 1.0)], callback=callback,
222-
options={'maxiter':max_iter})
221+
result = minimize(cost, x0, bounds=[(0.05, 0.95), (0.05, 0.95)], callback=callback,
222+
options={'maxiter':max_iter},constraints=cons, method="COBYLA")
223223
#print('SOLUTION: {}'.format(result.x))
224224
#print('SOLUTION FUN: {}'.format(result.fun))
225225
bifurcation_point = triad(result.x)
@@ -1901,10 +1901,10 @@ def cost(x, func=tree_cost_2, d_min=d_min, terminal=terminal,
19011901
scale=tree_scale,connectivity=tree.connectivity):
19021902
x = triad(x)
19031903
#dists = close_exact_point(lines, x)
1904-
#dists = numpy.array([numpy.linalg.norm(lines[0, 0:3] - x),
1905-
# numpy.linalg.norm(lines[0, 3:6] - x),
1906-
# numpy.linalg.norm(lines[1, 3:6] - x)])
1907-
#triad_penalty = numpy.max([0.0, -1.0 * numpy.min(dists - d_min)])/d_min * penalty
1904+
dists = numpy.array([numpy.linalg.norm(lines[0, 0:3] - x),
1905+
numpy.linalg.norm(lines[0, 3:6] - x),
1906+
numpy.linalg.norm(lines[1, 3:6] - x)])
1907+
triad_penalty = numpy.max([0.0, -1.0 * numpy.min(dists - d_min)])/d_min * penalty
19081908
#[TODO] angle penalty
19091909
#[TODO] require that resulting parent vessel is at least a certain length? remove buffer region around triad
19101910
# points
@@ -1924,7 +1924,7 @@ def cost(x, func=tree_cost_2, d_min=d_min, terminal=terminal,
19241924
#assert results > tree_scale, '{} results < {} tree_scale'.format(results, tree_scale)
19251925
#return (((np.clip(numpy.nan_to_num(results - scale, nan=2*scale+penalty), 0, 2*scale+penalty) + triad_penalty))/(scale+penalty))# + 1.0
19261926
#return -1/np.clip(numpy.nan_to_num(results - scale, nan=2*scale+penalty), 0, 2*scale+penalty)
1927-
return -1 / np.clip(numpy.nan_to_num(results, nan=2 * scale + penalty), 0, 2 * scale + penalty)
1927+
return -1 / np.clip(numpy.nan_to_num(results + triad_penalty, nan=2 * scale + penalty), 0, 2 * scale + penalty)
19281928
#return results
19291929
#return results
19301930
#return value

0 commit comments

Comments
 (0)