5 #include <wx/scrolwin.h>
11 #include "ImageCanvas.hh"
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>
43 wxWindowID
id, const wxPoint& pos, const wxSize& size,
44 long style, const wxString& name)
47 Bitmap_=(wxBitmap *)NULL;
48 wximage_=(wxImage *)NULL;
51 MyValueBarFrame_ = NULL;
55 ClearDrawingContext_=
true;
63 MyZoomWin_->Show(
false);
67 width_ = height_ = lastwidth_ = lastheight_ = 0;
68 KeepScrollPosition_ =
false;
69 SetHighScaleQuality(
false);
76 SBarWidths_[1] = 26 * SBar_->GetCharWidth();
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; }
98 MyHistoWin_=
new HistoFrame(
this, _T(
"Image Histogram"), pos, size);
99 MyHistoWin_->Show(
true);
105 MyValueBarFrame_->SetLegendSize(120,400);
106 MyValueBarFrame_->Show(
true);
125 BIASERR(
"error converting");
127 BIASDOUT(D_IC_IM,
"Show(im,name) called Show(im,tmpim,name)");
128 Show(im, tmpim, name);
130 BIASDOUT(D_IC_IM,
"Show(im,name) called Show(im,im,name)");
137 BIASERR(
"error converting");
139 BIASDOUT(D_IC_IM,
"Show(im,name) called Show(im,tmpIm,name)");
140 Show(im, tmpIm, name);
156 origim_mutex_.Lock();
157 BIASDOUT(D_IC_IM,
"Adress of origim: "<<&origim);
158 if(&origim_!=&origim)
161 origim_mutex_.Unlock();
163 if(&rgbim_!=&scaledrgbim)
166 BIASDOUT(D_IC_IM,
"Adress of rgbim_: "<<&rgbim_);
168 width_ = origim_.GetWidth ();
169 height_ = origim_.GetHeight();
176 wxPoint scrolledP(0,0),origP(0,0);
178 if(KeepScrollPosition_){
179 scrolledP = this->CalcScrolledPosition(origP);
181 scrolledP.x = -scrolledP.x;
182 scrolledP.y = -scrolledP.y;
185 if((scrolledP.x > ScaledImageSizeX_) || (scrolledP.y > ScaledImageSizeY_)){
190 if((scrolledP.x > (
int)width_) || (scrolledP.y > (
int)height_)){
197 if(width_ !=lastwidth_ || height_ != lastheight_){
198 scrolledP.x = scrolledP.y = 0;
203 SetVirtualSize( ScaledImageSizeX_ , ScaledImageSizeY_);
204 SetScrollbars(1, 1, ScaledImageSizeX_,ScaledImageSizeY_,scrolledP.x,scrolledP.y);
207 SetScrollbars(1, 1, width_, height_,scrolledP.x,scrolledP.y);
209 wxbitmap_mutex_.Lock();
210 if (wximage_ != NULL){
211 delete wximage_; wximage_ = NULL;
213 wximage_ =
new wxImage(rgbim_.GetWidth(), rgbim_.GetHeight(),
214 rgbim_.GetImageData(),
true);
216 #ifndef __APPLE__ // core dumps under mac os x 10.5
218 if((origim_.GetROI())&&(origim_.GetROI()->GetROIType()==
ROI_Mask))
220 if (wxRoiImage_ != NULL) {
221 delete wxRoiImage_; wxRoiImage_ = NULL;
223 origim_.GetROI()->GetMaskImage(roimask_);
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++)
233 if(alphaimg[p]!=0) alphaimg[p]=128;
236 wxRoiImage_ =
new wxImage(origim_.GetWidth(), origim_.GetHeight(),
238 wxRoiImage_->InitAlpha();
239 wxRoiImage_->SetAlpha(alphaimg,
true);
243 delete wxRoiImage_; wxRoiImage_ = NULL;
244 roimask_.Init(4,4,1);
248 wxbitmap_mutex_.Unlock();
249 if (MyZoomWin_->IsShown()) {
251 MyZoomWin_->NewImage(origim_, rgbim_,
AsciiToWx(ImageName_));
254 if(MyHistoWin_!=NULL){
255 if (MyHistoWin_->IsShown()) {
257 MyHistoWin_->NewImage(origim_,
AsciiToWx(ImageName_));
262 if(MyValueBarFrame_!=NULL){
263 if (MyValueBarFrame_->IsShown()) {
265 MyValueBarFrame_->SetImage(origim_);
270 if (mousex_>=0 && mousey_>=0){
271 UpdateStatusBar((
unsigned)mousex_, (
unsigned)mousey_);
282 wxPostEvent(this->GetEventHandler(),pe);
290 if(MyHistoWin_ != NULL)
291 return MyHistoWin_->GetPosition();
293 return wxPoint(10,10);
299 if(MyHistoWin_ != NULL)
300 return MyHistoWin_->GetSize();
302 return wxSize(300,250);
308 if(MyValueBarFrame_ != NULL)
309 return MyValueBarFrame_->GetPosition();
311 return wxPoint(10,10);
317 if(MyValueBarFrame_ != NULL)
318 return MyValueBarFrame_->GetSize();
320 return wxSize(300,250);
327 if(MyHistoWin_==NULL)
328 InitHisto(pos, size);
331 MyHistoWin_->NewImage(image,
AsciiToWx(ImageName_));
332 MyHistoWin_->Show(
true);
335 BIASERR(
"Hey, no image saved in image!");
343 if(MyHistoWin_==NULL)
344 InitHisto(pos, size);
346 if (!origim_.IsEmpty()){
347 MyHistoWin_->NewImage(origim_,
AsciiToWx(ImageName_));
348 MyHistoWin_->Show(
true);
351 BIASERR(
"Hey, no image saved in origim_!");
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);
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);
388 MyZoomWin_->NewImage(origim_, rgbim_,
AsciiToWx(ImageName_));
390 MyZoomWin_->SetZoom(DefaultZoom_);
391 MyZoomWin_->Show(
true);
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_)));
397 else MyZoomWin_->NewCoo(x, y);
406 if (SBar_==NULL)
return;
407 if(Bitmap_==NULL)
return;
412 BIASASSERT(SBar_ != NULL);
413 BIASASSERT(Bitmap_ != NULL);
414 if ((x>=0) && (x<width_) && (y>=0) && (y<height_))
419 os <<
"("<<setw(3)<<x<<
", "<<setw(3)<<y<<
") : (";
425 origim_mutex_.Lock();
427 for (
unsigned int channel=0;
428 channel<origim_.GetChannelCount();
435 origim_mutex_.Unlock();
437 SBar_->SetStatusText(
AsciiToWx(os.str()), SBarID_);
438 if(SBar_->GetFieldsCount() == 2)
440 SBarWidths_[1] = max(SBarWidths_[1], ((
int)(os.str().size()) * SBar_->GetCharWidth()));
441 SBar_->SetStatusWidths(SBar_->GetFieldsCount(), SBarWidths_);
451 x= mousex_; y=mousey_;
452 return ((mousex_>=0) && (mousey_>=0));
459 if(MyHistoWin_!=NULL && MyHistoWin_->IsShown())
469 if(MyValueBarFrame_!=NULL && MyValueBarFrame_->IsShown())
478 if(MyValueBarFrame_!=NULL && MyValueBarFrame_->IsShown())
479 MyValueBarFrame_->Hide();
485 KeepScrollPosition_ = flag;
492 if (MyZoomWin_->IsShown()){
511 wxScrolledWindow::WXCOMPAT_ScW_OnPaint(event);
512 wxBufferedPaintDC dc(
this);
521 wxbitmap_mutex_.Lock();
522 if (wximage_ && wximage_->IsOk()){
523 if (Bitmap_ != NULL) {
524 delete Bitmap_; Bitmap_ = NULL;
526 if (ShowScaled_ && ScaledImageSizeX_>0 && ScaledImageSizeY_>0) {
527 wximage_->Rescale(ScaledImageSizeX_, ScaledImageSizeY_,
528 UseHighScaleQuality_ ? wxIMAGE_QUALITY_HIGH : wxIMAGE_QUALITY_NORMAL);
530 Bitmap_ =
new wxBitmap( *wximage_ );
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;
538 if (ShowScaled_ && ScaledImageSizeX_>0 && ScaledImageSizeY_>0) {
539 wxRoiImage_->Rescale(ScaledImageSizeX_, ScaledImageSizeY_,
540 UseHighScaleQuality_ ? wxIMAGE_QUALITY_HIGH : wxIMAGE_QUALITY_NORMAL);
542 RoiBitmap_ =
new wxBitmap( *wxRoiImage_ );
546 if (Bitmap_ && Bitmap_->IsOk() && dc.IsOk()) {
549 if (ClearDrawingContext_) {
552 dc.DrawBitmap( *Bitmap_, 0, 0,
false );
554 #ifndef __APPLE__ // core dumps under mc os x 10.5
561 wxbitmap_mutex_.Unlock();
569 ROI* tmpRoi = origim_.GetROI();
572 wxPen pen(wxColor(0,255,255,128));
578 unsigned ulx,uly,lrx,lry;
580 if(!((ulx==0)&&(uly==0)&&
581 (lrx==origim_.GetWidth())&&(lry==origim_.GetHeight())))
583 wxPen pen(wxColor(0,255,255,128));
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);
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);
604 dc.DrawBitmap(*RoiBitmap_,0,0);
609 vector<unsigned> start, end;
610 if (!tmpRoi->
GetRows(start, end)){
611 BIASERR(
"should never happen");
614 if (start.size()!=end.size() || start.size()!=origim_.GetHeight()){
615 BIASERR(
"invalid roi");
618 double sx = 1.0, sy = 1.0;
620 sx = (double)ScaledImageSizeX_/(
double)origim_.GetWidth();
621 sy = (double)ScaledImageSizeY_/(
double)origim_.GetHeight();
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);
637 BIASWARN(
"imagecanvas::PaintRoiOnDc_ : exotic ROI type not handled! ");
646 if(event.AltDown() &&
event.GetWheelRotation() > 0){
648 ScaledImageSizeX_ = (int)(ScaledImageSizeX_ * 1.1);
649 ScaledImageSizeY_ = (int)(ScaledImageSizeY_ * 1.1);
651 else if(event.AltDown() &&
event.GetWheelRotation() < 0){
653 ScaledImageSizeX_ = (int)(ScaledImageSizeX_ * 0.9);
654 ScaledImageSizeY_ = (int)(ScaledImageSizeY_ * 0.9);
666 if (SBar_) SBar_->SetStatusText(wxT(
""), SBarID_);
686 if (GetParent()) GetParent()->PrepareDC(dc);
687 wxPoint pos =
event.GetPosition();
688 mousex_ = dc.DeviceToLogicalX( pos.x );
689 mousey_ = dc.DeviceToLogicalY( pos.y );
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);
699 UpdateStatusBar((
unsigned)mousex_, (
unsigned)mousey_);
709 wxPoint pos =
event.GetPosition();
710 unsigned x = (unsigned) dc.DeviceToLogicalX( pos.x );
711 unsigned y = (unsigned) dc.DeviceToLogicalY( pos.y );
720 event.ResumePropagation(wxEVENT_PROPAGATE_MAX);
736 event.ResumePropagation(wxEVENT_PROPAGATE_MAX);
virtual void OnSize(wxSizeEvent &event)
class for handling different region of interest (ROI) representations...
enum ERoiType GetROIType() const
is the mask image valid?
virtual void OnKeyPress(wxKeyEvent &event)
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
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...
It's a Frame used to have a Histogramm Canvas, which describes a histogramm of current image...
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
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.
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
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)...
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))
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
used by ImageCanvas and ScaledImageCanvas, should not be used directly
virtual void OnMouseMove(wxMouseEvent &event)
virtual void OnMouseEnter(wxMouseEvent &event)
virtual void PaintRoiOnDc_(wxBufferedPaintDC &dc)
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 ...
void RaiseZoomWindow(const bool raise_or_lower)
virtual void OnMouseLeave(wxMouseEvent &event)
enum EColorModel GetColorModel() const
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="")
virtual void OnLeftMouseButton(wxMouseEvent &event)
This is the base class for images in BIAS.
void KeepScrollPosition(bool flag)