| Conditions | 4 |
| Total Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 1 |
| CRAP Score | 17.7179 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | #!/usr/bin/env python |
||
| 78 | 1 | def boundary_of_center_object(pc, |
|
| 79 | downsample=None, |
||
| 80 | angle_threshold=0.1, |
||
| 81 | search_radius=0.1, |
||
| 82 | normal_search_radius=0.1): |
||
| 83 | """ |
||
| 84 | Find the boundary of the main object. |
||
| 85 | First applies dbscan to find the main object, |
||
| 86 | then estimates its footprint by taking the pointcloud boundary. |
||
| 87 | Resulting pointcloud has the same SRS and offset as the input. |
||
| 88 | |||
| 89 | Arguments: |
||
| 90 | pointcloud : pcl.PointCloud |
||
| 91 | |||
| 92 | downsample : If given, reduce the pointcloud to given percentage |
||
| 93 | values should be in [0,1] |
||
| 94 | |||
| 95 | angle_threshold : float defaults to 0.1 |
||
| 96 | |||
| 97 | search_radius : float defaults to 0.1 |
||
| 98 | |||
| 99 | normal_search_radius : float defaults to 0.1 |
||
| 100 | |||
| 101 | Returns: |
||
| 102 | boundary : pcl.PointCloud |
||
| 103 | """ |
||
| 104 | |||
| 105 | if downsample is not None: |
||
| 106 | log(' - Random downsampling factor:', downsample) |
||
| 107 | pc = utils.downsample_random(pc, downsample) |
||
| 108 | else: |
||
| 109 | log(' - Not downsampling') |
||
| 110 | |||
| 111 | # Main noise supression step |
||
| 112 | # Find largest clusters, accounting for at least 70% of the pointcloud. |
||
| 113 | # Presumably, this is the main object. |
||
| 114 | log(' - Starting dbscan on downsampled pointcloud') |
||
| 115 | mainobject = get_largest_dbscan_clusters(pc, 0.7, .075, 250) |
||
| 116 | save(mainobject, 'mainobject.las') |
||
| 117 | |||
| 118 | boundary = estimate_boundaries(mainobject, |
||
| 119 | angle_threshold=angle_threshold, |
||
| 120 | search_radius=search_radius, |
||
| 121 | normal_search_radius=normal_search_radius) |
||
| 122 | |||
| 123 | boundary = extract_mask(mainobject, boundary) |
||
| 124 | |||
| 125 | if len(boundary) == len(mainobject) or len(boundary) == 0: |
||
| 126 | log(' - Cannot find boundary') |
||
| 127 | return None |
||
| 128 | |||
| 129 | # project on the xy plane, take 2th percentile height |
||
| 130 | points = np.asarray(boundary) |
||
| 131 | points[:, 2] = np.percentile(points[:, 2], 2) |
||
| 132 | |||
| 133 | # Secondary noise supression step |
||
| 134 | # some cases have multiple objects close to eachother, and we need to |
||
| 135 | # filter some out. Assume the object is a single item; perform another |
||
| 136 | # dbscan to select the footprint of the main item |
||
| 137 | log(' - Starting dbscan on boundary') |
||
| 138 | mainboundary = get_largest_dbscan_clusters(boundary, 0.5, .1, 10) |
||
| 139 | |||
| 140 | # Evenly space out the points |
||
| 141 | mainboundary = utils.downsample_voxel(mainboundary, voxel_size=0.1) |
||
| 142 | |||
| 143 | utils.force_srs(mainboundary, same_as=pc) |
||
| 144 | |||
| 145 | return mainboundary |
||
| 146 |