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