MachineIntelligenceCore:Visualization
OpenGLApplication.cpp
Go to the documentation of this file.
1 
23 #include <iostream>
24 #include <fstream>
25 
26 #include <boost/thread/thread.hpp>
27 #include <boost/bind.hpp>
29 //#include <opengl/visualization/WindowManager.hpp>
30 
31 namespace mic {
32  namespace opengl {
33  namespace application {
34 
35  OpenGLApplication::OpenGLApplication(std::string node_name_) : Application(node_name_) {
36  // Empty for now.
37  }
38 
40  // Run the processing thread.
41  boost::thread processing_thread(boost::bind(&OpenGLApplication::processingThread, this));
42 
43  // Start main OpenGL loop.
44  VGL_MANAGER->startVisualizationLoop();
45  LOG(LINFO) << "OpenGL thread terminated. Waiting for the threads to join...";
46 
47  // Wait for the processing thread to end.
48  processing_thread.join();
49  LOG(LINFO) << "Threads joined";
50 
51  }
52 
54 
55  // Start from learning.
56  APP_STATE->setLearningModeOn();
57 
58  // Perform the initial step.
59  LOG(LINFO) << "Performing the initial step...";
61 
62  // Main application loop.
63  LOG(LINFO) << "Starting the main loop...";
64  while (!APP_STATE->Quit()) {
65 
66  // If not paused.
67  if (!APP_STATE->isPaused()) {
68  // If single step mode - pause after the step.
69  if (APP_STATE->isSingleStepModeOn())
70  APP_STATE->pressPause();
71 
72  // Enter critical section - with the use of scoped lock from AppState!
73  APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
74 
75  // Perform single step and - if required - break the loop.
76  iteration++;
77  if (!performSingleStep()) {
78  LOG(LINFO) << "Terminating application...";
79  APP_STATE->setQuit();
80  break;
81  }
82  else if (((long) number_of_iterations > 0) && ((long)iteration >= (long) number_of_iterations)) {
83  LOG(LINFO) << "Reached last Iteration. Terminating application...";
84  APP_STATE->setQuit();
85  break;
86  }//: else if
87 
88  } //: if! is paused & end of critical section
89 
90  // Sleep.
91  }//: while
92 
93  LOG(LINFO) << "Performing the final step...";
94  // Perform the final step.
96  LOG(LINFO) << "Final step complete";
97 
98  // Wait until OpenGL will "stop"...
99 // while (APP_STATE->usingOpenGL())
100 // APP_SLEEP();
101  // ... and then quit - not required, because we will wait anyway at thread.join()
102  }
103 
104  } /* namespace applications */
105  } /* namespace opengl */
106 } /* namespace mic */
virtual void performFinalStep(void)
The initial step - empty, to be overridden.
virtual void processingThread(void)
Function realizing the processing thread. Implements basic quit/pause/single step functionality...
#define VGL_MANAGER
Macro returning OpenGL window manager instance.
virtual void performInitialStep(void)
The initial step - empty, to be overridden.