Skip to content

Commit 02276bf

Browse files
Julian Myrchashahor02
authored andcommitted
o2-eve: screenshoot
fixed cut problem added date and time in filename
1 parent b770a34 commit 02276bf

File tree

2 files changed

+90
-13
lines changed

2 files changed

+90
-13
lines changed

EventVisualisation/View/include/EventVisualisationView/EventManagerFrame.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
/// \brief GUI (bottom buttons) for visualisation
1414
/// \author julian.myrcha@cern.ch
1515
/// \author p.nowakowski@cern.ch
16+
/// \author m.chwasiuk@cern.ch
1617

1718
#ifndef ALICE_O2_EVENTVISUALISATION_EVENTMANAGERFRAME_H
1819
#define ALICE_O2_EVENTVISUALISATION_EVENTMANAGERFRAME_H
1920

2021
#include "EventVisualisationView/EventManager.h"
2122
#include <TGMdiMainFrame.h>
23+
#include <TASImage.h>
2224

2325
class TGTextButton;
2426
class TGCompositeFrame;
@@ -41,6 +43,7 @@ class EventManagerFrame : public TGMainFrame
4143
void clearInTick(); // safely clears inTick
4244
static TGTextButton* makeButton(TGCompositeFrame* p, const char* txt, Int_t width = 0,
4345
Int_t lo = 0, Int_t ro = 0, Int_t to = 0, Int_t bo = 0);
46+
bool CopyImage(TASImage* dst, TASImage* src, Int_t x_dst, Int_t y_dst, Int_t x_src, Int_t y_src, UInt_t w_src, UInt_t h_src);
4447

4548
protected:
4649
o2::event_visualisation::EventManager* mEventManager; // Model object.

EventVisualisation/View/src/EventManagerFrame.cxx

Lines changed: 87 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <mutex>
2828
#include <chrono>
2929
#include <thread>
30+
#include <filesystem>
3031

3132
std::mutex mtx; // mutex for critical section
3233

@@ -152,34 +153,52 @@ namespace o2
152153
if (not setInTick()) {
153154
return;
154155
}
155-
UInt_t width = 2 * 1920;
156-
UInt_t height = 2 * 1080;
156+
UInt_t width = 3840;
157+
UInt_t height = 2160;
158+
UInt_t font_size = 30;
159+
UInt_t text_leading = 40;
160+
const char* fontColor = "#FFFFFF";
161+
const char* backgroundColor = "#19324b";
162+
const char* outDirectory = "Screenshots";
157163

158164
std::string runString = "Run:";
159165
std::string timestampString = "Timestamp:";
160166
std::string collidingsystemString = "Colliding system:";
161167
std::string energyString = "Energy:";
162168

169+
std::time_t time = std::time(nullptr);
170+
char time_str[100];
171+
std::strftime(time_str, sizeof(time_str), "%Y_%m_%d_%H_%M_%S", std::localtime(&time));
172+
173+
std::ostringstream filepath;
174+
filepath << outDirectory << "/Screenshot_" << time_str << ".png";
175+
163176
TASImage image(width, height);
164177

178+
image.FillRectangle(backgroundColor, 0, 0, width, height);
179+
165180
TImage* view3dImage = MultiView::getInstance()->getView(MultiView::EViews::View3d)->GetGLViewer()->GetPictureUsingBB();
166-
view3dImage->Scale(width * 0.66, height);
167-
view3dImage->CopyArea(&image, 0, 0, view3dImage->GetWidth(), view3dImage->GetHeight(), 0, 0);
181+
view3dImage->Scale(width * 0.65, height * 0.95);
182+
CopyImage(&image, (TASImage*)view3dImage, width * 0.015, height * 0.025, 0, 0, view3dImage->GetWidth(), view3dImage->GetHeight());
168183

169184
TImage* viewRphiImage = MultiView::getInstance()->getView(MultiView::EViews::ViewRphi)->GetGLViewer()->GetPictureUsingBB();
170-
viewRphiImage->Scale(width * 0.33, height * 0.5);
171-
viewRphiImage->CopyArea(&image, 0, 0, viewRphiImage->GetWidth(), viewRphiImage->GetHeight(), width * 0.66, 0);
185+
viewRphiImage->Scale(width * 0.3, height * 0.45);
186+
CopyImage(&image, (TASImage*)viewRphiImage, width * 0.68, height * 0.025, 0, 0, viewRphiImage->GetWidth(), viewRphiImage->GetHeight());
172187

