@@ -35,7 +35,7 @@ def order_points_in_loop(points):
35
35
36
36
return np .array (ordered_points )
37
37
38
- def get_slice_data (polydata ,param ,num_slices = True ):
38
+ def get_slice_data (inp_polydata ,param ,num_slices = True ):
39
39
"""
40
40
Obtains x,y pairs corresponding to a vtkCutter operation on input polydata
41
41
Params:
@@ -46,6 +46,9 @@ def get_slice_data(polydata,param,num_slices = True):
46
46
slices: list of numpy arrays corresponding to each polydata intersection
47
47
slice_actor_collection: vtkAssembly of slices for display
48
48
"""
49
+ #make sure that incoming polydata isn't connected to anything
50
+ polydata = vtk .vtkPolyData ()
51
+ polydata .DeepCopy (inp_polydata )
49
52
#suppress output from the vtk logger
50
53
vtk .vtkLogger .SetStderrVerbosity (vtk .vtkLogger .VERBOSITY_OFF )
51
54
@@ -62,6 +65,7 @@ def get_slice_data(polydata,param,num_slices = True):
62
65
63
66
slice_actor_collection = vtk .vtkAssembly ()
64
67
slices = []
68
+
65
69
for z in z_vals :
66
70
plane = vtk .vtkPlane ()
67
71
plane .SetNormal (0 , 0 , 1 )
@@ -72,13 +76,32 @@ def get_slice_data(polydata,param,num_slices = True):
72
76
cutter .SetInputData (polydata )
73
77
cutter .Update ()
74
78
75
- points = cutter .GetOutput ().GetPoints ()
79
+ #create loop extractor
80
+ loops_extract = vtk .vtkContourLoopExtraction ()
81
+ #make sure loops are closed
82
+ loops_extract .SetOutputModeToPolylines ()
83
+ #remove any duplicates etc.
84
+ loops_extract .CleanPointsOn ()
85
+ loops_extract .SetInputData (cutter .GetOutput ())
86
+ loops_extract .Update ()
76
87
77
- # Convert VTK points to numpy array
78
- if points :
79
- slice_points = v2n (points .GetData ())
80
- slices .append (slice_points )
88
+ #get output from loop extractor
89
+ output = loops_extract .GetOutput ()
90
+ loop_points = output .GetPoints ().GetData ()
91
+ loops = output .GetLines ().GetData ()
92
+ num_loops = output .GetLines ().GetNumberOfCells ()
81
93
94
+ #acquire discrete loops from loop extractor. index references the specific loop in each slice
95
+ index = 0
96
+ for i in range (num_loops ):
97
+ #poly_point_count is the number of points that comprise each loop
98
+ poly_point_count = np .asarray (loops )[index ]
99
+ #generate local index of points that comprise each loop
100
+ poly_point_ind = np .asarray (loops )[index + 1 :index + 1 + poly_point_count ]
101
+ #push to slices
102
+ slices .append (np .asarray (loop_points )[poly_point_ind ,:])
103
+ index += poly_point_count + 1
104
+
82
105
# Create a mapper and actor for visualization
83
106
cutter_mapper = vtk .vtkPolyDataMapper ()
84
107
cutter_mapper .SetInputConnection (cutter .GetOutputPort ())
@@ -88,6 +111,9 @@ def get_slice_data(polydata,param,num_slices = True):
88
111
actor .GetProperty ().SetLineWidth (2 )
89
112
actor .SetMapper (cutter_mapper )
90
113
slice_actor_collection .AddPart (actor )
114
+
115
+ #debug
116
+ # np.savetxt('new_outlines.csv', slices[0], delimiter=',')
91
117
92
118
return slices , slice_actor_collection
93
119
@@ -274,20 +300,20 @@ def get_intersections(outline, angular_offset, width, bead_offset = 0.5):
274
300
Intersections in all cases, the width of each pass or the number of passes depending on pass_param
275
301
"""
276
302
277
- zval = np .mean (outline [:,- 1 ])
278
- print ('get intersections' ,zval )
279
- # outline = outline[:,0:2]
303
+ trans_cent = np .eye (4 )
304
+ #move outline to centroid
305
+ trans_cent [0 :3 ,- 1 ] = - np .mean (outline , axis = 0 )
306
+ X = do_transform (outline ,trans_cent )
307
+ #and rotate by angular_offset
280
308
trans = np .eye (4 )
281
- #move outline to centroid and rotate by angular_offset
282
309
a = np .deg2rad (angular_offset ) #negative for counterclockwise
283
310
trans [0 :2 ,0 :2 ]= np .array ([[np .cos (a ),- np .sin (a )],[np .sin (a ),np .cos (a )]])
284
- trans [0 :3 ,- 1 ] = - np .mean (outline , axis = 0 )
285
- X = do_transform (outline ,trans )
286
-
311
+ X = do_transform (X ,trans )
312
+ zval = np .mean (X [:,- 1 ])
287
313
288
314
limits = get_limits (X ,0. )
289
315
290
- yrange = [limits [2 ]* 1. 2 ,limits [3 ]* 1. 2 ]
316
+ yrange = [limits [2 ]* 2 ,limits [3 ]* 2 ]
291
317
#break up on the basis of bead width
292
318
num_passes = int (np .floor ((limits [1 ]- (width * bead_offset ) - limits [0 ]+ (width * bead_offset ))/ (width * bead_offset )))
293
319
xrange = np .linspace (limits [0 ]+ (width * bead_offset ),limits [1 ]- (width * bead_offset ),num_passes )
@@ -305,8 +331,9 @@ def get_intersections(outline, angular_offset, width, bead_offset = 0.5):
305
331
#Needs to be 3D for transformation
306
332
intersections = np .asarray (intersections )
307
333
trans_intersections = do_transform (intersections ,np .linalg .inv (trans ))
334
+ trans_intersections = do_transform (trans_intersections ,np .linalg .inv (trans_cent ))
308
335
#return intersections , actual bead offset
309
- return np . column_stack (( trans_intersections [:, 0 : 2 ], np . ones ( len ( intersections )) * zval )) , (xrange [1 ]- xrange [0 ])/ width
336
+ return trans_intersections , (xrange [1 ]- xrange [0 ])/ width
310
337
311
338
def line_intersection (line1 , line2 ):
312
339
'''
@@ -381,7 +408,8 @@ def respace_equally(X,val):
381
408
Ynew = fy (sNew )
382
409
383
410
X_new = np .stack ((Xnew ,Ynew ),axis = - 1 )
384
- X_new = np .vstack ((X_new , X_new [0 ,:]))#make sure last point is the same as the first point
411
+ if not closed :
412
+ X_new = np .vstack ((X_new , X_new [0 ,:]))#make sure last point is the same as the first point
385
413
return X_new ,Perimeter ,nPts
386
414
387
415
def offset_poly (poly , offset ):
0 commit comments