Point Cloud Library (PCL)  1.14.1-dev
histogram_visualizer.h
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  * $Id$
37  *
38  */
39 
40 #pragma once
41 
42 #include <pcl/visualization/interactor_style.h>
43 #include <pcl/visualization/common/common.h>
44 #include <pcl/visualization/common/ren_win_interact_map.h>
45 
46 class vtkRenderWindowInteractor;
47 
48 namespace pcl
49 {
50  namespace visualization
51  {
52  /** \brief PCL histogram visualizer main class.
53  * \author Radu Bogdan Rusu
54  * \ingroup visualization
55  */
57  {
58  public:
59  using Ptr = shared_ptr<PCLHistogramVisualizer>;
60  using ConstPtr = shared_ptr<const PCLHistogramVisualizer>;
61 
62  /** \brief PCL histogram visualizer constructor. */
64 
65  virtual ~PCLHistogramVisualizer () = default;
66  /** \brief Spin once method. Calls the interactor and updates the screen once.
67  * \param[in] time - How long (in ms) should the visualization loop be allowed to run.
68  */
69  void
70  spinOnce (int time = 1);
71 
72  /** \brief Spin method. Calls the interactor and runs an internal loop. */
73  void
74  spin ();
75 
76  /** \brief Set the viewport's background color.
77  * \param[in] r the red component of the RGB color
78  * \param[in] g the green component of the RGB color
79  * \param[in] b the blue component of the RGB color
80  */
81  void
82  setBackgroundColor (const double &r, const double &g, const double &b);
83 
84  /** \brief Add a histogram feature to screen as a separate window, from a cloud containing a single histogram.
85  * \param[in] cloud the PointCloud dataset containing the histogram
86  * \param[in] hsize the length of the histogram
87  * \param[in] id the point cloud object id (default: cloud)
88  * \param[in] win_width the width of the window
89  * \param[in] win_height the height of the window
90  */
91  template <typename PointT> bool
92  addFeatureHistogram (const pcl::PointCloud<PointT> &cloud,
93  int hsize,
94  const std::string &id = "cloud", int win_width = 640, int win_height = 200);
95 
96  /** \brief Add a histogram feature to screen as a separate window from a cloud containing a single histogram.
97  * \param[in] cloud the PointCloud dataset containing the histogram
98  * \param[in] field_name the field name containing the histogram
99  * \param[in] id the point cloud object id (default: cloud)
100  * \param[in] win_width the width of the window
101  * \param[in] win_height the height of the window
102  */
103  bool
105  const std::string &field_name,
106  const std::string &id = "cloud", int win_width = 640, int win_height = 200);
107 
108  /** \brief Add a histogram feature to screen as a separate window.
109  * \param[in] cloud the PointCloud dataset containing the histogram
110  * \param[in] field_name the field name containing the histogram
111  * \param[in] index the point index to extract the histogram from
112  * \param[in] id the point cloud object id (default: cloud)
113  * \param[in] win_width the width of the window
114  * \param[in] win_height the height of the window
115  */
116  template <typename PointT> bool
117  addFeatureHistogram (const pcl::PointCloud<PointT> &cloud,
118  const std::string &field_name,
119  const pcl::index_t index,
120  const std::string &id = "cloud", int win_width = 640, int win_height = 200);
121 
122  /** \brief Add a histogram feature to screen as a separate window.
123  * \param[in] cloud the PointCloud dataset containing the histogram
124  * \param[in] field_name the field name containing the histogram
125  * \param[in] index the point index to extract the histogram from
126  * \param[in] id the point cloud object id (default: cloud)
127  * \param[in] win_width the width of the window
128  * \param[in] win_height the height of the window
129  */
130  bool
132  const std::string &field_name,
133  const pcl::index_t index,
134  const std::string &id = "cloud", int win_width = 640, int win_height = 200);
135 
136  /** \brief Update a histogram feature that is already on screen, with a cloud containing a single histogram.
137  * \param[in] cloud the PointCloud dataset containing the histogram
138  * \param[in] hsize the length of the histogram
139  * \param[in] id the point cloud object id (default: cloud)
140  */
141  template <typename PointT> bool
142  updateFeatureHistogram (const pcl::PointCloud<PointT> &cloud, int hsize, const std::string &id = "cloud");
143 
144 
145  /** \brief Update a histogram feature that is already on screen, with a cloud containing a single histogram.
146  * \param[in] cloud the PointCloud dataset containing the histogram
147  * \param[in] field_name the field name containing the histogram
148  * \param[in] id the point cloud object id (default: cloud)
149  */
150  bool
152  const std::string &field_name,
153  const std::string &id = "cloud");
154 
155 
156  /** \brief Update a histogram feature that is already on screen, with a cloud containing a single histogram.
157  * \param[in] cloud the PointCloud dataset containing the histogram
158  * \param[in] field_name the field name containing the histogram
159  * \param[in] index the point index to extract the histogram from
160  * \param[in] id the point cloud object id (default: cloud)
161  */
162  template <typename PointT> bool
163  updateFeatureHistogram (const pcl::PointCloud<PointT> &cloud, const std::string &field_name,
164  const pcl::index_t index, const std::string &id = "cloud");
165 
166 
167  /** \brief Update a histogram feature that is already on screen, with a cloud containing a single histogram.
168  * \param[in] cloud the PointCloud dataset containing the histogram
169  * \param[in] field_name the field name containing the histogram
170  * \param[in] index the point index to extract the histogram from
171  * \param[in] id the point cloud object id (default: cloud)
172  */
173  bool
175  const std::string &field_name, const pcl::index_t index,
176  const std::string &id = "cloud");
177 
178 
179  /** \brief Set the Y range to minp-maxp for all histograms.
180  * \param[in] minp the minimum Y range
181  * \param[in] maxp the maximum Y range
182  */
183  void
184  setGlobalYRange (float minp, float maxp);
185 
186  /** \brief Update all window positions on screen so that they fit. */
187  void
189 
190  protected:
191 
192  /** \brief Create a 2D actor from the given vtkDoubleArray histogram and add it to the screen.
193  * \param[in] xy_array the input vtkDoubleArray holding the histogram data
194  * \param[out] renwinint the resultant render window interactor holding the rendered object
195  * \param[in] id the point cloud object id
196  * \param[in] win_width the width of the window
197  * \param[in] win_height the height of the window
198  */
199  void
201  RenWinInteract &renwinint,
202  const std::string &id, const int win_width, const int win_height);
203 
204  /** \brief Remove the current 2d actor and create a new 2D actor from the given vtkDoubleArray histogram and add it to the screen.
205  * \param[in] xy_array the input vtkDoubleArray holding the histogram data
206  * \param[out] renwinupd the resultant render window interactor holding the rendered object
207  * \param[in] hsize Histogram size
208  */
209  void
211  RenWinInteract* renwinupd, const int hsize);
212 
213  private:
214  /** \brief A map of all windows on screen (with their renderers and interactors). */
215  RenWinInteractMap wins_;
216 
217  struct ExitMainLoopTimerCallback : public vtkCommand
218  {
219  static ExitMainLoopTimerCallback* New ()
220  {
221  return (new ExitMainLoopTimerCallback);
222  }
223  void
224  Execute (vtkObject*, unsigned long event_id, void* call_data) override;
225 
226  int right_timer_id;
227  vtkRenderWindowInteractor *interact;
228  };
229 
230  struct ExitCallback : public vtkCommand
231  {
232  ExitCallback () = default;
233 
234  static ExitCallback* New ()
235  {
236  return (new ExitCallback);
237  }
238 
239  void
240  Execute (vtkObject*, unsigned long event_id, void*) override;
241 
242  PCLHistogramVisualizer *his{nullptr};
243  };
244 
245  /** \brief Callback object enabling us to leave the main loop, when a timer fires. */
246  vtkSmartPointer<ExitMainLoopTimerCallback> exit_main_loop_timer_callback_;
247  vtkSmartPointer<ExitCallback> exit_callback_;
248  /** \brief Set to true when the histogram visualizer is ready to be terminated. */
249  bool stopped_{false};
250  };
251  }
252 }
253 
254 #include <pcl/visualization/impl/histogram_visualizer.hpp>
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
PCL histogram visualizer main class.
void updateWindowPositions()
Update all window positions on screen so that they fit.
shared_ptr< const PCLHistogramVisualizer > ConstPtr
void setGlobalYRange(float minp, float maxp)
Set the Y range to minp-maxp for all histograms.
bool addFeatureHistogram(const pcl::PCLPointCloud2 &cloud, const std::string &field_name, const pcl::index_t index, const std::string &id="cloud", int win_width=640, int win_height=200)
Add a histogram feature to screen as a separate window.
bool updateFeatureHistogram(const pcl::PCLPointCloud2 &cloud, const std::string &field_name, const pcl::index_t index, const std::string &id="cloud")
Update a histogram feature that is already on screen, with a cloud containing a single histogram.
void setBackgroundColor(const double &r, const double &g, const double &b)
Set the viewport's background color.
void createActor(const vtkSmartPointer< vtkDoubleArray > &xy_array, RenWinInteract &renwinint, const std::string &id, const int win_width, const int win_height)
Create a 2D actor from the given vtkDoubleArray histogram and add it to the screen.
void reCreateActor(const vtkSmartPointer< vtkDoubleArray > &xy_array, RenWinInteract *renwinupd, const int hsize)
Remove the current 2d actor and create a new 2D actor from the given vtkDoubleArray histogram and add...
PCLHistogramVisualizer()
PCL histogram visualizer constructor.
void spinOnce(int time=1)
Spin once method.
shared_ptr< PCLHistogramVisualizer > Ptr
bool updateFeatureHistogram(const pcl::PCLPointCloud2 &cloud, const std::string &field_name, const std::string &id="cloud")
Update a histogram feature that is already on screen, with a cloud containing a single histogram.
bool addFeatureHistogram(const pcl::PCLPointCloud2 &cloud, const std::string &field_name, 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.
std::map< std::string, RenWinInteract > RenWinInteractMap
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
#define PCL_EXPORTS
Definition: pcl_macros.h:323