Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ImageLegendFrame.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #include <Base/Common/W32Compat.hh>
26 #include "ImageLegendFrame.hh"
27 #include <Gui/ImageCanvas.hh>
28 #include <Base/Image/ImageConvert.hh>
29 #include <Base/Image/ImageIO.hh>
30 #include <Gui/StringConv.hh>
31 #include <Base/Common/FileHandling.hh>
32 
33 
34 
35 using namespace BIAS;
36 using namespace std;
37 
38 // icon
39 #if !defined(__WXPM__)
40 # include <img/biasviewwx.xpm>
41 #endif
42 
43 
45 ImageLegendFrame(wxWindow* parent, const wxString& title,
46  wxPoint pos, wxSize size)
47  : wxFrame(parent, -1, title, pos, size,
48  wxDEFAULT_FRAME_STYLE | wxCLIP_CHILDREN | wxFULL_REPAINT_ON_RESIZE)
49 {
50  SetIcon(wxIcon(biasviewwx_xpm));
51  defaultDir_="";
52  defaultFile_="";
53  vbWidth_ = 120;
54  vbHeight_ = 400;
55 
56  Setup(size);
57  Show();
58 
59 #ifdef WIN32
60  window_->Refresh();
61 #endif
62 
63 }
64 
65 
67 Setup(wxSize size)
68 {
69  // create tool bar
70  wxToolBar* toolBar = new wxToolBar(this, -1);
71 
72  wxSize ticksSize(40,25);
73  ticksSpin_= new wxSpinCtrl(toolBar,
74  ID_Ticks,
75  wxT("10"),
76  wxDefaultPosition, ticksSize,
77  wxSP_ARROW_KEYS, 1, 2000);
78  wxStaticText *tx= new wxStaticText(toolBar, ID_Static, AsciiToWx("# Ticks: "),wxDefaultPosition);
79  toolBar->AddControl(tx);
80  toolBar->AddControl(ticksSpin_);
81 
82  stringstream wi; wi<<vbWidth_;
83  stringstream he; he<<vbHeight_;
84  wxSize sizeSize(60,25);
85  toolBar->AddSeparator();
86  xSpin_= new wxSpinCtrl(toolBar,ID_X,AsciiToWx(wi.str()),wxDefaultPosition, sizeSize,
87  wxSP_ARROW_KEYS, 1, 2000);
88  ySpin_= new wxSpinCtrl(toolBar,ID_Y,AsciiToWx(he.str()),wxDefaultPosition, sizeSize,
89  wxSP_ARROW_KEYS, 1, 2000);
90 
91  toolBar->AddControl(new wxStaticText(toolBar, ID_Static, AsciiToWx(" Size:" ),wxDefaultPosition));
92  toolBar->AddControl(xSpin_);
93  toolBar->AddControl(new wxStaticText(toolBar, ID_Static, AsciiToWx(" X "),wxDefaultPosition));
94  toolBar->AddControl(ySpin_);
95  toolBar->AddControl(new wxStaticText(toolBar, ID_Static, AsciiToWx(" Y" ),wxDefaultPosition));
96  toolBar->AddSeparator();
97  wxButton *saveButton = new wxButton(toolBar, ID_Save, wxT("Save"),wxDefaultPosition,sizeSize);
98  toolBar->AddControl(saveButton);
99 
100  toolBar->Realize();
101  SetToolBar(toolBar);
102 
103 
104  int widths[] = {100, -1};
105  CreateStatusBar(2);
106  GetStatusBar()->SetStatusWidths(2, widths);
107  GetStatusBar()->SetStatusText(wxT("Legend"), 0);
108  GetStatusBar()->Show();
109  SetMinSize(wxSize(400, 470));
110  GetStatusBar()->SetStatusStyles(2, wxSB_NORMAL);
111  GetStatusBar()->SetMinHeight(30);
112 
113  wxBoxSizer *box = new wxBoxSizer(wxVERTICAL);
114  //Correct the size of the canvas (it's 6 pxl thinner and 31 pxl smaller)
115  wxSize size_canvas = wxSize(size.GetWidth()-6,
116  size.GetHeight()-61);
117  window_ = new ImageCanvas(this, GetStatusBar(), 1, -1,
118  wxDefaultPosition, size_canvas);
119  box->Add(window_, 1, wxALL | wxGROW, 3);
120 
121  SetSizer(box);
122 }
123 
124 
125 //Destructor
128 {}
129 
130 
131 BEGIN_EVENT_TABLE (ImageLegendFrame, wxWindow)
132  EVT_CLOSE (ImageLegendFrame::OnClose)
133  EVT_SIZE (ImageLegendFrame::OnSize)
134  EVT_BUTTON (ImageLegendFrame::ID_Save, ImageLegendFrame::OnSave)
135  EVT_SPINCTRL (ImageLegendFrame::ID_Ticks,ImageLegendFrame::OnTicks)
136  EVT_SPINCTRL (ImageLegendFrame::ID_X,ImageLegendFrame::OnLegendSize)
137  EVT_SPINCTRL (ImageLegendFrame::ID_Y,ImageLegendFrame::OnLegendSize)
138 END_EVENT_TABLE()
139 
140 
141 void ImageLegendFrame::
142 SetLegendSize(unsigned width, unsigned height){
143  vbWidth_ = width; vbHeight_=height;
144  xSpin_->SetValue(vbWidth_);
145  ySpin_->SetValue(vbHeight_);
146 }
147 
150 {
153  SetImage(imUC);
154  }
155  else if(im.GetStorageType()==ImageBase::ST_float){
156  Image<float> imFL= (Image<float>)im;
157  SetImage(imFL);
158  }
159 
160 }
163 {
165  vbUC_.Clear();
167  }
168 
169  unsigned char min,max;
170  im.GetMinMaxPixelValue(min,max);
171  vbUC_.SetValueRange(min,max);
172  vbUC_.SetDisplayRange(min,max);
173  vbUC_.SetUnit("");
175  vbUC_.Update();
176  window_->Show(vbUC_, "Legend");
177 }
178 
181 {
182  float min,max;
183  im.GetMinMaxPixelValue(min,max);
184  Image<float> tmp(im); tmp.ScaleShiftBetween(0,255);
185  Image<unsigned char> scaled;
187 
188  if(vbUC_.IsEmpty() ||scaled.GetChannelCount()!= vbUC_.GetChannelCount() ){
189  vbUC_.Clear();
191  }
192  vbUC_.SetDisplayRange(min,max);
193  unsigned char minUC,maxUC;
194  scaled.GetMinMaxPixelValue(minUC,maxUC);
195  vbUC_.SetValueRange(minUC,maxUC);
196  vbUC_.SetUnit("mm");
198  vbUC_.Update();
199  window_->Show(vbUC_, "Legend");
200 }
201 
202 
204 OnSave(wxCommandEvent& event){
205 
206  wxString message = _T("Save legend to");
207  wxString wildcard = _T("*.*");
208 
209  wxFileDialog wd(this,
210  message,
213  wildcard,
214  wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
215 
216  if (wxID_OK == wd.ShowModal()) {
217  defaultFile_ = WxToAscii(wd.GetPath());
218  defaultDir_ = WxToAscii(wd.GetDirectory());
220  }
221 }
222 
224 OnQuit(wxCommandEvent & event)
225 {
226  Close(true);
227 }
228 
229 
231 OnClose(wxCloseEvent & event)
232 {
233  Hide();
234 }
235 
236 
238 OnSize(wxSizeEvent& event)
239 {
240  //-61 in Height is for the StatusBar to be visible
241  window_->SetSize(this->GetSize().GetWidth(), this->GetSize().GetHeight()-61);
242 }
243 
244 
246 OnTicks(wxSpinEvent& WXUNUSED(event))
247 {
248  if(!vbUC_.IsEmpty()){
249  int num = ticksSpin_->GetValue();
250  vbUC_.SetTicks(num);
251  vbUC_.Update();
252  window_->Show(vbUC_, "Legend");
253  }
254 }
255 
257 OnLegendSize(wxSpinEvent& WXUNUSED(event))
258 {
259  if(!vbUC_.IsEmpty()){
260  int x = xSpin_->GetValue();
261  int y = ySpin_->GetValue();
263  vbUC_.Update();
264  window_->Show(vbUC_, "Legend");
265  }
266 }
void SetValueRange(double min, double max)
void OnClose(wxCloseEvent &event)
void SetDisplayRange(double min, double max)
void OnSize(wxSizeEvent &event)
ImageValueBar< unsigned char > vbUC_
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
Definition: StringConv.hh:32
gray values, 1 channel
Definition: ImageBase.hh:130
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Definition: ImageBase.hh:245
int ScaleShiftBetween(double Min, double Max)
scales and shifts image so afterwards every pixel has a value between Min and Max ...
Definition: Image.cpp:1118
float image storage type
Definition: ImageBase.hh:118
display image in wx application, provides zoom and investigation functionality
Definition: ImageCanvas.hh:38
void OnQuit(wxCommandEvent &event)
void OnSave(wxCommandEvent &event)
void GetMinMaxPixelValue(StorageType &min, StorageType &max, unsigned short int channel=0, unsigned int *mincoo=NULL, unsigned int *maxcoo=NULL) const
returns the minimal and maximal pixel value in channel only Finds minimum and maximum pixel value in ...
Definition: Image.cpp:802
void SetImage(BIAS::Image< unsigned char > &im)
ImageLegendFrame(wxWindow *parent, const wxString &title, wxPoint pos=wxPoint(10, 10), wxSize size=wxSize(300, 250))
Frame to display a Image legend, for example in biasviewwx.
void SetUnit(std::string unit)
void Clear(const StorageType value=0)
sets all pixels to zero/value
Definition: Image.hh:289
void ReInit(const unsigned int &width, const unsigned int &height, const unsigned int nChannels=1, const enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true, const EColorModel colormodel=CM_Grey)
(Re-)Initialize Image data if required.
Definition: ImageBase.cpp:131
static int ConvertST(const BIAS::ImageBase &source, BIAS::ImageBase &dest, ImageBase::EStorageType targetST)
Function to convert the storage type of images e.g.
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
Definition: ImageBase.hh:382
color values, 3 channels, order: red,green,blue
Definition: ImageBase.hh:131
void Setup(wxSize size=wxSize(300, 250))
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Definition: ImageIO.cpp:725
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
Definition: Image.cpp:421
void OnLegendSize(wxSpinEvent &event)
BIAS::ImageCanvas * window_
void SetTicks(int num_ticks)
enum EStorageType GetStorageType() const
Definition: ImageBase.hh:414
(8bit) unsigned char image storage type
Definition: ImageBase.hh:112
virtual void Show(BIAS::Image< unsigned char > &im, std::string name="")
BIAS::Image< unsigned char > * GetImageShown()
Definition: ImageCanvas.hh:84
void SetColorModel(ImageBase::EColorModel model)
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
void OnTicks(wxSpinEvent &event)