@@ -112,9 +112,7 @@ def hexa_to_quad(volumes):
112
112
raise ValueError ("Given volumes are not `hexa` volumes" )
113
113
114
114
fpe = 6 # faces per element
115
- faces = (
116
- np .ones (((volumes .shape [0 ] * fpe ), 4 ), dtype = settings .INT_DTYPE ) * - 1
117
- ) # -1 for safety check
115
+ faces = np .empty (((volumes .shape [0 ] * fpe ), 4 ), dtype = settings .INT_DTYPE )
118
116
119
117
faces [::fpe ] = volumes [:, [1 , 0 , 3 , 2 ]]
120
118
faces [1 ::fpe ] = volumes [:, [0 , 1 , 5 , 4 ]]
@@ -123,9 +121,6 @@ def hexa_to_quad(volumes):
123
121
faces [4 ::fpe ] = volumes [:, [3 , 0 , 4 , 7 ]]
124
122
faces [5 ::fpe ] = volumes [:, [4 , 5 , 6 , 7 ]]
125
123
126
- if (faces == - 1 ).any ():
127
- raise ValueError ("Something went wrong while computing faces" )
128
-
129
124
return faces
130
125
131
126
@@ -188,9 +183,8 @@ def faces_to_edges(faces):
188
183
vertices_per_face = faces .shape [1 ]
189
184
190
185
num_edges = int (num_faces * vertices_per_face )
191
- edges = (
192
- np .ones ((num_edges , 2 ), dtype = settings .INT_DTYPE ) * - 1
193
- ) # -1 for safety
186
+ edges = np .empty ((num_edges , 2 ), dtype = settings .INT_DTYPE )
187
+
194
188
edges [:, 0 ] = faces .ravel ()
195
189
196
190
for i in range (vertices_per_face ):
@@ -199,10 +193,6 @@ def faces_to_edges(faces):
199
193
200
194
edges [i ::vertices_per_face , 1 ] = faces [:, v_ind ]
201
195
202
- # Quick sanity check - No entries are left untouched.
203
- if (edges == - 1 ).any ():
204
- raise ValueError ("There was an error while computing edges." )
205
-
206
196
return edges
207
197
208
198
@@ -296,16 +286,13 @@ def make_quad_faces(resolutions):
296
286
except ValueError as e :
297
287
raise ValueError (f"Problem with generating node indices. { e } " )
298
288
299
- faces = np .ones ((total_faces , 4 ), dtype = settings .INT_DTYPE ) * - 1
289
+ faces = np .empty ((total_faces , 4 ), dtype = settings .INT_DTYPE )
300
290
301
291
faces [:, 0 ] = node_indices [: (nnpd [1 ] - 1 ), : (nnpd [0 ] - 1 )].ravel ()
302
292
faces [:, 1 ] = node_indices [: (nnpd [1 ] - 1 ), 1 : nnpd [0 ]].ravel ()
303
293
faces [:, 2 ] = node_indices [1 : nnpd [1 ], 1 : nnpd [0 ]].ravel ()
304
294
faces [:, 3 ] = node_indices [1 : nnpd [1 ], : (nnpd [0 ] - 1 )].ravel ()
305
295
306
- if faces .all () == - 1 :
307
- raise ValueError ("Something went wrong during `make_quad_faces`." )
308
-
309
296
return faces
310
297
311
298
@@ -343,7 +330,7 @@ def make_hexa_volumes(resolutions):
343
330
nnpd [::- 1 ]
344
331
)
345
332
346
- volumes = np .ones ((total_volumes , 8 ), dtype = settings .INT_DTYPE ) * int ( - 1 )
333
+ volumes = np .empty ((total_volumes , 8 ), dtype = settings .INT_DTYPE )
347
334
348
335
volumes [:, 0 ] = node_indices [
349
336
: (nnpd [2 ] - 1 ), : (nnpd [1 ] - 1 ), : (nnpd [0 ] - 1 )
@@ -368,9 +355,6 @@ def make_hexa_volumes(resolutions):
368
355
1 : nnpd [2 ], 1 : nnpd [1 ], : (nnpd [0 ] - 1 )
369
356
].ravel ()
370
357
371
- if (volumes == - 1 ).any ():
372
- raise ValueError ("Something went wrong during `make_hexa_volumes`." )
373
-
374
358
return volumes
375
359
376
360
@@ -407,10 +391,7 @@ def subdivide_edges(edges):
407
391
raise NotImplementedError
408
392
409
393
410
- def subdivide_tri (
411
- mesh ,
412
- return_dict = False ,
413
- ):
394
+ def subdivide_tri (mesh , return_dict = False ):
414
395
"""Subdivide triangles. Each triangle is divided into 4 meshes.
415
396
416
397
``Subdivided Faces``
@@ -581,7 +562,7 @@ def sorted_unique(connectivity, sorted_=False):
581
562
)
582
563
583
564
584
- def edges_to_polygons (outline_edges , return_edges = False , max_polygons = 100 ):
565
+ def edges_to_polygons (outline_edges , return_edges = False ):
585
566
"""
586
567
Organize outline edges, so that it describes a polygon.
587
568
Edges are expected to be extracted using `gus.Mesh.edges`, from
@@ -593,10 +574,6 @@ def edges_to_polygons(outline_edges, return_edges=False, max_polygons=100):
593
574
outline_edges: (n, 2) list-like
594
575
return_edges: bool
595
576
(Optional) Default is False. If set True, returns polygon as edges.
596
- max_polygons: int
597
- (Optional) Default is 100. Maximum expected polygons.
598
- Used as an exit criterium during polygon search.
599
-
600
577
601
578
Returns
602
579
--------
@@ -608,19 +585,19 @@ def edges_to_polygons(outline_edges, return_edges=False, max_polygons=100):
608
585
>>> m = gus.load_mesh("path_to_mesh_2d.stl")
609
586
>>> polygon_edges = edges_to_polygon(m.edges()[m.single_edges()])
610
587
"""
588
+ # we want to have an np array
589
+ outline_edges = np .asanyarray (outline_edges )
590
+
611
591
# Build a lookup_array
612
592
lookup_array = np .empty (outline_edges .max () + 1 , dtype = settings .INT_DTYPE )
613
593
lookup_array [outline_edges [:, 0 ]] = outline_edges [:, 1 ]
614
- # create some status variables
615
- watch_dog_max = abs (int (max_polygons ))
616
- watch_dog = 0
617
594
618
595
# select starting point - lowest index
619
596
starting_point = int (outline_edges .min ())
620
597
# initialize a set to keep track of processes vertices
621
598
next_candidates = set (outline_edges [:, 0 ])
622
599
polygons = []
623
- while True :
600
+ for _ in range ( len ( outline_edges )) :
624
601
# Get polygon - start with first two points
625
602
polygon = [starting_point ]
626
603
polygon .append (lookup_array [polygon [- 1 ]])
@@ -638,25 +615,12 @@ def edges_to_polygons(outline_edges, return_edges=False, max_polygons=100):
638
615
639
616
# check if we counted all the edges
640
617
# if so, exit
641
- lens = [ len ( p ) for p in polygons ]
642
- if sum ( lens ) == len ( outline_edges ) :
618
+ next_candidates . difference_update ( polygons [ - 1 ])
619
+ if len ( next_candidates ) == 0 :
643
620
break
644
621
645
- else :
646
- # let's try to find the next starting point
647
- next_candidates .difference_update (polygons [- 1 ])
648
- # Assign new
649
- starting_point = min (next_candidates )
650
-
651
- watch_dog += 1
652
- # Hope there're no more than number of max polygons.
653
- if watch_dog >= watch_dog_max :
654
- log .warning (
655
- f"Stopping after given max number of polygons { watch_dog_max } ."
656
- " If you want to continue searching, please set "
657
- "`max_polygons` to a bigger number"
658
- )
659
- break
622
+ # let's try to find the next starting point
623
+ starting_point = min (next_candidates )
660
624
661
625
if not return_edges :
662
626
return polygons
0 commit comments