35 #include <Base/Common/BIASpragmaStart.hh>
37 #include <wx/aboutdlg.h>
38 #include <wx/filename.h>
39 #include <wx/artprov.h>
40 #include <Base/Common/BIASpragmaEnd.hh>
42 #include <Base/Image/Image.hh>
43 #include <Base/Image/ImageIO.hh>
44 #include <Base/Common/FileHandling.hh>
45 #include <Gui/StringConv.hh>
46 #include <GLviewer/ContextWX.hh>
47 #include <GLviewer/Scenes/SceneBGImage.hh>
48 #ifdef BIAS_HAVE_OPENSCENEGRAPH
49 #include <GLviewer/Scenes/SceneOpenSceneGraph.hh>
51 #include <GLviewer/GLProjectionParametersPerspective.hh>
52 #include <GLviewer/Controller/DistanceMeasureControl.hh>
63 class CWxFrame :
public wxFrame
68 CWxFrame(
wxWindow *parent,
const wxString& title);
70 void OnOpen(wxCommandEvent &event);
71 void OnQuit(wxCommandEvent &event);
72 void OnScreenshot(wxCommandEvent& event);
73 void OnViewSize(wxCommandEvent& event);
74 void OnAbout(wxCommandEvent &event);
75 void OnScreenInfo(wxCommandEvent &event);
77 void OnResize(wxSizeEvent &event);
85 #ifdef BIAS_HAVE_OPENSCENEGRAPH
95 ID_Whatever = wxID_HIGHEST + 42,
108 void FitToImageSize_();
112 wxStatusBar* Statusbar_;
113 DECLARE_EVENT_TABLE()
118 BEGIN_EVENT_TABLE(CWxFrame, wxFrame)
119 EVT_MENU(wxID_OPEN, CWxFrame::OnOpen)
120 EVT_MENU(wxID_EXIT, CWxFrame::OnQuit)
121 EVT_MENU(wxID_ABOUT, CWxFrame::OnAbout)
122 EVT_MENU(ID_Screenshot, CWxFrame::OnScreenshot)
123 EVT_MENU(ID_VS_Free, CWxFrame::OnViewSize)
124 EVT_MENU(ID_VS_640, CWxFrame::OnViewSize)
125 EVT_MENU(ID_VS_800, CWxFrame::OnViewSize)
126 EVT_MENU(ID_VS_16_9, CWxFrame::OnViewSize)
127 EVT_MENU(ID_VS_16_10, CWxFrame::OnViewSize)
128 EVT_MENU(ID_ScreenInfo, CWxFrame::OnScreenInfo)
129 EVT_SIZE(CWxFrame::OnResize)
132 CWxFrame::CWxFrame(
wxWindow *parent, const wxString& title)
133 : wxFrame(parent, wxID_ANY, title),
134 Context_(NULL), Proj_(NULL),
137 #ifdef BIAS_HAVE_OPENSCENEGRAPH
140 int ContextAttribs[] = { WX_GL_RGBA,
146 WX_GL_DEPTH_SIZE, 24,
147 WX_GL_STENCIL_SIZE, 8,
148 WX_GL_DOUBLEBUFFER, 0 };
149 DummyContext_ =
new ContextWX(
this, wxID_ANY,
150 wxDefaultPosition, wxSize(640, 480), 0,
151 wxT(
"GLCanvas"),ContextAttribs);
152 DummyContext_->SetBlending(
false);
153 DummyContext_->SetBackfaceCulling(
false);
154 DummyContext_->SetMinSize( wxSize( 320,240 ) );
157 Statusbar_ = this->CreateStatusBar( 2, wxST_SIZEGRIP, wxID_ANY );
158 const int numFields = 2;
159 Statusbar_->SetFieldsCount(numFields);
160 const int widths[numFields] = { -1, 170 };
161 Statusbar_->SetStatusWidths(numFields, widths);
164 Toolbar_ = this->CreateToolBar( wxTB_HORIZONTAL, wxID_ANY );
165 Toolbar_->SetToolBitmapSize( wxSize( 24,24 ) );
166 Toolbar_->SetToolSeparation( 0 );
167 Toolbar_->SetToolPacking( 0 );
168 Toolbar_->AddTool( ID_ScreenInfo, wxT(
"Screen Info"),
169 wxArtProvider::GetIcon(wxART_INFORMATION,wxART_TOOLBAR) );
170 Toolbar_->AddTool( wxID_OPEN, wxT(
"Open File"),
171 wxArtProvider::GetIcon(wxART_FILE_OPEN ,wxART_TOOLBAR) );
176 wxMenu *menuFile =
new wxMenu;
177 menuFile->Append(wxID_OPEN);
178 menuFile->AppendSeparator();
179 menuFile->Append(wxID_EXIT);
180 wxMenu *menuEdit =
new wxMenu;
181 menuEdit->Append(ID_Screenshot, wxString(wxT(
"&Screenshot")) + wxT(
'\t') + wxT(
"F3"));
182 wxMenu *menuView =
new wxMenu;
183 menuView->AppendRadioItem(ID_VS_Free, wxString(wxT(
"View Size &Free")) + wxT(
'\t') + wxT(
"CTRL-SHIFT-0"));
184 menuView->AppendRadioItem(ID_VS_640, wxString(wxT(
"View Size 4:3 &small")) + wxT(
'\t') + wxT(
"CTRL-SHIFT-1"));
185 menuView->AppendRadioItem(ID_VS_800, wxString(wxT(
"View Size 4:3 &medium")) + wxT(
'\t') + wxT(
"CTRL-SHIFT-2"));
186 menuView->AppendRadioItem(ID_VS_16_9, wxString(wxT(
"View Size 16:&9 medium")) + wxT(
'\t') + wxT(
"CTRL-SHIFT-3"));
187 menuView->AppendRadioItem(ID_VS_16_10, wxString(wxT(
"View Size 16:&10 medium")) + wxT(
'\t') + wxT(
"CTRL-SHIFT-4"));
188 wxMenu *menuHelp =
new wxMenu;
189 menuHelp->Append(wxID_ABOUT);
190 Menubar_ =
new wxMenuBar;
191 Menubar_->Append(menuFile, wxT(
"&File"));
192 Menubar_->Append(menuEdit, wxT(
"&Edit"));
193 Menubar_->Append(menuView, wxT(
"&View"));
194 Menubar_->Append(menuHelp, wxT(
"&Help"));
196 SetMenuBar(Menubar_);
197 wxBoxSizer* mainSizer =
new wxBoxSizer(wxVERTICAL);
198 mainSizer->Add(Context_, 1, wxEXPAND|wxALL|wxALIGN_CENTRE, 0);
204 mainSizer->Fit(
this);
213 Context_ = DummyContext_;
215 LogoBG_.Init(400, 300, 3);
216 LogoBG_.FillImageWithConstValue(120);
217 BGImage_.SetImage(LogoBG_);
218 Context_->MakeGLContextCurrent();
219 Context_->SetBlending(
false);
224 Context_->SetBackgroundImageScene(&BGImage_);
225 #ifdef BIAS_HAVE_OPENSCENEGRAPH
228 if(Scene_->Init()!=0)
230 cerr<<
"Scene_ init failed !!!"<<endl;
232 Scene_->SetActive(
false);
233 Scene_->HeadlightSwitch(
true);
234 Context_->AppendScene(Scene_);
237 BIASWARN(
"Need OpenSceneGraph to show something")
240 Proj_->SetSimplePerspectiveCam(40.0);
242 Context_->SetGLProjectionParametersInterface(Proj_);
243 Context_->SetControl(&control_);
245 Context_->AppendScene(&control_);
247 Context_->PrintGLStatus();
248 Context_->InitializationComplete();
250 Context_->SetAutoClipping(
true);
251 Context_->SetAutoClipMinZNear(0.1);
255 Context_->SetClearColor(bg);
264 OnResize(wxSizeEvent &event)
266 cout <<
"size event: window size \t("
267 << GetSize().GetWidth() <<
" x " << GetSize().GetHeight() <<
")\n";
273 OnOpen(wxCommandEvent &event)
275 #ifdef BIAS_HAVE_OPENSCENEGRAPH
283 wxT(
"Model files (*.wrl;*.dae;*.osg;*.3ds;)|*.wrl;*.dae;*.osg;*.3ds;|All files (*.*)|*.*"),
285 int ret = dialog.ShowModal();
286 if (ret == wxID_OK) {
287 ret = Scene_->AppendSubTreeFromFile(WxToAscii(dialog.GetPath()));
291 text<<
"Error, model could not be loaded";
292 wxMessageBox(
AsciiToWx(text.str()),wxT(
"Error"), wxOK | wxICON_ERROR,
this);
296 if (!Context_->GetSceneCenter(SceneCenter, radius))
297 BIASERR(
"could not retrieve bounding box from scene");
299 CameraCenter = SceneCenter + 1.1 * radius;
300 cout<<
"using scene center "<<SceneCenter<<
" and new camera center "
301 <<CameraCenter <<endl;
303 if ((CameraCenter-SceneCenter).NormL2()>0.001) {
304 Proj_->GetMyselfAsProjectionParameterBase()->SetC(CameraCenter);
305 control_.SetPointOfInterest(SceneCenter);
307 cerr<<
"could not set poi, empty scene ?"<<endl;
313 text<<
"Error, BIAS does not have OpenSceneGraph to load models!";
314 wxMessageBox(
AsciiToWx(text.str()),wxT(
"Error"), wxOK | wxICON_ERROR,
this);
320 OnQuit(wxCommandEvent &event)
326 OnViewSize(wxCommandEvent& event)
332 OnScreenInfo(wxCommandEvent &event)
334 BIASASSERT(Context_);
337 Context_->MakeGLContextCurrent();
338 Proj_->GetImage(shot);
340 Proj_->GetImageSize(w, h);
342 wxString msg = wxT(
"Context size is ");
343 msg << Context_->GetSize().GetWidth() << wxT(
" x ")
344 << Context_->GetSize().GetHeight();
345 msg << wxT(
"\n") << wxT(
"Projection size is ");
346 msg << w << wxT(
" x ") << h;
347 msg << wxT(
"\n") << wxT(
"Screenshot size will be ");
350 wxMessageBox(msg, wxT(
"Example ContextWX - Screen Info"),
351 wxOK | wxICON_INFORMATION,
this);
356 OnScreenshot(wxCommandEvent& event)
358 BIASASSERT(Context_);
361 Context_->MakeGLContextCurrent();
362 Proj_->GetImage(shot);
364 wxFileDialog dlg(
this, _(
"Example ContextWX - Save Screenshot"),
365 wxGetCwd(), wxT(
"ContextScreenshot"),
366 _(
"PNG (*.png)|*.png|JPEG (*.jpg)|*.jpg"),
367 wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxFD_CHANGE_DIR);
368 if ( dlg.ShowModal() != wxID_OK)
return;
370 wxFileName fname( dlg.GetPath() );
372 if ( !fname.HasExt() ) {
373 int idx = dlg.GetFilterIndex();
376 fname.SetExt(_(
"jpg"));
379 fname.SetExt(_(
"png"));
385 if ( fname.GetExt() == wxT(
"jpg") ) {
388 if ( fname.GetExt() == wxT(
"png") ) {
392 wxMessageBox(wxT(
"Saving screenshot failed!"), wxT(
"Error"),
393 wxOK | wxICON_ERROR,
this);
399 OnAbout(wxCommandEvent &event)
402 desc << wxT(
" This example is part of the\n");
403 desc << wxT(
" BIAS library (Basic ImageAlgorithmS)\n");
404 wxString lic = wxT(
"BIAS is free software; you can redistribute it and/or modify\n \
405 it under the terms of the GNU Lesser General Public Licence as published by\n \
406 the Free Software Foundation; either version 2.1 of the Licence, or\n \
407 (at your option) any later version.\n \
409 BIAS is distributed in the hope that it will be useful,\n \
410 but WITHOUT ANY WARRANTY; without even the implied warranty of\n \
411 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n \
412 GNU Lesser General Public Licence for more details.\n \
414 You should have received a copy of the GNU Lesser General Public Licence\n \
415 along with BIAS; if not, write to the Free Software\n \
416 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n");
418 wxAboutDialogInfo aboutdlg;
419 aboutdlg.SetDescription( desc );
420 aboutdlg.SetLicence( lic );
421 aboutdlg.SetCopyright( wxT(
"Copyright (C) 2003-2010\n \
422 Multimediale Systeme der Informationsverarbeitung\n \
423 Institut fuer Informatik\n \
424 Christian-Albrechts-Universitaet Kiel") );
425 aboutdlg.SetWebSite( wxT(
"http://www.mip.informatik.uni-kiel.de/") );
427 wxAboutBox( aboutdlg );
434 static unsigned run = 0;
435 cout <<
"\n****** loads of sizes (no. " << run++ <<
") *****\n";
436 cout <<
"size locked? " << boolalpha << SizeLocked_ << endl;
437 cout <<
"window size \t(" << GetSize().GetWidth() <<
" x " << GetSize().GetHeight() <<
")\n";
438 cout <<
"client size \t(" << GetClientSize().GetWidth() <<
" x " << GetClientSize().GetHeight() <<
")\n";
439 cout <<
"menubar size \t(" << Menubar_->GetSize().GetWidth() <<
" x " << Menubar_->GetSize().GetHeight() <<
")\n";
440 cout <<
"toolbar size \t(" << Toolbar_->GetSize().GetWidth() <<
" x " << Toolbar_->GetSize().GetHeight() <<
")\n";
441 cout <<
"statusbar size \t(" << Statusbar_->GetSize().GetWidth() <<
" x " << Statusbar_->GetSize().GetHeight() <<
")\n";
442 cout <<
"context size \t(" << Context_->GetSize().GetWidth() <<
" x " << Context_->GetSize().GetHeight() <<
")\n";
443 Context_->MakeGLContextCurrent();
447 Proj_->GetImageSize(w,h);
448 cout <<
"projection image \t(" << w <<
" x " << h <<
")\n";
451 Context_->GetImage(img);
452 cout <<
"context image \t(" << img.
GetWidth() <<
" x " << img.
GetHeight() <<
")\n";
460 cout <<
"++++ fitting ++++" << endl;
461 BIASASSERT(Context_);
465 wxSize contextSize = Context_->GetSize();
471 if ( Menubar_->IsChecked(ID_VS_640) ) {
473 contextSize.Set(640, 480);
477 if ( Menubar_->IsChecked(ID_VS_800) ) {
479 contextSize.Set(800, 600);
483 if ( Menubar_->IsChecked(ID_VS_16_9) ) {
485 contextSize.Set(800, 450);
489 if ( Menubar_->IsChecked(ID_VS_16_10) ) {
491 contextSize.Set(800, 500);
495 if ( Menubar_->IsChecked(ID_VS_Free) ) {
500 Context_->SetSize(contextSize);
501 cout <<
"setting context size \t(" << Context_->GetSize().GetWidth() <<
" x " << Context_->GetSize().GetHeight() <<
")\n";
502 this->SetClientSize(contextSize);
505 wxSize minContextSize = Context_->GetMinSize();
506 if ( contextSize.GetWidth() < minContextSize.GetWidth()
507 || contextSize.GetHeight() < minContextSize.GetHeight() ) {
508 contextSize = minContextSize;
509 Context_->SetSize(contextSize);
511 this->SetClientSize(contextSize);
515 cout <<
"fit: context size \t(" << Context_->GetSize().GetWidth() <<
" x " << Context_->GetSize().GetHeight() <<
")\n";
519 wxString msg = wxT(
"Context size is ");
520 msg << Context_->GetSize().GetWidth() << wxT(
" x ")
521 << Context_->GetSize().GetHeight();
522 Statusbar_->SetStatusText(msg);
530 class CWxApp :
public wxApp
541 bool CWxApp::OnInit()
543 wxInitAllImageHandlers();
546 CWxFrame* mainFrame =
547 new CWxFrame(NULL, wxT(
"Example ContextWX"));
550 mainFrame->LateInit();
556 IMPLEMENT_APP(CWxApp)
class for distance measurements in 3d model, derives from TrackballControl and SceneBase ...
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
Scene that renders a background image behind all other scenes.
unsigned int GetWidth() const
Context implementation for wxWidgets.
unsigned int GetHeight() const
Implements narrow access to OpenSceneGraph.
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.
rescale internal projection parameters preeerving aspectration but use non-integer values...
class for rendering with projection parameters of ProjectionParametersPerspective ...