pcl画圆球_点云视窗类CloudViewer的介绍以及PCL程序:圆球几何体代码解析

点云视窗类CloudViewer是简单显示点云的可视化工具类,可以让用户用尽可能少的代码查看点云。注意:点云视窗类不能应用于多线程应用程序中。

有关CloudViewer类的成员变量和函数等等,可以C:\Program

Files\PCL 1.6.0\include\pcl-1.6\pcl\visualization\impl目录下的pcl_visualizer.hpp文件中查看。

/*

*PCL安装和环境配置请参考:

*代码出处:

*代码中加载的点云文件my_point_cloud.pcd,可以去下面地址复制粘贴:

*/

一、PCL程序:圆球几何体

#include

#include

#include

#include

int user_data;

void viewerOneOff (pcl::visualization::PCLVisualizer& viewer)

{

//设置背景颜色

viewer.setBackgroundColor (1.0, 0.5, 1.0);

//球体坐标

pcl::PointXYZ o;

o.x = 0;

o.y = 0;

o.z = 0;

//添加球体

viewer.addSphere (o, 1, "sphere", 0);

std::cout << "i only run once" << std::endl;

}

void viewerPsycho (pcl::visualization::PCLVisualizer& viewer)

{

static unsigned count = 0;

std::stringstream ss;

ss << "Once per viewer loop: " << count++;

viewer.removeShape ("text", 0);

viewer.addText (ss.str(), 200, 300, "text", 0);

//FIXME: possible race condition here:

user_data++;

}

int main ()

{

pcl::PointCloud<:pointxyzrgba>::Ptr cloud (new pcl::PointCloud<:pointxyzrgba>);

pcl::io::loadPCDFile ("my_point_cloud.pcd", *cloud); //加载点云文件

pcl::visualization::CloudViewer viewer("Cloud Viewer");//创建viewer对象

//blocks until the cloud is actually rendered

viewer.showCloud(cloud);

//use the following functions to get access to the underlying more advanced/powerful

//PCLVisualizer

//This will only get called once

viewer.runOnVisualizationThreadOnce (viewerOneOff);

//This will get called once per visualization iteration

viewer.runOnVisualizationThread (viewerPsycho);

while (!viewer.wasStopped ())

{

//you can also do cool processing here

//FIXME: Note that this is running in a separate thread from viewerPsycho

//and you should guard against race conditions yourself...

user_data++;

}

return 0;

}

因为代码量很大,本文中只是列出圆体几何体代码中所涉及到CloudViwer类中的函数。

1.viewer.addSphere ();

代码原型:

template bool

pcl::visualization::PCLVisualizer::addSphere (const PointT ¢er, double radius, double r, double g, double b, const std::string &id, int viewport)

{

// Check to see if this ID entry already exists (has it been already added to the visualizer?)

ShapeActorMap::iterator am_it = shape_actor_map_->find (id);

if (am_it != shape_actor_map_->end ())

{

PCL_WARN ("[addSphere] A shape with id already exists! Please choose a different id and retry.\n", id.c_str ());

return (false);

}

//vtkSmartPointer data = createSphere (center.getVector4fMap (), radius);

vtkSmartPointer data = vtkSmartPointer::New ();

data->SetRadius (radius);

data->SetCenter (double (center.x), double (center.y), double (center.z));

data->SetPhiResolution (10);

data->SetThetaResolution (10);

data->LatLongTessellationOff ();

data->Update ();

// Setup actor and mapper

vtkSmartPointer mapper = vtkSmartPointer::New ();

mapper->SetInputConnection (data->GetOutputPort ());

// Create an Actor

vtkSmartPointer actor = vtkSmartPointer::New ();

actor->SetMapper (mapper);

//createActorFromVTKDataSet (data, actor);

actor->GetProperty ()->SetRepresentationToWireframe ();

actor->GetProperty ()->SetInterpolationToGouraud ();

actor->GetMapper ()->ScalarVisibilityOff ();

actor->GetProperty ()->SetColor (r, g, b);

addActorToRenderer (actor, viewport);

// Save the pointer/ID pair to the global actor map

(*shape_actor_map_)[id] = actor;

return (true);

}

template bool

pcl::visualization::PCLVisualizer::addSphere (const PointT ¢er, double radius, const std::string &id, int viewport)

{

return (addSphere (center, radius, 0.5, 0.5, 0.5, id, viewport));

}

//暂时其他的函数找起来有点头疼,慢慢再找ing....

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值