Point Cloud Library (PCL)
1.3.1
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2011, 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 * Author: Suat Gedikli (gedikli@willowgarage.com) 00035 */ 00036 00037 #ifndef PCL_VISUALIZATION_IMAGE_VISUALIZER_H__ 00038 #define PCL_VISUALIZATION_IMAGE_VISUALIZER_H__ 00039 00040 #include <vtkImageViewer.h> 00041 #include <vtkImageViewer2.h> 00042 #include <vtkInteractorStyle.h> 00043 #include <boost/shared_array.hpp> 00044 #include <pcl/pcl_macros.h> 00045 #include <pcl/console/print.h> 00046 #include <vtkRenderWindow.h> 00047 #include <vtkRenderWindowInteractor.h> 00048 #include <vtkSmartPointer.h> 00049 #include <boost/signals2.hpp> 00050 #include <vtkCallbackCommand.h> 00051 #include <pcl/visualization/interactor_style.h> 00052 00053 namespace pcl 00054 { 00055 namespace visualization 00056 { 00057 typedef Eigen::Array<unsigned char, 3, 1> Vector3ub; 00058 static const Vector3ub green_color(0,255,0); 00059 static const Vector3ub red_color(255,0,0); 00060 static const Vector3ub blue_color(0,0,255); 00061 00062 class PCL_EXPORTS ImageViewer 00063 { 00064 public: 00065 ImageViewer (const std::string& window_title = ""); 00066 virtual ~ImageViewer (); 00067 00068 void 00069 showRGBImage (const unsigned char* data, unsigned width, unsigned height); 00070 00071 void 00072 showRGBImage (const pcl::PointCloud<pcl::PointXYZRGB> &data); 00073 00074 void 00075 showFloatImage (const float* data, unsigned int width, unsigned int height, 00076 float min_value, float max_value, bool grayscale = false); 00077 00078 void 00079 showShortImage (const unsigned short* short_image, unsigned int width, unsigned int height, 00080 unsigned short min_value, unsigned short max_value, bool grayscale); 00081 00082 void 00083 showAngleImage (const float* data, unsigned width, unsigned height); 00084 00085 void 00086 showHalfAngleImage (const float* data, unsigned width, unsigned height); 00087 00093 void 00094 markPoint (size_t u, size_t v, Vector3ub fg_color, Vector3ub bg_color = red_color, float radius = 2); 00095 00096 void 00097 setName(const std::string& name) 00098 { 00099 strcpy(image_viewer_->GetWindowName (), name.c_str ()); 00100 } 00101 00103 void 00104 spin (); 00105 00111 void 00112 spinOnce (int time = 1, bool force_redraw = false); 00113 00119 boost::signals2::connection 00120 registerKeyboardCallback (void (*callback) (const pcl::visualization::KeyboardEvent&, void*), 00121 void* cookie = NULL) 00122 { 00123 return (registerKeyboardCallback (boost::bind (callback, _1, cookie))); 00124 } 00125 00132 template<typename T> boost::signals2::connection 00133 registerKeyboardCallback (void (T::*callback) (const pcl::visualization::KeyboardEvent&, void*), 00134 T& instance, void* cookie = NULL) 00135 { 00136 return (registerKeyboardCallback (boost::bind (callback, boost::ref (instance), _1, cookie))); 00137 } 00138 00143 boost::signals2::connection 00144 registerKeyboardCallback (boost::function<void (const pcl::visualization::KeyboardEvent&)> ); 00145 00151 boost::signals2::connection 00152 registerMouseCallback (void (*callback) (const pcl::visualization::MouseEvent&, void*), 00153 void* cookie = NULL) 00154 { 00155 return (registerMouseCallback (boost::bind (callback, _1, cookie))); 00156 } 00157 00164 template<typename T> boost::signals2::connection 00165 registerMouseCallback (void (T::*callback) (const pcl::visualization::MouseEvent&, void*), 00166 T& instance, void* cookie = NULL) 00167 { 00168 return (registerMouseCallback (boost::bind (callback, boost::ref (instance), _1, cookie))); 00169 } 00170 00175 boost::signals2::connection 00176 registerMouseCallback (boost::function<void (const pcl::visualization::MouseEvent&)> ); 00177 00178 protected: // methods 00180 void 00181 resetStoppedFlag () { stopped_ = false; } 00182 00183 void 00184 emitMouseEvent (unsigned long event_id); 00185 00186 void 00187 emitKeyboardEvent (unsigned long event_id); 00188 00189 // Callbacks used to register for vtk command 00190 static void 00191 MouseCallback (vtkObject*, unsigned long eid, void* clientdata, void *calldata); 00192 static void 00193 KeyboardCallback (vtkObject*, unsigned long eid, void* clientdata, void *calldata); 00194 00195 protected: // types 00196 struct ExitMainLoopTimerCallback : public vtkCommand 00197 { 00198 static ExitMainLoopTimerCallback* New () 00199 { 00200 return (new ExitMainLoopTimerCallback); 00201 } 00202 virtual void 00203 Execute (vtkObject* vtkNotUsed (caller), unsigned long event_id, void* call_data) 00204 { 00205 if (event_id != vtkCommand::TimerEvent) 00206 return; 00207 int timer_id = *(int*)call_data; 00208 if (timer_id != right_timer_id) 00209 return; 00210 window->interactor_->TerminateApp (); 00211 } 00212 int right_timer_id; 00213 ImageViewer* window; 00214 }; 00215 struct ExitCallback : public vtkCommand 00216 { 00217 static ExitCallback* New () 00218 { 00219 return (new ExitCallback); 00220 } 00221 virtual void 00222 Execute (vtkObject* caller, unsigned long event_id, void* call_data) 00223 { 00224 if (event_id != vtkCommand::ExitEvent) 00225 return; 00226 window->stopped_ = true; 00227 window->interactor_->TerminateApp (); 00228 } 00229 ImageViewer* window; 00230 }; 00231 00232 private: 00233 boost::signals2::signal<void (const pcl::visualization::MouseEvent&)> mouse_signal_; 00234 boost::signals2::signal<void (const pcl::visualization::KeyboardEvent&)> keyboard_signal_; 00235 00236 vtkSmartPointer<vtkRenderWindowInteractor> interactor_; 00237 vtkCallbackCommand* mouse_command_; 00238 vtkCallbackCommand* keyboard_command_; 00239 00241 vtkSmartPointer<ExitMainLoopTimerCallback> exit_main_loop_timer_callback_; 00242 vtkSmartPointer<ExitCallback> exit_callback_; 00243 00245 vtkSmartPointer<vtkImageViewer> image_viewer_; 00246 00248 boost::shared_array<unsigned char> data_; 00250 size_t data_size_; 00251 00253 bool stopped_; 00254 00256 int timer_id_; 00257 }; 00258 } 00259 } 00260 00261 #endif /* __IMAGE_VISUALIZER_H__ */ 00262