Point Cloud Library (PCL)  1.14.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 
42 namespace pcl
43 {
44 
45 namespace visualization
46 {
47 
48 template <typename PointT> bool
50  const pcl::PointCloud<PointT> &cloud, int hsize,
51  const std::string &id, int win_width, int win_height)
52 {
53  std::vector<double> array_x(hsize), array_y(hsize);
54 
55  // Parse the cloud data and store it in the array
56  for (int i = 0; i < hsize; ++i)
57  {
58  array_x[i] = i;
59  array_y[i] = cloud[0].histogram[i];
60  }
61 
62  this->addPlotData(array_x, array_y, id.c_str(), vtkChart::LINE);
63  setWindowSize (win_width, win_height);
64  return true;
65 }
66 
67 
68 template <typename PointT> bool
70  const pcl::PointCloud<PointT> &cloud,
71  const std::string &field_name,
72  const pcl::index_t index,
73  const std::string &id, int win_width, int win_height)
74 {
75  if (index < 0 || index >= cloud.size ())
76  {
77  PCL_ERROR ("[addFeatureHistogram] Invalid point index (%d) given!\n", index);
78  return (false);
79  }
80 
81  // Get the fields present in this cloud
82  std::vector<pcl::PCLPointField> fields;
83  // Check if our field exists
84  int field_idx = pcl::getFieldIndex<PointT> (cloud, field_name, fields);
85  if (field_idx == -1)
86  {
87  PCL_ERROR ("[addFeatureHistogram] The specified field <%s> does not exist!\n", field_name.c_str ());
88  return (false);
89  }
90 
91  int hsize = fields[field_idx].count;
92  std::vector<double> array_x (hsize), array_y (hsize);
93 
94  for (int i = 0; i < hsize; ++i)
95  {
96  array_x[i] = i;
97  float data;
98  // TODO: replace float with the real data type
99  memcpy (&data, reinterpret_cast<const char*> (&cloud[index]) + fields[field_idx].offset + i * sizeof (float), sizeof (float));
100  array_y[i] = data;
101  }
102 
103  this->addPlotData(array_x, array_y, id.c_str(), vtkChart::LINE);
104  setWindowSize (win_width, win_height);
105  return (true);
106 }
107 
108 } // namespace visualization
109 } // namespace pcl
110 
111 #endif /* PCL_VISUALUALIZATION_PCL_PLOTTER_IMPL_H_ */
112 
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
std::size_t size() const
Definition: point_cloud.h:443
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.
void setWindowSize(int w, int h)
set/get method for the window size.
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:49
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
Definition: types.h:112