|
Point Cloud Library (PCL)
1.4.0
|
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 */ 00037 00038 #ifndef PCL_VISUALIZATION_IMAGE_VISUALIZER_H__ 00039 #define PCL_VISUALIZATION_IMAGE_VISUALIZER_H__ 00040 00041 #include <vtkImageViewer.h> 00042 #include <vtkImageViewer2.h> 00043 #include <vtkInteractorStyle.h> 00044 #include <boost/shared_array.hpp> 00045 #include <pcl/pcl_macros.h> 00046 #include <pcl/console/print.h> 00047 #include <vtkRenderWindow.h> 00048 #include <vtkRenderWindowInteractor.h> 00049 #include <vtkSmartPointer.h> 00050 #include <boost/signals2.hpp> 00051 #include <vtkCallbackCommand.h> 00052 #include <pcl/visualization/interactor_style.h> 00053 00054 namespace pcl 00055 { 00056 namespace visualization 00057 { 00058 typedef Eigen::Array<unsigned char, 3, 1> Vector3ub; 00059 static const Vector3ub green_color(0,255,0); 00060 static const Vector3ub red_color(255,0,0); 00061 static const Vector3ub blue_color(0,0,255); 00062 00066 class PCL_EXPORTS ImageViewer 00067 { 00068 public: 00072 ImageViewer (const std::string& window_title = ""); 00073 00075 virtual ~ImageViewer (); 00076 00082 void 00083 showRGBImage (const unsigned char* data, unsigned width, unsigned height); 00084 00088 void 00089 showRGBImage (const pcl::PointCloud<pcl::PointXYZRGB> &data); 00090 00099 void 00100 showFloatImage (const float* data, unsigned int width, unsigned int height, 00101 float min_value, float max_value, bool grayscale = false); 00102 00111 void 00112 showShortImage (const unsigned short* short_image, unsigned int width, unsigned int height, 00113 unsigned short min_value, unsigned short max_value, bool grayscale = false); 00114 00120 void 00121 showAngleImage (const float* data, unsigned width, unsigned height); 00122 00128 void 00129 showHalfAngleImage (const float* data, unsigned width, unsigned height); 00130 00138 void 00139 markPoint (size_t u, size_t v, Vector3ub fg_color, Vector3ub bg_color = red_color, float radius = 2); 00140 00144 void 00145 setWindowTitle (const std::string& name) 00146 { 00147 strcpy (image_viewer_->GetWindowName (), name.c_str ()); 00148 } 00149 00151 void 00152 spin (); 00153 00159 void 00160 spinOnce (int time = 1, bool force_redraw = false); 00161 00167 boost::signals2::connection 00168 registerKeyboardCallback (void (*callback) (const pcl::visualization::KeyboardEvent&, void*), 00169 void* cookie = NULL) 00170 { 00171 return (registerKeyboardCallback (boost::bind (callback, _1, cookie))); 00172 } 00173 00180 template<typename T> boost::signals2::connection 00181 registerKeyboardCallback (void (T::*callback) (const pcl::visualization::KeyboardEvent&, void*), 00182 T& instance, void* cookie = NULL) 00183 { 00184 return (registerKeyboardCallback (boost::bind (callback, boost::ref (instance), _1, cookie))); 00185 } 00186 00191 boost::signals2::connection 00192 registerKeyboardCallback (boost::function<void (const pcl::visualization::KeyboardEvent&)> cb); 00193 00199 boost::signals2::connection 00200 registerMouseCallback (void (*callback) (const pcl::visualization::MouseEvent&, void*), 00201 void* cookie = NULL) 00202 { 00203 return (registerMouseCallback (boost::bind (callback, _1, cookie))); 00204 } 00205 00212 template<typename T> boost::signals2::connection 00213 registerMouseCallback (void (T::*callback) (const pcl::visualization::MouseEvent&, void*), 00214 T& instance, void* cookie = NULL) 00215 { 00216 return (registerMouseCallback (boost::bind (callback, boost::ref (instance), _1, cookie))); 00217 } 00218 00223 boost::signals2::connection 00224 registerMouseCallback (boost::function<void (const pcl::visualization::MouseEvent&)> cb); 00225 00226 protected: // methods 00228 void 00229 resetStoppedFlag () { stopped_ = false; } 00230 00234 void 00235 emitMouseEvent (unsigned long event_id); 00236 00240 void 00241 emitKeyboardEvent (unsigned long event_id); 00242 00243 // Callbacks used to register for vtk command 00244 static void 00245 MouseCallback (vtkObject*, unsigned long eid, void* clientdata, void *calldata); 00246 static void 00247 KeyboardCallback (vtkObject*, unsigned long eid, void* clientdata, void *calldata); 00248 00249 protected: // types 00250 struct ExitMainLoopTimerCallback : public vtkCommand 00251 { 00252 static ExitMainLoopTimerCallback* New () 00253 { 00254 return (new ExitMainLoopTimerCallback); 00255 } 00256 virtual void 00257 Execute (vtkObject* vtkNotUsed (caller), unsigned long event_id, void* call_data) 00258 { 00259 if (event_id != vtkCommand::TimerEvent) 00260 return; 00261 int timer_id = *(int*)call_data; 00262 if (timer_id != right_timer_id) 00263 return; 00264 window->interactor_->TerminateApp (); 00265 } 00266 int right_timer_id; 00267 ImageViewer* window; 00268 }; 00269 struct ExitCallback : public vtkCommand 00270 { 00271 static ExitCallback* New () 00272 { 00273 return (new ExitCallback); 00274 } 00275 virtual void 00276 Execute (vtkObject* caller, unsigned long event_id, void* call_data) 00277 { 00278 if (event_id != vtkCommand::ExitEvent) 00279 return; 00280 window->stopped_ = true; 00281 window->interactor_->TerminateApp (); 00282 } 00283 ImageViewer* window; 00284 }; 00285 00286 private: 00287 boost::signals2::signal<void (const pcl::visualization::MouseEvent&)> mouse_signal_; 00288 boost::signals2::signal<void (const pcl::visualization::KeyboardEvent&)> keyboard_signal_; 00289 00290 vtkSmartPointer<vtkRenderWindowInteractor> interactor_; 00291 vtkCallbackCommand* mouse_command_; 00292 vtkCallbackCommand* keyboard_command_; 00293 00295 vtkSmartPointer<ExitMainLoopTimerCallback> exit_main_loop_timer_callback_; 00296 vtkSmartPointer<ExitCallback> exit_callback_; 00297 00299 vtkSmartPointer<vtkImageViewer> image_viewer_; 00300 00302 boost::shared_array<unsigned char> data_; 00304 size_t data_size_; 00305 00307 bool stopped_; 00308 00310 int timer_id_; 00311 }; 00312 } 00313 } 00314 00315 #endif /* __IMAGE_VISUALIZER_H__ */ 00316
1.7.6.1