Point Cloud Library (PCL)  1.3.1
histogram_visualizer.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2010, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * $Id: histogram_visualizer.h 3000 2011-10-31 22:57:26Z rusu $
00035  *
00036  */
00037 #ifndef PCL_PCL_HISTOGRAM_VISUALIZER_H_
00038 #define PCL_PCL_HISTOGRAM_VISUALIZER_H_
00039 
00040 #include <pcl/visualization/interactor_style.h>
00041 #include <pcl/visualization/common/common.h>
00042 #include <pcl/visualization/common/ren_win_interact_map.h>
00043 #include <vtkCommand.h>
00044 #include <vtkXYPlotActor.h>
00045 #include <vtkTextProperty.h>
00046 #include <vtkProperty2D.h>
00047 #include <vtkFieldData.h>
00048 #include <vtkDoubleArray.h>
00049 #if ((VTK_MAJOR_VERSION) == 5 && (VTK_MINOR_VERSION <= 4))
00050 #include <pcl/visualization/interactor.h>
00051 #else
00052 #include <vtkRenderWindowInteractor.h>
00053 #endif
00054 
00055 namespace pcl
00056 {
00057   namespace visualization
00058   {
00063     class PCL_EXPORTS PCLHistogramVisualizer
00064     {
00065       public:
00067         PCLHistogramVisualizer ();
00068 
00069         virtual ~PCLHistogramVisualizer () {}
00073 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
00074         void 
00075         spinOnce (int time = 1, bool force_redraw = false);
00076 #else
00077         void 
00078         spinOnce (int time = 1);
00079 #endif
00080 
00081         void 
00082         spin ();
00083         
00090         void 
00091         setBackgroundColor (const double &r, const double &g, const double &b, int viewport = 0);
00092 
00100         template <typename PointT> bool 
00101         addFeatureHistogram (const pcl::PointCloud<PointT> &cloud, 
00102                              int hsize, 
00103                              const std::string &id = "cloud", int win_width = 640, int win_height = 200);
00104 
00112         bool 
00113         addFeatureHistogram (const sensor_msgs::PointCloud2 &cloud, 
00114                              const std::string &field_name, 
00115                              const std::string &id = "cloud", int win_width = 640, int win_height = 200);
00116 
00125         template <typename PointT> bool 
00126         addFeatureHistogram (const pcl::PointCloud<PointT> &cloud, 
00127                              const std::string &field_name, 
00128                              const int index,
00129                              const std::string &id = "cloud", int win_width = 640, int win_height = 200);
00130 
00139         bool 
00140         addFeatureHistogram (const sensor_msgs::PointCloud2 &cloud, 
00141                              const std::string &field_name, 
00142                              const int index,
00143                              const std::string &id = "cloud", int win_width = 640, int win_height = 200);
00144 
00149         void 
00150         setGlobalYRange (float minp, float maxp);
00151 
00153         void 
00154         updateWindowPositions ();
00155 #if ((VTK_MAJOR_VERSION) == 5 && (VTK_MINOR_VERSION <= 4))
00156 
00157         bool 
00158         wasStopped ();
00159         
00161         void 
00162         resetStoppedFlag ();
00163 #endif
00164       protected:
00165 
00173         void
00174         createActor (const vtkSmartPointer<vtkDoubleArray> &xy_array, 
00175                      RenWinInteract &renwinint,
00176                      const std::string &id, const int win_width, const int win_height);
00177 
00178       private:
00180         RenWinInteractMap wins_;
00181 
00182         struct ExitMainLoopTimerCallback : public vtkCommand
00183         {
00184           static ExitMainLoopTimerCallback* New ()
00185           {
00186             return (new ExitMainLoopTimerCallback);
00187           }
00188           virtual void 
00189           Execute (vtkObject* vtkNotUsed (caller), unsigned long event_id, void* call_data)
00190           {
00191             if (event_id != vtkCommand::TimerEvent)
00192               return;
00193             int timer_id = *(int*)call_data;
00194 
00195             if (timer_id != right_timer_id)
00196               return;
00197 
00198             // Stop vtk loop and send notification to app to wake it up
00199 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
00200             interact->stopLoop ();
00201 #else
00202             interact->TerminateApp ();
00203 #endif
00204           }
00205           int right_timer_id;
00206 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
00207           PCLVisualizerInteractor *interact;
00208 #else
00209           vtkRenderWindowInteractor *interact;
00210 #endif
00211         };
00212         
00213         struct ExitCallback : public vtkCommand
00214         {
00215           static ExitCallback* New ()
00216           {
00217             return (new ExitCallback);
00218           }
00219           virtual void 
00220           Execute (vtkObject* caller, unsigned long event_id, void* call_data)
00221           {
00222             if (event_id != vtkCommand::ExitEvent)
00223               return;
00224 #if ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
00225            interact->stopped = true;
00226 #else
00227             his->stopped_ = true;
00228 #endif
00229           }
00230 #if (VTK_MAJOR_VERSION == 5 && (VTK_MINOR_VERSION <= 4))
00231           PCLVisualizerInteractor *interact;
00232 #else
00233           PCLHistogramVisualizer *his;
00234 #endif
00235         };
00236 
00238         vtkSmartPointer<ExitMainLoopTimerCallback> exit_main_loop_timer_callback_;
00239         vtkSmartPointer<ExitCallback> exit_callback_;
00240 #if !((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION <= 4))
00241 
00242         bool stopped_;
00243 #endif
00244     };
00245   }
00246 }
00247 
00248 #include <pcl/visualization/impl/histogram_visualizer.hpp>
00249 
00250 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines