$search
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 */ 00035 00036 /* \author Bastian Steder */ 00037 00038 #ifndef PCL_VISUALIZATION_IMAGE_WIDGET_WX_H_ 00039 #define PCL_VISUALIZATION_IMAGE_WIDGET_WX_H_ 00040 00041 #include <wx/wx.h> 00042 00043 #include <vector> 00044 00045 namespace pcl_visualization 00046 { 00056 class ImageWidgetWX 00057 { 00058 public: 00059 // =====CONSTRUCTOR & DESTRUCTOR===== 00061 ImageWidgetWX (); 00063 ~ImageWidgetWX (); 00064 00065 // =====STATIC METHODS===== 00066 // Handle the GUI events and return immediately 00067 static void spinOnce (); 00068 // Start loop that handles the GUI events 00069 static void spin (); 00070 00071 // =====TYPEDEFS===== 00072 typedef void (*PixelClickedHandler)(float pixel_x, float pixel_y); 00073 00074 // =====PUBLIC METHODS===== 00076 void setName (const std::string& name); 00077 00079 void setRGBImage (const unsigned char* data, unsigned int width, unsigned int height, const char* name="RGB image"); 00080 00082 void setFloatImage (const float* float_image, unsigned int width, unsigned int height, const char* name="float image", 00083 float min_value=-INFINITY, float max_value=INFINITY, bool grayscale=false); 00084 00086 void setAngleImage (const float* angle_image, unsigned int width, unsigned int height, const char* name="angle image"); 00087 00089 void setHalfAngleImage (const float* angle_image, unsigned int width, unsigned int height, const char* name="angle image"); 00090 00092 void markPoint (float x, float y, const wxPen* color=wxGREEN_PEN, const wxBrush* background=wxTRANSPARENT_BRUSH); 00093 00095 void markLine (float x1, float y1, float x2, float y2, const wxPen* color=wxGREEN_PEN); 00096 00097 00099 bool isShown () const; 00100 00102 void show (bool show_widget=true); 00103 00105 //void savePng (std::string filename) const; 00106 00110 void addPixelClickedHandler (PixelClickedHandler pixel_clicked_handler); 00111 00114 void setSize (int width=-1, int height=-1); 00115 00117 void informAboutImageFrameDestruction (); 00118 00119 // =====PUBLIC MEMBER VARIABLES===== 00121 bool keepAspectRatio; 00126 bool mouse_click_happened; 00127 float last_clicked_point_x, last_clicked_point_y; 00128 bool visualize_selected_point; 00129 bool print_selected_point; 00130 00131 // =====EVENTS===== 00133 void OnClose (wxCloseEvent& event); 00134 00135 protected: 00136 // =====CLASSES / STRUCTS===== 00137 struct ImagePoint 00138 { 00139 ImagePoint (float x_, float y_, const wxPen* color_=wxGREEN_PEN, const wxBrush* background_=wxTRANSPARENT_BRUSH) : x(x_), y(y_), color(color_), background(background_) {} 00140 float x,y; 00141 const wxPen* color; 00142 const wxBrush* background; 00143 }; 00144 struct ImageLine 00145 { 00146 ImageLine (float x1, float y1, float x2, float y2, const wxPen* color=wxGREEN_PEN) : x1(x1), y1(y1), x2(x2), y2(y2), color(color) {} 00147 float x1, y1, x2, y2; 00148 const wxPen* color; 00149 }; 00150 00151 class ImagePanel : public wxPanel 00152 { 00153 public: 00154 // =====CONSTRUCTOR & DESTRUCTOR===== 00155 ImagePanel (wxFrame* parent); 00156 ~ImagePanel (); 00157 00158 // =====EVENTS===== 00159 void paintEvent (wxPaintEvent & evt); 00160 void paintNow (); 00161 void OnSize (wxSizeEvent& event); 00162 void mouseReleased (wxMouseEvent& event); 00163 void render (wxDC& dc); 00164 void resizeImage (int newWidth=-1, int newHeight=-1); 00165 /* some useful events 00166 void mouseMoved(wxMouseEvent& event); 00167 void mouseDown(wxMouseEvent& event); 00168 void mouseWheelMoved(wxMouseEvent& event); 00169 void mouseReleased(wxMouseEvent& event); 00170 void rightClick(wxMouseEvent& event); 00171 void mouseLeftWindow(wxMouseEvent& event); 00172 void keyPressed(wxKeyEvent& event); 00173 void keyReleased(wxKeyEvent& event); 00174 */ 00175 00176 // =====PUBLIC MEMBER VARIABLES===== 00177 wxImage* image; 00178 int scaledWidth, scaledHeight; 00179 std::vector<ImagePoint> markedPoints; 00180 std::vector<ImageLine> lines; 00181 std::vector<PixelClickedHandler> pixel_clicked_handlers; 00182 protected: 00183 // =====PROTECTED MEMBER VARIABLES===== 00184 wxBitmap resized_; 00185 // =====PROTECTED METHODS===== 00186 ImageWidgetWX* getParentImageWidget () { return ((ImageFrame*)GetParent ())->parentImageWidget; } 00187 00188 DECLARE_EVENT_TABLE (); 00189 }; 00190 00191 class ImageFrame : public wxFrame 00192 { 00193 public: 00194 // =====TYPEDEFS===== 00195 typedef wxFrame BaseClass; 00196 // =====CONSTRUCTOR & DESTRUCTOR===== 00197 ImageFrame (ImageWidgetWX* parentImageWidget); 00198 ~ImageFrame (); 00199 00200 // =====EVENTS===== 00201 void OnSize (wxSizeEvent& event); 00202 00203 // =====METHODS===== 00204 void updateImage (unsigned char* data, unsigned int width, unsigned int height); 00205 00206 // =====EVENTS===== 00207 void OnClose (wxCloseEvent& event); 00208 00209 // =====PUBLIC MEMBER VARIABLES===== 00210 ImagePanel* image_panel; 00211 ImageWidgetWX* parentImageWidget; 00212 bool mouse_click_happened; 00213 float last_clicked_point_x, last_clicked_point_y; 00214 00215 protected: 00216 // =====PROTECTED MEMBER VARIABLES===== 00217 00218 DECLARE_EVENT_TABLE (); 00219 }; 00220 00221 //class StopMainLoopTimer : public wxTimer { 00222 //void Notify() { 00223 //wxTheApp->ExitMainLoop(); 00224 //} 00225 //}; 00226 00227 00228 // =====PROTECTED METHODS===== 00229 void reset (); 00230 00231 // =====PROTECTED MEMBER VARIABLES===== 00232 ImageFrame* image_frame; 00233 unsigned char* image_data; 00234 }; 00235 00236 } // namespace end 00237 00238 #endif //#ifndef PCL_VISUALIZATION_IMAGE_WIDGET_WX_H_