├── LICENSE ├── estimate ├── groove.py └── io.py └── main.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Latona, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /estimate/groove.py: -------------------------------------------------------------------------------- 1 | 2 | import numpy as np 3 | 4 | 5 | def is_grooves(gradients): 6 | # is_planes = np.logical_and(np.radians( 7 | # 30) < gradients, gradients < np.radians(150)) 8 | # return np.logical_not(is_planes) 9 | # return np.logical_and(np.radians(60) < gradients , gradients < np.radians(120)) 10 | ret = np.logical_and(np.radians(60) < gradients, 11 | gradients < np.radians(120)) 12 | 13 | print("===============================") 14 | print(np.count_nonzero(ret)) 15 | print(np.count_nonzero(np.logical_not(ret))) 16 | print("===============================") 17 | return ret 18 | 19 | 20 | def estimate_groove_index(dset): 21 | gradient_averages = dset[:, -1] 22 | _is_grooves = is_grooves(gradient_averages) 23 | groove_candidates = np.where(_is_grooves) 24 | return groove_candidates[0] 25 | 26 | 27 | if __name__ == '__main__': 28 | 29 | ary = np.array([np.radians(0), np.radians(30), np.radians(31), 30 | np.radians(149), np.radians(150), np.radians(180)]) 31 | 32 | candinates = is_grooves(ary) 33 | print(candinates) 34 | 35 | ary = ary.reshape(1, 6) 36 | print(ary) 37 | idx = estimate_groove_index(ary) 38 | print(idx) 39 | -------------------------------------------------------------------------------- /estimate/io.py: -------------------------------------------------------------------------------- 1 | import h5py 2 | 3 | 4 | class Hdf5Io(): 5 | 6 | def read_point_cloud_dataset(self, filepath, group, dataset): 7 | 8 | with h5py.File(filepath, 'r') as f: 9 | group = f[group] 10 | dset = group[dataset] 11 | return dset[:] 12 | 13 | return [] 14 | # points = dset[:, 0:3] 15 | # normals = dset[:, 3:6] 16 | # radians = dset[:, 6] 17 | 18 | def write_point_cloud_dataset_with_gradient_average(self, filepath, 19 | npcd, timestamp, 20 | group, dataset): 21 | is_success = False 22 | with h5py.File(filepath, 'a') as fw: 23 | 24 | group = fw.create_group(f'/{group}') 25 | 26 | dset = group.create_dataset( 27 | name=dataset, 28 | data=npcd, 29 | ) 30 | 31 | dset.attrs['created_at'] = timestamp 32 | is_success = True 33 | 34 | return is_success 35 | 36 | 37 | if __name__ == '__main__': 38 | 39 | hdf5 = Hdf5Io() 40 | 41 | path = '/home/latona/comet/Data/calculate-vectors-gradients/file/output/20200616192455470.hdf5' 42 | dset = hdf5.read_point_cloud_dataset( 43 | path, 'point-cloud', 'calculate-vectors-gradients') 44 | 45 | print(dset) 46 | print(dset.shape) 47 | print(type(dset)) 48 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | import aion.common_library as common 5 | import cupoch as cph 6 | import numpy as np 7 | import open3d as o3d 8 | from StatusJsonPythonModule.StatusJsonRest import StatusJsonRest 9 | 10 | from estimate.groove import estimate_groove_index, is_grooves 11 | from estimate.io import Hdf5Io 12 | 13 | OUTPUTDIR = common.get_output_path(os.getcwd(), __file__) 14 | 15 | TEST = False 16 | 17 | 18 | def main(): 19 | 20 | status_obj = StatusJsonRest(os.getcwd(), __file__) 21 | status_obj.initializeInputStatusJson() 22 | 23 | # NOTE: FOR TEST and need to fix 24 | if not TEST: 25 | pointcloud = status_obj.getMetadataFromJson( 26 | 'calculate-gradient-averages') 27 | path = pointcloud['filepath'] 28 | group = pointcloud['group'] 29 | r_dset_name = pointcloud['dataset'] 30 | timestamp = pointcloud['timestamp'] 31 | else: 32 | # path = "/home/latona/comet/Data/calculate-gradient-averages/file/output/20200615160546791.hdf5" 33 | path = "/home/latona/comet/Data/calculate-gradient-averages/file/output/20200617204904424.hdf5" 34 | group = "point-cloud" 35 | r_dset_name = "calculate-gradient-averages" 36 | 37 | hdf5io = Hdf5Io() 38 | dst = hdf5io.read_point_cloud_dataset(path, group, r_dset_name) 39 | gradients = dst[:, -1] 40 | _candinates = is_grooves(gradients) 41 | groove_candinates = _candinates.reshape(_candinates.shape[0], 1) 42 | 43 | _dst = np.block([dst[:], groove_candinates]) 44 | 45 | if TEST: 46 | print(dst.shape) 47 | idx = estimate_groove_index(dst) 48 | print(len(idx)) 49 | """ 50 | pcd = o3d.geometry.PointCloud() 51 | pcd.points = o3d.utility.Vector3dVector(dst[:, 0:3]) 52 | pcd.normals = o3d.utility.Vector3dVector(dst[:, 3:6]) 53 | pcd.paint_uniform_color([0., 0, 1]) 54 | np.asarray(pcd.colors)[idx[:], :] = [1, 0, 0] 55 | o3d.visualization.draw_geometries([pcd]) 56 | """ 57 | pcd = cph.geometry.PointCloud() 58 | pcd.points = cph.utility.Vector3fVector(dst[:, 0:3]) 59 | pcd.normals = cph.utility.Vector3fVector(dst[:, 3:6]) 60 | pcd.paint_uniform_color([0., 0., 1]) 61 | colors = np.asarray(pcd.colors.cpu()) 62 | colors[idx[:], :] = [1, 0, 0] 63 | pcd.colors = cph.utility.Vector3fVector(colors) 64 | downpcd = pcd.voxel_down_sample(1) 65 | downpcd.normals = cph.utility.Vector3fVector(dst[:, 3:6]) 66 | 67 | cph.visualization.draw_geometries([pcd]) 68 | 69 | if not TEST: 70 | output_path = output_path(OUTPUTDIR, f'{timestamp}.hdf') 71 | hdf5io.write_point_cloud_dataset_with_gradient_average( 72 | dset, output_path, group, w_dset_name 73 | ) 74 | 75 | 76 | if __name__ == '__main__': 77 | main() 78 | --------------------------------------------------------------------------------