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.\n", id.c_str ());
      return (false);
    }

    if (points->GetNumberOfPoints() < 2)
    {
      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[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);

效果

原文地址:https://www.cnblogs.com/kabe/p/10387109.html

时间: 2024-08-30 00:10:17

pcl-设置多线段宽度和颜色的相关文章

canvas总结:线段宽度与像素边界

在canvas中,我们经常需要绘制线段,主要使用moveTo和lineTo两个方法,moveTo移动至线段起始点,lineTo将线段绘制至终点.同时,绘制线段时可以指定线段的宽度,使用lineWidth属性,lineWidth默认为1,必须大于0 moveTo(x, y): 移动至坐标x,y lineTo(x, y): 线段终点坐标x,y 简单绘制代码如下: var context = document.getElementById('canvas').getContext('2d'); con

设置一个label显示多种颜色,多种字体大小

UILabel* label = [[UILabel alloc] init]; label.frame = CGRectMake(0, 100, 200, 100); label.textColor = [UIColor blackColor]; NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"1234567890"]; NSRange range = NSMak

设置状态栏以及全局的颜色

一.在Application中设置样式: android:theme="@style/AppTheme" <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPri

设置表格单双行颜色

<script type="text/javascript"> $(document).ready(function () { $("table").attr("bgColor", "#222222"); //设置表格的背景颜色 $("tr").attr("bgColor", "#3366CC"); //为单数行表格设置背景颜色 $("tr:ev

iOS不得姐项目--登录模块的布局,设置文本框占位文字颜色,自定义内部控件竖直排列的按钮

一.登录模块的布局 将一整部分切割成若干部分来完成,如图分成了三部分来完成 设置顶部状态栏为白色的方法 二.设置文本框占位文字颜色 <1>方法一与方法二实现原理是同一种,都是通过设置placeholder的NSAttributeString来设置文字属性 方法二效果图: <2>第三种方法是通过RunTime找到隐藏的可以设置placeholder颜色的属性,通过KVC来赋值.RunTime会单独拿出来讲 三.按钮自定义,重新排列子控件的排列位置

设置表格td宽度

CSS布局,表格宽度不听使唤的实例.想把表格第一例宽度设为20,其他自适应.但CSS中宽度是等宽的.只设这一行也不起作用.但是在实际应用中总是等宽处理,并不按照样式来走. XML/HTML代码 <table width="100%"> <tr> <td colspan="6" align="center"><strong>少 儿 瑜 伽 课 程 </strong></td>

Count the Colors (zoj 1610 线段树 区间颜色覆盖)

Count the Colors Time Limit: 2 Seconds      Memory Limit: 65536 KB Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones. Your task is counting the segments of different colors you can s

li进度条宽度和颜色按顺序显示的效果。

实际项目中li和里边的数值是动态生成的,需要控制它的宽度和颜色,效果如图: 如果能实现颜色按数值规律变化就好了,目前颜色是固定到数组中的. 实例代码如下: <!DOCTYPE html><html><head>    <meta charset="utf-8">    <title></title>    <style media="screen">    li{        pa

为什么没法设置span的宽度和高度

为什么没法设置span的宽度和高度: 很多刚开始学习div+css布局的时候可能会碰到这样的问题,使用CSS代码无法设置span的高度和宽度,尽管CSS代码没有错误,却无法生效.例如 <!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author" content="http://www.51texiao.cn/"