Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleImageCanvasGLBase.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 /** Simple example for BIAS::ImageCanvasGLBase(Base) usage.
24 @author: Jan Woetzel */
25 #include <bias_config.h>
26 
27 //#include <Base/Common/LeakChecking.h>
28 
29 #include "ExampleImageCanvasGLBase.hh"
30 
31 // BIAS
32 #include <Gui/ConsoleRedirectIO.hh>
33 #include <Base/Image/Image.hh>
34 #include <Base/Image/ImageIO.hh>
35 
36 // WX
37 #include <wx/sizer.h>
38 #include <wx/log.h>
39 
40 //-----------------
41 
42 // global var. for mode
43 int g_mode=0;
44 const int MODE_MAX=1; // 0,1,..
45 
46 //-----------------
47 
48 using namespace std;
49 
50 // required for wx RTTI dynamic construction:
51 IMPLEMENT_APP(ExampleImageCanvasGLBaseApp)
52 
53 // --------------------------------------------------------
54 
55 bool ExampleImageCanvasGLBaseApp::OnInit()
56 {
57  // utility: create a Redirection console for cout, cerr etc.
59  // testing output:
60  cout<<"Hello cout"<<endl;
61  cout<<"Hello cerr"<<endl;
62 
63  MyFrame *frame = new MyFrame( wxT("ExampleImageCanvasGLBase"), wxPoint(0,0), wxSize(640,480) );
64  frame->Show(TRUE);
65  SetTopWindow(frame);
66 
67  return TRUE;
68 }
69 
70 
71 // --------------------------------------------------------
72 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
73 EVT_MENU(ID_QUIT, MyFrame::OnQuit)
74 EVT_MENU(ID_ABOUT, MyFrame::OnAbout)
75 EVT_MENU(ID_MODECHANGE, MyFrame::OnModeChange)
76 EVT_MENU(ID_LOADIMAGE, MyFrame::OnLoadImage)
77 END_EVENT_TABLE()
78 // --------------------------------------------------------
79 
80 
81 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
82 : wxFrame((wxFrame *)NULL, -1, title, pos, size)
83 ,p_canvas1(NULL)
84 ,p_canvas2(NULL)
85 {
86  // Create a simple top Menu
87  wxMenu *menuFile = new wxMenu;
88  menuFile->Append( ID_ABOUT, wxT("&About...") );
89  menuFile->Append( ID_LOADIMAGE, wxT("&Load Image...\tCtrl-L") );
90  // TODO menuFile->Append( ID_MODECHANGE, wxT("Change &Mode...\tCtrl-M") );
91  menuFile->AppendSeparator();
92  menuFile->Append( ID_QUIT, wxT("E&xit") );
93 
94  wxMenuBar *menuBar = new wxMenuBar;
95  menuBar->Append(menuFile, wxT("&File"));
96  SetMenuBar(menuBar);
97 
98  // Create a simple bottom status bar
99  CreateStatusBar(1);
100 
101  // Canvas to test:
102  p_canvas1=new BIAS::ImageCanvasGLBase(this, -1);
103  // create aseond canvas that shares the GL context:
104  p_canvas2=new BIAS::ImageCanvasGLBase(this, p_canvas1->GetContext(),-1 );
105 
106  // put them into sizers:
107  wxBoxSizer * sizer = new wxBoxSizer(wxHORIZONTAL);
108  sizer->Add( p_canvas1 ,1,wxEXPAND|wxALL);
109 #if wxCHECK_VERSION(2, 6, 2)
110  sizer->AddSpacer(4); // available in 2.6.2 but not 2.4.2 (JW)
111 #endif
112  sizer->Add(p_canvas2 ,1,wxEXPAND|wxALL);
113 
114  // limit min. size:
115  sizer->SetItemMinSize(p_canvas1, 200,100);
116  sizer->SetItemMinSize(p_canvas2, 200,100);
117  sizer->SetSizeHints(this);
118 
119  // set sizer and triggers Layout()
120  SetSizerAndFit(sizer);
121 
122  // now work with the canvases:
123  // enable Mipmapping just for one of them to see the effect:
124  p_canvas1->EnableMipMapping(true);
125 
126  // HACK> context is created too late
127 #ifdef WIN32
128  this->LoadImages();
129 #endif // WIN32
130 
131  // set the image to display:
132  //p_canvas1->Set(img);
133  //p_canvas2->Set(img); // allocates GPU texture meory twice
134  // TODO: share texobjs "id" instead: See wglShareLists (JW)
135  //p_canvas2->Set(p_canvas1->GetTexobj() );
136 }
137 
138 
139 void MyFrame::OnQuit(wxCommandEvent& ){
140  Close(TRUE);
141 }
142 
143 
144 void MyFrame::OnAbout(wxCommandEvent& )
145 {
146  wxString title(wxT("About"));
147  wxString msg; // message
148  msg<<wxT("About - ")<<AsciiToWx(FUNCNAME)<<wxT("\n");
149  msg<<wxT("author: Jan Woetzel (c) 2003-2005\n");
150  msg<<wxT("build: ")<<AsciiToWx(__DATE__)<<wxT(" ")<<AsciiToWx(__TIME__)<<wxT("\n");
151  msg<<wxT("from ")<<AsciiToWx(__FILE__)<<wxT("\n");
152  msg<<wxT("GUI using: ")<<wxVERSION_STRING<<wxT("\n");
153  msg<<wxT("\n");
154  COUT(msg);
155  wxMessageBox(msg, title, wxICON_INFORMATION | wxOK );
156 }
157 
158 
159 void MyFrame::OnModeChange(wxCommandEvent& )
160 {
161  CALLINFO;
162  g_mode++;
163  if (g_mode>MODE_MAX)
164  g_mode=0;
165 }
166 
167 
168 void MyFrame::LoadImages()
169 {
170  CALLINFO;
171  // set the image to display:
172  // an image we want to display using OpenGL:
174  string filename(BIAS_TESTS_DATA "r4.jpg");
175  if (0!=BIAS::ImageIO::Load( filename,img)){
176  BIASERR("could not load image"<<filename);
177  return;
178  };
179  cout<<"loaded "<<filename<<" for display "<<endl;
180 
181  // now work with the canvases:
182  if (p_canvas1!=NULL) {
183  // set the image to display:
184  p_canvas1->Set(img);
185  } else {
186  BIASERR("p_canvas1 is NULL");
187  }
188 
189  if (p_canvas2!=NULL) {
190  // set the image to display:
191  p_canvas2->Set(img);
192  } else {
193  BIASERR("p_canvas2 is NULL");
194  }
195 
196  COUT(FUNCNAME<<" done."<<endl);
197 }
198 
199 
200 
201 void MyFrame::OnLoadImage(wxCommandEvent& )
202 {
203  //CALLINFO;
204  LoadImages();
205 }
206 
void BIASGui_EXPORT ConsoleRedirectIO(std::string name=std::string(""))
Extra Console for WIN32 WinMain gui applications.
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
Definition: StringConv.hh:32
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
2D image display canvas using OpenGL rendering internally.