Point Cloud Library (PCL)  1.5.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
histogram_visualizer.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2010-2011, Willow Garage, Inc.
00006  *
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of Willow Garage, Inc. nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  * $Id: histogram_visualizer.h 4702 2012-02-23 09:39:33Z gedikli $
00037  *
00038  */
00039 #ifndef PCL_PCL_HISTOGRAM_VISUALIZER_H_
00040 #define PCL_PCL_HISTOGRAM_VISUALIZER_H_
00041 
00042 #include <pcl/visualization/interactor_style.h>
00043 #include <pcl/visualization/common/common.h>
00044 #include <pcl/visualization/common/ren_win_interact_map.h>
00045 #include <vtkCommand.h>
00046 #include <vtkXYPlotActor.h>
00047 #include <vtkTextProperty.h>
00048 #include <vtkProperty2D.h>
00049 #include <vtkFieldData.h>
00050 #include <vtkDoubleArray.h>
00051 #if ((VTK_MAJOR_VERSION) == 5 && (VTK_MINOR_VERSION <= 4))
00052 #include <pcl/visualization/interactor.h>
00053 #else
00054 #include <vtkRenderWindowInteractor.h>
00055 #endif
00056 
00057 namespace pcl
00058 {
00059   namespace visualization
00060   {
00065     class PCL_EXPORTS PCLHistogramVisualizer
00066     {
00067       public:
00069         PCLHistogramVisualizer ();
00070 
00071         virtual ~PCLHistogramVisualizer () {}
00075 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
00076         void 
00077         spinOnce (int time = 1, bool force_redraw = false);
00078 #else
00079         void 
00080         spinOnce (int time = 1);
00081 #endif
00082 
00083         void 
00084         spin ();
00085         
00092         void 
00093         setBackgroundColor (const double &r, const double &g, const double &b, int viewport = 0);
00094 
00102         template <typename PointT> bool 
00103         addFeatureHistogram (const pcl::PointCloud<PointT> &cloud, 
00104                              int hsize, 
00105                              const std::string &id = "cloud", int win_width = 640, int win_height = 200);
00106 
00114         bool 
00115         addFeatureHistogram (const sensor_msgs::PointCloud2 &cloud, 
00116                              const std::string &field_name, 
00117                              const std::string &id = "cloud", int win_width = 640, int win_height = 200);
00118 
00127         template <typename PointT> bool 
00128         addFeatureHistogram (const pcl::PointCloud<PointT> &cloud, 
00129                              const std::string &field_name, 
00130                              const int index,
00131                              const std::string &id = "cloud", int win_width = 640, int win_height = 200);
00132 
00141         bool 
00142         addFeatureHistogram (const sensor_msgs::PointCloud2 &cloud, 
00143                              const std::string &field_name, 
00144                              const int index,
00145                              const std::string &id = "cloud", int win_width = 640, int win_height = 200);
00146         
00152         template <typename PointT> bool 
00153         updateFeatureHistogram (const pcl::PointCloud<PointT> &cloud, int hsize, const std::string &id = "cloud");
00154         
00155                              
00161         bool 
00162         updateFeatureHistogram (const sensor_msgs::PointCloud2 &cloud, 
00163                                 const std::string &field_name, 
00164                                 const std::string &id = "cloud");
00165                              
00166         
00173         template <typename PointT> bool 
00174         updateFeatureHistogram (const pcl::PointCloud<PointT> &cloud, const std::string &field_name,
00175                                  const int index, const std::string &id = "cloud");
00176         
00177                              
00184         bool 
00185         updateFeatureHistogram (const sensor_msgs::PointCloud2 &cloud, 
00186                                 const std::string &field_name, const int index,
00187                                 const std::string &id = "cloud");         
00188 
00189 
00194         void 
00195         setGlobalYRange (float minp, float maxp);
00196 
00198         void 
00199         updateWindowPositions ();
00200 #if ((VTK_MAJOR_VERSION) == 5 && (VTK_MINOR_VERSION <= 4))
00201 
00202         bool 
00203         wasStopped ();
00204         
00206         void 
00207         resetStoppedFlag ();
00208 #endif
00209       protected:
00210 
00218         void
00219         createActor (const vtkSmartPointer<vtkDoubleArray> &xy_array, 
00220                      RenWinInteract &renwinint,
00221                      const std::string &id, const int win_width, const int win_height);
00222         
00228         void
00229         reCreateActor (const vtkSmartPointer<vtkDoubleArray> &xy_array, 
00230                        RenWinInteract* renwinupd, const int hsize);
00231 
00232       private:
00234         RenWinInteractMap wins_;
00235 
00236         struct ExitMainLoopTimerCallback : public vtkCommand
00237         {
00238           static ExitMainLoopTimerCallback* New ()
00239           {
00240             return (new ExitMainLoopTimerCallback);
00241           }
00242           virtual void 
00243           Execute (vtkObject* vtkNotUsed (caller), unsigned long event_id, void* call_data)
00244           {
00245             if (event_id != vtkCommand::TimerEvent)
00246               return;
00247             int timer_id = *(int*)call_data;
00248 
00249             if (timer_id != right_timer_id)
00250               return;
00251 
00252             // Stop vtk loop and send notification to app to wake it up
00253 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
00254             interact->stopLoop ();
00255 #else
00256             interact->TerminateApp ();
00257 #endif
00258           }
00259           int right_timer_id;
00260 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
00261           PCLVisualizerInteractor *interact;
00262 #else
00263           vtkRenderWindowInteractor *interact;
00264 #endif
00265         };
00266         
00267         struct ExitCallback : public vtkCommand
00268         {
00269           static ExitCallback* New ()
00270           {
00271             return (new ExitCallback);
00272           }
00273           virtual void 
00274           Execute (vtkObject* caller, unsigned long event_id, void* call_data)
00275           {
00276             if (event_id != vtkCommand::ExitEvent)
00277               return;
00278 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
00279            interact->stopped = true;
00280 #else
00281             his->stopped_ = true;
00282 #endif
00283           }
00284 #if (VTK_MAJOR_VERSION == 5 && (VTK_MINOR_VERSION <= 4))
00285           PCLVisualizerInteractor *interact;
00286 #else
00287           PCLHistogramVisualizer *his;
00288 #endif
00289         };
00290 
00292         vtkSmartPointer<ExitMainLoopTimerCallback> exit_main_loop_timer_callback_;
00293         vtkSmartPointer<ExitCallback> exit_callback_;
00294 #if !((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
00295 
00296         bool stopped_;
00297 #endif
00298     };
00299   }
00300 }
00301 
00302 #include <pcl/visualization/impl/histogram_visualizer.hpp>
00303 
00304 #endif