@@ -547,7 +547,7 @@ def laplacian2_fixed_point(vertices, entities):
547
547
return vertices_new , entities
548
548
549
549
550
- def laplacian2 (vertices , entities , max_iter = 20 , tol = 0.01 , verbose = 1 ):
550
+ def laplacian2 (vertices , entities , max_iter = 20 , tol = 0.01 , verbose = 1 , pfix = None ):
551
551
"""Move vertices to the average position of their connected neighbors
552
552
with the goal to hopefully improve geometric entity quality.
553
553
@@ -559,6 +559,10 @@ def laplacian2(vertices, entities, max_iter=20, tol=0.01, verbose=1):
559
559
:type max_iter: `int`, optional
560
560
:param tol: iterations will cease when movement < tol
561
561
:type tol: `float`, optional
562
+ :param verbose: display progress to the screen
563
+ :type verbose: `float`, optional
564
+ :param pfix: coordinates that you don't wish to move
565
+ :type pfix: array-like
562
566
563
567
:return vertices: updated vertices of mesh
564
568
:rtype: numpy.ndarray[`float` x dim]
@@ -568,6 +572,12 @@ def laplacian2(vertices, entities, max_iter=20, tol=0.01, verbose=1):
568
572
if vertices .ndim != 2 :
569
573
raise NotImplementedError ("Laplacian smoothing only works in 2D for now" )
570
574
575
+ def _closest_node (node , nodes ):
576
+ nodes = np .asarray (nodes )
577
+ deltas = nodes - node
578
+ dist_2 = np .einsum ("ij,ij->i" , deltas , deltas )
579
+ return np .argmin (dist_2 )
580
+
571
581
eps = np .finfo (float ).eps
572
582
573
583
n = len (vertices )
@@ -580,6 +590,13 @@ def laplacian2(vertices, entities, max_iter=20, tol=0.01, verbose=1):
580
590
)
581
591
bnd = get_boundary_vertices (entities )
582
592
edge = get_edges (entities )
593
+ if pfix is not None :
594
+ ifix = []
595
+ for fix in pfix :
596
+ ifix .append (_closest_node (fix , vertices ))
597
+ ifix = np .asarray (ifix )
598
+ bnd = np .concatenate ((bnd , ifix ))
599
+
583
600
W = np .sum (S , 1 )
584
601
if np .any (W == 0 ):
585
602
print ("Invalid mesh. Disjoint vertices found. Returning" , flush = True )
0 commit comments