|
30 | 30 | #include <TEveElement.h> |
31 | 31 | #include <TGListTree.h> |
32 | 32 | #include <TEveCalo.h> |
33 | | -#include "FairLogger.h" |
| 33 | +#include <FairLogger.h> |
| 34 | +#include <rapidjson/document.h> |
| 35 | +#include <rapidjson/stringbuffer.h> |
| 36 | +#include <rapidjson/writer.h> |
| 37 | +#include <gsl/span> |
34 | 38 |
|
35 | 39 | #define elemof(e) (unsigned int)(sizeof(e) / sizeof(e[0])) |
36 | 40 |
|
37 | 41 | using namespace std; |
| 42 | +using namespace rapidjson; |
38 | 43 |
|
39 | 44 | namespace o2 |
40 | 45 | { |
@@ -98,11 +103,17 @@ void EventManager::displayCurrentEvent() |
98 | 103 | multiView->registerElements(dataTypeLists, dataTypeListsPhi); |
99 | 104 |
|
100 | 105 | if (vizSettings.firstEvent) { |
101 | | - saveVisualisationSettings(); |
| 106 | + ifstream s(TEMP_SETTINGS_PATH); |
| 107 | + if (s.good()) { |
| 108 | + restoreVisualisationSettings(); |
| 109 | + } else { |
| 110 | + saveVisualisationSettings(); |
| 111 | + } |
102 | 112 | vizSettings.firstEvent = false; |
103 | 113 | } else { |
104 | 114 | restoreVisualisationSettings(); |
105 | 115 | } |
| 116 | + |
106 | 117 | if (this->mShowDate) { |
107 | 118 | multiView->getAnnotationTop()->SetText( |
108 | 119 | TString::Format("Run %d\n%s", dataSource->getRunNumber(), dataSource->getCollisionTime().c_str())); |
@@ -365,10 +376,122 @@ void EventManager::saveVisualisationSettings() |
365 | 376 | vizSettings.clusterSize[i] = clusterSet->GetMarkerSize(); |
366 | 377 | } |
367 | 378 | } |
| 379 | + |
| 380 | + ofstream settings(TEMP_SETTINGS_PATH); |
| 381 | + |
| 382 | + if (settings.good()) { |
| 383 | + Document d; |
| 384 | + d.SetObject(); |
| 385 | + auto& allocator = d.GetAllocator(); |
| 386 | + |
| 387 | + auto jsonArray = [](const auto& array, auto& allocator) { |
| 388 | + Value arr(kArrayType); |
| 389 | + |
| 390 | + for (const auto& value : array) { |
| 391 | + arr.PushBack(value, allocator); |
| 392 | + } |
| 393 | + |
| 394 | + return arr; |
| 395 | + }; |
| 396 | + |
| 397 | + d.AddMember("trackVisibility", jsonArray(vizSettings.trackVisibility, allocator), allocator); |
| 398 | + d.AddMember("trackColor", jsonArray(vizSettings.trackColor, allocator), allocator); |
| 399 | + d.AddMember("trackStyle", jsonArray(vizSettings.trackStyle, allocator), allocator); |
| 400 | + d.AddMember("trackWidth", jsonArray(vizSettings.trackWidth, allocator), allocator); |
| 401 | + d.AddMember("clusterVisibility", jsonArray(vizSettings.clusterVisibility, allocator), allocator); |
| 402 | + d.AddMember("clusterColor", jsonArray(vizSettings.clusterColor, allocator), allocator); |
| 403 | + d.AddMember("clusterStyle", jsonArray(vizSettings.clusterStyle, allocator), allocator); |
| 404 | + d.AddMember("clusterSize", jsonArray(vizSettings.clusterSize, allocator), allocator); |
| 405 | + |
| 406 | + auto jsonCamera = [&jsonArray](MultiView::EViews view, auto& allocator) { |
| 407 | + Value obj(kObjectType); |
| 408 | + |
| 409 | + auto& camera = MultiView::getInstance()->getView(view)->GetGLViewer()->CurrentCamera(); |
| 410 | + |
| 411 | + const gsl::span baseSpan(camera.RefCamBase().CArr(), 16); |
| 412 | + obj.AddMember("base", jsonArray(baseSpan, allocator), allocator); |
| 413 | + |
| 414 | + const gsl::span transSpan(camera.GetCamTrans().CArr(), 16); |
| 415 | + obj.AddMember("trans", jsonArray(transSpan, allocator), allocator); |
| 416 | + |
| 417 | + if (camera.IsOrthographic()) { |
| 418 | + obj.AddMember("zoom", dynamic_cast<TGLOrthoCamera&>(camera).GetZoom(), allocator); |
| 419 | + } else if (camera.IsPerspective()) { |
| 420 | + obj.AddMember("fov", dynamic_cast<TGLPerspectiveCamera&>(camera).GetFOV(), allocator); |
| 421 | + } |
| 422 | + |
| 423 | + return obj; |
| 424 | + }; |
| 425 | + |
| 426 | + d.AddMember("camera3d", jsonCamera(MultiView::View3d, allocator), allocator); |
| 427 | + d.AddMember("cameraRphi", jsonCamera(MultiView::ViewRphi, allocator), allocator); |
| 428 | + d.AddMember("cameraZY", jsonCamera(MultiView::ViewZY, allocator), allocator); |
| 429 | + |
| 430 | + StringBuffer strbuf; |
| 431 | + Writer<StringBuffer> writer(strbuf); |
| 432 | + d.Accept(writer); |
| 433 | + |
| 434 | + settings << strbuf.GetString(); |
| 435 | + } |
368 | 436 | } |
369 | 437 |
|
370 | 438 | void EventManager::restoreVisualisationSettings() |
371 | 439 | { |
| 440 | + ifstream settings(TEMP_SETTINGS_PATH); |
| 441 | + |
| 442 | + if (settings.good()) { |
| 443 | + string json((istreambuf_iterator<char>(settings)), istreambuf_iterator<char>()); |
| 444 | + Document d; |
| 445 | + d.Parse(json.c_str()); |
| 446 | + |
| 447 | + auto updateArray = [](auto& array, const auto& document, const char* name, const auto& accessor) { |
| 448 | + for (size_t i = 0; i < elemof(array); ++i) { |
| 449 | + array[i] = accessor(document[name][i]); |
| 450 | + } |
| 451 | + }; |
| 452 | + |
| 453 | + auto getBool = [](const GenericValue<UTF8<char>>& v) { return v.GetBool(); }; |
| 454 | + auto getUint = [](const GenericValue<UTF8<char>>& v) { return v.GetUint(); }; |
| 455 | + auto getFloat = [](const GenericValue<UTF8<char>>& v) { return v.GetFloat(); }; |
| 456 | + |
| 457 | + updateArray(vizSettings.trackVisibility, d, "trackVisibility", getBool); |
| 458 | + updateArray(vizSettings.trackColor, d, "trackColor", getUint); |
| 459 | + updateArray(vizSettings.trackStyle, d, "trackStyle", getUint); |
| 460 | + updateArray(vizSettings.trackWidth, d, "trackWidth", getUint); |
| 461 | + updateArray(vizSettings.clusterVisibility, d, "clusterVisibility", getBool); |
| 462 | + updateArray(vizSettings.clusterColor, d, "clusterColor", getUint); |
| 463 | + updateArray(vizSettings.clusterStyle, d, "clusterStyle", getUint); |
| 464 | + updateArray(vizSettings.clusterSize, d, "clusterSize", getFloat); |
| 465 | + |
| 466 | + auto updateCamera = [getFloat](MultiView::EViews view, const auto& document, const char* name) { |
| 467 | + auto& camera = MultiView::getInstance()->getView(view)->GetGLViewer()->CurrentCamera(); |
| 468 | + |
| 469 | + std::array<Double_t, 16> values; |
| 470 | + |
| 471 | + for (size_t i = 0; i < values.size(); ++i) { |
| 472 | + values[i] = getFloat(document[name]["base"][i]); |
| 473 | + } |
| 474 | + camera.RefCamBase() = TGLMatrix(values.data()); |
| 475 | + |
| 476 | + for (size_t i = 0; i < values.size(); ++i) { |
| 477 | + values[i] = getFloat(document[name]["trans"][i]); |
| 478 | + } |
| 479 | + camera.RefCamTrans() = TGLMatrix(values.data()); |
| 480 | + |
| 481 | + if (camera.IsOrthographic()) { |
| 482 | + dynamic_cast<TGLOrthoCamera&>(camera).SetZoom(getFloat(document[name]["zoom"])); |
| 483 | + } else if (camera.IsPerspective()) { |
| 484 | + dynamic_cast<TGLPerspectiveCamera&>(camera).SetFOV(getFloat(document[name]["fov"])); |
| 485 | + } |
| 486 | + |
| 487 | + camera.IncTimeStamp(); |
| 488 | + }; |
| 489 | + |
| 490 | + updateCamera(MultiView::View3d, d, "camera3d"); |
| 491 | + updateCamera(MultiView::ViewRphi, d, "cameraRphi"); |
| 492 | + updateCamera(MultiView::ViewZY, d, "cameraZY"); |
| 493 | + } |
| 494 | + |
372 | 495 | const auto& tracks = *dataTypeLists[EVisualisationDataType::Tracks]; |
373 | 496 |
|
374 | 497 | for (auto elm : tracks.RefChildren()) { |
@@ -398,6 +521,8 @@ void EventManager::restoreVisualisationSettings() |
398 | 521 | clusterSet->SetMarkerSize(vizSettings.clusterSize[i]); |
399 | 522 | } |
400 | 523 | } |
| 524 | + |
| 525 | + MultiView::getInstance()->redraw3D(); |
401 | 526 | } |
402 | 527 |
|
403 | 528 | } // namespace event_visualisation |
|
0 commit comments