Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
histogram_visualizer.h
Go to the documentation of this file.
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: histogram_visualizer.h 6161 2012-07-05 17:37:29Z rusu $
37  *
38  */
39 #ifndef PCL_PCL_HISTOGRAM_VISUALIZER_H_
40 #define PCL_PCL_HISTOGRAM_VISUALIZER_H_
41 
43 #include <pcl/visualization/vtk.h>
46 
47 namespace pcl
48 {
49  namespace visualization
50  {
56  {
57  public:
60 
65 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
66  void
67  spinOnce (int time = 1, bool force_redraw = false);
68 #else
69  void
70  spinOnce (int time = 1);
71 #endif
72 
73  void
74  spin ();
75 
82  void
83  setBackgroundColor (const double &r, const double &g, const double &b, int viewport = 0);
84 
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 
104  bool
105  addFeatureHistogram (const sensor_msgs::PointCloud2 &cloud,
106  const std::string &field_name,
107  const std::string &id = "cloud", int win_width = 640, int win_height = 200);
108 
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 
131  bool
132  addFeatureHistogram (const sensor_msgs::PointCloud2 &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 
142  template <typename PointT> bool
143  updateFeatureHistogram (const pcl::PointCloud<PointT> &cloud, int hsize, const std::string &id = "cloud");
144 
145 
151  bool
152  updateFeatureHistogram (const sensor_msgs::PointCloud2 &cloud,
153  const std::string &field_name,
154  const std::string &id = "cloud");
155 
156 
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 
174  bool
175  updateFeatureHistogram (const sensor_msgs::PointCloud2 &cloud,
176  const std::string &field_name, const int index,
177  const std::string &id = "cloud");
178 
179 
184  void
185  setGlobalYRange (float minp, float maxp);
186 
188  void
189  updateWindowPositions ();
190 #if ((VTK_MAJOR_VERSION) == 5 && (VTK_MINOR_VERSION <= 4))
191 
192  bool
193  wasStopped ();
194 
196  void
197  resetStoppedFlag ();
198 #endif
199  protected:
200 
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 
218  void
219  reCreateActor (const vtkSmartPointer<vtkDoubleArray> &xy_array,
220  RenWinInteract* renwinupd, const int hsize);
221 
222  private:
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* vtkNotUsed (caller), unsigned long event_id, void* call_data)
234  {
235  if (event_id != vtkCommand::TimerEvent)
236  return;
237  int timer_id = *(reinterpret_cast<int*> (call_data));
238 
239  if (timer_id != right_timer_id)
240  return;
241 
242  // Stop vtk loop and send notification to app to wake it up
243 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
244  interact->stopLoop ();
245 #else
246  interact->TerminateApp ();
247 #endif
248  }
249  int right_timer_id;
250 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
251  PCLVisualizerInteractor *interact;
252 #else
253  vtkRenderWindowInteractor *interact;
254 #endif
255  };
256 
257  struct ExitCallback : public vtkCommand
258  {
259  ExitCallback () : his () {}
260 
261  static ExitCallback* New ()
262  {
263  return (new ExitCallback);
264  }
265 
266  virtual void
267  Execute (vtkObject*, unsigned long event_id, void*)
268  {
269  if (event_id != vtkCommand::ExitEvent)
270  return;
271  his->stopped_ = true;
272  }
273  PCLHistogramVisualizer *his;
274  };
275 
277  vtkSmartPointer<ExitMainLoopTimerCallback> exit_main_loop_timer_callback_;
278  vtkSmartPointer<ExitCallback> exit_callback_;
280  bool stopped_;
281  };
282  }
283 }
284 
286 
287 #endif