-
Notifications
You must be signed in to change notification settings - Fork 0
Minor virtual radar improvements #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HunterM321
wants to merge
3
commits into
virtual_teach_edits
Choose a base branch
from
radar_pix4d
base: virtual_teach_edits
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,3 +14,4 @@ src/vtr3_pyposegraph.egg-info | |
| src/vtr_gps_plotting | ||
| *.db3 | ||
| build | ||
| point_clouds/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import open3d as o3d | ||
| import numpy as np | ||
|
|
||
| # Input and output file paths | ||
| input_ply = "point_clouds/pin_4_crop_sub.ply" | ||
| output_ply = "point_clouds/pin_4_filtered.ply" | ||
|
|
||
| # Read the point cloud | ||
| pcd = o3d.io.read_point_cloud(input_ply) | ||
|
|
||
| # Convert to numpy array | ||
| points = np.asarray(pcd.points) | ||
|
|
||
| pix4d_pc_base_height = -12 | ||
| radar_height = 1.5 | ||
| radar_angle = 2 # degrees | ||
| radar_range = 20 # meters | ||
|
|
||
| # Calculate centroid of x and y coordinates | ||
| centroid_x = np.mean(points[:, 0]) | ||
| centroid_y = np.mean(points[:, 1]) | ||
|
|
||
| # Radar position in the point cloud coordinate system | ||
| # Using centroid of points for x and y coordinates | ||
| radar_position = np.array([centroid_x, centroid_y, pix4d_pc_base_height + radar_height]) | ||
|
|
||
| # Calculate horizontal distance of each point from radar in x-y plane | ||
| distances = np.sqrt((points[:, 0] - radar_position[0])**2 + | ||
| (points[:, 1] - radar_position[1])**2) | ||
|
|
||
| # Calculate allowed z-range at each distance based on radar_angle | ||
| allowed_deviation = distances * np.tan(np.deg2rad(radar_angle)) | ||
|
|
||
| # Calculate upper and lower bounds for each point | ||
| lower_bounds = radar_position[2] - allowed_deviation | ||
| upper_bounds = radar_position[2] + allowed_deviation | ||
|
|
||
| # Filter points that fall within the conic field of view | ||
| mask = (points[:, 2] >= lower_bounds) & (points[:, 2] <= upper_bounds) & (distances <= radar_range) | ||
| filtered_points = points[mask] | ||
|
|
||
| # Set z coordinates to 0 | ||
| filtered_points[:, 2] = 0 | ||
|
|
||
| # Create new point cloud | ||
| filtered_pcd = o3d.geometry.PointCloud() | ||
| filtered_pcd.points = o3d.utility.Vector3dVector(filtered_points) | ||
|
|
||
| # Optionally, copy colors if present | ||
| if pcd.has_colors(): | ||
| colors = np.asarray(pcd.colors) | ||
| filtered_pcd.colors = o3d.utility.Vector3dVector(colors[mask]) | ||
|
|
||
| # Save the filtered point cloud | ||
| o3d.io.write_point_cloud(output_ply, filtered_pcd) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,9 +17,17 @@ | |||||
|
|
||||||
| parser = argparse.ArgumentParser(prog = 'Plot Point Clouds Path', | ||||||
| description = 'Plots point clouds') | ||||||
| parser.add_argument('-g', '--graph', default=os.getenv("VTRDATA"), help="The filepath to the pose graph folder. (Usually /a/path/graph)") # option that takes a value | ||||||
| parser.add_argument('-g', '--graph', default=os.getenv("VTRDATA"), help="The filepath to the pose graph folder. (Usually /a/path/graph)") | ||||||
| parser.add_argument('--save_pc', type=lambda x: (str(x).lower() == 'true'), default=False, help="Whether to save point clouds (True/False).") | ||||||
| parser.add_argument('--save_dir', type=str, default=None, help="Directory to save point clouds (required if --save_pc is True).") | ||||||
| args = parser.parse_args() | ||||||
|
|
||||||
| if args.save_pc and not args.save_dir: | ||||||
| parser.error("--save_dir must be specified if --save_pc is True.") | ||||||
|
|
||||||
| if args.save_pc and not os.path.exists(args.save_dir): | ||||||
| os.makedirs(args.save_dir) | ||||||
|
|
||||||
| factory = Rosbag2GraphFactory(args.graph) | ||||||
|
|
||||||
| test_graph = factory.buildGraph() | ||||||
|
|
@@ -33,7 +41,6 @@ | |||||
| live_2_map = [] | ||||||
| map_2_live = [] | ||||||
|
|
||||||
|
|
||||||
| first = True | ||||||
| paused = False | ||||||
| def toggle(vis): | ||||||
|
|
@@ -49,13 +56,18 @@ def toggle(vis): | |||||
| vis.poll_events() | ||||||
| vis.update_renderer() | ||||||
|
|
||||||
| cloud_count = 0 | ||||||
|
|
||||||
| for i in range(test_graph.major_id + 1): | ||||||
| v_start = test_graph.get_vertex((i, 0)) | ||||||
| paused = True | ||||||
| vertices = list(TemporalIterator(v_start)) | ||||||
| vertices_to_plot = vertices[:-10] if len(vertices) > 10 else vertices | ||||||
|
|
||||||
| for vertex, e in vertices_to_plot: | ||||||
| # Accumulate all points for this major_id | ||||||
| accumulated_points = [] | ||||||
|
|
||||||
| for idx, (vertex, e) in enumerate(vertices_to_plot): | ||||||
|
|
||||||
| new_points, map_ptr = extract_map_from_vertex(test_graph, vertex) | ||||||
|
|
||||||
|
|
@@ -76,6 +88,18 @@ def toggle(vis): | |||||
| else: | ||||||
| pcd.paint_uniform_color((0.1*vertex.run, 0.25*vertex.run, 0.45)) | ||||||
|
|
||||||
| # Save every 20th point cloud if requested | ||||||
| if args.save_pc and (cloud_count % 20 == 0): | ||||||
| filename = os.path.join(args.save_dir, f"cloud_{cloud_count:05d}.ply") | ||||||
| o3d.io.write_point_cloud(filename, pcd) | ||||||
| print(f"Saved point cloud to {filename}") | ||||||
|
|
||||||
| # Accumulate all points for this major_id | ||||||
| if args.save_pc: | ||||||
| accumulated_points.append(new_points.T) | ||||||
|
||||||
| accumulated_points.append(new_points.T) | |
| accumulated_points.append(new_points) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The script uses hardcoded file paths and parameters (e.g., input_ply, output_ply, base heights). Consider adding argparse support to make these values configurable and remove magic numbers for better flexibility.