25 #ifndef WINDOWGRAYSCALEBATCH_H_
26 #define WINDOWGRAYSCALEBATCH_H_
32 #include <types/MNISTTypes.hpp>
36 namespace visualization {
62 return "Display original image(s), without any normalization";
64 return "Display image(s) normalized to <0,1>";
66 return "Display image(s) in a hot-cold normalization <-1,1> i.e. red are positive and blue are negative";
68 return "Display inverted hot-cold normalization <-1,1> i.e. red are negative and blue are positive";
90 return "Display no grid";
92 return "Display only grid dividing sample cells";
94 return "Display grid dividing samples";
96 return "Display both sample and batch grids";
108 template <
typename eT=
float>
117 unsigned int position_x_ = 0,
unsigned int position_y_ = 0,
118 unsigned int width_ = 512,
unsigned int height_ = 512,
119 bool draw_batch_grid_ =
true,
bool draw_sample_grid_ =
false) :
120 Window(name_, position_x_, position_y_, width_, height_),
139 APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
150 APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
160 LOG(LTRACE) <<
"WindowGrayscaleBatch::Display handler of window " << glutGetWindow();
162 APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
165 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
166 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
171 size_t batch_width = ceil(sqrt(
batch_data.size()));
172 size_t batch_height = ceil((eT)
batch_data.size()/batch_width);
182 eT scale_x = (eT)glutGet(GLUT_WINDOW_WIDTH)/(eT)(cols * batch_width);
183 eT scale_y = (eT)glutGet(GLUT_WINDOW_HEIGHT)/(eT)(rows * batch_height);
186 for (
size_t by=0; by < batch_height; by++)
187 for (
size_t bx=0; bx < batch_width; bx++) {
189 if ((by*batch_width + bx) >=
batch_data.size())
192 eT* data_ptr =
batch_data[by*batch_width + bx]->data();
195 eT min = std::numeric_limits<double>::max();
196 eT max = std::numeric_limits<double>::min();
198 for(
size_t i=0; i< rows*cols; i++) {
199 min = (min > data_ptr[i]) ? data_ptr[i] : min;
200 max = (max < data_ptr[i]) ? data_ptr[i] : max;
212 for (
size_t y = 0; y < rows; y++) {
213 for (
size_t x = 0; x < cols; x++) {
215 eT val = data_ptr[x*rows + y];
216 eT red, green, blue, alpha;
220 case Normalization::Norm_Positive:
221 red = green = blue = (val - min)/diff;
224 case Normalization::Norm_HotCold:
225 red = (val > 0.0) ? val/max : 0.0f;
227 blue = (val < 0.0) ? val/min : 0.0f;
230 case Normalization::Norm_TensorFLow:
231 blue = (val > 0.0) ? val/max : 0.0f;
233 red = (val < 0.0) ? val/min : 0.0f;
237 case Normalization::Norm_None:
239 red = green = blue = alpha = val/diff;
245 red, green, blue, alpha);
254 case Grid::Grid_Sample :
255 draw_grid(0.3f, 0.8f, 0.3f, 0.3f, batch_width * cols, batch_height * rows);
257 case Grid::Grid_Batch:
258 draw_grid(0.3f, 0.8f, 0.3f, 0.3f, batch_width, batch_height, 4.0);
260 case Grid::Grid_Both:
261 draw_grid(0.3f, 0.8f, 0.3f, 0.3f, batch_width * cols, batch_height * rows);
262 draw_grid(0.3f, 0.8f, 0.3f, 0.3f, batch_width, batch_height, 4.0);
265 case Grid::Grid_None:
284 APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
310 APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
331 std::vector <std::shared_ptr<mic::types::Matrix<eT> > >
batch_data;
Grid grid
Flag determining whether or what kind of grid to draw.
OpenGL-based window responsible for displaying grayscale (singlechannel) batch in a window...
void keyhandlerToggleNormalizationMode(void)
void draw_filled_rectangle(float x, float y, float h, float w, float r, float g, float b, float a)
void setSampleUnsynchronized(mic::types::MatrixPtr< eT > sample_ptr_)
Normalization normalization
Flag determining whether or what kind of normalization to use.
virtual ~WindowGrayscaleBatch()
void setBatchUnsynchronized(std::vector< std::shared_ptr< mic::types::Matrix< eT > > > &batch_data_)
std::string norm2str(Normalization norm_)
void setBatchSynchronized(std::vector< std::shared_ptr< mic::types::Matrix< eT > > > &batch_data_)
WindowGrayscaleBatch(std::string name_="WindowGrayscaleBatch", Normalization normalization_=Norm_None, Grid grid_=Grid_Batch, unsigned int position_x_=0, unsigned int position_y_=0, unsigned int width_=512, unsigned int height_=512, bool draw_batch_grid_=true, bool draw_sample_grid_=false)
void keyhandlerGridMode(void)
Contains declaration of parent class of all OpenGL-based windows.
void displayHandler(void)
Parent class of all OpenGL-based windows (abstract).
std::string grid2str(Grid grid_)
std::vector< std::shared_ptr< mic::types::Matrix< eT > > > batch_data
Class containing enumerators used in grayscale windows.
void draw_grid(float r, float g, float b, float a, float cells_h, float cells_v, float line_width_=1.0)
Declaration of WindowManager class along with a bunch of helpful types and macros.
void setSampleSynchronized(mic::types::MatrixPtr< eT > sample_ptr_)