PCL多视图显示

#include <iostream>
#include <boost/thread/thread.hpp>
#include <pcl/common/common_headers.h>
#include <pcl/common/common_headers.h>
#include <pcl/features/normal_3d.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/console/parse.h>
#include <pcl/io/io.h>


// -----Main-----
int
main (int argc, char** argv)
{
        pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
        pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>);

     //用loadFile读入两个文件,赋于cloud和cloud_filtered

       if(pcl::io::loadPCDFile<pcl::PointXYZ>("scene_1.pcd",*cloud)==-1)//*打开点云文件
        {
                PCL_ERROR("Couldn't read file test_pcd.pcd\n");
                return(-1);
        }
std::cout<<"Loaded 1"<<std::endl;

        if(pcl::io::loadPCDFile<pcl::PointXYZ>("scene_2.pcd",*cloud_filtered)==-1)//*打开点云文件
        {
                PCL_ERROR("Couldn't read file test_pcd.pcd\n");
                return(-1);
        }

std::cout<<"Loaded 2"<<std::endl;



//可视化
//viewer->addPointCloud(cloud,"sample cloud1");
//双视口
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
viewer->initCameraParameters();
int v1(0),v2(0);;

  viewer->createViewPort(0.0,0.0,0.5,1.0,v1);//(Xmin,Ymin,Xmax,Ymax)设置窗口坐标
  viewer->setBackgroundColor(0,0,0,v1);//设置背景
  viewer->addText("original", 10,10,"v1 text", v1);//设置视口名称
  viewer->addPointCloud(cloud,"sample cloud1", v1);//添加点云

  viewer->createViewPort(0.5,0.0,1.0,1.0,v2);
  viewer->setBackgroundColor(0.3,0.3,0.3,v2);
  viewer->addText("after filtered", 10,10,"v2 text", v2);
  viewer->addPointCloud(cloud_filtered,"sample cloud2", v2);

  viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_FONT_SIZE,3,"sample cloud1");
  viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_FONT_SIZE,3,"sample cloud2");
   while (!viewer->wasStopped ())
    {

     viewer->spinOnce();
    }


}

你可能感兴趣的:(PCL)