MachineIntelligenceCore:Visualization
window_grayscale_image_test.cpp
Go to the documentation of this file.
1 
26 #include <boost/thread/thread.hpp>
27 #include <boost/bind.hpp>
28 
29 #include <types/MNISTTypes.hpp>
30 
31 #include <logger/Log.hpp>
32 #include <logger/ConsoleOutput.hpp>
33 using namespace mic::logger;
34 
37 using namespace mic::opengl::visualization;
38 
41 
46 void test_thread_body (void) {
47 
48  // Generate a batch.
49  mic::types::MNISTBatch<float> batch;
50  for(size_t i=0; i< 15; i++) {
51  // Generate "data".
52  MatrixXfPtr data (new MatrixXf(3, 5));
53  data->setZero();
54  (*data)(i)=1;
55  batch.data().push_back(data);
56 
57  // Generate "label".
58  batch.labels().push_back(std::make_shared<unsigned int>(i));
59 
60  // Add index.
61  batch.indices().push_back(i);
62  }//: for
63 
64  // Main application loop.
65  while (!APP_STATE->Quit()) {
66 
67  // If not paused.
68  if (!APP_STATE->isPaused()) {
69 
70  // If single step mode - pause after the step.
71  if (APP_STATE->isSingleStepModeOn())
72  APP_STATE->pressPause();
73 
74  { // Enter critical section - with the use of scoped lock from AppState!
75  APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
76 
77  // Select random image-label pair.
78  mic::types::MNISTSample<float> sample = batch.getRandomSample();
79 
80  // Set sample to be displayed.
81  w_batch->setSampleUnsynchronized(sample.data());
82  }//: end of critical section
83 
84  }//: if
85 
86  // Sleep.
87  APP_SLEEP();
88  }//: while
89 
90 }//: image_encoder_and_visualization_test
91 
92 
93 
101 int main(int argc, char* argv[]) {
102  // Set console output to logger.
103  LOGGER->addOutput(new ConsoleOutput());
104  LOG(LINFO) << "Logger initialized. Starting application";
105 
106  // Initialize GLUT! :]
107  VGL_MANAGER->initializeGLUT(argc, argv);
108 
109  // Create two visualization windows - in the same, main thread :]
110  w_batch = new WindowGrayscaleBatch<float>("Grayscale image", Grayscale::Norm_HotCold, Grayscale::Grid_Both, 0, 0, 512, 512);
111 
112  boost::thread test_thread(boost::bind(&test_thread_body));
113 
114  // Start visualization thread.
115  VGL_MANAGER->startVisualizationLoop();
116 
117  LOG(LINFO) << "Waiting for threads to join...";
118  // End test thread.
119  test_thread.join();
120  LOG(LINFO) << "Threads joined - ending application";
121 }//: main
void test_thread_body(void)
Function for testing ImageEncoder/WindowImage2D classes.
OpenGL-based window responsible for displaying grayscale (singlechannel) batch in a window...
WindowGrayscaleBatch< float > * w_batch
Window displaying the image.
#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.