Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ImageCanvas.cpp
1 #include <sstream>
2 #include <iomanip>
3 
4 
5 #include <wx/scrolwin.h>
6 #ifdef WIN32
7 #include <wx/image.h>
8 #endif //WIN32
9 
10 
11 #include "ImageCanvas.hh"
12 
13 #include <Base/Image/ImageConvert.hh>
14 #include <Gui/StringConv.hh>
15 #include <Gui/ZoomFrame.hh>
16 #include <Gui/HistoFrame.hh>
17 #include <Gui/ImageLegendFrame.hh>
18 #include <Image/PyramidImage.hh>
19 #include <Gui/wxcompat.hh>
20 
21 
22 using namespace BIAS;
23 using namespace std;
24 
25 BEGIN_EVENT_TABLE (ImageCanvas, wxScrolledWindow)
26  EVT_PAINT (ImageCanvas::OnPaint)
27  EVT_ERASE_BACKGROUND (ImageCanvas::OnErase)
28  EVT_MOTION (ImageCanvas::OnMouseMove)
29  EVT_RIGHT_DOWN (ImageCanvas::OnRightMouseButton)
30  EVT_LEAVE_WINDOW(ImageCanvas::OnMouseLeave)
31  EVT_ENTER_WINDOW(ImageCanvas::OnMouseEnter)
32  //EVT_SIZE (ImageCanvas::OnSize)
33  EVT_KEY_DOWN (ImageCanvas::OnKeyPress)
34  EVT_LEFT_DCLICK (ImageCanvas::OnLeftMouseButton)
35  EVT_LEFT_DOWN (ImageCanvas::OnLeftMouseButton)
36  EVT_MOUSEWHEEL (ImageCanvas::OnMouseWheel)
37 END_EVENT_TABLE()
38 
39 
40 //////////////////////////////////////////////////
42 ImageCanvas(wxWindow* parent, wxStatusBar* sbar, int sbarid,
43  wxWindowID id, const wxPoint& pos, const wxSize& size,
44  long style, const wxString& name)
45  : wxScrolledWindow(parent, id, pos, size, style, name), origim_()
46 {
47  Bitmap_=(wxBitmap *)NULL;
48  wximage_=(wxImage *)NULL;
49  SBar_=sbar;
50  SBarID_=sbarid;
51  MyValueBarFrame_ = NULL;
52  Title_=name;
53  mousex_=mousey_=-1;
54  DefaultZoom_=5;
55  ClearDrawingContext_=true;
56  ShowScaled_ = false;
57 
58  //HINT: If it sparks while having a sequence of mixed images
59  // (unsigned char/float) then do like it with MyHistoWin_
60  // done is (set to NULL in the beginning and by every
61  // use of zoomcanvas check if MyZoomWin_ initialized is)
62  MyZoomWin_=new ZoomFrame(this, Title_);
63  MyZoomWin_->Show(false);
64  MyHistoWin_=NULL;
65  ScaledImageSizeX_=0;
66  ScaledImageSizeY_=0;
67  width_ = height_ = lastwidth_ = lastheight_ = 0;
68  KeepScrollPosition_ = false;
69  SetHighScaleQuality(false);
70  wxRoiImage_ = NULL;
71  RoiBitmap_ = NULL;
72  DrawRoi_ = false;
73  SBarWidths_[0] = -2;
74  if(SBar_ != NULL)
75  {
76  SBarWidths_[1] = 26 * SBar_->GetCharWidth();
77  }
78  else
79  {
80  SBarWidths_[1] = 350;
81  }
82 }
83 
84 //////////////////////////////////////////////////
87 {
88  if( wxRoiImage_!=NULL) { delete wxRoiImage_; wxRoiImage_ = NULL; }
89  if (wximage_ != NULL) { delete wximage_; wximage_ = NULL; }
90  if (RoiBitmap_!=NULL) { delete RoiBitmap_; RoiBitmap_ = NULL; }
91  if (Bitmap_ != NULL) { delete Bitmap_; Bitmap_ = NULL; }
92 }
93 
94 //////////////////////////////////////////////////
95 void ImageCanvas::
96 InitHisto(wxPoint pos, wxSize size)
97 {
98  MyHistoWin_=new HistoFrame(this, _T("Image Histogram"), pos, size);
99  MyHistoWin_->Show(true);
100 }
101 //////////////////////////////////////////////////
102 void ImageCanvas::
103 InitImageValueBar(wxPoint pos, wxSize size){
104  MyValueBarFrame_=new ImageLegendFrame(this, _T("Image Legend"), pos, size);
105  MyValueBarFrame_->SetLegendSize(120,400);
106  MyValueBarFrame_->Show(true);
107 }
108 //////////////////////////////////////////////////
109 void ImageCanvas::
111 {
113  pim.GetSingleImage(im);
114  Show(im, name);
115 }
116 
117 //////////////////////////////////////////////////
118 void ImageCanvas::
120 {
123  Image<unsigned char> tmpim;
124  if (ImageConvert::Convert(im, tmpim, ImageBase::CM_RGB)!=0){
125  BIASERR("error converting");
126  }
127  BIASDOUT(D_IC_IM,"Show(im,name) called Show(im,tmpim,name)");
128  Show(im, tmpim, name);
129  } else {
130  BIASDOUT(D_IC_IM,"Show(im,name) called Show(im,im,name)");
131  if(im.IsPlanar())
132  {
134  tmpIm;
135  if(ImageConvert::Convert(im, tmpIm, ImageBase::CM_RGB) != 0)
136  {
137  BIASERR("error converting");
138  }
139  BIASDOUT(D_IC_IM,"Show(im,name) called Show(im,tmpIm,name)");
140  Show(im, tmpIm, name);
141  }
142  else
143  {
144  Show(im, im, name);
145  }
146  }
147 
148 }
149 
150 //////////////////////////////////////////////////
151 void ImageCanvas::
153  BIAS::Image<unsigned char>& scaledrgbim,
154  std::string name)
155 {
156  origim_mutex_.Lock();
157  BIASDOUT(D_IC_IM,"Adress of origim: "<<&origim);
158  if(&origim_!=&origim) //only copy if not already the same
159  origim_ = origim;
160 
161  origim_mutex_.Unlock();
162 
163  if(&rgbim_!=&scaledrgbim)
164  rgbim_=scaledrgbim;
165 
166  BIASDOUT(D_IC_IM,"Adress of rgbim_: "<<&rgbim_);
167 
168  width_ = origim_.GetWidth ();
169  height_ = origim_.GetHeight();
170 
171  //// rgb display image may have other size, e.g. 3*width for X3B
172  //width_ = max(origim.GetWidth (), scaledrgbim.GetWidth () );
173  //height_ = max(origim.GetHeight(), scaledrgbim.GetHeight() );
174 
175  ImageName_ = name;
176  wxPoint scrolledP(0,0),origP(0,0);
177 
178  if(KeepScrollPosition_){
179  scrolledP = this->CalcScrolledPosition(origP);
180 
181  scrolledP.x = -scrolledP.x;
182  scrolledP.y = -scrolledP.y;
183 
184  if(ShowScaled_){
185  if((scrolledP.x > ScaledImageSizeX_) || (scrolledP.y > ScaledImageSizeY_)){
186  scrolledP.x = 0;
187  scrolledP.y = 0;
188  }
189  }else{
190  if((scrolledP.x > (int)width_) || (scrolledP.y > (int)height_)){
191  scrolledP.x = 0;
192  scrolledP.y = 0;
193  }
194  }
195  }
196  //reset scrollings of image dimension changed
197  if(width_ !=lastwidth_ || height_ != lastheight_){
198  scrolledP.x = scrolledP.y = 0;
199  }
200 
201  if(ShowScaled_) {
202  // adjust virtual size and scrollbars to requested scaled image size
203  SetVirtualSize( ScaledImageSizeX_ , ScaledImageSizeY_);
204  SetScrollbars(1, 1, ScaledImageSizeX_,ScaledImageSizeY_,scrolledP.x,scrolledP.y);
205  }
206  else{
207  SetScrollbars(1, 1, width_, height_,scrolledP.x,scrolledP.y);
208  }
209  wxbitmap_mutex_.Lock();
210  if (wximage_ != NULL){
211  delete wximage_; wximage_ = NULL;
212  }
213  wximage_ =new wxImage(rgbim_.GetWidth(), rgbim_.GetHeight(),
214  rgbim_.GetImageData(), true); //don't delete array
215 
216 #ifndef __APPLE__ // core dumps under mac os x 10.5
217  //if roi is mask store mask
218  if((origim_.GetROI())&&(origim_.GetROI()->GetROIType()==ROI_Mask))
219  {
220  if (wxRoiImage_ != NULL) {
221  delete wxRoiImage_; wxRoiImage_ = NULL;
222  }
223  origim_.GetROI()->GetMaskImage(roimask_);
224  // bunt malloc is deleted in destructor of wxImage!
225  unsigned char* bunt =(unsigned char*) malloc(3*origim_.GetWidth()*origim_.GetHeight());
226  unsigned num = origim_.GetWidth()*origim_.GetHeight();
227  unsigned char* alphaimg = roimask_.GetImageData();
228  for(unsigned p=0;p<num; p++)
229  {
230  bunt[p*3]=0;
231  bunt[p*3+1]=255;
232  bunt[p*3+2]=255;
233  if(alphaimg[p]!=0) alphaimg[p]=128;
234  }
235  //passing false as forth argument makes wxImage delete bunt
236  wxRoiImage_ = new wxImage(origim_.GetWidth(), origim_.GetHeight(),
237  bunt,false);
238  wxRoiImage_->InitAlpha();
239  wxRoiImage_->SetAlpha(alphaimg,true); //don't delete array
240 
241  }
242  else{
243  delete wxRoiImage_; wxRoiImage_ = NULL;
244  roimask_.Init(4,4,1);
245  }
246 #endif // __APPLE__
247 
248  wxbitmap_mutex_.Unlock();
249  if (MyZoomWin_->IsShown()) {
250  //BIAS_MUTEX_LOCK(origim_mutex_);
251  MyZoomWin_->NewImage(origim_, rgbim_, AsciiToWx(ImageName_));
252  //BIAS_MUTEX_UNLOCK(origim_mutex_);
253  }
254  if(MyHistoWin_!=NULL){
255  if (MyHistoWin_->IsShown()) {
256  //BIAS_MUTEX_LOCK(origim_mutex_);
257  MyHistoWin_->NewImage(origim_, AsciiToWx(ImageName_));
258  //BIAS_MUTEX_UNLOCK(origim_mutex_);
259  }
260  }
261  //show value bar frame
262  if(MyValueBarFrame_!=NULL){
263  if (MyValueBarFrame_->IsShown()) {
264  //BIAS_MUTEX_LOCK(origim_mutex_);
265  MyValueBarFrame_->SetImage(origim_);
266  //BIAS_MUTEX_UNLOCK(origim_mutex_);
267  }
268  }
269 
270  if (mousex_>=0 && mousey_>=0){
271  UpdateStatusBar((unsigned)mousex_, (unsigned)mousey_);
272  }
273 
274 
275  lastwidth_=width_;
276  lastheight_=height_;
277 
278 #ifdef WIN32
279  this->Refresh();
280 #else
281  wxPaintEvent pe;
282  wxPostEvent(this->GetEventHandler(),pe);
283 #endif
284 
285 }
286 //////////////////////////////////////////////////
287 wxPoint ImageCanvas::
289 {
290  if(MyHistoWin_ != NULL)
291  return MyHistoWin_->GetPosition();
292  else
293  return wxPoint(10,10);
294 }
295 //////////////////////////////////////////////////
296 wxSize ImageCanvas::
298 {
299  if(MyHistoWin_ != NULL)
300  return MyHistoWin_->GetSize();
301  else
302  return wxSize(300,250);
303 }
304 //////////////////////////////////////////////////
305 wxPoint ImageCanvas::
307 {
308  if(MyValueBarFrame_ != NULL)
309  return MyValueBarFrame_->GetPosition();
310  else
311  return wxPoint(10,10);
312 }
313 //////////////////////////////////////////////////
314 wxSize ImageCanvas::
316 {
317  if(MyValueBarFrame_ != NULL)
318  return MyValueBarFrame_->GetSize();
319  else
320  return wxSize(300,250);
321 }
322 
323 //////////////////////////////////////////////////
324 void ImageCanvas::
325 ShowHistogramm(ImageBase& image, wxPoint pos, wxSize size)
326 {
327  if(MyHistoWin_==NULL)
328  InitHisto(pos, size);
329 
330  if (!image.IsEmpty()){
331  MyHistoWin_->NewImage(image, AsciiToWx(ImageName_));
332  MyHistoWin_->Show(true);
333  }
334  else{
335  BIASERR("Hey, no image saved in image!");
336  }
337 }
338 
339 //////////////////////////////////////////////////
340 void ImageCanvas::
341 ShowHistogramm(wxPoint pos, wxSize size)
342 {
343  if(MyHistoWin_==NULL)
344  InitHisto(pos, size);
345 
346  if (!origim_.IsEmpty()){
347  MyHistoWin_->NewImage(origim_, AsciiToWx(ImageName_));
348  MyHistoWin_->Show(true);
349  }
350  else{
351  BIASERR("Hey, no image saved in origim_!");
352  }
353 }
354 
355 //////////////////////////////////////////////////
356 void ImageCanvas::
357 ShowImageValueBar(ImageBase& image, wxPoint pos, wxSize size)
358 {
359  if(MyValueBarFrame_==NULL)
360  InitImageValueBar(pos, size);
361  if (!origim_.IsEmpty()){
362  MyValueBarFrame_->SetSize(size);
363  MyValueBarFrame_->SetPosition(pos);
364  MyValueBarFrame_->SetImage(image);
365  MyValueBarFrame_->Show(true);
366  }
367 }
368 
369 //////////////////////////////////////////////////
370 void ImageCanvas::
371 ShowImageValueBar(wxPoint pos, wxSize size)
372 {
373  if(MyValueBarFrame_==NULL)
374  InitImageValueBar(pos, size);
375  if (!origim_.IsEmpty()){
376  MyValueBarFrame_->SetSize(size);
377  MyValueBarFrame_->SetPosition(pos);
378  MyValueBarFrame_->SetImage(origim_);
379  MyValueBarFrame_->Show(true);
380  }
381 }
382 
383 //////////////////////////////////////////////////
384 void ImageCanvas::
385 Zoom(unsigned x, unsigned y)
386 {
387  //BIAS_MUTEX_LOCK(origim_mutex_);
388  MyZoomWin_->NewImage(origim_, rgbim_, AsciiToWx(ImageName_));
389  //BIAS_MUTEX_UNLOCK(origim_mutex_);
390  MyZoomWin_->SetZoom(DefaultZoom_);
391  MyZoomWin_->Show(true);
392 
393  if (ShowScaled_ && ScaledImageSizeX_>0 && ScaledImageSizeY_>0) {
394  MyZoomWin_->NewCoo((int)((float)x * ((float)width_ / (float)ScaledImageSizeX_)),
395  (int)((float)y *((float)height_/(float)ScaledImageSizeY_)));
396  }
397  else MyZoomWin_->NewCoo(x, y);
398 }
399 
400 //////////////////////////////////////////////////
401 void ImageCanvas::
402 UpdateStatusBar(unsigned x, unsigned y)
403 {
404 
405  // check if there is nothing to do:
406  if (SBar_==NULL) return;
407  if(Bitmap_==NULL) return;
408 
409  // TODO: do we really need these lockings?
410  //BIAS_MUTEX_LOCK(wxbitmap_mutex_);
411 
412  BIASASSERT(SBar_ != NULL);
413  BIASASSERT(Bitmap_ != NULL);
414  if ((x>=0) && (x<width_) && (y>=0) && (y<height_))
415  {
416 
417  ostringstream os;
418  //displate coordinate:
419  os << "("<<setw(3)<<x<<", "<<setw(3)<<y<<") : (";
420 
421  // determine pixel type relying on storage type
422  // dynamic_check to BIAS::Image<T> does not work because base image is
423  // loaded
424 
425  origim_mutex_.Lock();
426  {
427  for (unsigned int channel=0;
428  channel<origim_.GetChannelCount();
429  channel++){
430  if (channel!=0)
431  os <<","; // no comma before first value
432  BIAS::ImageBase::PrintPixelValue(origim_, x,y, (unsigned short)channel, os );
433  }
434  }
435  origim_mutex_.Unlock();
436  os <<")";
437  SBar_->SetStatusText(AsciiToWx(os.str()), SBarID_);
438  if(SBar_->GetFieldsCount() == 2)
439  {
440  SBarWidths_[1] = max(SBarWidths_[1], ((int)(os.str().size()) * SBar_->GetCharWidth()));
441  SBar_->SetStatusWidths(SBar_->GetFieldsCount(), SBarWidths_);
442  }
443  }
444  //BIAS_MUTEX_UNLOCK(wxbitmap_mutex_);
445 }
446 
447 //////////////////////////////////////////////////
448 bool ImageCanvas::
449 GetMousePos(int& x, int& y)
450 {
451  x= mousex_; y=mousey_;
452  return ((mousex_>=0) && (mousey_>=0));
453 }
454 
455 //////////////////////////////////////////////////
456 bool ImageCanvas::
458 {
459  if(MyHistoWin_!=NULL && MyHistoWin_->IsShown())
460  return true;
461  else
462  return false;
463 }
464 
465 //////////////////////////////////////////////////
466 bool ImageCanvas::
468 {
469  if(MyValueBarFrame_!=NULL && MyValueBarFrame_->IsShown())
470  return true;
471  else
472  return false;
473 }
474 
475 //////////////////////////////////////////////////
476 void ImageCanvas::
478  if(MyValueBarFrame_!=NULL && MyValueBarFrame_->IsShown())
479  MyValueBarFrame_->Hide();
480 }
481 
482 void ImageCanvas::
484 {
485  KeepScrollPosition_ = flag;
486 }
487 
488 //////////////////////////////////////////////////
489 void ImageCanvas::
490 RaiseZoomWindow(const bool raise_or_lower)
491 {
492  if (MyZoomWin_->IsShown()){
493  if (raise_or_lower){
494  MyZoomWin_->Raise();
495  } else {
496  MyZoomWin_->Lower();
497  }
498  }
499 }
500 
501 //////////////////////////////////////////////////
502 void ImageCanvas::
503 OnErase(wxEraseEvent& )
504 {}
505 
506 //////////////////////////////////////////////////
507 void ImageCanvas::
508 OnPaint(wxPaintEvent & event)
509 {
510 
511  wxScrolledWindow::WXCOMPAT_ScW_OnPaint(event);
512  wxBufferedPaintDC dc(this);
513 
514  // documentation of wxBufferedPaintDC says:
515  // "you probably do not want to call PrepareDC [...] as it already does this
516  // internally for the real underlying wxPaintDC"
517  // but scrolling the canvas leads to broken areas!!!
518  // however, problem can be fixed by calling PrepareDC()
519  PrepareDC(dc);
520 
521  wxbitmap_mutex_.Lock();
522  if (wximage_ && wximage_->IsOk()){
523  if (Bitmap_ != NULL) {
524  delete Bitmap_; Bitmap_ = NULL;
525  }
526  if (ShowScaled_ && ScaledImageSizeX_>0 && ScaledImageSizeY_>0) {
527  wximage_->Rescale(ScaledImageSizeX_, ScaledImageSizeY_,
528  UseHighScaleQuality_ ? wxIMAGE_QUALITY_HIGH : wxIMAGE_QUALITY_NORMAL);
529  }
530  Bitmap_ = new wxBitmap( *wximage_ );
531  }
532 
533 #ifndef __APPLE__ // core dumps under mc os x 10.5
534  if (wxRoiImage_ && wxRoiImage_->IsOk()){
535  if (RoiBitmap_ != NULL) {
536  delete RoiBitmap_; RoiBitmap_ = NULL;
537  }
538  if (ShowScaled_ && ScaledImageSizeX_>0 && ScaledImageSizeY_>0) {
539  wxRoiImage_->Rescale(ScaledImageSizeX_, ScaledImageSizeY_,
540  UseHighScaleQuality_ ? wxIMAGE_QUALITY_HIGH : wxIMAGE_QUALITY_NORMAL);
541  }
542  RoiBitmap_ = new wxBitmap( *wxRoiImage_ );
543  }
544 #endif // __APPLE__
545 
546  if (Bitmap_ && Bitmap_->IsOk() && dc.IsOk()) {
547  // since now using double buffering, turning off
548  // clearing is actually unnecessary
549  if (ClearDrawingContext_) {
550  dc.Clear();
551  }
552  dc.DrawBitmap( *Bitmap_, 0, 0,false );
553 
554 #ifndef __APPLE__ // core dumps under mc os x 10.5
555  if(DrawRoi_)
556  {
557  PaintRoiOnDc_(dc);
558  }//if draw roi
559 #endif
560  }
561  wxbitmap_mutex_.Unlock();
562  //wxPostEvent(this->GetParent()->GetEventHandler(), event);
563 }
564 
565 //////////////////////////////////////////////////
566 void ImageCanvas::
567 PaintRoiOnDc_(wxBufferedPaintDC& dc)
568 {
569  ROI* tmpRoi = origim_.GetROI();
570  if(!tmpRoi) return;
571 
572  wxPen pen(wxColor(0,255,255,128));
573  dc.SetPen(pen);
574  switch(tmpRoi->GetROIType())
575  {
576  case ROI_Corners:
577  {
578  unsigned ulx,uly,lrx,lry;
579  tmpRoi->GetCorners(ulx,uly,lrx,lry);
580  if(!((ulx==0)&&(uly==0)&&
581  (lrx==origim_.GetWidth())&&(lry==origim_.GetHeight())))
582  {
583  wxPen pen(wxColor(0,255,255,128));
584  if(ShowScaled_)
585  {
586  double sx = (double)ScaledImageSizeX_/(double)origim_.GetWidth();
587  double sy = (double)ScaledImageSizeY_/(double)origim_.GetHeight();
588  ulx = (unsigned)(double(ulx)* sx);
589  uly = (unsigned)(double(uly)* sy);
590  lrx = (unsigned)(double(lrx)* sx);
591  lry = (unsigned)(double(lry)* sy);
592  }
593  dc.DrawLine(ulx,uly,lrx,uly);
594  dc.DrawLine(lrx,uly,lrx,lry);
595  dc.DrawLine(lrx,lry,ulx,lry);
596  dc.DrawLine(ulx,lry,ulx,uly);
597  } //if size valid
598  break;
599  } //case
600  case ROI_Mask:
601  {
602  //pixel not in the ROI is set to UCHAR_MAX and every other pixel to 0
603  if(RoiBitmap_)
604  dc.DrawBitmap(*RoiBitmap_,0,0);
605  }
606  break;
607  case ROI_Rows:
608  {
609  vector<unsigned> start, end;
610  if (!tmpRoi->GetRows(start, end)){
611  BIASERR("should never happen");
612  BIASABORT;
613  }
614  if (start.size()!=end.size() || start.size()!=origim_.GetHeight()){
615  BIASERR("invalid roi");
616  BIASABORT;
617  }
618  double sx = 1.0, sy = 1.0;
619  if(ShowScaled_){
620  sx = (double)ScaledImageSizeX_/(double)origim_.GetWidth();
621  sy = (double)ScaledImageSizeY_/(double)origim_.GetHeight();
622  }
623  const unsigned height = origim_.GetHeight();
624  for (unsigned y=0; y<height; y++){
625  if (start[y]!=0 || end[y]!=0){
626  unsigned tx = (unsigned)rint(sx*(double)(start[y]));
627  unsigned ty = (unsigned)rint(sy*(double)(y));
628  dc.DrawPoint(tx, ty);
629  tx = (unsigned)rint(sx*(double)(end[y]));
630  dc.DrawPoint(tx, ty);
631  }
632  }
633  }
634  break;
635  case ROI_Points:
636  default:
637  BIASWARN("imagecanvas::PaintRoiOnDc_ : exotic ROI type not handled! ");
638  break;
639  }
640 
641 }
642 
643 //////////////////////////////////////////////////
644 void ImageCanvas::
645 OnMouseWheel(wxMouseEvent &event){
646  if(event.AltDown() && event.GetWheelRotation() > 0){
647  ShowScaled_ =true;
648  ScaledImageSizeX_ = (int)(ScaledImageSizeX_ * 1.1);
649  ScaledImageSizeY_ = (int)(ScaledImageSizeY_ * 1.1);
650  }
651  else if(event.AltDown() && event.GetWheelRotation() < 0){
652  ShowScaled_ =true;
653  ScaledImageSizeX_ = (int)(ScaledImageSizeX_ * 0.9);
654  ScaledImageSizeY_ = (int)(ScaledImageSizeY_ * 0.9);
655  }
656  // cout<<"Mouse wheel"<<endl;
657  wxPaintEvent e;
658  OnPaint(e);
659  event.Skip();
660 }
661 
662 //////////////////////////////////////////////////
663 void ImageCanvas::
664 OnMouseLeave(wxMouseEvent &event)
665 {
666  if (SBar_) SBar_->SetStatusText(wxT(""), SBarID_);
667  mousex_=mousey_=-1;
668  event.Skip();
669 }
670 
671 //////////////////////////////////////////////////
672 void ImageCanvas::
673 OnMouseEnter(wxMouseEvent &event)
674 {
675  //if (SBar_) SBar_->SetStatusText(wxT("Test"), 0);
676  //mousex_=mousey_=-1;
677  //event.Skip();
678 }
679 
680 //////////////////////////////////////////////////
681 void ImageCanvas::
682 OnMouseMove(wxMouseEvent &event)
683 {
684  wxClientDC dc(this);
685  PrepareDC(dc);
686  if (GetParent()) GetParent()->PrepareDC(dc);
687  wxPoint pos = event.GetPosition();
688  mousex_ = dc.DeviceToLogicalX( pos.x );
689  mousey_ = dc.DeviceToLogicalY( pos.y );
690 
691  if (ShowScaled_) {
692  // if we are in scaled mode, correct coordinates by scale !
693  double w = ScaledImageSizeX_, h = ScaledImageSizeY_;
694  double ow = origim_.GetWidth(), oh = origim_.GetHeight();
695  double ratiox = ow/w , ratioy = oh/h;
696  mousex_ = (int)(mousex_ * ratiox);
697  mousey_ = (int)(mousey_ * ratioy);
698  }
699  UpdateStatusBar((unsigned)mousex_, (unsigned)mousey_);
700  //event.Skip();
701 }
702 
703 //////////////////////////////////////////////////
704 void ImageCanvas::
705 OnRightMouseButton(wxMouseEvent &event)
706 {
707  wxClientDC dc(this);
708  PrepareDC(dc);
709  wxPoint pos = event.GetPosition();
710  unsigned x = (unsigned) dc.DeviceToLogicalX( pos.x );
711  unsigned y = (unsigned) dc.DeviceToLogicalY( pos.y );
712  Zoom(x, y);
713  MyZoomWin_->Raise();
714 }
715 
716 //////////////////////////////////////////////////
717 void ImageCanvas::
718 OnLeftMouseButton(wxMouseEvent &event)
719 {
720  event.ResumePropagation(wxEVENT_PROPAGATE_MAX);
721  event.Skip();
722 }
723 
724 //////////////////////////////////////////////////
725 void ImageCanvas::
726 OnSize(wxSizeEvent& event)
727 {
728  Fit();
729  event.Skip();
730 }
731 
732 //////////////////////////////////////////////////
733 void ImageCanvas::
734 OnKeyPress(wxKeyEvent &event)
735 {
736  event.ResumePropagation(wxEVENT_PROPAGATE_MAX);
737  // cerr <<"ImageCanvas::OnKeyPress\n";
738  event.Skip();
739 }
virtual void OnSize(wxSizeEvent &event)
class for handling different region of interest (ROI) representations...
Definition: ROI.hh:118
enum ERoiType GetROIType() const
is the mask image valid?
Definition: ROI.hh:303
virtual void OnKeyPress(wxKeyEvent &event)
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
Definition: StringConv.hh:32
void GetCorners(unsigned &UpperLeftX, unsigned &UpperLeftY, unsigned &LowerRightX, unsigned &LowerRightY) const
Return the region of interest, by saving the coordinates within the variables defined by the paramete...
Definition: ROI.hh:443
It&#39;s a Frame used to have a Histogramm Canvas, which describes a histogramm of current image...
Definition: HistoFrame.hh:47
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Definition: ImageBase.hh:245
static void PrintPixelValue(const ImageBase &im, const unsigned int x, const unsigned int y, const unsigned short channel=0, std::ostream &os=std::cout)
print the (typed) pixel value to stream.
Definition: ImageBase.cpp:1919
virtual void OnPaint(wxPaintEvent &event)
void GetSingleImage(Image< StorageType > &im) const
returns a single image containing all pyramid images
display image in wx application, provides zoom and investigation functionality
Definition: ImageCanvas.hh:38
bool IsPlanar() const
Definition: ImageBase.hh:484
bool GetMousePos(int &x, int &y)
virtual void OnErase(wxEraseEvent &event)
void ShowImageValueBar(wxPoint pos=wxPoint(10, 10), wxSize size=wxSize(100, 100))
virtual void OnMouseWheel(wxMouseEvent &event)
PGR XB3 in format 7 mode 3 delivers an image that consists of 3 channels with 8bbp (overal 24bpp)...
Definition: ImageBase.hh:152
Frame to display a Image legend, for example in biasviewwx.
void UpdateStatusBar(unsigned x, unsigned y)
void InitHisto(wxPoint pos=wxPoint(10, 10), wxSize size=wxSize(100, 100))
Definition: ImageCanvas.cpp:96
void Zoom(unsigned x, unsigned y)
void ShowHistogramm(wxPoint pos=wxPoint(10, 10), wxSize size=wxSize(100, 100))
bool ImageValueBarIsShown()
color values, 3 channels, order: red,green,blue
Definition: ImageBase.hh:131
used by ImageCanvas and ScaledImageCanvas, should not be used directly
Definition: ZoomFrame.hh:23
virtual void OnMouseMove(wxMouseEvent &event)
virtual void OnMouseEnter(wxMouseEvent &event)
virtual void PaintRoiOnDc_(wxBufferedPaintDC &dc)
wxPoint GetValueBarPos()
bool GetRows(std::vector< unsigned > &start, std::vector< unsigned > &end) const
Horizontal start and end position per image row, the length of the vectors always corresponds to the ...
Definition: ROI.hh:261
void RaiseZoomWindow(const bool raise_or_lower)
virtual void OnMouseLeave(wxMouseEvent &event)
enum EColorModel GetColorModel() const
Definition: ImageBase.hh:407
void InitImageValueBar(wxPoint pos=wxPoint(10, 10), wxSize size=wxSize(100, 100))
static int Convert(BIAS::ImageBase &source, BIAS::ImageBase &dest, enum BIAS::ImageBase::EColorModel targetColorModel, bool bPlanar=false)
main general conversion function, calls desired specialized functions, always initializes the destIma...
virtual void OnRightMouseButton(wxMouseEvent &event)
virtual void Show(BIAS::Image< unsigned char > &im, std::string name="")
wxSize GetValueBarSize()
virtual void OnLeftMouseButton(wxMouseEvent &event)
wxPoint GetHistoPos()
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
void KeepScrollPosition(bool flag)