title: Read and visualize multiple .ply in PCL
body: <p>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. </p>
  
  <p>This is what I've tried so far. Previously <code>spinOnce()</code> 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?!!)</p>
  
  <p>What is going wrong? How should I change the code to show models with a faster pace?</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  #include &lt;pcl/io/pcd_io.h&gt;
  #include &lt;pcl/io/ply_io.h&gt;
  #include &lt;pcl/point_cloud.h&gt;
  #include &lt;pcl/console/parse.h&gt;
  #include &lt;pcl/common/transforms.h&gt;
  #include &lt;pcl/visualization/pcl_visualizer.h&gt;
  
  // This function displays the help
  void showHelp(char *program_name)
  {
      std::cout &lt;&lt; std::endl;
      std::cout &lt;&lt; "Usage: " &lt;&lt; program_name &lt;&lt; " cloud_filename.[pcd|ply]" &lt;&lt; std::endl;
      std::cout &lt;&lt; "-h: Show this help." &lt;&lt; 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&lt;int&gt; 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&lt;pcl::PointXYZRGB&gt;::Ptr source_cloud (new pcl::PointCloud&lt;pcl::PointXYZRGB&gt; ());
  
  for(int i=0; i&lt;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; "Error loading point cloud " &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&gt; rgb(source_cloud);
  //  pcl::visualization::PointCloudColorHandlerCustom&lt;pcl::PointXYZ&gt; 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()
  </code></pre>