openrave.org

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
orqtcoinviewercustom.cpp
Go to the documentation of this file.
1 
9 #include <openrave-core.h>
10 #include <vector>
11 #include <cstring>
12 #include <sstream>
13 
14 #include <boost/thread/thread.hpp>
15 #include <boost/bind.hpp>
16 
17 #include <QMainWindow>
18 
19 using namespace OpenRAVE;
20 using namespace std;
21 
22 void SetViewer(EnvironmentBasePtr penv, const string& viewername)
23 {
24  ViewerBasePtr viewer = RaveCreateViewer(penv,viewername);
25  BOOST_ASSERT(!!viewer);
26 
27  // attach it to the environment:
28  penv->Add(viewer);
29 
30  // finally call the viewer's infinite loop (this is why a separate thread is needed)
31  bool showgui = true;
32  viewer->main(showgui);
33 }
34 
35 int g_counter=0;
37 {
38  ++g_counter;
39  // this is only true for the current qtcoinviewer implementation
40  QMainWindow* wnd = dynamic_cast<QMainWindow*>(pviewer.get());
41  if( (g_counter/60) & 1 ) {
42  wnd->show();
43  }
44  else {
45  wnd->hide();
46  }
47 }
48 
49 int main(int argc, char ** argv)
50 {
51  //int num = 1;
52  string scenefilename = "data/lab1.env.xml";
53  string viewername = "qtcoin";
54 
55  // parse the command line options
56  int i = 1;
57  while(i < argc) {
58  if((strcmp(argv[i], "-h") == 0)||(strcmp(argv[i], "-?") == 0)||(strcmp(argv[i], "/?") == 0)||(strcmp(argv[i], "--help") == 0)||(strcmp(argv[i], "-help") == 0)) {
59  RAVELOG_INFO("orloadviewer [--num n] [--scene filename] viewername\n");
60  return 0;
61  }
62  else if( strcmp(argv[i], "--scene") == 0 ) {
63  scenefilename = argv[i+1];
64  i += 2;
65  }
66  else
67  break;
68  }
69  if( i < argc ) {
70  viewername = argv[i++];
71  }
72 
73  RaveInitialize(true); // start openrave core
74  EnvironmentBasePtr penv = RaveCreateEnvironment(); // create the main environment
76 
77  boost::thread thviewer(boost::bind(SetViewer,penv,viewername));
78  penv->Load(scenefilename); // load the scene
79 
80 
81  UserDataPtr pregistration;
82  while(!pregistration) {
83  if( !pregistration && !!penv->GetViewer() ) {
84  pregistration = penv->GetViewer()->RegisterViewerThreadCallback(boost::bind(ViewerCallback,penv->GetViewer()));
85  }
86  boost::this_thread::sleep(boost::posix_time::milliseconds(1));
87  }
88 
89  thviewer.join(); // wait for the viewer thread to exit
90  pregistration.reset();
91  penv->Destroy(); // destroy
92  return 0;
93 }