1 #include "ScaledImageCanvas.hh"
3 #include <Gui/StringConv.hh>
4 #include <Base/Image/ImageConvert.hh>
5 #include <Image/PyramidImage.hh>
32 int sbarid, wxWindowID
id,
33 const wxPoint& pos,
const wxSize& size,
34 long style,
const wxString& name)
35 : wxPanel(parent, id, pos, size, style, name), scaledf_()
39 wxDefaultSize, wxHSCROLL | wxVSCROLL, name);
61 wxT(
"Auto(Scale/Offset)"), wxDefaultPosition,
65 wxBoxSizer *hbox_scale =
new wxBoxSizer(wxHORIZONTAL);
66 wxBoxSizer *hbox_offset =
new wxBoxSizer(wxHORIZONTAL);
80 wxSize(-1, -1), wxSL_HORIZONTAL);
83 double scal_v =
ScaleSL_->GetValue();
84 ostringstream sc_stream; sc_stream << scal_v;
86 wxDefaultPosition,
box_size, wxSP_ARROW_KEYS);
89 wxDefaultPosition,
box_size, wxTE_PROCESS_ENTER);
91 wxDefaultPosition,
box_size, wxTE_PROCESS_ENTER);
95 wxString value_sc_steps =
AsciiToWx(sc_stream.str());
98 wxSP_ARROW_KEYS, 1, 80000);
100 hbox_scale->Add(
new wxStaticText(
this, -1, _T(
"Scale: ") ), 0, wxALL, 3);
102 hbox_scale->Add(
new wxStaticText(
this, -1, _T(
" [ ") ), 0, wxALL, 3);
104 hbox_scale->Add(
ScaleSL_, 1, wxALL | wxGROW, 3);
106 hbox_scale->Add(
new wxStaticText(
this, -1, _T(
"] Steps: ") ), 0, wxALL, 3);
107 hbox_scale->Add(Scale_Steps_);
108 hbox_scale->Add(
new wxStaticText(
this, -1, _T(
" | ") ), 0, wxALL, 3);
110 wxStaticText* temp =
new wxStaticText(
this, -1, wxT(
""),
112 hbox_scale->Add(temp);
120 wxSize(-1, -1), wxSL_HORIZONTAL);
123 ostringstream of_stream; of_stream <<
OffsSL_->GetValue();
125 wxDefaultPosition,
box_size, wxSP_ARROW_KEYS);
128 wxDefaultPosition,
box_size, wxTE_PROCESS_ENTER);
130 wxDefaultPosition,
box_size, wxTE_PROCESS_ENTER);
134 wxString value_of_steps =
AsciiToWx(of_stream.str());
137 wxSP_ARROW_KEYS, 1, 80000);
139 hbox_offset->Add(
new wxStaticText(
this, -1, _T(
"Offset: ") ), 0, wxALL, 3);
141 hbox_offset->Add(
new wxStaticText(
this, -1, _T(
" [ ") ), 0, wxALL, 3);
143 hbox_offset->Add(
OffsSL_, 1, wxALL | wxGROW, 3);
145 hbox_offset->Add(
new wxStaticText(
this, -1, _T(
"] Steps: ") ), 0, wxALL, 3);
146 hbox_offset->Add(Offset_Steps_);
147 hbox_offset->Add(
new wxStaticText(
this, -1, _T(
" | ") ), 0, wxALL, 3);
151 wxBoxSizer *vbox =
new wxBoxSizer(wxVERTICAL);
153 vbox->Add(
MiaScWi_, 1, wxALL | wxGROW, 0);
154 vbox->Add(hbox_scale, 0, wxGROW, 0);
155 vbox->Add(hbox_offset, 0, wxGROW, 0);
156 vbox->SetSizeHints(
this);
200 wxMessageBox(
AsciiToWx(
string(
"p_StatBar NULL. " + s)) );
231 double scale=0, shift=0;
234 double a1, a2, b1, b2;
236 a1 = scale*10; a2 = scale/10;
239 a1 = scale/10; a2 = scale*10;
246 b1 = shift*10; b2 = shift/10;
249 b1 = shift/10; b2 = shift*10;
252 b1 = -50.0; b2 = 50.0;
285 cout <<
"invalid scale (too small) - clipping it to minimum" << endl;
289 cout <<
"invalid scale (too big) - clipping it to maximum" << endl;
294 BIASASSERT(value>=0);
317 cout <<
"invalid offset (too small) - clipping it to minimum" << endl;
321 cout <<
"invalid offset (too big) - clipping it to maximum" << endl;
341 double sc=1.0, ofs=0.0;
354 ostringstream sc_stream; sc_stream << sc;
355 ostringstream of_stream; of_stream << ofs;
357 wxString value_sc =
AsciiToWx(sc_stream.str());
358 wxString value_of =
AsciiToWx(of_stream.str());
369 ss<<
"scale "<<sc<<
" offset: "<<ofs;
388 BIASERR(
"error converting to unsigned char");
420 double scale_l = atof(WxToAscii(
Scale_L_->GetValue()));
421 double scale_r = atof(WxToAscii(
Scale_R_->GetValue()));
423 if(scale_l > scale_r){
426 ostringstream sc_stream;
427 sc_stream << scale_l;
433 ostringstream sc_stream;
434 sc_stream << scale_r;
448 double offset_l = atof(WxToAscii(
Offset_L_->GetValue()));
449 double offset_r = atof(WxToAscii(
Offset_R_->GetValue()));
451 if(offset_l > offset_r){
454 ostringstream of_stream;
456 of_stream << offset_r;
461 ostringstream of_stream;
463 of_stream << offset_l;
477 int scale_new =(int)rint((scale -
MinScale_)*(double)slider_sc_digits/
479 int offset_new = (int)rint((offset -
MinOffSet_)*(double)slider_of_digits/
483 ScaleSL_->SetValue((
int)slider_sc_digits);
484 else if(scale_new < 0)
489 if(offset_new > (
int)slider_of_digits)
490 OffsSL_->SetValue((
int)slider_of_digits);
491 else if(offset_new < 0)
494 OffsSL_->SetValue((
int)offset_new);
533 SetRanges(
double value_sc_double_l,
534 double value_sc_double_r,
535 double value_of_double_l,
536 double value_of_double_r){
537 ostringstream sc_stream_l; sc_stream_l << value_sc_double_l;
538 Scale_L_->SetValue(
AsciiToWx(sc_stream_l.str()));
539 ostringstream sc_stream_r; sc_stream_r << value_sc_double_r;
540 Scale_R_->SetValue(
AsciiToWx(sc_stream_r.str()));
542 ostringstream of_stream_l; of_stream_l << value_of_double_l;
543 Offset_L_->SetValue(
AsciiToWx(of_stream_l.str()));
544 ostringstream of_stream_r; of_stream_r << value_of_double_r;
545 Offset_R_->SetValue(
AsciiToWx(of_stream_r.str()));
547 UpdateScaleOffsetBorders();
554 double &value_sc_double_l,
555 double &value_sc_double_r,
556 double &value_of_double_l,
557 double &value_of_double_r,
572 value_sc_double_l = atof(WxToAscii(
Scale_L_->GetValue()));
573 value_sc_double_r = atof(WxToAscii(
Scale_R_->GetValue()));
574 value_of_double_l = atof(WxToAscii(
Offset_L_->GetValue()));
575 value_of_double_r = atof(WxToAscii(
Offset_R_->GetValue()));
582 double value_sc_double_l,
583 double value_sc_double_r,
584 double value_of_double_l,
585 double value_of_double_r,
606 SetRanges(value_sc_double_l,value_sc_double_r
607 ,value_of_double_l,value_of_double_r);
616 double offset_factor){
621 if(scale_factor > 0.0 &&
622 offset_factor > 0.0){
624 double value_sc_double = ((double)(
ScaleSL_->GetValue())*
627 double value_of_double = ((double)(
OffsSL_->GetValue())*
636 double value_sc_double_l = value_sc_double/scale_factor;
637 ostringstream sc_stream_l; sc_stream_l << value_sc_double_l;
639 double value_sc_double_r = value_sc_double*scale_factor;
640 ostringstream sc_stream_r; sc_stream_r << value_sc_double_r;
643 double value_of_double_l = value_of_double-offset_factor;
644 ostringstream of_stream_l; of_stream_l << value_of_double_l;
646 double value_of_double_r = value_of_double+offset_factor;
647 ostringstream of_stream_r; of_stream_r << value_of_double_r;
699 ScaleSL_->SetRange(0, value_sc_steps_new);
704 OffsSL_->SetValue((
int)rint((
double)
OffsSL_->GetValue()*diff_of));
705 OffsSL_->SetRange(0, value_of_steps_new);
708 slider_sc_digits = value_sc_steps_new;
709 slider_of_digits = value_of_steps_new;
712 cout << slider_sc_digits << endl;
713 cout << slider_of_digits << endl;
740 double scale=0, shift=0;
744 double a1, a2, b1, b2;
746 a1 = scale*10; a2 = scale/10;
749 a1 = scale/10; a2 = scale*10;
756 b1 = shift*10; b2 = shift/10;
759 b1 = shift/10; b2 = shift*10;
762 b1 = -50.0; b2 = 50.0;
wxString scale_border_r_value
int SetOffset(double offset)
void SetNiceRanges(double scale_factor, double offset_factor)
set ranges so that they would look beautiful
int AboveThresholdToValue(StorageType Threshold, StorageType Value)
sets alls pixels with values above Threshold to Value
void KeepScrollPosition(bool flag)
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
int BelowThresholdToValue(StorageType Threshold, StorageType Value)
sets alls pixels with values below Threshold to Value
wxSpinCtrl * Scale_Steps_
wxString offset_border_l_value
void GetSingleImage(Image< StorageType > &im) const
returns a single image containing all pyramid images
void SetStatusBarPtr(wxStatusBar *p_sbar)
pointer to sbar to be used JW
void OnScaleOffset(wxScrollEvent &event)
void OnAutoScaleOffset(wxCommandEvent &event)
display image in wx application, provides zoom and investigation functionality
int ScaleShift(double Scale, double Shift)
scales and shifts image (all channels simultanously)
BIAS::Image< float > scaledf_
int SetScale(double scale)
void UpdateScaleOffsetBorders()
wxString offset_border_r_value
void OnHisto(wxCommandEvent &event)
void SetScaleRange(double min, double max)
void RaiseZoomWindow(const bool raise_or_lower)
ImageCanvas * GetImageCanvas()
void SetOffsetRange(double min, double max)
void GetScaleParameters(bool &Auto, double &value_sc_double_l, double &value_sc_double_r, double &value_of_double_l, double &value_of_double_r, double &scale, double &offset, int &value_sc_steps, int &value_of_steps)
BIAS::Image< unsigned char > rgbim_
static int ConvertST(const BIAS::ImageBase &source, BIAS::ImageBase &dest, ImageBase::EStorageType targetST)
Function to convert the storage type of images e.g.
color values, 3 channels, order: red,green,blue
void Show(BIAS::ImageBase &im, std::string name)
void RaiseZoomWindow(const bool raise_or_lower)
void SetStatusText(const std::string &s)
display text to sbar if one is assigned
ScaledImageCanvas(wxWindow *parent, wxStatusBar *sbar=NULL, int sbarid=0, wxWindowID id=-1, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name=wxT("ScaledScrolledWindow"))
BIAS::ImageBase & GetOrigimg()
void SetRanges(double value_sc_double_l, double value_sc_double_r, double value_of_double_l, double value_of_double_r)
set ranges of sliders
BIAS::Image< unsigned char > ucim_
void OnMouseWheel(wxMouseEvent &event)
enum EColorModel GetColorModel() const
wxCheckBox * Check_Auto_Sc_Of_
wxStaticText * Offset_Text_
void OnScaleOffsetSteps(wxSpinEvent &event)
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...
wxSpinCtrl * Offset_Steps_
enum EStorageType GetStorageType() const
(8bit) unsigned char image storage type
virtual void Show(BIAS::Image< unsigned char > &im, std::string name="")
wxString scale_border_l_value
void SetAutoadaptScale(const bool b)
recalculate scale and shift for each new frame or not ?
display float images in wx application, provides zoom, scale, shift and investigation functionality ...
wxStaticText * Scale_Text_
void OnScaleOffsetBorders(wxCommandEvent &event)
BIAS::ImageBase & GetShownImage()
This is the base class for images in BIAS.
void SetScaleParameters(bool Auto, double value_sc_double_l, double value_sc_double_r, double value_of_double_l, double value_of_double_r, double scale, double offset, int value_sc_steps, int value_of_steps)
int CalcScaleShift(double Min, double Max, double &Scale, double &Shift) const
calculate the values needed by ScaleShiftBetween
void KeepScrollPosition(bool flag)