显示点云有使用vtk的,有使用 ros 中riz ?库的,使用pcl显示点云数据比较方便,但是对于一些模型形状只能固定特定的效果,比如说直线段,只能绘制点到点两点之间的线段。但是项目需要绘制点1到点2到...点n多条线段的连接,并且绘制设置线段宽度。

步骤:

1、把

 vtkRenderWindowInteractorFix.cpp 
 vtkRenderWindowInteractorFix.h
 pcl_visualizer.h 
 pcl_visualizer.cpp
 shapes.h
shapes.cpp
这几个文件加入到工程P里,修改其依赖的头文件路径;屏蔽之前项目中使用的这三个头文件;添加编译这三个文件所依赖的vtk库。
2、代码修改
/*****自定义多点连接线段,可以设置线段宽度*****/
pcl_visualizer.cpp
/*****自定义多点连接线段,可以设置线段宽度*****/
bool pcl::visualization::PCLVisualizer::addMultyLine(vtkSmartPointer<vtkPoints> points,float width,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::console::print_warn (stderr, "[addMultyLine] A shape with id <%s> already exists! Please choose a different id and retry.\n", id.c_str ());
return (false);
} if (points->GetNumberOfPoints() < )
{
PCL_WARN ("[addMultyLine] point size less 2.\n");
return (false);
} vtkSmartPointer<vtkDataSet> data = createLine (points); // Create an Actor
vtkSmartPointer<vtkLODActor> actor;
createActorFromVTKDataSet (data, actor);
actor->GetProperty ()->SetRepresentationToSurface ();
actor->GetProperty()->SetLineWidth(width);
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);
}

shape.cpp

vtkSmartPointer<vtkDataSet>
pcl::visualization::createLine (vtkSmartPointer<vtkPoints> points)
{
vtkSmartPointer<vtkLineSource> lineSource = vtkSmartPointer<vtkLineSource>::New();
lineSource->SetPoints(points);
lineSource->Update();
return (lineSource->GetOutput());
}

例子

   vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();

   double origin[] = {0.0, 0.0, 0.0};
double p0[] = {1.0, 0.0, 0.0};
double p1[] = {2.0, 0.0, 0.0};
double p2[] = {3.0, 0.0, 0.0};
double p3[] = {4.0, 0.0, 0.0}; points->InsertNextPoint(origin);
points->InsertNextPoint(p0);
points->InsertNextPoint(p1);
points->InsertNextPoint(p2);
points->InsertNextPoint(p3);
m_viewerOrg->addMultyLine(points,,,,,"multiline",);

效果

最新文章

  1. 异步编程 In .NET
  2. apche配置后报错(Forbidden)没有权限
  3. VS2008 C++ 调用MATLAB 2009b 生成的DLL .
  4. HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)
  5. Ctrl+Scroll改变所有Editor的缩放比例 (Code::Blocks)
  6. 利用 Excel 公式进行数据整理
  7. VirtualBox的四种网络连接方式
  8. ASP.NET在删除掉数据库文件后报错处理
  9. Java官方Demo Mark
  10. PHP文件上传与安全
  11. wemall app商城源码android开发MD5加密工具类
  12. JS中的this的应用总结
  13. 利用Eclipse中的Maven构建Web项目(一)
  14. vue/axios请求拦截
  15. Razor视图
  16. Python二级-----------程序冲刺4
  17. 斐波那契数列(C#)
  18. luogu5021 [NOIp2018]赛道修建 (二分答案+dp(贪心?))
  19. 2073: [POI2004]PRZ
  20. HTTP 500.21 处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”

热门文章

  1. Hadoop 系列(六)—— HDFS 常用 Shell 命令
  2. Java的集合整理
  3. Linux中su和sudo的用法整理
  4. Java Swing 资料(转载学习)
  5. 从ghost映像.gho文件快速创建vmware虚拟机
  6. Lua for - ipairs,pairs,# 遍历的运行时间
  7. Bootstrap框架 简单使用
  8. 【干货】小程序内嵌 H5 代码详解
  9. LeetCode算法01 Valid Parentheses
  10. layui.table前端+后台处理+分页