00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
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
00061 ImageWidgetWX ();
00063 ~ImageWidgetWX ();
00064
00065
00066
00067 static void spinOnce ();
00068
00069 static void spin ();
00070
00071
00072 typedef void (*PixelClickedHandler)(float pixel_x, float pixel_y);
00073
00074
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
00106
00110 void addPixelClickedHandler (PixelClickedHandler pixel_clicked_handler);
00111
00114 void setSize (int width=-1, int height=-1);
00115
00117 void informAboutImageFrameDestruction ();
00118
00119
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
00133 void OnClose (wxCloseEvent& event);
00134
00135 protected:
00136
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
00155 ImagePanel (wxFrame* parent);
00156 ~ImagePanel ();
00157
00158
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
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
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
00184 wxBitmap resized_;
00185
00186 ImageWidgetWX* getParentImageWidget () { return ((ImageFrame*)GetParent ())->parentImageWidget; }
00187
00188 DECLARE_EVENT_TABLE ();
00189 };
00190
00191 class ImageFrame : public wxFrame
00192 {
00193 public:
00194
00195 typedef wxFrame BaseClass;
00196
00197 ImageFrame (ImageWidgetWX* parentImageWidget);
00198 ~ImageFrame ();
00199
00200
00201 void OnSize (wxSizeEvent& event);
00202
00203
00204 void updateImage (unsigned char* data, unsigned int width, unsigned int height);
00205
00206
00207 void OnClose (wxCloseEvent& event);
00208
00209
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
00217
00218 DECLARE_EVENT_TABLE ();
00219 };
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229 void reset ();
00230
00231
00232 ImageFrame* image_frame;
00233 unsigned char* image_data;
00234 };
00235
00236 }
00237
00238 #endif //#ifndef PCL_VISUALIZATION_IMAGE_WIDGET_WX_H_