Skip to content
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

[custom] chatGPT code on pcl visualization : different behavior between pcl::visualization::PCLVisualizer::Ptr and pcl::visualization::PCLVisualizer #6027

Closed
hitbuyi opened this issue May 1, 2024 · 2 comments

Comments

@hitbuyi
Copy link

hitbuyi commented May 1, 2024

I use chatGPT to generate PCL code on show, my task is very simple, to visualize a lidar cloud point,the color is according to lidar's intensity. Below two versions of code are generated by chatGPT, my enviroments are

OS: ubuntu20.04
PCL:1.14(built from source)
VTK: 9.1.0

v1: use pcl::visualization::PCLVisualizer::Ptr, it can display lidar points in white-black, without color

    //create point cloud,the two versions are the same 
    pcl::PointCloud<pcl::PointXYZI>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZI>);
    float x, y, z, intensity;
    while (input_file.read(reinterpret_cast<char*>(&x), sizeof(float)) &&
           input_file.read(reinterpret_cast<char*>(&y), sizeof(float)) &&
           input_file.read(reinterpret_cast<char*>(&z), sizeof(float)) &&
           input_file.read(reinterpret_cast<char*>(&intensity), sizeof(float))) {
        pcl::PointXYZI point;
        point.x = x;
        point.y = y;
        point.z = z;
        point.intensity = intensity;
        cloud->push_back(point);
    }
    input_file.close();

    // Create PCL visualizer
    pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("Cloud Viewer"));
    viewer->setBackgroundColor(0, 0, 0);
    viewer->addPointCloud<pcl::PointXYZI>(cloud, "cloud");
    // Colorize points based on intensity
    pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZI> intensity_color(cloud, "intensity");
    viewer->addPointCloud<pcl::PointXYZI>(cloud, intensity_color, "cloud");
    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "cloud");

    // Run visualization
    while (!viewer->wasStopped()) {
        viewer->spinOnce(100);
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
    }
    return 0;

the result is
v1

v2: use,pcl::visualization::PCLVisualizer, it can display lidar points with color

    //create point cloud,the two versions are the same 
    pcl::PointCloud<pcl::PointXYZI>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZI>);
    float x, y, z, intensity;
    while (input_file.read(reinterpret_cast<char*>(&x), sizeof(float)) &&
           input_file.read(reinterpret_cast<char*>(&y), sizeof(float)) &&
           input_file.read(reinterpret_cast<char*>(&z), sizeof(float)) &&
           input_file.read(reinterpret_cast<char*>(&intensity), sizeof(float))) {
        pcl::PointXYZI point;
        point.x = x;
        point.y = y;
        point.z = z;
        point.intensity = intensity;
        cloud->push_back(point);
    }
    input_file.close();
   // Step 2: Assign colors based on intensity
    pcl::visualization::PCLVisualizer viewer("Cloud Viewer");
    viewer.setBackgroundColor(0, 0, 0);
    pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZI> intensity_color(cloud, "intensity");
    viewer.addPointCloud<pcl::PointXYZI>(cloud, intensity_color, "cloud");
    viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "cloud");

    // Step 3: Visualize the point cloud
    while (!viewer.wasStopped()) {
        viewer.spinOnce(100);
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
    }
    return 0;

the result is
v2

Why this happen? I think they are the same, just one use pointer, the other not.

@hitbuyi hitbuyi added the status: triage Labels incomplete label May 1, 2024
@mvieth
Copy link
Member

mvieth commented May 1, 2024

@hitbuyi The first version calls addPointCloud twice, the first time without the handler. The second call to addPointCloud is ignored because the id "cloud" is the same. You actually get a warning from PCL:
[addPointCloud] The id <cloud> already exists! Please choose a different id and retry.
Please be aware that chatGPT often produces complete garbage. Do not blindly trust it, double check everything. We can not provide any support for chatGPT generated code.

@mvieth mvieth closed this as completed May 1, 2024
@mvieth mvieth added kind: question Type of issue module: visualization and removed status: triage Labels incomplete labels May 1, 2024
@hitbuyi
Copy link
Author

hitbuyi commented May 6, 2024

@hitbuyi The first version calls addPointCloud twice, the first time without the handler. The second call to addPointCloud is ignored because the id "cloud" is the same. You actually get a warning from PCL: [addPointCloud] The id <cloud> already exists! Please choose a different id and retry. Please be aware that chatGPT often produces complete garbage. Do not blindly trust it, double check everything. We can not provide any support for chatGPT generated code.

It solved my problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants