@@ -80,7 +80,6 @@ def find_good_pca(self, mark_size, in_height, in_rad_min, in_rad_max):
80
80
81
81
# Put the cylinders in here so we can sort them before storing
82
82
cyl_list_to_sort = []
83
- cyl = Cylinder ()
84
83
85
84
# Go through all the bins...
86
85
for b in self .my_pcd .bin_list .values ():
@@ -100,16 +99,16 @@ def find_good_pca(self, mark_size, in_height, in_rad_min, in_rad_max):
100
99
count_size_neighbor [1 ] += n_in_region
101
100
count_size_neighbor [2 ] = max (count_size_neighbor [0 ], n_in_region )
102
101
102
+ cyl = Cylinder ()
103
103
cyl .set_fit_pts (b [0 ], [reg [0 ] for reg in region ], self .my_pcd .pts ())
104
104
cyl .fit_pca ()
105
105
# Don't bother if the ratio is really, really off
106
106
if not (pca_clip_low < cyl .pca_ratio () < pca_clip_high ):
107
107
n_bad_bins = n_bad_bins + 1
108
108
continue
109
109
110
- cyl .fit_radius ()
111
-
112
110
# If height is not close to target means we have a blob of unconnected points
111
+ cyl .fit_radius ()
113
112
if not height_clip_low < cyl .height < height_clip_high :
114
113
n_bad_bins += 1
115
114
continue
@@ -130,8 +129,7 @@ def find_good_pca(self, mark_size, in_height, in_rad_min, in_rad_max):
130
129
pca_score [p_id ].score = score
131
130
b_use = True
132
131
if b_use :
133
- cyl_save = copy (cyl )
134
- cyl_list_to_sort .append ((cyl_save , score ))
132
+ cyl_list_to_sort .append ((cyl , score ))
135
133
136
134
count_bad = 0 # Number of points not in any cylinder
137
135
self .pt_score = []
@@ -151,20 +149,20 @@ def find_good_pca(self, mark_size, in_height, in_rad_min, in_rad_max):
151
149
print ("Tried {0} bins, {1} bad bins, {2} not covered, skipped {3} total {4}" .format (n_bins_tried , n_bad_bins , count_bad , n_skipped , len (cyl_list_to_sort )))
152
150
return len (cyl_list_to_sort )
153
151
154
- def optimize_cyl (self , mark_size = 0.9 , err_max = 0.4 ):
152
+ def optimize_cyl (self , mark_size = 0.9 ):
155
153
"""
156
154
Optimize the cylinders from the find_good_pca; eliminate bad ones
157
155
:param mark_size: Size of region to mark off of covered
158
156
:param err_max: Maximum error from err_fit in Cylinder allowed
159
157
:return:
160
158
"""
161
- covered = [False for i in range (0 , len ( self .my_pcd .pc_data ))]
159
+ covered = [False for i in range (0 , self .my_pcd .n_pts ( ))]
162
160
163
161
clip = mark_size * self .height
164
162
165
163
# Already sorted - just do optimize fit
166
164
for i , cyl in enumerate (self .cyls_pca ):
167
- if covered [cyl .id ]:
165
+ if covered [cyl .id () ]:
168
166
continue
169
167
170
168
cyl .optimize_ang (self .radius_min , self .radius_max )
@@ -182,8 +180,8 @@ def optimize_cyl(self, mark_size=0.9, err_max=0.4):
182
180
cyl_keep = copy (cyl )
183
181
self .cyls_fitted .append (cyl_keep )
184
182
185
- for p_id in cyl .pts_ids :
186
- dist = MyPointCloud .dist (cyl .pt_center , self .my_pcd .pc_data [ p_id ] )
183
+ for p_id in cyl .data . pts_ids :
184
+ dist = MyPointCloud .dist (cyl .pt_center () , self .my_pcd .pt ( p_id ) )
187
185
if dist < clip :
188
186
self .pt_score [p_id ] = cyl .err
189
187
covered [p_id ] = True
@@ -192,7 +190,7 @@ def optimize_cyl(self, mark_size=0.9, err_max=0.4):
192
190
193
191
def read (self , fid ):
194
192
self .check_header (fid )
195
- member_name , n_read , _ = self .read_class_members (fid , ["cyls_pca" , "cyls_fitted" , "my_pcd" ])
193
+ member_name , n_found = self .read_class_members (fid , ["cyls_pca" , "cyls_fitted" , "my_pcd" ])
196
194
pts = None
197
195
try :
198
196
with open (self .my_pcd_file_name , "r" ) as fid_pcd :
@@ -205,7 +203,7 @@ def read(self, fid):
205
203
raise ValueError ("Should be cyls_pca, was {0}" .format (member_name ))
206
204
207
205
self .cyls_pca = []
208
- for _ in range (0 , n_read ):
206
+ for _ in range (0 , n_found ):
209
207
self .cyls_pca .append (Cylinder ())
210
208
self .cyls_pca [- 1 ].read (fid , all_pts = pts )
211
209
@@ -237,11 +235,11 @@ def write(self, fid):
237
235
238
236
239
237
def test_cylinder_cover_rw ():
240
- with open ("data/cyl_cover.txt" , 'w' ) as f :
241
- my_cyl_cov .write (f )
238
+ with open ("data/cyl_cover.txt" , 'w' ) as fid :
239
+ my_cyl_cov .write (fid )
242
240
243
- with open ("data/cyl_cover.txt" , 'r' ) as f :
244
- my_cyl_cov .read (f )
241
+ with open ("data/cyl_cover.txt" , 'r' ) as fid :
242
+ my_cyl_cov .read (fid )
245
243
246
244
247
245
if __name__ == '__main__' :
@@ -263,21 +261,21 @@ def test_cylinder_cover_rw():
263
261
rad_min = width_small_branch / 2.0
264
262
rad_max = width_large_branch / 2.0
265
263
266
- b_read = False
264
+ b_read = True
267
265
if b_read :
268
266
with open ("data/cyl_cover_pca.txt" , 'r' ) as f :
269
267
my_cyl_cov .read (f )
270
268
271
- my_cyl_cov .optimize_cyl (mark_size = 0.9 , err_max = 0.4 )
269
+ my_cyl_cov .optimize_cyl (mark_size = 0.9 )
272
270
with open ("data/cyl_cover_all.txt" , 'w' ) as f :
273
271
my_cyl_cov .write (f )
274
272
else :
275
- my_cyl_cov .find_good_pca (mark_size = 0.75 , in_height = height_cyl , in_rad_min = rad_min , in_rad_max = rad_max )
273
+ my_cyl_cov .find_good_pca (mark_size = 0.5 , in_height = height_cyl , in_rad_min = rad_min , in_rad_max = rad_max )
276
274
277
275
with open ("data/cyl_cover_pca.txt" , 'w' ) as f :
278
276
my_cyl_cov .write (f )
279
277
280
- my_cyl_cov .optimize_cyl (mark_size = 0.9 , err_max = 0.4 )
278
+ my_cyl_cov .optimize_cyl (mark_size = 0.9 )
281
279
with open ("data/cyl_cover_all.txt" , 'w' ) as f :
282
280
my_cyl_cov .write (f )
283
281
0 commit comments