Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleImageCanvasFloat.cpp

Simple example to display a float image via ScaledImageCanvas

Author
MIP
/* This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Vision N GmbH
Schauenburgerstr. 116
24118 Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/
/**
@example ExampleImageCanvasFloat.cpp
@relates ScaledImageCanvas
@brief Simple example to display a float image via ScaledImageCanvas
@ingroup g_examples
@author MIP
*/
#include <Base/Common/W32Compat.hh>
#include <wx/wx.h>
#include <Gui/ScaledImageCanvas.hh>
#include <Gui/StringConv.hh>
#include <Base/Image/ImageIO.hh>
using namespace BIAS;
using namespace std;
/** \cond HIDDEN_SYMBOLS */
enum { ID_Quit = 1, ID_About, ID_Load};
class MyApp: public wxApp
{
virtual bool OnInit();
};
IMPLEMENT_APP(MyApp)
class MyFrame: public wxFrame
{
public:
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnLoad(wxCommandEvent& event);
DECLARE_EVENT_TABLE()
};
bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame( wxT("ImageCanvas"), wxPoint(50,50),
wxSize(450,340) );
if (argc>1) {
BIASASSERT(frame!=NULL);
string filename(WxToAscii(argv[1]));
ImageBase img;
//Image<float> im;
if (ImageIO::Load(filename, img)!=0){
BIASERR("error loading "<<filename<<endl);
} else {
// OK
//frame->SetStatusText("trying to load "+filename);
BIASASSERT(frame->_ic != NULL);
frame->_ic->Show(img, filename.c_str() );
cout<<"loaded image file "<<filename<<" successfully."<<endl;
//frame->SetStatusText("loaded "+filename);
}
};
frame->Show(TRUE);
SetTopWindow(frame);
return TRUE;
}
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(ID_Quit, MyFrame::OnQuit)
EVT_MENU(ID_About, MyFrame::OnAbout)
EVT_MENU(ID_Load, MyFrame::OnLoad)
END_EVENT_TABLE()
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
wxMenu *menuFile = new wxMenu;
menuFile->Append( ID_About, wxT("&About...") );
menuFile->Append( ID_Load, wxT("&Load...") );
menuFile->AppendSeparator();
menuFile->Append( ID_Quit, wxT("E&xit") );
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append(menuFile, wxT("&File"));
SetMenuBar(menuBar);
CreateStatusBar(2);
SetStatusText(wxT("ImageName"), 0);
wxBoxSizer *box=new wxBoxSizer(wxVERTICAL);
_ic=new ScaledImageCanvas(this, GetStatusBar(), 1);
box->Add(_ic, 1, wxALL| wxGROW, 5);
box->SetSizeHints(this);
SetSizer(box);
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{ Close(TRUE); }
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxMessageBox(wxT("This is a wxWidgets Hello world sample"),
wxT("About Hello World"), wxOK | wxICON_INFORMATION, this);
}
void MyFrame::OnLoad(wxCommandEvent& WXUNUSED(event))
{
wxFileDialog fileDialog(this, wxT("Choose a file"), wxT("."), wxT(""));
if (fileDialog.ShowModal() == wxID_OK){
string fname=WxToAscii(fileDialog.GetPath());
if (ImageIO::Load(fname, im)!=0){
BIASERR("error loading "<<fname<<"\nshould a be float image");
} else {
SetStatusText(fileDialog.GetFilename().c_str(), 0);
_ic->Show(im, WxToAscii(fileDialog.GetFilename()));
}
} else {
cerr << "canceled loading image" << endl;
}
}
/** \endcond */