Skip to content

Commit fefabda

Browse files
committed
Fix changes to members in cylinder/point cloud
1 parent 7dd3fa7 commit fefabda

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

CylinderCover.py

+18-20
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ def find_good_pca(self, mark_size, in_height, in_rad_min, in_rad_max):
8080

8181
# Put the cylinders in here so we can sort them before storing
8282
cyl_list_to_sort = []
83-
cyl = Cylinder()
8483

8584
# Go through all the bins...
8685
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):
10099
count_size_neighbor[1] += n_in_region
101100
count_size_neighbor[2] = max(count_size_neighbor[0], n_in_region)
102101

102+
cyl = Cylinder()
103103
cyl.set_fit_pts(b[0], [reg[0] for reg in region], self.my_pcd.pts())
104104
cyl.fit_pca()
105105
# Don't bother if the ratio is really, really off
106106
if not (pca_clip_low < cyl.pca_ratio() < pca_clip_high):
107107
n_bad_bins = n_bad_bins + 1
108108
continue
109109

110-
cyl.fit_radius()
111-
112110
# If height is not close to target means we have a blob of unconnected points
111+
cyl.fit_radius()
113112
if not height_clip_low < cyl.height < height_clip_high:
114113
n_bad_bins += 1
115114
continue
@@ -130,8 +129,7 @@ def find_good_pca(self, mark_size, in_height, in_rad_min, in_rad_max):
130129
pca_score[p_id].score = score
131130
b_use = True
132131
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))
135133

136134
count_bad = 0 # Number of points not in any cylinder
137135
self.pt_score = []
@@ -151,20 +149,20 @@ def find_good_pca(self, mark_size, in_height, in_rad_min, in_rad_max):
151149
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)))
152150
return len(cyl_list_to_sort)
153151

154-
def optimize_cyl(self, mark_size=0.9, err_max=0.4):
152+
def optimize_cyl(self, mark_size=0.9):
155153
"""
156154
Optimize the cylinders from the find_good_pca; eliminate bad ones
157155
:param mark_size: Size of region to mark off of covered
158156
:param err_max: Maximum error from err_fit in Cylinder allowed
159157
:return:
160158
"""
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())]
162160

163161
clip = mark_size * self.height
164162

165163
# Already sorted - just do optimize fit
166164
for i, cyl in enumerate(self.cyls_pca):
167-
if covered[cyl.id]:
165+
if covered[cyl.id()]:
168166
continue
169167

170168
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):
182180
cyl_keep = copy(cyl)
183181
self.cyls_fitted.append(cyl_keep)
184182

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))
187185
if dist < clip:
188186
self.pt_score[p_id] = cyl.err
189187
covered[p_id] = True
@@ -192,7 +190,7 @@ def optimize_cyl(self, mark_size=0.9, err_max=0.4):
192190

193191
def read(self, fid):
194192
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"])
196194
pts = None
197195
try:
198196
with open(self.my_pcd_file_name, "r") as fid_pcd:
@@ -205,7 +203,7 @@ def read(self, fid):
205203
raise ValueError("Should be cyls_pca, was {0}".format(member_name))
206204

207205
self.cyls_pca = []
208-
for _ in range(0, n_read):
206+
for _ in range(0, n_found):
209207
self.cyls_pca.append(Cylinder())
210208
self.cyls_pca[-1].read(fid, all_pts=pts)
211209

@@ -237,11 +235,11 @@ def write(self, fid):
237235

238236

239237
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)
242240

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)
245243

246244

247245
if __name__ == '__main__':
@@ -263,21 +261,21 @@ def test_cylinder_cover_rw():
263261
rad_min = width_small_branch / 2.0
264262
rad_max = width_large_branch / 2.0
265263

266-
b_read = False
264+
b_read = True
267265
if b_read:
268266
with open("data/cyl_cover_pca.txt", 'r') as f:
269267
my_cyl_cov.read(f)
270268

271-
my_cyl_cov.optimize_cyl(mark_size=0.9, err_max=0.4)
269+
my_cyl_cov.optimize_cyl(mark_size=0.9)
272270
with open("data/cyl_cover_all.txt", 'w') as f:
273271
my_cyl_cov.write(f)
274272
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)
276274

277275
with open("data/cyl_cover_pca.txt", 'w') as f:
278276
my_cyl_cov.write(f)
279277

280-
my_cyl_cov.optimize_cyl(mark_size=0.9, err_max=0.4)
278+
my_cyl_cov.optimize_cyl(mark_size=0.9)
281279
with open("data/cyl_cover_all.txt", 'w') as f:
282280
my_cyl_cov.write(f)
283281

0 commit comments

Comments
 (0)