25 #include "biasGLviewerWx.hh"
26 #include <Gui/StringConv.hh>
27 #include <Utils/IOUtils.hh>
28 #include <img/miplogochars32x32.xpm>
35 #define GRP_SEGMENTATION 3
36 #define GRP_BACKGROUND 4
64 const wxString& title, const wxPoint& pos, const wxSize& size,
long style) :
65 wxFrame(parent,
id, title, pos, size, style)
67 SetIcon(wxIcon(miplogochars32x32_xpm));
69 this->SetSizeHints(wxDefaultSize, wxDefaultSize);
71 toolBar_ = this->CreateToolBar(wxTB_DOCKABLE | wxTB_HORIZONTAL, wxID_ANY);
73 fullscreenButton_ =
new wxButton(toolBar_, ID_FULLSCREEN, wxT(
"Fullscreen"),
74 wxDefaultPosition, wxDefaultSize, 0);
75 toolBar_->AddControl(fullscreenButton_);
77 loadModelButton_ =
new wxButton(toolBar_, ID_LOADMODEL, wxT(
"Load Model"),
78 wxDefaultPosition, wxDefaultSize, 0);
79 toolBar_->AddControl(loadModelButton_);
81 deleteModelsButton_ =
new wxButton(toolBar_, ID_DELETEMODELS, wxT(
"Delete Models"),
82 wxDefaultPosition, wxDefaultSize, 0);
83 toolBar_->AddControl(deleteModelsButton_);
85 screenshotButton_ =
new wxButton(toolBar_, ID_SCREENSHOT, wxT(
"Screenshot"),
86 wxDefaultPosition, wxDefaultSize, 0);
87 toolBar_->AddControl(screenshotButton_);
90 measureCheckbox_ =
new wxCheckBox(toolBar_,ID_CHECK_MEASURE,wxT(
"Measure"));
91 measureCheckbox_->SetValue(
false);
92 toolBar_->AddControl(measureCheckbox_);
96 menubar_ =
new wxMenuBar(0);
97 fileMenu_ =
new wxMenu();
98 fileMenu_->Append(ID_SAVE_PARAMETER, wxT(
"&Save Parameters") );
99 menuItemShowParameter_ =
new wxMenuItem(fileMenu_, ID_SHOW_PARAMETER, wxString(
100 wxT(
"Show &Parameters")), wxEmptyString, wxITEM_CHECK);
101 fileMenu_->Append(menuItemShowParameter_);
102 fileMenu_->Append( wxID_EXIT, wxT(
"E&xit") );
103 menubar_->Append(fileMenu_, wxT(
"&File"));
105 viewMenu_ =
new wxMenu();
106 menuItemFullscreen_ =
new wxMenuItem(fileMenu_, ID_FULLSCREEN, wxString(
107 wxT(
"&Fullscreen")), wxEmptyString, wxITEM_CHECK);
108 viewMenu_->Append(menuItemFullscreen_);
109 menuItemSolid_ =
new wxMenuItem(fileMenu_, ID_SOLID, wxString(
110 wxT(
"&Solid")), wxEmptyString, wxITEM_CHECK);
111 viewMenu_->Append(menuItemSolid_);
112 menuItemLines_ =
new wxMenuItem(fileMenu_, ID_LINES, wxString(
113 wxT(
"&Lines")), wxEmptyString, wxITEM_CHECK);
114 viewMenu_->Append(menuItemLines_);
115 menuItemPoints_ =
new wxMenuItem(fileMenu_, ID_POINTS, wxString(
116 wxT(
"&Points")), wxEmptyString, wxITEM_CHECK);
117 viewMenu_->Append(menuItemPoints_);
119 menubar_->Append(viewMenu_, wxT(
"&View"));
121 helpMenu_ =
new wxMenu();
122 helpMenu_->Append(wxID_ABOUT, wxT(
"&About...") );
123 menubar_->Append(helpMenu_, wxT(
"&Help"));
125 this->SetMenuBar(menubar_);
127 const int numFields = 2;
128 CreateStatusBar(numFields);
134 int ContextAttribs[] = { WX_GL_RGBA,
140 WX_GL_DEPTH_SIZE, 24,
141 WX_GL_STENCIL_SIZE, 8,
142 WX_GL_DOUBLEBUFFER, 0 };
143 contextWX_ =
new ContextWX(
this, wxID_ANY,wxDefaultPosition, wxSize(640, 480), 0,wxT(
"GLCanvas"),ContextAttribs);
144 contextWX_->SetBlending(
false);
145 contextWX_->SetBackfaceCulling(
false);
154 contextWX_->SetGLProjectionParametersInterface(virtualCamera_);
155 contextWX_->SetControl(&Control_);
156 contextWX_->SetAutoClipping(
true);
157 contextWX_->SetAutoClipMinZNear(0.1);
158 contextWX_->SetClearColor(cc);
159 contextWX_->InitializationComplete();
166 timer_.SetOwner(
this, ID_TIMER);
167 timer_.Start(5,
true);
177 void BIASOpenGLViewerFrame::
178 OnMeasure(wxCommandEvent& event){
179 Control_.SetDistanceMeasure(event.IsChecked());
182 void BIASOpenGLViewerFrame::
183 OnTimer(wxTimerEvent& ) {
185 contextWX_->Refresh();
186 timer_.Start(5,
true);
192 screenShotControl_.Init(contextWX_, *screenShotName_,
"png",
"",
true);
195 lightScene_.SetLightAsHeadLight(
true);
196 lightScene_.SetDrawLightPosition(
false);
201 contextWX_->AppendScene(&lightScene_);
202 #ifdef BIAS_HAVE_OPENSCENEGRAPH
204 contextWX_->AppendScene(&scene_);
207 #ifdef BIAS_HAVE_GLUT
208 contextWX_->AppendScene(&sceneGlut_);
210 contextWX_->AppendScene(&Control_);
211 contextWX_->AppendAdditionalListener(&screenShotControl_);
217 if(*useSceneCenter_) {
220 if (!contextWX_->GetSceneCenter(SceneCenter, radius))
221 BIASERR(
"could not retrieve bounding box from scene");
223 if(C != NULL && Q != NULL){
225 CameraQuaternion = *Q;
226 virtualCamera_->GetMyselfAsProjectionParameterBase()->SetC(CameraCenter);
227 virtualCamera_->GetMyselfAsProjectionParameterBase()->SetQ(CameraQuaternion);
228 Control_.SetPointOfInterest(SceneCenter);
232 CameraCenter = SceneCenter + 1.1 * radius;
233 cout<<
"using scene center "<<SceneCenter<<
" and new camera center "
234 <<CameraCenter <<endl;
236 if ((CameraCenter-SceneCenter).NormL2()>0.001) {
237 virtualCamera_->GetMyselfAsProjectionParameterBase()->SetC(CameraCenter);
238 Control_.SetPointOfInterest(SceneCenter);
240 cerr<<
"could not set poi, empty scene ?"<<endl;
251 void BIASOpenGLViewerFrame::
252 OnSaveParameters(wxCommandEvent& event){
255 wxFileDialog dialog(
this,wxT(
"Save Parameters"),wxT(
""),wxT(
""),
256 wxT(
"MIP Parameter files (*.param)|*.param"),
257 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
258 int ret = dialog.ShowModal();
260 fileName = dialog.GetPath();
261 WriteParameter(WxToAscii(fileName));
270 void BIASOpenGLViewerFrame::
271 OnShowParameters(wxCommandEvent& event){
272 if(paramFrame_ != NULL){
273 if(event.IsChecked() ){
274 paramFrame_->Show(
true);
277 paramFrame_->Show(
false);
288 void BIASOpenGLViewerFrame::
289 OnAbout(wxCommandEvent& WXUNUSED(event))
292 desc << wxT(
"The BIAS OpenGL Viewer, part of the\n\n");
293 desc << wxT(
" BIAS library (Basic ImageAlgorithmS)\n");
295 text <<
"built on " << __DATE__ <<
" " << __TIME__ <<
"\n"
296 <<
"GUI using: " << WxToAscii(wxVERSION_STRING)<<
"\n";
299 wxString lic = wxT(
"BIAS is free software; you can redistribute it and/or modify\n \
300 it under the terms of the GNU Lesser General Public Licence as published by\n \
301 the Free Software Foundation; either version 2.1 of the Licence, or\n \
302 (at your option) any later version.\n \
304 BIAS is distributed in the hope that it will be useful,\n \
305 but WITHOUT ANY WARRANTY; without even the implied warranty of\n \
306 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n \
307 GNU Lesser General Public Licence for more details.\n \
309 You should have received a copy of the GNU Lesser General Public Licence\n \
310 along with BIAS; if not, write to the Free Software\n \
311 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n");
313 wxAboutDialogInfo aboutdlg;
314 aboutdlg.SetDescription( desc );
315 aboutdlg.SetLicence( lic );
316 aboutdlg.SetCopyright( wxT(
"Copyright (C) 2003-2010\n \
317 Multimediale Systeme der Informationsverarbeitung\n \
318 Institut fuer Informatik\n \
319 Christian-Albrechts-Universitaet Kiel") );
320 aboutdlg.SetWebSite( wxT(
"http://www.mip.informatik.uni-kiel.de/") );
322 wxAboutBox( aboutdlg );
331 void BIASOpenGLViewerFrame::
332 OnDeleteModels(wxCommandEvent& event){
333 #ifdef BIAS_HAVE_OPENSCENEGRAPH
344 firstUnknownParam_ =0;
345 bool ret = IOUtils::ParseCommandLineEvalHelp(*
this,argc, argv,firstUnknownParam_);
346 if(!ret) BIASWARN(
"Parsing command line arguments failed. Please check them!");
348 wxSize panelSize(400,600);
350 paramFrame_ = GetFrame(
this);
351 if(paramFrame_ ==NULL ){
352 BIASERR(
"Param Panel can not be created, exiting!");
356 #ifdef BIAS_HAVE_OPENSCENEGRAPH
357 if(argc - firstUnknownParam_ >= 1 && firstUnknownParam_ > 0) {
358 for(
int i=0;i< (argc - firstUnknownParam_);i++){
359 cout<<
"loading "<<argv[firstUnknownParam_+i]<<
"... \n"; cout.flush();
360 if(scene_.AppendSubTreeFromFile(argv[firstUnknownParam_+i])!=0)
371 #ifdef BIAS_HAVE_GLUT
372 sceneGlut_.SetDrawTeapot(*teapot_,0.4);
373 sceneGlut_.SetDrawCube(*cube_,0.4);
374 sceneGlut_.SetDrawIcosahedron(*icosahedron_);
375 sceneGlut_.SetDrawTetrahedron(*tetrahedron_);
382 #ifdef BIAS_HAVE_OPENSCENEGRAPH
383 string model=BIAS_IMG_DIR;
384 model +=
"BIAS_LOGO_3D.3ds";
385 if(scene_.AppendSubTreeFromFile(model)==0){
388 ResetSceneCenter(&C,&Q);
402 int groupID = GetFreeGroupID();
403 useFlyMode_ = AddParamBool(
404 "fly",
"set mouse control to fly mode",
false, 0 ,groupID);
405 useRotMode_ = AddParamBool(
406 "onlyRot",
"turn only rotation for mouse control on",
false, 0, groupID);
407 SetGroupName(groupID,
"Animation / Control");
410 groupID = GetFreeGroupID();
411 zNear_ = AddParamDouble(
412 "zNear",
"set near clipping plane distance, overrides autoClipping", 0.001, 0.000001, DBL_MAX, 0 ,groupID);
413 zFar_ = AddParamDouble(
414 "zFar",
"set near clipping plane distance, overrides autoClipping", 10000, 0.00001, DBL_MAX, 0, groupID);
415 fov_ = AddParamDouble(
416 "fov",
"field of view in degree", 0, 0, 359.9, 0, groupID);
417 autoClipping_ = AddParamBool(
418 "autoClipping",
"turns auto clipping on/off",
true, 0 , groupID);
419 backfaceCulling_ = AddParamBool(
420 "backfaceCulling",
"do not draw back faces of triangles?",
false, 0, groupID);
421 #ifdef BIAS_HAVE_GLUT
422 teapot_ = AddParamBool(
"teapot",
"Add a glut teapot to scene",
false, 0, groupID);
423 RegisterCallbackObject(
"teapot",
this);
425 cube_ = AddParamBool(
"cube",
"Add a glut cube to scene",
false, 0, groupID);
426 RegisterCallbackObject(
"cube",
this);
427 tetrahedron_ = AddParamBool(
"tetrahedron",
"Add a glut tetrahedron to scene",
false, 0, groupID);
428 RegisterCallbackObject(
"tetrahedron",
this);
429 icosahedron_ = AddParamBool(
"icosahedron",
"Add a glut icosahedron to scene",
false, 0, groupID);
430 RegisterCallbackObject(
"icosahedron",
this);
432 SetGroupName(groupID,
"View");
435 groupID = GetFreeGroupID();
436 projectionFile_ = AddParamString(
437 "projection",
"load camera parameters from this file, sets findSceneCenter to false if useJustIntrinsics is false (default)",
439 useSceneCenter_ = AddParamBool(
440 "findSceneCenter",
"sets camera to center of scene",
442 useJustIntrinsics_ = AddParamBool(
443 "useJustIntrinsics",
"uses only intrinsics from loaded projection",
447 std::vector<std::string> reshapeBehaviour;
448 reshapeBehaviour.push_back(
"Deny");
449 reshapeBehaviour.push_back(
"AutoRescaleParams");
450 reshapeBehaviour.push_back(
"AutoCutImage");
451 reshapeBehaviour.push_back(
"AutoSimplePerspectiveCam");
453 autoReshapeBehaviour_ = AddParamEnum(
454 "reshapeBehaviour",
"sets the automatic reshape behaviour of the camera",
455 reshapeBehaviour, 1,NULL, 0, groupID);
456 SetGroupName(groupID,
"Camera");
459 groupID = GetFreeGroupID();
460 winwidth_ = AddParamInt(
461 "winwidth",
"window width", 0, 0, INT_MAX,
'w', groupID);
462 winheight_ = AddParamInt(
463 "winheight",
"window width", 0, 0, INT_MAX,
'h', groupID);
464 screenShotName_ = AddParamString(
465 "screenShotName",
"name for screenshoys default is 'screenShot'",
"screenShot", 0, groupID);
466 backGroundColor_ = AddParamVecDbl(
467 "bgColor",
"set background clear color",
"200.0 230.0 230.0", 0, groupID);
468 SetGroupName(groupID,
"Window");
479 #ifdef BIAS_HAVE_GLUT
480 if (strcmp((
const char*) paramname.c_str(),
"teapot") == 0) {
481 sceneGlut_.SetDrawTeapot(*teapot_,0.4);
484 else if (strcmp((
const char*) paramname.c_str(),
"cube") == 0) {
485 sceneGlut_.SetDrawCube(*cube_,0.4);
488 else if (strcmp((
const char*) paramname.c_str(),
"icosahedron") == 0) {
489 sceneGlut_.SetDrawIcosahedron(*icosahedron_);
492 else if (strcmp((
const char*) paramname.c_str(),
"tetrahedron") == 0) {
493 sceneGlut_.SetDrawTetrahedron(*tetrahedron_);
505 void BIASOpenGLViewerFrame::
506 OnAddModel(wxCommandEvent& event) {
507 #ifdef BIAS_HAVE_OPENSCENEGRAPH
515 wxT(
"Model files (*.wrl;*.dae;*.obj;*.osg;*.3ds;)|*.wrl;*.dae;*.obj;*.osg;*.3ds;|All files (*.*)|*.*"),
517 int ret = dialog.ShowModal();
518 if (ret == wxID_OK) {
519 if(scene_.AppendSubTreeFromFile(WxToAscii(dialog.GetPath()))!=0)
524 contextWX_->Refresh();
529 text<<
"OpenSceneGraph is not activated in BIAS, please activate to load 3D Models.";
530 wxMessageBox(
AsciiToWx(text.str()),wxT(
"Error"), wxOK | wxICON_ERROR,
this);
539 void BIASOpenGLViewerFrame::OnQuit(wxCloseEvent& event) {
548 void BIASOpenGLViewerFrame::OnExit(wxCommandEvent& ) {
556 void BIASOpenGLViewerFrame::
557 OnFullscreen(wxCommandEvent& event) {
558 ShowFullScreen(!IsFullScreen(), wxFULLSCREEN_NOCAPTION | wxFULLSCREEN_NOSTATUSBAR);
559 menuItemFullscreen_->Check(IsFullScreen());
562 void BIASOpenGLViewerFrame::
563 OnScreenshot(wxCommandEvent& event){
564 bool ret = screenShotControl_.StoreScreenShot();
567 text<<
"Storing screenshot failed.";
568 wxMessageBox(
AsciiToWx(text.str()),wxT(
"Error"), wxOK | wxICON_ERROR,
this);
572 void BIASOpenGLViewerFrame::
573 OnViewSolid( wxCommandEvent& event ){
575 glPolygonMode( GL_FRONT_AND_BACK, GL_FILL);
577 menuItemSolid_->Check(
true);
578 menuItemPoints_->Check(
false);
579 menuItemLines_->Check(
false);
582 void BIASOpenGLViewerFrame::
583 OnViewLines( wxCommandEvent& event ){
584 glPolygonMode( GL_FRONT_AND_BACK, GL_LINE);
586 menuItemSolid_->Check(
false);
587 menuItemPoints_->Check(
false);
588 menuItemLines_->Check(
true);
591 void BIASOpenGLViewerFrame::
592 OnViewPoints( wxCommandEvent& event ){
593 glPolygonMode( GL_FRONT_AND_BACK, GL_POINT);
595 menuItemSolid_->Check(
false);
596 menuItemPoints_->Check(
true);
597 menuItemLines_->Check(
false);
602 class BIASOpenGLViewerApp:
public wxApp
604 virtual bool OnInit();
609 DECLARE_APP(BIASOpenGLViewerApp)
612 IMPLEMENT_APP(BIASOpenGLViewerApp)
614 bool BIASOpenGLViewerApp::OnInit()
619 string fileName=
"BIASOpenGLViewer.param";
621 wxSize guiSize(640,480);
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
Class BIASOpenGLViewerFrame.
rescale internal projection parameters preserving aspect ratio and scale by integer values only...
Context implementation for wxWidgets.
void SetParameterFile(int argc, char **argv, std::string ¶mFile)
int ResetSceneCenter(BIAS::Vector3< double > *C=NULL, BIAS::Quaternion< double > *Q=NULL)
Class for converting an array of wxStrings to an array of non-const ASCII strings.
void ParameterChanged(const std::string ¶mname, const void *data)
class for rendering with projection parameters of ProjectionParametersPerspective ...