Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ImageCanvasRectangularSelection.cpp
1 #include "ImageCanvasRectangularSelection.hh"
2 
3 #include <Base/Image/ImageConvert.hh>
4 #include <Base/ImageUtils/ImageDraw.hh>
5 
6 using namespace BIAS;
7 using namespace std;
8 
10 {
11 }
12 
14 {
15 }
16 
17 //void ICECallbackInterface::RectangleSelected(int tl[2], int br[2])
19 {
20  BIASERR("error: function of derived class should be called");
21 }
22 
23 /////////////////////////////////////////////////////////////////
24 
27  wxStatusBar* sbar,
28  int sbarid, wxWindowID id,
29  const wxPoint& pos,
30  const wxSize& size,
31  long style,
32  const wxString& name)
33  : ImageCanvas(parent, sbar, sbarid, id, pos, size, style, name)
34 {
36  SelectRectangle_=false;
37  CallbackObj_=NULL;
38  BottomRight_[0]=0;
39  BottomRight_[1]=0;
40  TopLeft_[0]=0;
41  TopLeft_[1]=0;
42 }
43 
46 {
47 }
48 
51 {
52  origim_mutex_.Lock();
53  BIASDOUT(D_IC_IM,"origim_ in SelectRectangle adr: "<<&origim_);
54  // BIASDOUT(D_IC_IM,"rgbim_ in SelectRectangle adr: "<<&rgbim_);
55  origim_mutex_.Unlock();
57  SelectRectangle_=true;
58  CallbackObj_=&obj;
59 
60 }
61 
63  EVT_LEFT_DOWN (ImageCanvasRectangularSelection::OnLeftMouseButton)
64  EVT_RIGHT_DOWN (ImageCanvasRectangularSelection::OnRightMouseButton)
65  EVT_MOTION (ImageCanvasRectangularSelection::OnMouseMove)
66  EVT_PAINT (ImageCanvasRectangularSelection::OnPaint)
67 END_EVENT_TABLE()
68 
70 OnLeftMouseButton(wxMouseEvent &event)
71 {
72  if (SelectRectangle_){
73  wxClientDC dc(this);
74  PrepareDC(dc);
75  wxPoint pos = event.GetPosition();
76  unsigned x = (unsigned) dc.DeviceToLogicalX( pos.x );
77  unsigned y = (unsigned) dc.DeviceToLogicalY( pos.y );
78  switch (NumLeftClicks_){
79  case 0:
80  TopLeft_[0]=x; TopLeft_[1]=y;
81  NumLeftClicks_++;
82  break;
83  case 1:
84  {
85  BottomRight_[0]=x; BottomRight_[1]=y;
86  CallbackObj_->RectangleSelected(TopLeft_, BottomRight_);
87  SelectRectangle_=false;
88  CallbackObj_=NULL;
89  NumLeftClicks_=0;
90  RefreshDrawImage_();
91  wxPaintEvent pe;
92  wxPostEvent(this->GetEventHandler(), pe);
93  }
94  break;
95  default:
96  BIASERR("something strange happend");
97  break;
98  }
99  } else {
100  event.Skip();
101  }
102 }
103 
105 OnRightMouseButton(wxMouseEvent &event)
106 {
107  if (SelectRectangle_){
108  NumLeftClicks_ = 0;
109  SelectRectangle_=false;
111  wxPaintEvent pe;
112  wxPostEvent(this->GetEventHandler(), pe);
113  }
114  else
115  event.Skip();
116 }
117 
119 OnPaint(wxPaintEvent &event) //wxCommandEvent &event)
120 {
122  {
123  event.Skip();
124  }
125  else
126  event.Skip();
127 }
128 
130 {
131  if (NumLeftClicks_==1 && SelectRectangle_){
132  wxClientDC dc(this);
133  PrepareDC(dc);
134  wxPoint pos = event.GetPosition();
135  int x = dc.DeviceToLogicalX( pos.x );
136  int y = dc.DeviceToLogicalY( pos.y );
137  BottomRight_[0]=x;
138  BottomRight_[1]=y;
140  }
141 
142  event.Skip();
143 }
144 
146 DrawRectangle_(int tl[2], int br[2])
147 {
148  unsigned char color[]={255, 0, 0};
150  int tmp;
151  int mtl[]={tl[0], tl[1]}, mbr[]={br[0], br[1]};
152 
153  if (mtl[0]>mbr[0]) { tmp=mtl[0]; mtl[0]=mbr[0]; mbr[0]=tmp; }
154  if (mtl[1]>mbr[1]) { tmp=mtl[1]; mtl[1]=mbr[1]; mbr[1]=tmp; }
155  ImageDraw<unsigned char>::RectangleCorners(rgbim_, mtl[0], mtl[1], mbr[0],
156  mbr[1], color);
157  BIASDOUT(D_IC_IM,"Rectangle drawn in Image adr: "<<&rgbim_);
158  wxPaintEvent pe;
159  wxPostEvent(this->GetEventHandler(), pe);
160 }
161 
164 {
165  Image<unsigned char> tmprgb;
168  BIASERR("error converting");
169  }
170  } else {
171  tmprgb=origim_;
172  }
173  Show(origim_, tmprgb, ImageName_);
174 }
BIAS::ImageBase origim_
Definition: ImageCanvas.hh:156
virtual void RectangleSelected(int tl[2], int br[2])
this function should be overloaded
provides functionality for selection of rectangle, point, ...
display image in wx application, provides zoom and investigation functionality
Definition: ImageCanvas.hh:38
ImageCanvasRectangularSelection(wxWindow *parent, wxStatusBar *sbar=NULL, int sbarid=0, wxWindowID id=-1, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(320, 240), long style=wxHSCROLL|wxVSCROLL, const wxString &name=AsciiToWx("ScrolledWindow"))
callback interface for ImageCanvasExtended
virtual void OnRightMouseButton(wxMouseEvent &event)
static int RectangleCorners(Image< StorageType > &im, const int minx, const int miny, const int maxx, const int maxy, const StorageType value[])
rectangles
Definition: ImageDraw.cpp:94
void SelectRectangle(ICECallbackInterface &obj)
Call SelectRectangle with an object derived from ICECallbackInterface.
color values, 3 channels, order: red,green,blue
Definition: ImageBase.hh:131
std::string ImageName_
Definition: ImageCanvas.hh:185
enum EColorModel GetColorModel() const
Definition: ImageBase.hh:407
BIAS::Image< unsigned char > rgbim_
Definition: ImageCanvas.hh:157
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 Show(BIAS::Image< unsigned char > &im, std::string name="")