Go to the documentation of this file.00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008
00009
00010
00011 #include "vgui_roi_tableau.h"
00012 #include <vcl_string.h>
00013
00014 #include <vil1/vil1_load.h>
00015 #include <vil1/vil1_crop.h>
00016
00017 #include <vgui/vgui_event.h>
00018 #include <vgui/vgui_matrix_state.h>
00019 #include <vgui/vgui_gl.h>
00020 #include <vgui/vgui_glu.h>
00021
00022
00023
00024 vgui_roi_tableau::vgui_roi_tableau()
00025 : vgui_tableau()
00026 {
00027 cropped_image_ = 0;
00028 }
00029
00030 vgui_roi_tableau::vgui_roi_tableau(vil1_image const &I,char const *t_name,
00031 float x,float y,float w,float h)
00032 : vgui_tableau(),name_(t_name)
00033 {
00034 cropped_image_ = vil1_crop(I,int(x+0.5),int(y+0.5),int(w+0.5),int(h+0.5));
00035 roi_.sx = x;
00036 roi_.sy = y;
00037 roi_.width = w;
00038 roi_.height = h;
00039 }
00040
00041 vgui_roi_tableau::~vgui_roi_tableau() {}
00042
00043 vcl_string vgui_roi_tableau::type_name() const
00044 {
00045 return "vgui_roi_tableau";
00046 }
00047
00048
00049 vcl_string vgui_roi_tableau::file_name() const
00050 {
00051 return name_;
00052 }
00053
00054 vcl_string vgui_roi_tableau::pretty_name() const
00055 {
00056 return type_name() + "[" + name_ + "]";
00057 }
00058
00059
00060
00061 vil1_image vgui_roi_tableau::get_image() const
00062 {
00063 return cropped_image_;
00064 }
00065 #if 0
00066
00067 static inline vcl_string __FILE__rem_dir(const char *s)
00068 {
00069 char const *slash = vcl_strrchr(s,'/');
00070 return slash ? slash+1 : s;
00071 }
00072 #endif
00073
00074 void vgui_roi_tableau::set_image(vil1_image const &I)
00075 {
00076
00077
00078 cropped_image_ = vil1_crop( I, int(roi_.sx), int(roi_.sy),
00079 int(roi_.width), int(roi_.height));
00080 }
00081
00082
00083 void vgui_roi_tableau::set_image(char const *f)
00084 {
00085 set_image( vil1_load(f ? f : "az32_10.tif") );
00086 }
00087
00088
00089
00090 unsigned vgui_roi_tableau::width() const
00091 {
00092 return cropped_image_.width();
00093 }
00094
00095 unsigned vgui_roi_tableau::height() const
00096 {
00097 return cropped_image_.height();
00098 }
00099
00100 bool vgui_roi_tableau::get_bounding_box(float low[3], float high[3]) const
00101 {
00102 low[0] = 0; high[0] = width();
00103 low[1] = 0; high[1] = height();
00104 low[2] = 0; high[2] = 0;
00105 return true;
00106 }
00107
00108
00109
00110 bool vgui_roi_tableau::handle(vgui_event const &e)
00111 {
00112
00113 if (vgui_matrix_state::gl_matrices_are_cleared()) {
00114 GLint vp[4];
00115 glGetIntegerv(GL_VIEWPORT, vp);
00116 int wdth = vp[2];
00117 int hght = vp[3];
00118
00119 glMatrixMode(GL_PROJECTION);
00120 glLoadIdentity();
00121 gluOrtho2D(0, wdth, hght, 0);
00122
00123 glMatrixMode(GL_MODELVIEW);
00124 glLoadIdentity();
00125 }
00126
00127
00128 if (e.type == vgui_DRAW) {
00129
00130 get_child(0)->draw();
00131
00132 glBegin(GL_LINE_LOOP);
00133 glVertex2f(roi_.sx,roi_.sy);
00134 glVertex2f(roi_.sx+roi_.width,roi_.sy);
00135 glVertex2f(roi_.sx+roi_.width,roi_.sy+roi_.height);
00136 glVertex2f(roi_.sx,roi_.sy+roi_.height);
00137 glEnd();
00138
00139 return true;
00140 }
00141
00142
00143 else
00144 return get_child(0)->handle(e);
00145 }
00146
00147