Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleImageCanvas.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 ExampleImageCanvas.cpp
24  @relates ImageCanvas
25  @brief Simple example for ImageCanvas Usage
26  @ingroup g_examples
27  @author MIP
28 */
29 
30 #include <bias_config.h>
31 
32 #include <wx/wx.h>
33 #include <Gui/ImageCanvas.hh>
34 #include <Gui/StringConv.hh>
35 #include <Base/Image/ImageIO.hh>
36 
37 using namespace BIAS;
38 using namespace std;
39 
40 /** \cond HIDDEN_SYMBOLS */
41 enum { ID_Quit = 1, ID_About, ID_Load};
42 
43 class MyApp: public wxApp
44 {
45  virtual bool OnInit();
46 };
47 
48 IMPLEMENT_APP(MyApp)
49 
50 class MyFrame: public wxFrame
51 {
52 public:
53 
54  MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
55 
56  void OnQuit(wxCommandEvent& event);
57  void OnAbout(wxCommandEvent& event);
58  void OnLoad(wxCommandEvent& event);
59 
60  ImageCanvas *_ic;
61 
62  DECLARE_EVENT_TABLE()
63 };
64 
65 bool MyApp::OnInit()
66 {
67  MyFrame *frame = new MyFrame( wxT("ImageCanvas"), wxPoint(50,50),
68  wxSize(450,340) );
69  frame->Show(TRUE);
70  SetTopWindow(frame);
71  return TRUE;
72 }
73 
74 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
75  EVT_MENU(ID_Quit, MyFrame::OnQuit)
76  EVT_MENU(ID_About, MyFrame::OnAbout)
77  EVT_MENU(ID_Load, MyFrame::OnLoad)
78 END_EVENT_TABLE()
79 
80 
81 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
82  : wxFrame((wxFrame *)NULL, -1, title, pos, size)
83 {
84  wxMenu *menuFile = new wxMenu;
85 
86  menuFile->Append( ID_About, wxT("&About...") );
87  menuFile->Append( ID_Load, wxT("&Load...") );
88  menuFile->AppendSeparator();
89  menuFile->Append( ID_Quit, wxT("E&xit") );
90 
91  wxMenuBar *menuBar = new wxMenuBar;
92  menuBar->Append(menuFile, wxT("&File"));
93  SetMenuBar(menuBar);
94 
95  CreateStatusBar(2);
96  SetStatusText(wxT("ImageName"), 0);
97 
98  wxBoxSizer *box=new wxBoxSizer(wxVERTICAL);
99  _ic=new ImageCanvas(this, GetStatusBar(), 1);
100  box->Add(_ic, 1, wxALL| wxGROW |wxALIGN_CENTER, 5);
101  box->SetSizeHints(this);
102  SetSizer(box);
103 
104  //const string fn("ucim.pgm");
105  const string fn(BIAS_TESTS_DATA "r4.jpg" );
107  int res=ImageIO::Load(fn, im);
108  if (res!=0){
109  cout<<"could not load "<<fn<<endl;
110  wxMessageBox(_T( "could not load image. aborting. ") );
111  BIASABORT;
112  }
113  SetStatusText(_T("image"), 0);
114  _ic->Show(im, "image" );
115  FitInside();
116 }
117 
118 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
119 { Close(TRUE); }
120 
121 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
122 {
123  wxMessageBox(wxT("This is a wxWidgets Hello world sample"),
124  wxT("About Hello World"), wxOK | wxICON_INFORMATION, this);
125 }
126 
127 void MyFrame::OnLoad(wxCommandEvent& WXUNUSED(event))
128 {
129  wxFileDialog fileDialog(this, wxT("Choose a file"), wxT("."), wxT("ucim.pgm"));
130  if (fileDialog.ShowModal() == wxID_OK){
131  string fname=WxToAscii(fileDialog.GetPath());
133  if (ImageIO::Load(fname, im)!=0){
134  BIASERR("errro loading "<<fname);
135  } else {
136  SetStatusText(fileDialog.GetFilename(), 0);
137  _ic->Show(im, WxToAscii(fileDialog.GetFilename()));
138  }
139  } else {
140  cerr << "canceled loadin image" << endl;
141  }
142 }
143 /** \endcond */
display image in wx application, provides zoom and investigation functionality
Definition: ImageCanvas.hh:38
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