MachineIntelligenceCore:Visualization
window_rgb_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 <fstream>
30 
31 #include <types/MNISTTypes.hpp>
32 #include <types/TensorTypes.hpp>
33 
34 #include <logger/Log.hpp>
35 #include <logger/ConsoleOutput.hpp>
36 using namespace mic::logger;
37 
38 #include <importers/CIFARImporter.hpp>
39 #include <importers/BMPImporter.hpp>
40 
43 using namespace mic::opengl::visualization;
44 
47 
48 
53 void test_thread_body (void) {
54 
55  // Import exemplary BMPs.
56  mic::importers::BMPImporter<float> importer;
57  importer.setDataFilename("../../../data/rainbow.bmp");
58  /*mic::importers::CIFARImporter<float> importer;
59  importer.setDataFilename("../data/cifar-10-batches-bin/data_batch_1.bin;../data/cifar-10-batches-bin/data_batch_2.bin");*/
60  if (!importer.importData())
61  return;
62 
63  importer.setBatchSize(4);
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  // Select random sample/batch.
79  //mic::types::TensorSample<float> sample = importer.getRandomSample();
80  mic::types::TensorBatch<float> batch = importer.getRandomBatch();
81 
82  // Set sample/batch to be displayed.
83  w_batch->setBatchUnsynchronized(batch.data());
84  //w_batch->setSampleUnsynchronized(sample.data());
85  }//: end of critical section
86 
87  }//: if
88 
89  // Sleep.
90  APP_SLEEP();
91  }//: while
92 
93 }//: image_encoder_and_visualization_test
94 
95 
96 
104 int main(int argc, char* argv[]) {
105  // Set console output to logger.
106  LOGGER->addOutput(new ConsoleOutput());
107  LOG(LINFO) << "Logger initialized. Starting application";
108  //LOGGER->setSeverityLevel(Debug);
109 
110  // Initialize GLUT! :]
111  VGL_MANAGER->initializeGLUT(argc, argv);
112 
113  // Create two visualization windows - in the same, main thread :]
114  w_batch = new WindowRGBTensor<float>("Batch", RGB::Chan_RGB, RGB::Norm_None, RGB::Grid_Batch, 0, 0, 3*512, 512);
115 
116  boost::thread test_thread(boost::bind(&test_thread_body));
117 
118  // Start visualization thread.
119  VGL_MANAGER->startVisualizationLoop();
120 
121  LOG(LINFO) << "Waiting for threads to join...";
122  // End test thread.
123  test_thread.join();
124  LOG(LINFO) << "Threads joined - ending application";
125 }//: main
void test_thread_body(void)
Function for testing ImageEncoder/WindowImage2D classes.
WindowRGBTensor< 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)...
OpenGL-based window responsible for displaying RGB (three channel) batch in a window.
Declaration of WindowManager class along with a bunch of helpful types and macros.