Visualize multiple .ply files in PCL

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Visualize multiple .ply files in PCL

arianaa30
This post was updated on .
I am new to Point Cloud Library (PCL) and C++ programming. I have a simple code to load multiple .ply files and visualize them using the code below. It iterates through a loop to load multiple .ply files given as the arguments (say test0.ply, test1.ply ... test99.ply) and visualize them one after another. I need to visualize them as fast as possible possible like as if they are frames of a video.

This is what I've tried so far. Previously spinOnce() was placed outside of my loop and I was not seeing anything. But then I just moved it inside the loop and iterate through the list and try to visualize them. Now it works, however, it is VERY slow (only 1 FPS?!!)

What is going wrong? How should I change the code to show models with a faster pace?



#include <iostream>

#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/point_cloud.h>
#include <pcl/console/parse.h>
#include <pcl/common/transforms.h>
#include <pcl/visualization/pcl_visualizer.h>

// This function displays the help
void showHelp(char *program_name)
{
    std::cout << std::endl;
    std::cout << "Usage: " << program_name << " cloud_filename.[pcd|ply]" << std::endl;
    std::cout << "-h: Show this help." << std::endl;
}

// Main function
int main(int argc,char **argv)
{
    // Show help
    if(pcl::console::find_switch(argc,argv,"-h") || pcl::console::find_switch(argc,argv,"--help"))
    {
        showHelp(argv[0]);
        return 0;
    }

    // Fetch point cloud filename in arguments | Works with PLY files
    std::vector<int> filenames;

    filenames = pcl::console::parse_file_extension_argument(argc,argv,".ply");



    // Visualization
    printf("\n Point cloud colors :\n"
        " \t white \t = \t original point cloud \n");

    pcl::visualization::PCLVisualizer viewer(" Point Cloud Visualizer");
    viewer.setBackgroundColor(0.05,0.05,0.05,0); // Set background to a dark grey

    // Load file | Works with PLY files
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr source_cloud (new pcl::PointCloud<pcl::PointXYZRGB> ());

for(int i=0; i<argc-1; i++)
{

cout<<argv[filenames[i]]<<endl;

        if(pcl::io::loadPLYFile(argv[filenames[i]],*source_cloud) < 0)
        {
            std::cout << "Error loading point cloud " << argv[filenames[i+1]] << std::endl << std::endl;
            showHelp (argv[i+1]);
            return -1;
        }


    // Define R,G,B colors for the point cloud
    pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(source_cloud);
//  pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> source_cloud_color_handler(source_cloud,255,255,255); // White

    // We add the point cloud to the viewer and pass the color handler
if(i!=0){
    viewer.removePointCloud("original_cloud"+(i-1));
}
    viewer.addPointCloud(source_cloud,rgb,"original_cloud"+i);
    viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,2,"original_cloud"+i);

viewer.spinOnce(100, true);
    }

        return 0;
    } // End main()
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Visualize multiple .ply files in PCL

denix56
Hi!
Replace the lines where you remove Pointclouds. If you didnt add any clouds before, removal is unnecessary. Or replace i-1 with i and remove condition i!= 0.

12 июля 2017 г. 17:37 пользователь "[hidden email]" <[hidden email]> написал:
I am new to Point Cloud Library (PCL) and C++ programming. I have a simple
code to load a .ply file and visualize it using the code below. I need to
iterate through multiple .ply files given as the arguments (say test0.ply,
test1.ply ... test99.ply) and visualize them one after another as fast as
possible as if they are frames of a video.

This is what I've tried so far. I simply iterate through the list and try to
visualize them. However, nothing is being shown on the window except the
last model once the iteration is finished (looks like once the model is
going to be shown it quickly goes to next one and therefore no
visualization).

What is going wrong? How should I change the code to achieve that?


#include <iostream>

#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/point_cloud.h>
#include <pcl/console/parse.h>
#include <pcl/common/transforms.h>
#include <pcl/visualization/pcl_visualizer.h>

// This function displays the help
void showHelp(char *program_name)
{
    std::cout << std::endl;
    std::cout << "Usage: " << program_name << " cloud_filename.[pcd|ply]" <<
std::endl;
    std::cout << "-h: Show this help." << std::endl;
}

// Main function
int main(int argc,char **argv)
{
    // Show help
    if(pcl::console::find_switch(argc,argv,"-h") ||
pcl::console::find_switch(argc,argv,"--help"))
    {
        showHelp(argv[0]);
        return 0;
    }

    // Fetch point cloud filename in arguments | Works with PLY files
    std::vector<int> filenames;

    filenames =
pcl::console::parse_file_extension_argument(argc,argv,".ply");



    // Visualization
    printf("\n Point cloud colors :\n"
        " \t white \t = \t original point cloud \n");

    pcl::visualization::PCLVisualizer viewer(" Point Cloud Visualizer");
    viewer.setBackgroundColor(0.05,0.05,0.05,0); // Set background to a dark
grey

    // Load file | Works with PLY files
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr source_cloud (new
pcl::PointCloud<pcl::PointXYZRGB> ());

for(int i=0; i<argc-1; i++)
{

cout&lt;&lt;argv[filenames[i]]&lt;&lt;endl;

        if(pcl::io::loadPLYFile(argv[filenames[i]],*source_cloud) &lt; 0)
        {
            std::cout &lt;&lt; &quot;Error loading point cloud &quot;
&lt;&lt; argv[filenames[i+1]] &lt;&lt; std::endl &lt;&lt; std::endl;
            showHelp (argv[i+1]);
            return -1;
        }


    // Define R,G,B colors for the point cloud
    pcl::visualization::PointCloudColorHandlerRGBField&lt;pcl::PointXYZRGB>
rgb(source_cloud);
//  pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ>
source_cloud_color_handler(source_cloud,255,255,255); // White

    // We add the point cloud to the viewer and pass the color handler
if(i!=0){
    viewer.removePointCloud("original_cloud"+(i-1));
}
    viewer.addPointCloud(source_cloud,rgb,"original_cloud"+i);

viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,2,"original_cloud"+i);
}

    while(!viewer.wasStopped()){   // Display the visualizer until the 'q'
key is pressed
        viewer.spinOnce();
    }

    return 0;
} // End main()



--
View this message in context: http://www.pcl-users.org/Visualize-multiple-ply-files-in-PCL-tp4044757.html
Sent from the Point Cloud Library (PCL) Users mailing list mailing list archive at Nabble.com.
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users


_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Visualize multiple .ply files in PCL

arianaa30
If I don't remove the previously added point clouds, they all stack up on each other.

Anyways, That doesn't help with the speed which is my problem now.
Loading...