BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSColourScaleViridis.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2023.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#include "BDSColourScaleViridis.hh"
20
21#include "G4Colour.hh"
22#include "G4Types.hh"
23
24#include <algorithm>
25#include <array>
26#include <cmath>
27#include <vector>
28
29std::vector<std::array<G4double, 3>> BDSColourScaleViridis::data = {
30 {0.267004, 0.004874, 0.329415},
31 {0.277018, 0.050344, 0.375715},
32 {0.282327, 0.094955, 0.417331},
33 {0.282884, 0.13592 , 0.453427},
34 {0.278826, 0.17549 , 0.483397},
35 {0.270595, 0.214069, 0.507052},
36 {0.258965, 0.251537, 0.524736},
37 {0.244972, 0.287675, 0.53726 },
38 {0.229739, 0.322361, 0.545706},
39 {0.214298, 0.355619, 0.551184},
40 {0.19943 , 0.387607, 0.554642},
41 {0.185556, 0.41857 , 0.556753},
42 {0.172719, 0.448791, 0.557885},
43 {0.160665, 0.47854 , 0.558115},
44 {0.149039, 0.508051, 0.55725 },
45 {0.13777 , 0.537492, 0.554906},
46 {0.127568, 0.566949, 0.550556},
47 {0.120565, 0.596422, 0.543611},
48 {0.120638, 0.625828, 0.533488},
49 {0.132268, 0.655014, 0.519661},
50 {0.157851, 0.683765, 0.501686},
51 {0.196571, 0.711827, 0.479221},
52 {0.24607 , 0.73891 , 0.452024},
53 {0.304148, 0.764704, 0.419943},
54 {0.369214, 0.788888, 0.382914},
55 {0.440137, 0.811138, 0.340967},
56 {0.515992, 0.831158, 0.294279},
57 {0.595839, 0.848717, 0.243329},
58 {0.678489, 0.863742, 0.189503},
59 {0.762373, 0.876424, 0.137064},
60 {0.845561, 0.887322, 0.099702},
61 {0.926106, 0.89733 , 0.104071}};
62
63
64BDSColourScaleViridis::BDSColourScaleViridis():
65 dataStep(1.0 / (G4double)(data.size()-1))
66{;}
67
68BDSColourScaleViridis::~BDSColourScaleViridis()
69{;}
70
71G4Colour BDSColourScaleViridis::GetValue(G4double numberFromZeroToOne) const
72{
73 numberFromZeroToOne = std::min(numberFromZeroToOne, 1.0); // ensure <= 1
74 numberFromZeroToOne = std::max(0.0, numberFromZeroToOne); // ensure >= 0
75 // (x - xMin) / xStep
76 // xMin is 0 by definition
77 G4double arrayCoords = numberFromZeroToOne / dataStep;
78 G4int arrayIndex = (G4int) std::floor(arrayCoords);
79
80 const auto& value = data.at(arrayIndex);
81 return G4Colour(value[0], value[1], value[2]);
82}