forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREveCamera.cxx
More file actions
135 lines (106 loc) · 3.95 KB
/
Copy pathREveCamera.cxx
File metadata and controls
135 lines (106 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// @(#)root/eve7:$Id$
// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007, 2018
/*************************************************************************
* Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include <ROOT/REveCamera.hxx>
#include <ROOT/REveManager.hxx>
#include <nlohmann/json.hpp>
#include <iostream>
using namespace ROOT::Experimental;
////////////////////////////////////////////////////////////////////////////////
/// Default constructor
REveCamera::REveCamera() : REveElement("REveCamera")
{
Setup(kCameraPerspXOZ, "PerspXOZ", REveVector(-1.0, 0.0, 0.0), REveVector(0.0, 1.0, 0.0));
fCamBase.UnitTrans();
fCamTrans.UnitTrans();
}
////////////////////////////////////////////////////////////////////////////////
/// Constructor with name
REveCamera::REveCamera(const std::string &name) : REveElement(name)
{
Setup(kCameraPerspXOZ, name, REveVector(-1.0, 0.0, 0.0), REveVector(0.0, 1.0, 0.0));
fCamBase.UnitTrans();
fCamTrans.UnitTrans();
}
////////////////////////////////////////////////////////////////////////////////
/// Setup camera with type, name, direction and up vectors
void REveCamera::Setup(ECameraType type, const std::string &name, const REveVector &hAxis, const REveVector &vAxis)
{
fType = type;
fName = name;
// Set up base camera matrix from direction and up vectors
fCamBase.UnitTrans();
fCamTrans.UnitTrans();
fCamBase.SetBaseVec(1, hAxis.fX, hAxis.fY, hAxis.fZ);
fCamBase.SetBaseVec(3, vAxis.fX, vAxis.fY, vAxis.fZ);
REveVector y = vAxis.Cross(hAxis);
fCamBase.SetBaseVec(2, y.fX, y.fY, y.fZ);
StampObjProps();
}
////////////////////////////////////////////////////////////////////////////////
/// Set camera base matrix from array (called from client via MIR)
void REveCamera::SetCamBaseMtx(const std::vector<Double_t> &arr)
{
if (arr.size() == 16) {
fCamBase.SetFromArray(arr.data());
StampObjProps();
}
}
void REveCamera::SetCamBaseMtx(const std::string &json_str)
{
auto j = nlohmann::json::parse(json_str);
std::vector<Double_t> arr = j.get<std::vector<Double_t>>();
SetCamBaseMtx(arr);
}
void REveCamera::SetCamTransMtx(const std::vector<Double_t> &arr)
{
if (arr.size() == 16) {
fCamTrans.SetFromArray(arr.data());
fInitialized = kTRUE;
}
}
// Set translation matrix with an array of 17 floats
// The first 16 floats are 4x4 matrix element
// The 17th value is setting the zoom value in orthographic type
void REveCamera::SetCamTransMtxStr(const char *ins)
{
std::stringstream ss(ins);
std::vector<double> arr;
std::string item;
while (std::getline(ss, item, ',')) {
arr.push_back(std::stod(item));
}
fOrthoZoom = arr.back();
arr.pop_back();
fCamTrans.SetFromArray(arr.data());
fInitialized = true;
StampObjProps();
SetCamTransMtx(arr);
}
void REveCamera::SetOrthoZoom(float zoom)
{
fOrthoZoom = zoom;
}
////////////////////////////////////////////////////////////////////////////////
/// Write core JSON for camera
Int_t REveCamera::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
{
Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
j["fType"] = fType;
j["fName"] = fName;
j["fInitialized"] = fInitialized; // Stream to client
// Stream both matrices
// Client will read these as fMatrix arrays (16 elements each)
const Double_t *camBaseArr = fCamBase.Array();
j["camBase"] = std::vector<Double_t>(camBaseArr, camBaseArr + 16);
const Double_t *camTransArr = fCamTrans.Array();
j["camTrans"] = std::vector<Double_t>(camTransArr, camTransArr + 16);
j["fZoom"] = fOrthoZoom;
return ret;
}