Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleImageCanvasFloat.cpp
1 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3  Copyright (C) 2003-2009 (see file CONTACT for details)
4  Vision N GmbH
5  Schauenburgerstr. 116
6  24118 Kiel
7 
8  BIAS is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation; either version 2.1 of the License, or
11  (at your option) any later version.
12 
13  BIAS is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with BIAS; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
21 
22 /**
23  @example ExampleImageCanvasFloat.cpp
24  @relates ScaledImageCanvas
25  @brief Simple example to display a float image via ScaledImageCanvas
26  @ingroup g_examples
27  @author MIP
28 */
29 
30 
31 #include <Base/Common/W32Compat.hh>
32 
33 #include <wx/wx.h>
34 
35 #include <Gui/ScaledImageCanvas.hh>
36 #include <Gui/StringConv.hh>
37 #include <Base/Image/ImageIO.hh>
38 
39 using namespace BIAS;
40 using namespace std;
41 
42 /** \cond HIDDEN_SYMBOLS */
43 enum { ID_Quit = 1, ID_About, ID_Load};
44 
45 class MyApp: public wxApp
46 {
47  virtual bool OnInit();
48 };
49 
50 IMPLEMENT_APP(MyApp)
51 
52 class MyFrame: public wxFrame
53 {
54 public:
55 
56  MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
57 
58  void OnQuit(wxCommandEvent& event);
59  void OnAbout(wxCommandEvent& event);
60  void OnLoad(wxCommandEvent& event);
61 
62  ScaledImageCanvas *_ic;
63 
64  DECLARE_EVENT_TABLE()
65 };
66 
67 bool MyApp::OnInit()
68 {
69  MyFrame *frame = new MyFrame( wxT("ImageCanvas"), wxPoint(50,50),
70  wxSize(450,340) );
71 
72  if (argc>1) {
73  BIASASSERT(frame!=NULL);
74  string filename(WxToAscii(argv[1]));
75  ImageBase img;
76  //Image<float> im;
77  if (ImageIO::Load(filename, img)!=0){
78  BIASERR("error loading "<<filename<<endl);
79  } else {
80  // OK
81  //frame->SetStatusText("trying to load "+filename);
82  BIASASSERT(frame->_ic != NULL);
83  frame->_ic->Show(img, filename.c_str() );
84  cout<<"loaded image file "<<filename<<" successfully."<<endl;
85  //frame->SetStatusText("loaded "+filename);
86  }
87  };
88  frame->Show(TRUE);
89  SetTopWindow(frame);
90  return TRUE;
91 }
92 
93 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
94  EVT_MENU(ID_Quit, MyFrame::OnQuit)
95  EVT_MENU(ID_About, MyFrame::OnAbout)
96  EVT_MENU(ID_Load, MyFrame::OnLoad)
97 END_EVENT_TABLE()
98 
99 
100 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
101  : wxFrame((wxFrame *)NULL, -1, title, pos, size)
102 {
103  wxMenu *menuFile = new wxMenu;
104 
105  menuFile->Append( ID_About, wxT("&About...") );
106  menuFile->Append( ID_Load, wxT("&Load...") );
107  menuFile->AppendSeparator();
108  menuFile->Append( ID_Quit, wxT("E&xit") );
109 
110  wxMenuBar *menuBar = new wxMenuBar;
111  menuBar->Append(menuFile, wxT("&File"));
112 
113  SetMenuBar(menuBar);
114 
115  CreateStatusBar(2);
116  SetStatusText(wxT("ImageName"), 0);
117 
118  wxBoxSizer *box=new wxBoxSizer(wxVERTICAL);
119 
120  _ic=new ScaledImageCanvas(this, GetStatusBar(), 1);
121  box->Add(_ic, 1, wxALL| wxGROW, 5);
122  box->SetSizeHints(this);
123  SetSizer(box);
124 }
125 
126 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
127 { Close(TRUE); }
128 
129 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
130 {
131  wxMessageBox(wxT("This is a wxWidgets Hello world sample"),
132  wxT("About Hello World"), wxOK | wxICON_INFORMATION, this);
133 }
134 
135 void MyFrame::OnLoad(wxCommandEvent& WXUNUSED(event))
136 {
137  wxFileDialog fileDialog(this, wxT("Choose a file"), wxT("."), wxT(""));
138  if (fileDialog.ShowModal() == wxID_OK){
139  string fname=WxToAscii(fileDialog.GetPath());
140  Image<float> im;
141  if (ImageIO::Load(fname, im)!=0){
142  BIASERR("error loading "<<fname<<"\nshould a be float image");
143  } else {
144  SetStatusText(fileDialog.GetFilename().c_str(), 0);
145  _ic->Show(im, WxToAscii(fileDialog.GetFilename()));
146  }
147  } else {
148  cerr << "canceled loading image" << endl;
149  }
150 }
151 /** \endcond */
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
Definition: ImageIO.cpp:141
display float images in wx application, provides zoom, scale, shift and investigation functionality ...
This is the base class for images in BIAS.
Definition: ImageBase.hh:102