pcl-设置多线段宽度和颜色
2024-10-20 00:43:44
显示点云有使用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",);
效果
最新文章
- 异步编程 In .NET
- apche配置后报错(Forbidden)没有权限
- VS2008 C++ 调用MATLAB 2009b 生成的DLL .
- HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)
- Ctrl+Scroll改变所有Editor的缩放比例 (Code::Blocks)
- 利用 Excel 公式进行数据整理
- VirtualBox的四种网络连接方式
- ASP.NET在删除掉数据库文件后报错处理
- Java官方Demo Mark
- PHP文件上传与安全
- wemall app商城源码android开发MD5加密工具类
- JS中的this的应用总结
- 利用Eclipse中的Maven构建Web项目(一)
- vue/axios请求拦截
- Razor视图
- Python二级-----------程序冲刺4
- 斐波那契数列(C#)
- luogu5021 [NOIp2018]赛道修建 (二分答案+dp(贪心?))
- 2073: [POI2004]PRZ
- HTTP 500.21 处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”