Created
June 17, 2025 14:06
-
-
Save themightyoarfish/b746f7b89c36e4bbb72dfe6814b1fbf0 to your computer and use it in GitHub Desktop.
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
| #include <chrono> | |
| #include <iostream> | |
| #include <pcl/common/angles.h> | |
| #include <pcl/io/pcd_io.h> | |
| #include <pcl/point_types.h> | |
| #include <pcl/visualization/pcl_visualizer.h> | |
| #include <thread> | |
| int main(int argc, char **argv) { | |
| if (argc < 2) { | |
| std::cerr << "Usage: " << argv[0] << " <pointcloud.pcd>\n"; | |
| return -1; | |
| } | |
| // Load the point cloud | |
| pcl::PointCloud<pcl::PointXYZI>::Ptr cloud( | |
| new pcl::PointCloud<pcl::PointXYZI>); | |
| if (pcl::io::loadPCDFile<pcl::PointXYZI>(argv[1], *cloud) == -1) { | |
| std::cerr << "Couldn't read file " << argv[1] << "\n"; | |
| return -1; | |
| } | |
| std::cout << "Loaded " << cloud->width * cloud->height << " data points.\n"; | |
| // Initialize the visualizer | |
| pcl::visualization::PCLVisualizer::Ptr viewer( | |
| new pcl::visualization::PCLVisualizer("3D Viewer")); | |
| viewer->setBackgroundColor(0, 0, 0); | |
| auto colorh_ = pcl::make_shared< | |
| pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZI>>( | |
| "intensity"); | |
| colorh_->setInputCloud(cloud); | |
| viewer->addPointCloud<pcl::PointXYZI>(cloud, *colorh_, "sample cloud"); | |
| // Set initial camera parameters | |
| viewer->initCameraParameters(); | |
| pcl::visualization::Camera camera; | |
| viewer->getCameraParameters(camera); // Get current parameters first | |
| // Modify the parameters | |
| camera.pos[0] = 0.0; | |
| camera.pos[1] = 0.0; | |
| camera.pos[2] = 0.1; | |
| // some point giving the direction to look at | |
| Eigen::Vector3f focal(1.02815783, 0.46027309, 0.1); | |
| focal.normalize(); | |
| camera.focal[0] = focal(0); | |
| camera.focal[1] = focal(1); | |
| camera.focal[2] = focal(2); | |
| // upper edge of view will be in this direction | |
| camera.view[0] = 0.0; | |
| camera.view[1] = -1.0; | |
| camera.view[2] = 0.0; // Z-up | |
| camera.clip[0] = 0.01; | |
| camera.clip[1] = 10.0; | |
| // view angle in height dimension (y in opencv) | |
| const auto image_height_angle_deg = 83.0; | |
| camera.fovy = pcl::deg2rad(image_height_angle_deg); | |
| // Apply the camera parameters | |
| viewer->setCameraParameters(camera); | |
| // Run visualization loop | |
| while (!viewer->wasStopped()) { | |
| viewer->spinOnce(100); | |
| std::this_thread::sleep_for(std::chrono::milliseconds(100)); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment