contrib/brl/bbas/bgui/bgui_image_tableau.cxx
Go to the documentation of this file.
00001 // This is brl/bbas/bgui/bgui_image_tableau.cxx
00002 #include "bgui_image_tableau.h"
00003 //:
00004 // \file
00005 // \author J.L. Mundy
00006 // \brief  See bgui_image_tableau.h for a description of this file.
00007 
00008 #include <vcl_cmath.h>
00009 #include <vcl_cstdio.h> // sprintf
00010 #include <vgui/vgui_event.h>
00011 #include <vgui/vgui.h>
00012 #include <vgui/vgui_projection_inspector.h>
00013 #include <vil1/vil1_image.h>
00014 #include <vil1/vil1_rgba.h>
00015 #include <vil/vil_image_view.h>
00016 #include <vgui/vgui_range_map_params.h>
00017 
00018 
00019 //-----------------------------------------------------------------------------
00020 //: The constructor takes a snapshot of the current viewport and scissor areas.
00021 //  The destructor restores that state.
00022 //--------------------------------------------------------------------------------
00023 
00024 bgui_image_tableau::bgui_image_tableau()
00025 {
00026   handle_motion_ = true; locked_ = false; show_path_=false;
00027   tt_ = new vgui_text_tableau();
00028 }
00029 
00030 bgui_image_tableau::bgui_image_tableau(vil_image_resource_sptr const & img,
00031                                        vgui_range_map_params_sptr const& rmp)
00032  : base(img, rmp) { handle_motion_ = true; locked_ = false; show_path_=false;
00033  tt_ = new vgui_text_tableau();}
00034 
00035 bgui_image_tableau::bgui_image_tableau(vil_image_view_base const & img,
00036                                        vgui_range_map_params_sptr const& rmp)
00037  : base(img, rmp) { handle_motion_ = true; locked_ = false; show_path_=false;
00038  tt_ = new vgui_text_tableau();}
00039 
00040 bgui_image_tableau::bgui_image_tableau(vil1_image const & img,
00041                                        vgui_range_map_params_sptr const& rmp)
00042  : base(img, rmp) { handle_motion_ = true; locked_ = false; show_path_=false;
00043  tt_ = new vgui_text_tableau();}
00044 
00045 bgui_image_tableau::bgui_image_tableau(char const *f,
00046                                        vgui_range_map_params_sptr const& rmp)
00047  : base(f, rmp) { handle_motion_ = true; locked_ = false; show_path_=false;
00048  tt_ = new vgui_text_tableau();}
00049 
00050 //--------------------------------------------------------------------------------
00051 
00052 vil1_image bgui_image_tableau::get_image() const
00053 {
00054   return base::get_image();
00055 }
00056 
00057 vil_image_resource_sptr bgui_image_tableau::get_image_resource() const
00058 {
00059   return base::get_image_resource();
00060 }
00061 
00062 void bgui_image_tableau::get_pixel_info_from_frame_buffer(const int x, const int y, vgui_event const &e, char* msg)
00063 {
00064   // It's easier to get the buffer in vil1_rgba format and then convert to
00065   // RGB, because that avoids alignment problems with glReadPixels.
00066   glPixelZoom(1,1);
00067   glPixelTransferi(GL_MAP_COLOR,0);
00068   glPixelTransferi(GL_RED_SCALE,1);   glPixelTransferi(GL_RED_BIAS,0);
00069   glPixelTransferi(GL_GREEN_SCALE,1); glPixelTransferi(GL_GREEN_BIAS,0);
00070   glPixelTransferi(GL_BLUE_SCALE,1);  glPixelTransferi(GL_BLUE_BIAS,0);
00071 
00072   glPixelStorei(GL_PACK_ALIGNMENT,1);   // byte alignment.
00073   glPixelStorei(GL_PACK_ROW_LENGTH,0);  // use default value (the arg to pixel routine).
00074   glPixelStorei(GL_PACK_SKIP_PIXELS,0); //
00075   glPixelStorei(GL_PACK_SKIP_ROWS,0);   //
00076   vil1_rgba<GLubyte> pixel;
00077   glReadPixels(e.wx, e.wy,             //
00078                1, 1,             // height and width (only one pixel)
00079                GL_RGBA,          // format
00080                GL_UNSIGNED_BYTE, // type
00081                &pixel);
00082   vcl_sprintf(msg, "(%d, %d)   (ubyte)[ R=%d,G=%d,B=%d]", x, y,
00083               pixel.r, pixel.g, pixel.b);
00084 }
00085 
00086 void bgui_image_tableau::
00087 get_pixel_info_from_image(const int x, const int y,
00088                           vgui_event const &e, char* msg)
00089 {
00090   //only implemented for vil image resource and common vil types
00091   //(I don't like macros)
00092   vil_image_resource_sptr r = this->get_image_resource();
00093   if (!r) {
00094     if (!this->get_image())
00095     {
00096       vcl_sprintf(msg, "(%d, %d)   ?", x, y);
00097       return;
00098     }
00099     else
00100     {
00101       this->get_pixel_info_from_frame_buffer(x, y, e, msg);
00102       return;
00103     }
00104   }
00105   //At this point, we have a vil_image and can proceed with the cases.
00106   unsigned w = r->ni(), h = r->nj(), n_p = r->nplanes();
00107   if (x<0||x>=int(w)||y<0||y>=int(h))
00108   {
00109     vcl_sprintf(msg, "(%d, %d)   ?", 0, 0);
00110     return;
00111   }
00112   vil_pixel_format type = r->pixel_format();
00113   switch (type )
00114   {
00115    case VIL_PIXEL_FORMAT_BOOL:
00116    {
00117     vil_image_view<bool> v = r->get_view();
00118     if (!v)
00119       vcl_sprintf(msg, "Pixel Not Available");
00120     else
00121       vcl_sprintf(msg, "(%d, %d)   (bool) %d", x, y, v(x,y));
00122     return;
00123    }
00124    case  VIL_PIXEL_FORMAT_BYTE:
00125    {
00126     if (n_p==1)
00127     {
00128       vil_image_view<vxl_byte> v = r->get_view(x,1,y,1);
00129       if (!v)
00130         vcl_sprintf(msg, "Pixel Not Available");
00131       else
00132         vcl_sprintf(msg, "(%d, %d)   (ubyte) %d", x, y, v(0,0));
00133       return;
00134     }
00135     else if (n_p==3)
00136     {
00137       vil_image_view<vxl_byte > v = r->get_view(x,1,y,1);
00138       if (!v)
00139         vcl_sprintf(msg, "Pixel Not Available");
00140       else
00141         vcl_sprintf(msg, "(%d, %d)   (ubyte)[ R=%d,G=%d,B=%d]", x, y,
00142                     v(0,0,0), v(0,0,1), v(0,0,2) );
00143       return;
00144     }
00145     else if (n_p==4) {
00146       vil_image_view<vxl_byte > v = r->get_view(x,1,y,1);
00147       if (!v)
00148         vcl_sprintf(msg, "Pixel Not Available");
00149       else//as a default, just display first three bands as RGB
00150         vcl_sprintf(msg, "(%d, %d) (ubyte)[ R=%d,G=%d,B=%d, X=%d]", x, y,
00151                     v(0,0,0), v(0,0,1), v(0,0,2), v(0,0,3));
00152       return;
00153     }
00154     return;
00155    }
00156    case  VIL_PIXEL_FORMAT_SBYTE:
00157    {
00158     if (n_p==1)
00159     {
00160       vil_image_view<vxl_sbyte> v = r->get_view(x,1,y,1);
00161       if (!v)
00162         vcl_sprintf(msg, "Pixel Not Available");
00163       else
00164         vcl_sprintf(msg, "(%d, %d)   (sbyte) %d", x, y, v(0,0));
00165       return;
00166     }
00167     else if (n_p==3)
00168     {
00169       vil_image_view<vil_rgb<vxl_sbyte> > v = r->get_view(x,1,y,1);
00170       if (!v)
00171         vcl_sprintf(msg, "Pixel Not Available");
00172       else
00173         vcl_sprintf(msg, "(%d, %d)   (sbyte)[ R=%d,G=%d,B=%d]", x, y,
00174                     v(0,0).R(), v(0,0).G(),v(0,0).B() );
00175       return;
00176     }
00177     else if (n_p==4) {
00178       vil_image_view<vxl_byte > v = r->get_view(x,1,y,1);
00179       if (!v)
00180         vcl_sprintf(msg, "Pixel Not Available");
00181       else//as a default, just display first three bands as RGB
00182         vcl_sprintf(msg, "(%d, %d) (sbyte)[ R=%d,G=%d,B=%d,X=%d]", x, y,
00183                     v(0,0,0), v(0,0,1), v(0,0,2), v(0,0,3));
00184       return;
00185     }
00186     return;
00187    }
00188    case  VIL_PIXEL_FORMAT_UINT_16:
00189    {
00190     if (n_p==1)
00191     {
00192       vil_image_view<vxl_uint_16> v = r->get_view(x,1,y,1);
00193       if (!v)
00194         vcl_sprintf(msg, "Pixel Not Available");
00195       else
00196         vcl_sprintf(msg, "(%d, %d)   (uint16) %d", x, y, v(0,0));
00197       return;
00198     }
00199     else if (n_p==3)
00200     {
00201       vil_image_view<vil_rgb<vxl_uint_16> > v = r->get_view(x,1,y,1);
00202       if (!v)
00203         vcl_sprintf(msg, "Pixel Not Available");
00204       else
00205         vcl_sprintf(msg, "(%d, %d)   (uint16)[ R=%d,G=%d,B=%d]", x, y,
00206                     v(0,0).R(), v(0,0).G(),v(0,0).B() );
00207     }
00208     else if (n_p==4)
00209     {
00210       vil_image_view<vil_rgba<vxl_uint_16> > v = r->get_view(x,1,y,1);
00211       if (!v) {
00212         vcl_sprintf(msg, "Pixel Not Available");
00213         return;
00214       }
00215       else
00216       {
00217         int band_map = 0;
00218         if (rmp_)
00219           band_map = rmp_->band_map_;
00220         switch (band_map)
00221         {
00222          case vgui_range_map_params::RGB_m :
00223           vcl_sprintf(msg, "(%d, %d)   (RGB:uint16)[ R=%d,G=%d,B=%d,I=%d]",
00224                       x, y, v(0,0).R(), v(0,0).G(),v(0,0).B(),v(0,0).A() );
00225           break;
00226          case vgui_range_map_params::XRG_m :
00227           vcl_sprintf(msg, "(%d, %d)   (IRG:uint16)[ R=%d,G=%d,B=%d,I=%d]",
00228                       x, y, v(0,0).R(), v(0,0).G(),v(0,0).B(),v(0,0).A() );
00229           break;
00230          case vgui_range_map_params::RXB_m :
00231           vcl_sprintf(msg, "(%d, %d)   (RIB:uint16)[ R=%d,G=%d,B=%d,I=%d]",
00232                       x, y, v(0,0).R(), v(0,0).G(),v(0,0).B(),v(0,0).A() );
00233           break;
00234          case vgui_range_map_params::RGX_m :
00235           vcl_sprintf(msg, "(%d, %d)   (RGI:uint16)[ R=%d,G=%d,B=%d,I=%d]",
00236                       x, y, v(0,0).R(), v(0,0).G(),v(0,0).B(),v(0,0).A() );
00237           break;
00238          default:
00239           vcl_sprintf(msg, "Pixel Not Available");
00240           return;
00241         }
00242       }
00243     }
00244    }
00245    case  VIL_PIXEL_FORMAT_INT_16: {
00246     if (n_p==1)
00247     {
00248       vil_image_view<vxl_int_16> v = r->get_view(x,1,y,1);
00249       if (!v)
00250         vcl_sprintf(msg, "Pixel Not Available");
00251       else
00252         vcl_sprintf(msg, "(%d, %d)   (int16) %d", x, y, v(0,0));
00253       return;
00254     }
00255     else if (n_p==3)
00256     {
00257       vil_image_view<vil_rgb<vxl_int_16> > v = r->get_view(x,1,y,1);
00258       if (!v)
00259         vcl_sprintf(msg, "Pixel Not Available");
00260       else
00261         vcl_sprintf(msg, "(%d, %d)   (int16)[ R=%d,G=%d,B=%d]", x, y,
00262                     v(0,0).R(), v(0,0).G(),v(0,0).B() );
00263       return;
00264     }
00265     return;
00266    }
00267    case  VIL_PIXEL_FORMAT_UINT_32: {
00268     if (n_p==1)
00269     {
00270       vil_image_view<vxl_uint_32> v = r->get_view(x,1,y,1);
00271       if (!v)
00272         vcl_sprintf(msg, "Pixel Not Available");
00273       else
00274         vcl_sprintf(msg, "(%d, %d)   (uint32) %d", x, y, v(0,0));
00275       return;
00276     }
00277     else if (n_p==3)
00278     {
00279       vil_image_view<vil_rgb<vxl_uint_32> > v = r->get_view(x,1,y,1);
00280       if (!v)
00281         vcl_sprintf(msg, "Pixel Not Available");
00282       else
00283         vcl_sprintf(msg, "(%d, %d)   (uint32)[ R=%d,G=%d,B=%d]", x, y,
00284                     v(0,0).R(), v(0,0).G(),v(0,0).B() );
00285       return;
00286     }
00287     return;
00288    }
00289    case  VIL_PIXEL_FORMAT_FLOAT: {
00290     vil_image_view<float> v = r->get_view(x,1,y,1);
00291     if (!v)
00292       vcl_sprintf(msg, "Pixel Not Available");
00293     else if (n_p == 1)
00294       vcl_sprintf(msg, "(%d, %d)   (float) %f", x, y, v(0,0));
00295     else if (n_p ==3)
00296       vcl_sprintf(msg, "(%d, %d)   (float)[ R=%6.3f,G=%6.3f,B=%6.3f]", x, y,
00297                   v(0,0,0), v(0,0,1), v(0,0,2) );
00298     return;
00299    }
00300    case  VIL_PIXEL_FORMAT_DOUBLE: {
00301     vil_image_view<double> v = r->get_view(x,1,y,1);
00302     if (!v)
00303       vcl_sprintf(msg, "Pixel Not Available");
00304     else
00305       vcl_sprintf(msg, "(%d, %d)   (double) %g", x, y, v(0,0));
00306     return;
00307    }
00308    case VIL_PIXEL_FORMAT_RGB_BYTE: {
00309     vil_image_view<vil_rgb<vxl_byte> > v = r->get_view(x,1,y,1);
00310     if (!v)
00311       vcl_sprintf(msg, "Pixel Not Available");
00312     else
00313       vcl_sprintf(msg, "(%d, %d)   (ubyte)[ R=%d,G=%d,B=%d]", x, y,
00314                   v(0,0).R(), v(0,0).G(),v(0,0).B() );
00315       return;
00316    }
00317    case VIL_PIXEL_FORMAT_RGB_UINT_16: {
00318     vil_image_view<vil_rgb<vxl_uint_16> > v = r->get_view(x,1,y,1);
00319     if (!v)
00320       vcl_sprintf(msg, "Pixel Not Available");
00321     else
00322       vcl_sprintf(msg, "(%d, %d)   (uint16)[ R=%d,G=%d,B=%d]", x, y,
00323                   v(0,0).R(), v(0,0).G(),v(0,0).B() );
00324     return;
00325    }
00326 #if 0
00327    case VIL_PIXEL_FORMAT_UINT_32:
00328    case VIL_PIXEL_FORMAT_INT_32:
00329    case VIL_PIXEL_FORMAT_RGB_SBYTE:
00330    case VIL_PIXEL_FORMAT_RGB_INT_16:
00331    case VIL_PIXEL_FORMAT_RGB_UINT_32:
00332    case VIL_PIXEL_FORMAT_RGB_INT_32:
00333    case VIL_PIXEL_FORMAT_RGB_FLOAT:
00334    case VIL_PIXEL_FORMAT_RGB_DOUBLE:
00335    case VIL_PIXEL_FORMAT_RGBA_UINT_32:
00336    case VIL_PIXEL_FORMAT_RGBA_INT_32:
00337    case VIL_PIXEL_FORMAT_RGBA_UINT_16:
00338    case VIL_PIXEL_FORMAT_RGBA_INT_16:
00339    case VIL_PIXEL_FORMAT_RGBA_BYTE:
00340    case VIL_PIXEL_FORMAT_RGBA_SBYTE:
00341    case VIL_PIXEL_FORMAT_RGBA_FLOAT:
00342    case VIL_PIXEL_FORMAT_RGBA_DOUBLE:
00343    case VIL_PIXEL_FORMAT_COMPLEX_FLOAT:
00344    case VIL_PIXEL_FORMAT_COMPLEX_DOUBLE:
00345 #endif
00346    default:
00347     vcl_sprintf(msg, "Pixel Not Available");
00348   }
00349 }
00350 
00351 double bgui_image_tableau::
00352 get_pixel_value(const unsigned c, const unsigned r)
00353 {
00354   vil_image_resource_sptr rs = this->get_image_resource();
00355   if (!rs)
00356     return 0;
00357   if (c>=rs->ni()||r>=rs->nj())
00358     return 0;
00359   unsigned n_p = rs->nplanes();
00360   vil_pixel_format type = rs->pixel_format();
00361   switch (type )
00362   {
00363     case VIL_PIXEL_FORMAT_BOOL: {
00364       vil_image_view<bool> v = rs->get_view();
00365       if (!v)
00366         return 0;
00367       else
00368         return static_cast<double>(v(0,0));
00369     }
00370     case  VIL_PIXEL_FORMAT_BYTE: {
00371       vil_image_view<vxl_byte> v = rs->get_view(c,1,r,1);
00372       if (!v)
00373         return 0;
00374       if (n_p==1)
00375         return static_cast<double>(v(0,0));
00376       else if (n_p==3)
00377         return static_cast<double>(v(0,0,0)+v(0,0,1)+v(0,0,2))/3;
00378     }
00379     case  VIL_PIXEL_FORMAT_SBYTE: {
00380       vil_image_view<vxl_sbyte> v = rs->get_view(c,1,r,1);
00381       if (!v)
00382         return 0;
00383       else
00384         if (n_p==1)
00385           return static_cast<double>(v(0,0));
00386         else if (n_p==3)
00387           return static_cast<double>(v(0,0,0)+v(0,0,1)+v(0,0,2))/3;
00388     }
00389     case  VIL_PIXEL_FORMAT_UINT_16: {
00390       vil_image_view<vxl_uint_16> v = rs->get_view(c,1,r,1);
00391       if (!v)
00392         return 0;
00393       else
00394         if (n_p==1)
00395           return static_cast<double>(v(0,0));
00396         else if (n_p==3)
00397           return static_cast<double>(v(0,0,0)+v(0,0,1)+v(0,0,2))/3;
00398         else if (n_p==4)
00399           return static_cast<double>(v(0,0,0)+v(0,0,1)+v(0,0,2)+v(0,0,3))/4;
00400     }
00401     case  VIL_PIXEL_FORMAT_INT_16: {
00402       vil_image_view<vxl_int_16> v = rs->get_view(c,1,r,1);
00403       if (!v)
00404         return 0;
00405       else
00406         if (n_p==1)
00407           return static_cast<double>(v(0,0));
00408         else if (n_p==3)
00409           return static_cast<double>(v(0,0,0)+v(0,0,1)+v(0,0,2))/3;
00410     }
00411     case  VIL_PIXEL_FORMAT_FLOAT: {
00412       vil_image_view<float> v = rs->get_view(c,1,r,1);
00413       if (!v)
00414         return 0;
00415       else
00416         return static_cast<double>(v(0,0));
00417     }
00418     case  VIL_PIXEL_FORMAT_DOUBLE: {
00419       vil_image_view<double> v = rs->get_view(c,1,r,1);
00420       if (!v)
00421         return 0;
00422       else
00423         return v(0,0);
00424     }
00425     case VIL_PIXEL_FORMAT_RGB_BYTE: {
00426       vil_image_view<vil_rgb<vxl_byte> > v = rs->get_view(c,1,r,1);
00427       if (!v)
00428         return 0;
00429       else
00430         return static_cast<double>(v(0,0).R()+v(0,0).G()+v(0,0).B())/3;
00431     }
00432     case VIL_PIXEL_FORMAT_RGB_UINT_16: {
00433       vil_image_view<vil_rgb<vxl_uint_16> > v = rs->get_view(c,1,r,1);
00434       if (!v)
00435         return 0;
00436       else
00437         return static_cast<double>(v(0,0).R()+v(0,0).G()+v(0,0).B())/3;
00438     }
00439     default:
00440       return 0;
00441    }
00442 }
00443 
00444 //: get the pixel value as color
00445 vcl_vector<double> bgui_image_tableau::get_color_pixel_value(const unsigned c, const unsigned r)
00446 {
00447   vil_image_resource_sptr rs = this->get_image_resource();
00448   if (!rs)
00449     return vcl_vector<double>(0);
00450   if (c>=rs->ni()||r>=rs->nj())
00451     return vcl_vector<double>(0);
00452   unsigned n_p = rs->nplanes();
00453   vcl_vector<double> val(n_p, 0.0);
00454   if (n_p==1)
00455   {
00456     val[0]=this->get_pixel_value(c, r);
00457     return val;
00458   }
00459   vil_pixel_format type = rs->pixel_format();
00460   switch (type )
00461   {
00462     case  VIL_PIXEL_FORMAT_BYTE: {
00463       vil_image_view<vxl_byte> v = rs->get_view(c,1,r,1);
00464       if (!v)
00465         return val;
00466       for (unsigned p = 0; p<n_p; ++p)
00467         val[p]=static_cast<double>(v(0,0,p));
00468       return val;
00469     }
00470     case  VIL_PIXEL_FORMAT_UINT_16: {
00471       vil_image_view<vxl_uint_16> v = rs->get_view(c,1,r,1);
00472       if (!v)
00473         return val;
00474       for (unsigned p = 0; p<n_p; ++p)
00475         val[p]=static_cast<double>(v(0,0,p));
00476       return val;
00477     }
00478     default:
00479       return val;
00480   }
00481 }
00482 
00483 void bgui_image_tableau::image_line(const float col_start,
00484                                     const float row_start,
00485                                     const float col_end,
00486                                     const float row_end,
00487                                     vcl_vector<double>& line_pos,
00488                                     vcl_vector<double>& vals)
00489 {
00490   line_pos.clear();vals.clear();
00491   //Get the image data
00492   // the line length in pixels
00493   float length = vcl_sqrt((col_end-col_start)*(col_end-col_start) +
00494                           (row_end-row_start)*(row_end-row_start));
00495   if (length == 0)
00496     return;
00497   //initialize the line scan parameters
00498   float xstep = (col_end-col_start)/length;
00499   float ystep = (row_end-row_start)/length;
00500   float sinc = vcl_sqrt(xstep*xstep + ystep*ystep);
00501   float spos = 0;
00502   line_pos.push_back(spos);
00503   unsigned c = static_cast<unsigned>(col_start),
00504    r = static_cast<unsigned>(row_start);
00505   vals.push_back(get_pixel_value(c, r));
00506 
00507   //extract the pixel values along the line
00508   float xpos = col_start, ypos = row_start;
00509   unsigned nsteps = static_cast<unsigned>(length);
00510   for (unsigned i = 0; i<nsteps; ++i)
00511   {
00512     xpos += xstep;
00513     ypos += ystep;
00514     spos += sinc;
00515     c = static_cast<unsigned>(xpos);
00516     r = static_cast<unsigned>(ypos);
00517     line_pos.push_back(spos);
00518     vals.push_back(get_pixel_value(c, r));
00519   }
00520 }
00521 
00522 //: Extract a line of pixel values return color if available
00523 void bgui_image_tableau::image_line(const float col_start,
00524                                     const float row_start,
00525                                     const float col_end,
00526                                     const float row_end,
00527                                     vcl_vector<double>& line_pos,
00528                                     vcl_vector<vcl_vector<double> >& vals)
00529 {
00530   line_pos.clear();vals.clear();
00531   //Get the image data
00532   // the line length in pixels
00533   float length = vcl_sqrt((col_end-col_start)*(col_end-col_start) +
00534                           (row_end-row_start)*(row_end-row_start));
00535   if (length == 0)
00536     return;
00537   //initialize the line scan parameters
00538   float xstep = (col_end-col_start)/length;
00539   float ystep = (row_end-row_start)/length;
00540   float sinc = vcl_sqrt(xstep*xstep + ystep*ystep);
00541   float spos = 0;
00542   line_pos.push_back(spos);
00543   unsigned c = static_cast<unsigned>(col_start),
00544    r = static_cast<unsigned>(row_start);
00545   vcl_vector<double> cv = get_color_pixel_value(c, r);
00546   unsigned n_bands = cv.size();
00547   vals.resize(n_bands);
00548   for (unsigned i = 0; i<n_bands; ++i)
00549     vals[i].push_back(cv[i]);
00550 
00551   //extract the pixel values along the line
00552   float xpos = col_start, ypos = row_start;
00553   unsigned nsteps = static_cast<unsigned>(length);
00554   for (unsigned i = 0; i<nsteps; ++i)
00555   {
00556     xpos += xstep;
00557     ypos += ystep;
00558     spos += sinc;
00559     c = static_cast<unsigned>(xpos);
00560     r = static_cast<unsigned>(ypos);
00561     line_pos.push_back(spos);
00562     cv = get_color_pixel_value(c, r);
00563     for (unsigned i = 0; i<n_bands; ++i)
00564       vals[i].push_back(cv[i]);
00565   }
00566 }
00567 
00568 
00569 //--------------------------------------------------------------------------------
00570 //:
00571 // Handle all events for this tableau.
00572 bool bgui_image_tableau::handle(vgui_event const &e)
00573 {
00574   static bool button_down = false;
00575   if (e.type == vgui_DRAW)
00576   {
00577     base::handle(e);
00578     if (tt_) tt_->handle(e);
00579     return true;
00580   }
00581 
00582   if (e.type == vgui_BUTTON_DOWN)
00583   {
00584     button_down = true;
00585     if (handle_motion_)
00586       vgui::out << ' ' << vcl_endl;
00587   }
00588   else if (e.type == vgui_BUTTON_UP)
00589   {
00590     button_down = false;
00591   }
00592   else if (e.type == vgui_MOTION && handle_motion_ && !button_down)
00593   {
00594     // Get X,Y position to display on status bar:
00595     float pointx, pointy;
00596     vgui_projection_inspector p_insp;
00597     p_insp.window_to_image_coordinates(e.wx, e.wy, pointx, pointy);
00598     int intx = (int)vcl_floor(pointx), inty = (int)vcl_floor(pointy);
00599     char msg[100];
00600 
00601     this->get_pixel_info_from_image(intx, inty,e, msg);
00602 
00603     // gets a snapshot of the viewport so that it restores it back after vgui::out
00604     // this is needed, because vgui::out changes viewport, and image tableau
00605     // gets confused
00606     bgui_image_tableau_vp_sc_snapshot snap;
00607 
00608     // Display on status bar:
00609     if (!locked_) {
00610       if (show_path_)
00611         vgui::out << msg << "  " << this->file_name() << vcl_endl;
00612       else
00613         vgui::out << msg << vcl_endl;
00614     }
00615   }
00616   return base::handle(e);
00617 }
00618 
00619 //--------------------------------------------------------------------------------