173188
TImage* viewZrhoImage = MultiView::getInstance()->getView(MultiView::EViews::ViewZrho)->GetGLViewer()->GetPictureUsingBB();
174-
viewZrhoImage->Scale(width * 0.33, height * 0.5);
175-
viewZrhoImage->CopyArea(&image, 0, 0, viewZrhoImage->GetWidth(), viewZrhoImage->GetHeight(), width * 0.66, height * 0.5);
189+
viewZrhoImage->Scale(width * 0.3, height * 0.45);
190+
CopyImage(&image, (TASImage*)viewZrhoImage, width * 0.68, height * 0.525, 0, 0, viewZrhoImage->GetWidth(), viewZrhoImage->GetHeight());
176191

177-
image.DrawText(10, 1000, runString.c_str(), 24, "#FFFFFF");
178-
image.DrawText(10, 1020, timestampString.c_str(), 24, "#FFFFFF");
179-
image.DrawText(10, 1040, collidingsystemString.c_str(), 24, "#FFFFFF");
180-
image.DrawText(10, 1060, energyString.c_str(), 24, "#FFFFFF");
192+
image.DrawText(10, height - 4 * text_leading, runString.c_str(), font_size, fontColor);
193+
image.DrawText(10, height - 3 * text_leading, timestampString.c_str(), font_size, fontColor);
194+
image.DrawText(10, height - 2 * text_leading, collidingsystemString.c_str(), font_size, fontColor);
195+
image.DrawText(10, height - 1 * text_leading, energyString.c_str(), font_size, fontColor);
196+
197+
if (!std::filesystem::is_directory(outDirectory)) {
198+
std::filesystem::create_directory(outDirectory);
199+
}
200+
image.WriteImage(filepath.str().c_str(), TImage::kPng);
181201

182-
image.WriteImage("Screenshot.png", TImage::kPng);
183202
clearInTick();
184203
}
185204

@@ -275,5 +294,60 @@ namespace o2
275294
exit(0);
276295
}
277296

297+
bool EventManagerFrame::CopyImage(TASImage* dst, TASImage* src, Int_t x_dst, Int_t y_dst, Int_t x_src, Int_t y_src,
298+
UInt_t w_src, UInt_t h_src)
299+
{
300+
301+
if (!dst) {
302+
return false;
303+
}
304+
if (!src) {
305+
return false;
306+
}
307+
308+
int x = 0;
309+
int y = 0;
310+
int idx_src = 0;
311+
int idx_dst = 0;
312+
x_src = x_src < 0 ? 0 : x_src;
313+
y_src = y_src < 0 ? 0 : y_src;
314+
315+
if ((x_src >= (int)src->GetWidth()) || (y_src >= (int)src->GetHeight())) {
316+
return false;
317+
}
318+
319+
w_src = x_src + w_src > src->GetWidth() ? src->GetWidth() - x_src : w_src;
320+
h_src = y_src + h_src > src->GetHeight() ? src->GetHeight() - y_src : h_src;
321+
UInt_t yy = (y_src + y) * src->GetWidth();
322+
323+
src->BeginPaint(false);
324+
dst->BeginPaint(false);
325+
326+
UInt_t* dst_image_array = dst->GetArgbArray();
327+
UInt_t* src_image_array = src->GetArgbArray();
328+
329+
if (!dst_image_array || !src_image_array) {
330+
return false;
331+
}
332+
333+
for (y = 0; y < (int)h_src; y++) {
334+
for (x = 0; x < (int)w_src; x++) {
335+
336+
idx_src = yy + x + x_src;
337+
idx_dst = (y_dst + y) * dst->GetWidth() + x + x_dst;
338+
339+
if ((x + x_dst < 0) || (y_dst + y < 0) ||
340+
(x + x_dst >= (int)dst->GetWidth()) || (y + y_dst >= (int)dst->GetHeight())) {
341+
continue;
342+
}
343+
344+
dst_image_array[idx_dst] = src_image_array[idx_src];
345+
}
346+
yy += src->GetWidth();
347+
}
348+
349+
return true;
350+
}
351+
278352
} // namespace event_visualisation
279353
}

0 commit comments

Comments
 (0)