MachineIntelligenceCore:Visualization
window_grayscale_batch_test.cpp
Go to the documentation of this file.
1 
27 #include <boost/thread/thread.hpp>
28 #include <boost/bind.hpp>
29 
30 #include <types/MNISTTypes.hpp>
31 
32 #include <logger/Log.hpp>
33 #include <logger/ConsoleOutput.hpp>
34 using namespace mic::logger;
35 
38 using namespace mic::opengl::visualization;
39 
42 
47 void test_thread_body (void) {
48 
49  // Generate a batch that will be used for returning minibatches of size 5.
50  mic::types::MNISTBatch<float> batch(6);
51  for(size_t i=0; i< 18; i++) {
52  // Generate "data".
53  MatrixXfPtr data (new MatrixXf(3, 6));
54  data->setZero();
55  (*data)(i)=(float)(i-9.0)/18.0;
56  batch.data().push_back(data);
57 
58  // Generate "label".
59  batch.labels().push_back(std::make_shared<unsigned int>(i));
60 
61  // Add index.
62  batch.indices().push_back(i);
63  }//: for
64 
65  // Main application loop.
66  while (!APP_STATE->Quit()) {
67 
68  // If not paused.
69  if (!APP_STATE->isPaused()) {
70 
71  // If single step mode - pause after the step.
72  if (APP_STATE->isSingleStepModeOn())
73  APP_STATE->pressPause();
74 
75  { // Enter critical section - with the use of scoped lock from AppState!
76  APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
77 
78  // Retrieve the next minibatch.
79  mic::types::MNISTBatch<float> bt = batch.getNextBatch();
80 
81  // Set sample to be displayed.
82  w_batch->setBatchUnsynchronized(bt.data());
83  }//: end of critical section
84 
85  }//: if
86 
87  // Sleep.
88  APP_SLEEP();
89  }//: while
90 
91 }//: image_encoder_and_visualization_test
92 
93 
94 
102 int main(int argc, char* argv[]) {
103  // Set console output to logger.
104  LOGGER->addOutput(new ConsoleOutput());
105  LOG(LINFO) << "Logger initialized. Starting application";
106 
107  // Initialize GLUT! :]
108  VGL_MANAGER->initializeGLUT(argc, argv);
109 
110  // Create batch visualization window.
111  w_batch = new WindowGrayscaleBatch<float>("Grayscale batch", Grayscale::Norm_HotCold, Grayscale::Grid_Both, 0, 0, 512, 512);
112 
113  boost::thread test_thread(boost::bind(&test_thread_body));
114 
115  // Start visualization thread.
116  VGL_MANAGER->startVisualizationLoop();
117 
118  LOG(LINFO) << "Waiting for threads to join...";
119  // End test thread.
120  test_thread.join();
121  LOG(LINFO) << "Threads joined - ending application";
122 }//: main
OpenGL-based window responsible for displaying grayscale (singlechannel) batch in a window...
WindowGrayscaleBatch< float > * w_batch
Window displaying the image.
void test_thread_body(void)
Function for testing ImageEncoder/WindowImage2D classes.
#define VGL_MANAGER
Macro returning OpenGL window manager instance.
int main(int argc, char *argv[])
Main program function. Runs two threads: main (for GLUT) and another one (for data processing)...
Declaration of WindowManager class along with a bunch of helpful types and macros.