Point Cloud Library (PCL)  1.9.1-dev
pcl_plotter.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, 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  */
37 
38 #ifndef PCL_VISUALUALIZATION_PCL_PLOTTER_IMPL_H_
39 #define PCL_VISUALUALIZATION_PCL_PLOTTER_IMPL_H_
40 
41 template <typename PointT> bool
43  const pcl::PointCloud<PointT> &cloud, int hsize,
44  const std::string &id, int win_width, int win_height)
45 {
46  std::vector<double> array_x(hsize), array_y(hsize);
47 
48  // Parse the cloud data and store it in the array
49  for (int i = 0; i < hsize; ++i)
50  {
51  array_x[i] = i;
52  array_y[i] = cloud.points[0].histogram[i];
53  }
54 
55  this->addPlotData(array_x, array_y, id.c_str(), vtkChart::LINE);
56  setWindowSize (win_width, win_height);
57  return true;
58 }
59 
60 
61 template <typename PointT> bool
63  const pcl::PointCloud<PointT> &cloud,
64  const std::string &field_name,
65  const int index,
66  const std::string &id, int win_width, int win_height)
67 {
68  if (index < 0 || index >= cloud.points.size ())
69  {
70  PCL_ERROR ("[addFeatureHistogram] Invalid point index (%d) given!\n", index);
71  return (false);
72  }
73 
74  // Get the fields present in this cloud
75  std::vector<pcl::PCLPointField> fields;
76  // Check if our field exists
77  int field_idx = pcl::getFieldIndex<PointT> (cloud, field_name, fields);
78  if (field_idx == -1)
79  {
80  PCL_ERROR ("[addFeatureHistogram] The specified field <%s> does not exist!\n", field_name.c_str ());
81  return (false);
82  }
83 
84  int hsize = fields[field_idx].count;
85  std::vector<double> array_x (hsize), array_y (hsize);
86 
87  for (int i = 0; i < hsize; ++i)
88  {
89  array_x[i] = i;
90  float data;
91  // TODO: replace float with the real data type
92  memcpy (&data, reinterpret_cast<const char*> (&cloud.points[index]) + fields[field_idx].offset + i * sizeof (float), sizeof (float));
93  array_y[i] = data;
94  }
95 
96  this->addPlotData(array_x, array_y, id.c_str(), vtkChart::LINE);
97  setWindowSize (win_width, win_height);
98  return (true);
99 }
100 
101 #endif /* PCL_VISUALUALIZATION_PCL_PLOTTER_IMPL_H_ */
102 
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:423
void setWindowSize(int w, int h)
set/get method for the window size.
void addPlotData(double const *array_X, double const *array_Y, unsigned long size, char const *name="Y Axis", int type=vtkChart::LINE, char const *color=nullptr)
Adds a plot with correspondences in the arrays arrayX and arrayY.
bool addFeatureHistogram(const pcl::PointCloud< PointT > &cloud, int hsize, const std::string &id="cloud", int win_width=640, int win_height=200)
Add a histogram feature to screen as a separate window, from a cloud containing a single histogram...
Definition: pcl_plotter.hpp:42
PointCloud represents the base class in PCL for storing collections of 3D points. ...