Simple animation with use of pcl::visualization::PCLVisualizer

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Simple animation with use of pcl::visualization::PCLVisualizer

A.Shaferov
Hello!

I am trying to create simple animation viewer for series of PLY files.
PLY files are listed on command line like that:
./viewer 1.ply 2.ply 3.ply
I can change background (added for testing) in animation loop, but changing
of point cloud is not working.
It shows same point cloud all the time.
What is wrong here?

#include <iostream>

#include <list>
#include <iterator>
#include <string>

#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>

#include <unistd.h>
#include <signal.h>

static bool change_frame = true;

static void handler(int sig){
    change_frame = true;
}

int main (int argc, char** argv){
    bool tr = true;
    std::list<pcl::PointCloud&lt;pcl::PointXYZRGB>::Ptr> sources_list;

    for(int i = 1; i < argc; i++)
    {
        pcl::PointCloud<pcl::PointXYZRGB>::Ptr srccld (new
pcl::PointCloud<pcl::PointXYZRGB> ());
        if (pcl::io::loadPLYFile (argv[1], *srccld) < 0)  {
            std::cout << "Error loading point cloud " << argv[1] <<
std::endl << std::endl;
            return -1;
        }
        sources_list.push_back(srccld);
    }

    signal(SIGALRM, handler);
    ualarm(500000, 500000);

    std::list<pcl::PointCloud&lt;pcl::PointXYZRGB>::Ptr>::iterator it1 =
sources_list.begin();
    pcl::visualization::PCLVisualizer viewer ("Matrix transformation
example");
    viewer.addCoordinateSystem (1.0, "cloud", 0);
    viewer.setBackgroundColor(0.05, 0.05, 0.05, 0);

    while (!viewer.wasStopped ()) {
        if (change_frame) {
            std::cout << "Changing frame\n";
            change_frame = false;
            if (it1 == sources_list.end()) it1 = sources_list.begin();
            std::cout << *it1 << "\n";
            if (tr) { // Change background for testing
                tr = false;
                viewer.setBackgroundColor(0.05, 0.05, 0.05, 0);
            } else {
                tr = true;
                viewer.setBackgroundColor(0.5, 0.5, 0.5, 0);
            }
            viewer.removeAllPointClouds();
           
pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB>
source_cloud_color_handler (*it1);
            viewer.addPointCloud (*it1, source_cloud_color_handler, "cld");
            viewer.setPointCloudRenderingProperties
(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "cld");
            it1++;
        }
        viewer.spinOnce ();
    }
    return 0;
}






--
Sent from: http://www.pcl-users.org/
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: Simple animation with use of pcl::visualization::PCLVisualizer

A.Shaferov
Oops! It was my stupid mistake.
if (pcl::io::loadPLYFile (argv[1], *srccld) < 0)
instead of
if (pcl::io::loadPLYFile (argv[i], *srccld) < 0)



--
Sent from: http://www.pcl-users.org/
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users