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