55
66import click # needed for documentation
77import typer
8- from pyntcloud .io import TO_FILE
98from rich .console import Console
109from rosbags .highlevel import AnyReader
1110
1211import pointcloudset
1312from pointcloudset import Dataset
13+ from pointcloudset .io import POINTCLOUD_TO_FILE
1414
1515app = typer .Typer ()
1616console = Console ()
1717
18- TO_FILE_PYNTCLOUD = list (TO_FILE .keys ())
19- TO_FILE_CLI = TO_FILE_PYNTCLOUD .append ("POINTCLOUDSET" )
18+
19+ TO_FILE_PYNTCLOUD = [k .lower () for k in POINTCLOUD_TO_FILE .keys ()]
20+ TO_FILE_CLI = TO_FILE_PYNTCLOUD + ["pointcloudset" ]
2021
2122
2223@app .command ()
@@ -35,16 +36,16 @@ def convert(
3536 Examples:
3637
3738 convert all ROS1 bag files in a directory
38- $ pointcloudset convert -d converted .
39+ $ pointcloudset convert . -d converted
3940
4041 convert all frames of bagfile xyz.bag into csv files
41- $ pointcloudset convert -o csv -d converted_csv xyz.bag
42+ $ pointcloudset convert xyz.bag -o csv -d converted_csv xyz.bag
4243
4344 convert a ROS2 directoy to a pointcloudset file
44- $ pointcloudset convert -d converted something_ros2
45+ $ pointcloudset convert something_ros2 -d converted
4546
4647 convert the first 10 frames of a bag file int0las files
47- $ pointcloudset convert -o las -d converted_las --start 1 --end 10 xyz.bag
48+ $ pointcloudset convert xyz.bag -o las -d converted_las --start 1 --end 10
4849 """
4950 console .line ()
5051 console .rule (f"pointcloudset { pointcloudset .__version__ } " )
@@ -66,7 +67,7 @@ def convert(
6667 folder_to_write = folder_to_write_path ,
6768 )
6869 console .print (f"{ Path (bagfile_path ).name } converted to { folder_to_write_path } " )
69- elif output_format .upper () in TO_FILE_PYNTCLOUD :
70+ elif output_format .lower () in TO_FILE_CLI :
7071 _convert_bag2files (
7172 topic ,
7273 start_frame_number ,
@@ -145,7 +146,7 @@ def _gen_file_paths(file_name):
145146
146147def _gen_folder (folder_to_write : str , ros_file_path : str , output_format : str ) -> Path :
147148 """Generate the folder to write the converted files to."""
148- suffix = "_pointcloudset" if output_format == "POINTCLOUDSET" else " "
149+ suffix = "_pointcloudset" if output_format == "POINTCLOUDSET" else f"_ { output_format . lower () } "
149150 folder_to_write_path = Path (folder_to_write ).joinpath (Path (ros_file_path ).stem + suffix )
150151 folder_to_write_path .mkdir (exist_ok = False , parents = True )
151152 return folder_to_write_path
@@ -179,11 +180,11 @@ def _convert_bag2files(
179180 if end_frame_number is None :
180181 end_frame_number = len (dataset )
181182 for frame in range (start_frame_number , end_frame_number ):
182- pyntcloud = dataset [frame ]. to_instance ( "PYNTCLOUD" )
183+ frame_pc = dataset [frame ]
183184 orig_file = Path (ros_file_path ).stem
184185 filename = folder_to_write_path .joinpath (f"{ orig_file } _{ frame } .{ output_format .lower ()} " )
185186 console .print (f"frame { frame } of { Path (ros_file_path ).name } converted to { filename } " )
186- pyntcloud .to_file (filename . as_posix () )
187+ frame_pc .to_file (filename )
187188
188189
189190typer_click_object = typer .main .get_command (app )
0 commit comments