Advertisement
SUGIYAMA

pcd_viewer

Sep 19th, 2013
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 21.90 KB | None | 0 0
  1. /*
  2.  * Software License Agreement (BSD License)
  3.  *
  4.  *  Point Cloud Library (PCL) - www.pointclouds.org
  5.  *  Copyright (c) 2009-2012, Willow Garage, Inc.
  6.  *
  7.  *  All rights reserved.
  8.  *
  9.  *  Redistribution and use in source and binary forms, with or without
  10.  *  modification, are permitted provided that the following conditions
  11.  *  are met:
  12.  *
  13.  *   * Redistributions of source code must retain the above copyright
  14.  *     notice, this list of conditions and the following disclaimer.
  15.  *   * Redistributions in binary form must reproduce the above
  16.  *     copyright notice, this list of conditions and the following
  17.  *     disclaimer in the documentation and/or other materials provided
  18.  *     with the distribution.
  19.  *   * Neither the name of Willow Garage, Inc. nor the names of its
  20.  *     contributors may be used to endorse or promote products derived
  21.  *     from this software without specific prior written permission.
  22.  *
  23.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24.  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25.  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26.  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  27.  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  28.  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  29.  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  30.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31.  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32.  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  33.  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34.  *  POSSIBILITY OF SUCH DAMAGE.
  35.  *
  36.  * $Id: pcd_viewer.cpp 5094 2012-03-15 01:03:51Z rusu $
  37.  *
  38.  */
  39. // PCL
  40. #include <Eigen/Geometry>
  41. #include <pcl/common/common.h>
  42. #include <pcl/io/pcd_io.h>
  43. #include <cfloat>
  44. #include <pcl/visualization/point_cloud_handlers.h>
  45. #include <pcl/visualization/pcl_visualizer.h>
  46. #include <pcl/visualization/histogram_visualizer.h>
  47. #include <pcl/visualization/point_picking_event.h>
  48. #include <pcl/console/print.h>
  49. #include <pcl/console/parse.h>
  50. #include <pcl/console/time.h>
  51. #include <vtkPolyDataReader.h>
  52.  
  53. using namespace pcl::console;
  54.  
  55. typedef pcl::visualization::PointCloudColorHandler<sensor_msgs::PointCloud2> ColorHandler;
  56. typedef ColorHandler::Ptr ColorHandlerPtr;
  57. typedef ColorHandler::ConstPtr ColorHandlerConstPtr;
  58.  
  59. typedef pcl::visualization::PointCloudGeometryHandler<sensor_msgs::PointCloud2> GeometryHandler;
  60. typedef GeometryHandler::Ptr GeometryHandlerPtr;
  61. typedef GeometryHandler::ConstPtr GeometryHandlerConstPtr;
  62.  
  63. #define NORMALS_SCALE 0.01
  64. #define PC_SCALE 0.001
  65.  
  66. bool
  67. isValidFieldName (const std::string &field)
  68. {
  69.   if (field == "_")
  70.     return (false);
  71.  
  72.   if ((field == "vp_x") || (field == "vx") || (field == "vp_y") || (field == "vy") || (field == "vp_z") || (field == "vz"))
  73.     return (false);
  74.   return (true);
  75. }
  76.  
  77. bool
  78. isMultiDimensionalFeatureField (const sensor_msgs::PointField &field)
  79. {
  80.   if (field.count > 1)
  81.     return (true);
  82.   return (false);
  83. }
  84.  
  85. void
  86. printHelp (int argc, char **argv)
  87. {
  88.   print_error ("Syntax is: %s <file_name 1..N>.<pcd or vtk> <options>\n", argv[0]);
  89.   print_info ("  where options are:\n");
  90.   print_info ("                     -bc r,g,b                = background color\n");
  91.   print_info ("                     -fc r,g,b                = foreground color\n");
  92.   print_info ("                     -ps X                    = point size ("); print_value ("1..64"); print_info (") \n");
  93.   print_info ("                     -opaque X                = rendered point cloud opacity ("); print_value ("0..1"); print_info (")\n");
  94.  
  95.   print_info ("                     -ax "); print_value ("n"); print_info ("                    = enable on-screen display of ");
  96.   print_color (stdout, TT_BRIGHT, TT_RED, "X"); print_color (stdout, TT_BRIGHT, TT_GREEN, "Y"); print_color (stdout, TT_BRIGHT, TT_BLUE, "Z");
  97.   print_info (" axes and scale them to "); print_value ("n\n");
  98.   print_info ("                     -ax_pos X,Y,Z            = if axes are enabled, set their X,Y,Z position in space (default "); print_value ("0,0,0"); print_info (")\n");
  99.  
  100.   print_info ("\n");
  101.   print_info ("                     -cam (*)                 = use given camera settings as initial view\n");
  102.   print_info (stderr, " (*) [Clipping Range / Focal Point / Position / ViewUp / Distance / Field of View Y / Window Size / Window Pos] or use a <filename.cam> that contains the same information.\n");
  103.  
  104.   print_info ("\n");
  105.   print_info ("                     -multiview 0/1           = enable/disable auto-multi viewport rendering (default "); print_value ("disabled"); print_info (")\n");
  106.   print_info ("\n");
  107.  
  108.   print_info ("\n");
  109.   print_info ("                     -normals 0/X             = disable/enable the display of every Xth point's surface normal as lines (default "); print_value ("disabled"); print_info (")\n");
  110.   print_info ("                     -normals_scale X         = resize the normal unit vector size to X (default "); print_value ("0.02"); print_info (")\n");
  111.   print_info ("\n");
  112.   print_info ("                     -pc 0/X                  = disable/enable the display of every Xth point's principal curvatures as lines (default "); print_value ("disabled"); print_info (")\n");
  113.   print_info ("                     -pc_scale X              = resize the principal curvatures vectors size to X (default "); print_value ("0.02"); print_info (")\n");
  114.   print_info ("\n");
  115.  
  116.   print_info ("\n(Note: for multiple .pcd files, provide multiple -{fc,ps,opaque} parameters; they will be automatically assigned to the right file)\n");
  117. }
  118.  
  119. // Global visualizer object
  120. pcl::visualization::PCLHistogramVisualizer ph_global;
  121. boost::shared_ptr<pcl::visualization::PCLVisualizer> p;
  122.  
  123. void
  124. pp_callback (const pcl::visualization::PointPickingEvent& event, void* cookie)
  125. {
  126.   if (event.getPointIndex () == -1)
  127.     return;
  128.   sensor_msgs::PointCloud2::Ptr cloud = *(sensor_msgs::PointCloud2::Ptr*)cookie;
  129.   if (!cloud)
  130.     return;
  131.  
  132.   // If two points were selected, draw an arrow between them
  133.   pcl::PointXYZ p1, p2;
  134.   if (event.getPoints (p1.x, p1.y, p1.z, p2.x, p2.y, p2.z) && p)
  135.   {
  136.     std::stringstream ss;
  137.     ss << p1 << p2;
  138.     p->addArrow<pcl::PointXYZ, pcl::PointXYZ> (p1, p2, 1.0, 1.0, 1.0, ss.str ());
  139.     return;
  140.   }
  141.  
  142.   // Else, if a single point has been selected
  143.   std::stringstream ss;
  144.   ss << event.getPointIndex ();
  145.   // Get the cloud's fields
  146.   for (size_t i = 0; i < cloud->fields.size (); ++i)
  147.   {
  148.     if (!isMultiDimensionalFeatureField (cloud->fields[i]))
  149.       continue;
  150.     ph_global.addFeatureHistogram (*cloud, cloud->fields[i].name, event.getPointIndex (), ss.str ());
  151.   }
  152.   if (p)
  153.   {
  154.     pcl::PointXYZ pos;
  155.     event.getPoint (pos.x, pos.y, pos.z);
  156.     p->addText3D<pcl::PointXYZ> (ss.str (), pos, 0.0005, 1.0, 1.0, 1.0, ss.str ());
  157.   }
  158.   ph_global.spinOnce ();
  159. }
  160.  
  161. /* ---[ */
  162. int
  163. main (int argc, char** argv)
  164. {
  165.   srand (time (0));
  166.  
  167.   print_info ("The viewer window provides interactive commands; for help, press 'h' or 'H' from within the window.\n");
  168.  
  169.   if (argc < 2)
  170.   {
  171.     printHelp (argc, argv);
  172.     return (-1);
  173.   }
  174.  
  175.   // Command line parsing
  176.   double bcolor[3] = {0, 0, 0};
  177.   pcl::console::parse_3x_arguments (argc, argv, "-bc", bcolor[0], bcolor[1], bcolor[2]);
  178.  
  179.   std::vector<double> fcolor_r, fcolor_b, fcolor_g;
  180.   bool fcolorparam = pcl::console::parse_multiple_3x_arguments (argc, argv, "-fc", fcolor_r, fcolor_g, fcolor_b);
  181.  
  182.   std::vector<int> psize;
  183.   pcl::console::parse_multiple_arguments (argc, argv, "-ps", psize);
  184.  
  185.   std::vector<double> opaque;
  186.   pcl::console::parse_multiple_arguments (argc, argv, "-opaque", opaque);
  187.  
  188.   int mview = 0;
  189.   pcl::console::parse_argument (argc, argv, "-multiview", mview);
  190.  
  191.   int normals = 0;
  192.   pcl::console::parse_argument (argc, argv, "-normals", normals);
  193.   double normals_scale = NORMALS_SCALE;
  194.   pcl::console::parse_argument (argc, argv, "-normals_scale", normals_scale);
  195.  
  196.   int pc = 0;
  197.   pcl::console::parse_argument (argc, argv, "-pc", pc);
  198.   double pc_scale = PC_SCALE;
  199.   pcl::console::parse_argument (argc, argv, "-pc_scale", pc_scale);
  200.  
  201.   // Parse the command line arguments for .pcd files
  202.   std::vector<int> p_file_indices   = pcl::console::parse_file_extension_argument (argc, argv, ".pcd");
  203.   std::vector<int> vtk_file_indices = pcl::console::parse_file_extension_argument (argc, argv, ".vtk");
  204.  
  205.   if (p_file_indices.size () == 0 && vtk_file_indices.size () == 0)
  206.   {
  207.     print_error ("No .PCD or .VTK file given. Nothing to visualize.\n");
  208.     return (-1);
  209.   }
  210.  
  211.   // Multiview enabled?
  212.   int y_s = 0, x_s = 0;
  213.   double x_step = 0, y_step = 0;
  214.   if (mview)
  215.   {
  216.     print_highlight ("Multi-viewport rendering enabled.\n");
  217.  
  218.     if (p_file_indices.size () != 0)
  219.     {
  220.       y_s = static_cast<int>(floor (sqrt (static_cast<float>(p_file_indices.size ()))));
  221.       x_s = y_s + static_cast<int>(ceil ((p_file_indices.size () / static_cast<double>(y_s)) - y_s));
  222.       print_highlight ("Preparing to load "); print_value ("%d", p_file_indices.size ());
  223.     }
  224.     else if (vtk_file_indices.size () != 0)
  225.     {
  226.       y_s = static_cast<int>(floor (sqrt (static_cast<float>(vtk_file_indices.size ()))));
  227.       x_s = y_s + static_cast<int>(ceil ((vtk_file_indices.size () / static_cast<double>(y_s)) - y_s));
  228.       print_highlight ("Preparing to load "); print_value ("%d", vtk_file_indices.size ());
  229.     }
  230.  
  231.     x_step = static_cast<double>(1.0 / static_cast<double>(x_s));
  232.     y_step = static_cast<double>(1.0 / static_cast<double>(y_s));
  233.     print_info (" files ("); print_value ("%d", x_s);    print_info ("x"); print_value ("%d", y_s);
  234.     print_info (" / ");      print_value ("%f", x_step); print_info ("x"); print_value ("%f", y_step);
  235.     print_info (")\n");
  236.   }
  237.  
  238.   // Fix invalid multiple arguments
  239.   if (psize.size () != p_file_indices.size () && psize.size () > 0)
  240.     for (size_t i = psize.size (); i < p_file_indices.size (); ++i)
  241.       psize.push_back (1);
  242.   if (opaque.size () != p_file_indices.size () && opaque.size () > 0)
  243.     for (size_t i = opaque.size (); i < p_file_indices.size (); ++i)
  244.       opaque.push_back (1.0);
  245.  
  246.   // Create the PCLVisualizer object
  247.   boost::shared_ptr<pcl::visualization::PCLHistogramVisualizer> ph;
  248.  
  249.   // Using min_p, max_p to set the global Y min/max range for the histogram
  250.   float min_p = FLT_MAX; float max_p = -FLT_MAX;
  251.  
  252.   int k = 0, l = 0, viewport = 0;
  253.   // Load the data files
  254.   pcl::PCDReader pcd;
  255.   pcl::console::TicToc tt;
  256.   ColorHandlerPtr color_handler;
  257.   GeometryHandlerPtr geometry_handler;
  258.  
  259.   // Go through VTK files
  260.   for (size_t i = 0; i < vtk_file_indices.size (); ++i)
  261.   {
  262.     // Load file
  263.     tt.tic ();
  264.     print_highlight (stderr, "Loading "); print_value (stderr, "%s ", argv[vtk_file_indices.at (i)]);
  265.     vtkPolyDataReader* reader = vtkPolyDataReader::New ();
  266.     reader->SetFileName (argv[vtk_file_indices.at (i)]);
  267.     reader->Update ();
  268.     vtkSmartPointer<vtkPolyData> polydata = reader->GetOutput ();
  269.     if (!polydata)
  270.       return (-1);
  271.     print_info ("[done, "); print_value ("%g", tt.toc ()); print_info (" ms : "); print_value ("%d", polydata->GetNumberOfPoints ()); print_info (" points]\n");
  272.  
  273.     // Create the PCLVisualizer object here on the first encountered XYZ file
  274.     if (!p)
  275.       p.reset (new pcl::visualization::PCLVisualizer (argc, argv, "PCD viewer"));
  276.  
  277.     // Multiview enabled?
  278.     if (mview)
  279.     {
  280.       p->createViewPort (k * x_step, l * y_step, (k + 1) * x_step, (l + 1) * y_step, viewport);
  281.       k++;
  282.       if (k >= x_s)
  283.       {
  284.         k = 0;
  285.         l++;
  286.       }
  287.     }
  288.  
  289.     // Add as actor
  290.     std::stringstream cloud_name ("vtk-");
  291.     cloud_name << argv[vtk_file_indices.at (i)] << "-" << i;
  292.     p->addModelFromPolyData (polydata, cloud_name.str (), viewport);
  293.  
  294.     // Change the shape rendered color
  295.     if (fcolorparam && fcolor_r.size () > i && fcolor_g.size () > i && fcolor_b.size () > i)
  296.       p->setShapeRenderingProperties (pcl::visualization::PCL_VISUALIZER_COLOR, fcolor_r[i], fcolor_g[i], fcolor_b[i], cloud_name.str ());
  297.  
  298.     // Change the shape rendered point size
  299.     if (psize.size () > 0)
  300.       p->setShapeRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, psize.at (i), cloud_name.str ());
  301.  
  302.     // Change the shape rendered opacity
  303.     if (opaque.size () > 0)
  304.       p->setShapeRenderingProperties (pcl::visualization::PCL_VISUALIZER_OPACITY, opaque.at (i), cloud_name.str ());
  305.   }
  306.  
  307.   sensor_msgs::PointCloud2::Ptr cloud;
  308.   // Go through PCD files
  309.   for (size_t i = 0; i < p_file_indices.size (); ++i)
  310.   {
  311.     cloud.reset (new sensor_msgs::PointCloud2);
  312.     Eigen::Vector4f origin;
  313.     Eigen::Quaternionf orientation;
  314.     int version;
  315.  
  316.     print_highlight (stderr, "Loading "); print_value (stderr, "%s ", argv[p_file_indices.at (i)]);
  317.  
  318.     tt.tic ();
  319.     if (pcd.read (argv[p_file_indices.at (i)], *cloud, origin, orientation, version) < 0)
  320.       return (-1);
  321.  
  322.     std::stringstream cloud_name;
  323.  
  324.     // ---[ Special check for 1-point multi-dimension histograms
  325.     if (cloud->fields.size () == 1 && isMultiDimensionalFeatureField (cloud->fields[0]))
  326.     {
  327.       cloud_name << argv[p_file_indices.at (i)];
  328.  
  329.       if (!ph)
  330.         ph.reset (new pcl::visualization::PCLHistogramVisualizer);
  331.       print_info ("[done, "); print_value ("%g", tt.toc ()); print_info (" ms : "); print_value ("%d", cloud->fields[0].count); print_info (" points]\n");
  332.  
  333.       pcl::getMinMax (*cloud, 0, cloud->fields[0].name, min_p, max_p);
  334.       ph->addFeatureHistogram (*cloud, cloud->fields[0].name, cloud_name.str ());
  335.       continue;
  336.     }
  337.  
  338.     cloud_name << argv[p_file_indices.at (i)] << "-" << i;
  339.  
  340.     // Create the PCLVisualizer object here on the first encountered XYZ file
  341.     if (!p)
  342.     {
  343.       p.reset (new pcl::visualization::PCLVisualizer (argc, argv, "PCD viewer"));
  344.       p->registerPointPickingCallback (&pp_callback, (void*)&cloud);
  345.       Eigen::Matrix3f rotation;
  346.       rotation = orientation;
  347.       p->setCameraPose (origin [0]                  , origin [1]                  , origin [2],
  348.                         origin [0] + rotation (0, 2), origin [1] + rotation (1, 2), origin [2] + rotation (2, 2),
  349.                                      rotation (0, 1),              rotation (1, 1),              rotation (2, 1));
  350.     }
  351.  
  352.     // Multiview enabled?
  353.     if (mview)
  354.     {
  355.       p->createViewPort (k * x_step, l * y_step, (k + 1) * x_step, (l + 1) * y_step, viewport);
  356.       k++;
  357.       if (k >= x_s)
  358.       {
  359.         k = 0;
  360.         l++;
  361.       }
  362.     }
  363.  
  364.     if (cloud->width * cloud->height == 0)
  365.     {
  366.       print_error ("[error: no points found!]\n");
  367.       return (-1);
  368.     }
  369.     print_info ("[done, "); print_value ("%g", tt.toc ()); print_info (" ms : "); print_value ("%d", (int)cloud->width * cloud->height); print_info (" points]\n");
  370.     print_info ("Available dimensions: "); print_value ("%s\n", pcl::getFieldsList (*cloud).c_str ());
  371.  
  372.     // If no color was given, get random colors
  373.     if (fcolorparam)
  374.     {
  375.       if (fcolor_r.size () > i && fcolor_g.size () > i && fcolor_b.size () > i)
  376.         color_handler.reset (new pcl::visualization::PointCloudColorHandlerCustom<sensor_msgs::PointCloud2> (cloud, fcolor_r[i], fcolor_g[i], fcolor_b[i]));
  377.       else
  378.         color_handler.reset (new pcl::visualization::PointCloudColorHandlerRandom<sensor_msgs::PointCloud2> (cloud));
  379.     }
  380.     else
  381.       color_handler.reset (new pcl::visualization::PointCloudColorHandlerRandom<sensor_msgs::PointCloud2> (cloud));
  382.  
  383.     // Add the dataset with a XYZ and a random handler
  384.     geometry_handler.reset (new pcl::visualization::PointCloudGeometryHandlerXYZ<sensor_msgs::PointCloud2> (cloud));
  385.     // Add the cloud to the renderer
  386.     //p->addPointCloud<pcl::PointXYZ> (cloud_xyz, geometry_handler, color_handler, cloud_name.str (), viewport);
  387.     p->addPointCloud (cloud, geometry_handler, color_handler, origin, orientation, cloud_name.str (), viewport);
  388.  
  389.     // If normal lines are enabled
  390.     if (normals != 0)
  391.     {
  392.       int normal_idx = pcl::getFieldIndex (*cloud, "normal_x");
  393.       if (normal_idx == -1)
  394.       {
  395.         print_error ("Normal information requested but not available.\n");
  396.         continue;
  397.         //return (-1);
  398.       }
  399.       //
  400.       // Convert from blob to pcl::PointCloud
  401.       pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_xyz (new pcl::PointCloud<pcl::PointXYZ>);
  402.       pcl::fromROSMsg (*cloud, *cloud_xyz);
  403.       cloud_xyz->sensor_origin_ = origin;
  404.       cloud_xyz->sensor_orientation_ = orientation;
  405.  
  406.       pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>);
  407.       pcl::fromROSMsg (*cloud, *cloud_normals);
  408.       std::stringstream cloud_name_normals;
  409.       cloud_name_normals << argv[p_file_indices.at (i)] << "-" << i << "-normals";
  410.       p->addPointCloudNormals<pcl::PointXYZ, pcl::Normal> (cloud_xyz, cloud_normals, normals, normals_scale, cloud_name_normals.str (), viewport);
  411.     }
  412.  
  413.     // If principal curvature lines are enabled
  414.     if (pc != 0)
  415.     {
  416.       if (normals == 0)
  417.         normals = pc;
  418.  
  419.       int normal_idx = pcl::getFieldIndex (*cloud, "normal_x");
  420.       if (normal_idx == -1)
  421.       {
  422.         print_error ("Normal information requested but not available.\n");
  423.         continue;
  424.         //return (-1);
  425.       }
  426.       int pc_idx = pcl::getFieldIndex (*cloud, "principal_curvature_x");
  427.       if (pc_idx == -1)
  428.       {
  429.         print_error ("Principal Curvature information requested but not available.\n");
  430.         continue;
  431.         //return (-1);
  432.       }
  433.       //
  434.       // Convert from blob to pcl::PointCloud
  435.       pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_xyz (new pcl::PointCloud<pcl::PointXYZ>);
  436.       pcl::fromROSMsg (*cloud, *cloud_xyz);
  437.       cloud_xyz->sensor_origin_ = origin;
  438.       cloud_xyz->sensor_orientation_ = orientation;
  439.       pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>);
  440.       pcl::fromROSMsg (*cloud, *cloud_normals);
  441.       pcl::PointCloud<pcl::PrincipalCurvatures>::Ptr cloud_pc (new pcl::PointCloud<pcl::PrincipalCurvatures>);
  442.       pcl::fromROSMsg (*cloud, *cloud_pc);
  443.       std::stringstream cloud_name_normals_pc;
  444.       cloud_name_normals_pc << argv[p_file_indices.at (i)] << "-" << i << "-normals";
  445.       int factor = (std::min)(normals, pc);
  446.       p->addPointCloudNormals<pcl::PointXYZ, pcl::Normal> (cloud_xyz, cloud_normals, factor, normals_scale, cloud_name_normals_pc.str (), viewport);
  447.       p->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_COLOR, 1.0, 0.0, 0.0, cloud_name_normals_pc.str ());
  448.       p->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_LINE_WIDTH, 3, cloud_name_normals_pc.str ());
  449.       cloud_name_normals_pc << "-pc";
  450.       p->addPointCloudPrincipalCurvatures (cloud_xyz, cloud_normals, cloud_pc, factor, pc_scale, cloud_name_normals_pc.str (), viewport);
  451.       p->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_LINE_WIDTH, 3, cloud_name_normals_pc.str ());
  452.     }
  453.  
  454.     // Add every dimension as a possible color
  455.     if (!fcolorparam)
  456.     {
  457.       for (size_t f = 0; f < cloud->fields.size (); ++f)
  458.       {
  459.         if (cloud->fields[f].name == "rgb" || cloud->fields[f].name == "rgba")
  460.           color_handler.reset (new pcl::visualization::PointCloudColorHandlerRGBField<sensor_msgs::PointCloud2> (cloud));
  461.         else
  462.         {
  463.           if (!isValidFieldName (cloud->fields[f].name))
  464.             continue;
  465.           color_handler.reset (new pcl::visualization::PointCloudColorHandlerGenericField<sensor_msgs::PointCloud2> (cloud, cloud->fields[f].name));
  466.         }
  467.         // Add the cloud to the renderer
  468.         //p->addPointCloud<pcl::PointXYZ> (cloud_xyz, color_handler, cloud_name.str (), viewport);
  469.         p->addPointCloud (cloud, color_handler, origin, orientation, cloud_name.str (), viewport);
  470.       }
  471.     }
  472.     // Additionally, add normals as a handler
  473.     geometry_handler.reset (new pcl::visualization::PointCloudGeometryHandlerSurfaceNormal<sensor_msgs::PointCloud2> (cloud));
  474.     if (geometry_handler->isCapable ())
  475.       //p->addPointCloud<pcl::PointXYZ> (cloud_xyz, geometry_handler, cloud_name.str (), viewport);
  476.       p->addPointCloud (cloud, geometry_handler, origin, orientation, cloud_name.str (), viewport);
  477.  
  478.     // Set immediate mode rendering ON
  479.     p->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_IMMEDIATE_RENDERING, 1.0, cloud_name.str ());
  480.  
  481.     // Change the cloud rendered point size
  482.     if (psize.size () > 0)
  483.       p->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, psize.at (i), cloud_name.str ());
  484.  
  485.     // Change the cloud rendered opacity
  486.     if (opaque.size () > 0)
  487.       p->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_OPACITY, opaque.at (i), cloud_name.str ());
  488.  
  489.     // Reset camera viewpoint to center of cloud if camera parameters were not passed manually and this is the first loaded cloud
  490.     //if (i == 0 && !p->cameraParamsSet ())
  491.      // p->resetCameraViewpoint (cloud_name.str ());
  492.   }
  493.  
  494.   if (p)
  495.     p->setBackgroundColor (bcolor[0], bcolor[1], bcolor[2]);
  496.   // Read axes settings
  497.   double axes  = 0.0;
  498.   pcl::console::parse_argument (argc, argv, "-ax", axes);
  499.   if (axes != 0.0 && p)
  500.   {
  501.     double ax_x = 0.0, ax_y = 0.0, ax_z = 0.0;
  502.     pcl::console::parse_3x_arguments (argc, argv, "-ax_pos", ax_x, ax_y, ax_z, false);
  503.     // Draw XYZ axes if command-line enabled
  504.     p->addCoordinateSystem (axes, ax_x, ax_y, ax_z);
  505.   }
  506.  
  507.   // Clean up the memory used by the binary blob
  508.   // Note: avoid resetting the cloud, otherwise the PointPicking callback will fail
  509.   //cloud.reset ();
  510.  
  511.   if (ph)
  512.   {
  513.     print_highlight ("Setting the global Y range for all histograms to: "); print_value ("%f -> %f\n", min_p, max_p);
  514.     ph->setGlobalYRange (min_p, max_p);
  515.     ph->updateWindowPositions ();
  516.     if (p)
  517.       p->spin ();
  518.     else
  519.       ph->spin ();
  520.   }
  521.   else if (p)
  522.     p->spin ();
  523. }
  524. /* ]--- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement