pcl-设置多线段宽度和颜色

Posted kabe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pcl-设置多线段宽度和颜色相关的知识,希望对你有一定的参考价值。

显示点云有使用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.
", id.c_str ());
      return (false);
    }

    if (points->GetNumberOfPoints() < 2)
    {
      PCL_WARN ("[addMultyLine] point size less 2.
");
      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[3] = {0.0, 0.0, 0.0};
   double p0[3] = {1.0, 0.0, 0.0};
   double p1[3] = {2.0, 0.0, 0.0};
   double p2[3] = {3.0, 0.0, 0.0};
   double p3[3] = {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,100,255,0,0,"multiline",0);

效果

技术图片

 



以上是关于pcl-设置多线段宽度和颜色的主要内容,如果未能解决你的问题,请参考以下文章

PCL异常处理:pcl 1.8.13rdpartyoostincludeoost-1_64oost ypeofmsvc ypeof_impl.hpp(125): error(代码片段

PCL:多平面分割

css静态网页背景颜色或者背景图片宽度都不能占满整个网页,右边有很大一块白色的,代码如下图,求解决。

wpf datagrid 滚动条如何设置宽度和颜色

PCL:基于颜色的区域生长分割

PCL:Visualizer 可视化❤️自定义颜色显示