标签:prope idt lob *** smart img OWIN add window
显示点云有使用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);
效果
标签:prope idt lob *** smart img OWIN add window
原文地址:https://www.cnblogs.com/kabe/p/10387109.html