File: test_shapes_multiport.cpp

package info (click to toggle)
pcl 1.11.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 142,936 kB
  • sloc: cpp: 512,326; xml: 28,792; ansic: 13,656; python: 526; lisp: 93; makefile: 74; sh: 27
file content (56 lines) | stat: -rw-r--r-- 1,817 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/io/pcd_io.h>

using pcl::PointCloud;
using pcl::PointXYZ;

int 
main (int , char **)
{
  srand (unsigned (time (0)));

  PointCloud<PointXYZ>::Ptr cloud (new PointCloud<PointXYZ>);

  cloud->points.resize (5);
  for (std::size_t i = 0; i < cloud->size (); ++i)
  {
    (*cloud)[i].x = float (i); 
    (*cloud)[i].y = float (i / 2);
    (*cloud)[i].z = 0.0f;
  }

  // Start the visualizer
  pcl::visualization::PCLVisualizer p ("test_shapes");
  int leftPort(0);
  int rightPort(0);
  p.createViewPort(0, 0, 0.5, 1, leftPort);
  p.createViewPort(0.5, 0, 1, 1, rightPort);
  p.setBackgroundColor (1, 1, 1);
  p.addCoordinateSystem (1.0, "first");

  //p.addPolygon (cloud, "polygon");
  p.addPolygon<PointXYZ> (cloud, 1.0, 0.0, 0.0, "polygon", leftPort);
  p.setShapeRenderingProperties (pcl::visualization::PCL_VISUALIZER_LINE_WIDTH, 10, "polygon", leftPort);
  
  p.addLine<PointXYZ, PointXYZ> ((*cloud)[0], (*cloud)[1], 0.0, 1.0, 0.0, "line", leftPort);
  p.setShapeRenderingProperties (pcl::visualization::PCL_VISUALIZER_LINE_WIDTH, 50, "line", leftPort);

  p.addSphere<PointXYZ> ((*cloud)[0], 1, 0.0, 1.0, 0.0, "sphere", leftPort);
  p.setShapeRenderingProperties (pcl::visualization::PCL_VISUALIZER_LINE_WIDTH, 5, "sphere", leftPort);
//  p.removePolygon ("poly");

  p.addText ("text", 200, 200, 1.0, 0, 0, "text", leftPort);
  
  p.addText3D ("text3D", (*cloud)[0], 1.0, 1.0, 0.0, 0.0, "", rightPort);
  p.spin ();
  p.removeCoordinateSystem ("first", 0);
  p.spin ();
  p.addCoordinateSystem (1.0, 5, 3, 1, "second");
  p.spin ();
  p.removeCoordinateSystem ("second", 0);
  p.spin ();
  p.addText3D ("text3D_to_remove", (*cloud)[1], 1.0, 0.0, 1.0, 0.0, "", rightPort);
  p.spin ();
  p.removeText3D ("text3D_to_remove", rightPort);
  p.spin ();
}