25 #ifndef WINDOWRGBTENSOR_H_
26 #define WINDOWRGBTENSOR_H_
32 #include <types/TensorTypes.hpp>
36 namespace visualization {
61 return "Displays separate channels, colored according to the channel type (R/G/B)";
63 return "Displays separate channels, all in grayscale";
65 return "Displays RGB image";
85 return "Display original image(s), without any normalization";
107 return "Display no grid";
109 return "Display only grid dividing sample cells";
111 return "Display grid dividing samples";
113 return "Display both sample and batch grids";
124 template <
typename eT=
float>
133 unsigned int position_x_ = 0,
unsigned int position_y_ = 0,
134 unsigned int width_ = 512,
unsigned int height_ = 512,
135 bool draw_batch_grid_ =
true,
bool draw_sample_grid_ =
false) :
136 Window(name_, position_x_, position_y_, width_, height_),
157 APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
168 APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
179 LOG(LTRACE) <<
"WindowRGBTensor::Display handler of window " << glutGetWindow();
181 APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
184 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
185 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
190 size_t batch_width = ceil(sqrt(
batch_data.size()));
191 size_t batch_height = ceil((eT)
batch_data.size()/batch_width);
202 for (
size_t by=0; by < batch_height; by++)
203 for (
size_t bx=0; bx < batch_width; bx++) {
205 if ((by*batch_width + bx) >=
batch_data.size())
209 eT* data_ptr =
batch_data[by*batch_width + bx]->data();
212 height =
batch_data[by*batch_width + bx]->dim(0);
213 width =
batch_data[by*batch_width + bx]->dim(1);
214 depth =
batch_data[by*batch_width + bx]->dim(2);
219 case ChannelDisplay::Chan_SeparateColor:
222 scale_x = (eT)glutGet(GLUT_WINDOW_WIDTH)/(eT)(width * batch_width * 3);
223 scale_y = (eT)glutGet(GLUT_WINDOW_HEIGHT)/(eT)(height * batch_height);
226 for (
size_t y = 0; y <
height; y++) {
227 for (
size_t x = 0; x <
width; x++) {
229 eT red = data_ptr[y*width + x];
230 eT green = data_ptr[y*width + x + (height*
width)];
231 eT blue = data_ptr[y*width + x + 2*(height*
width)];
259 case ChannelDisplay::Chan_SeparateGrayscale:
262 scale_x = (eT)glutGet(GLUT_WINDOW_WIDTH)/(eT)(width * batch_width * 3);
263 scale_y = (eT)glutGet(GLUT_WINDOW_HEIGHT)/(eT)(height * batch_height);
266 for (
size_t y = 0; y <
height; y++) {
267 for (
size_t x = 0; x <
width; x++) {
269 eT red = data_ptr[y*width + x];
270 eT green = data_ptr[y*width + x + (height*
width)];
271 eT blue = data_ptr[y*width + x + 2*(height*
width)];
299 case ChannelDisplay::Chan_RGB:
302 scale_x = (eT)glutGet(GLUT_WINDOW_WIDTH)/(eT)(width * batch_width);
303 scale_y = (eT)glutGet(GLUT_WINDOW_HEIGHT)/(eT)(height * batch_height);
306 for (
size_t y = 0; y <
height; y++) {
307 for (
size_t x = 0; x <
width; x++) {
309 eT red = data_ptr[y*width + x];
310 eT green = data_ptr[y*width + x + (height*
width)];
311 eT blue = data_ptr[y*width + x + 2*(height*
width)];
331 case Grid::Grid_Sample :
334 case ChannelDisplay::Chan_SeparateColor:
335 case ChannelDisplay::Chan_SeparateGrayscale:
336 draw_grid(0.3f, 0.8f, 0.3f, 0.3f, batch_width * width * 3, batch_height * height);
339 case ChannelDisplay::Chan_RGB:
340 draw_grid(0.3f, 0.8f, 0.3f, 0.3f, batch_width * width, batch_height * height);
343 case Grid::Grid_Batch:
344 draw_grid(0.3f, 0.8f, 0.3f, 0.3f, batch_width, batch_height, 4.0);
346 case Grid::Grid_Both:
349 case ChannelDisplay::Chan_SeparateColor:
350 case ChannelDisplay::Chan_SeparateGrayscale:
351 draw_grid(0.3f, 0.8f, 0.3f, 0.3f, batch_width * width * 3, batch_height * height);
354 case ChannelDisplay::Chan_RGB:
355 draw_grid(0.3f, 0.8f, 0.3f, 0.3f, batch_width * width, batch_height * height);
357 draw_grid(0.3f, 0.8f, 0.3f, 0.3f, batch_width, batch_height, 4.0);
360 case Grid::Grid_None:
378 APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
405 APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
std::string norm2str(Normalization norm_)
std::vector< mic::types::TensorPtr< eT > > batch_data
void draw_filled_rectangle(float x, float y, float h, float w, float r, float g, float b, float a)
std::string chan2str(ChannelDisplay chan_)
void setBatchUnsynchronized(std::vector< mic::types::TensorPtr< eT > > &batch_data_)
Grid grid
Grid display mode.
ChannelDisplay channel_display
Grid display mode.
void keyhandlerGridMode(void)
void setSampleSynchronized(mic::types::TensorPtr< eT > sample_ptr_)
void setSampleUnsynchronized(mic::types::TensorPtr< eT > sample_ptr_)
WindowRGBTensor(std::string name_="WindowRGBTensor", ChannelDisplay channel_display_=Chan_RGB, 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)
Normalization normalization
Normalization mode.
Contains declaration of parent class of all OpenGL-based windows.
void setBatchSynchronized(std::vector< mic::types::TensorPtr< eT > > &batch_data_)
std::string grid2str(Grid grid_)
void keyhandlerToggleChannelDisplayMode(void)
virtual ~WindowRGBTensor()
Parent class of all OpenGL-based windows (abstract).
void displayHandler(void)
OpenGL-based window responsible for displaying RGB (three channel) batch in a window.
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.
Class containing enumerators used in windows displaying RGB images (tensors).