ATLAS Offline Software
ColorCodeConverter.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // //
7 // Implementation of class ColorCodeConverter //
8 // //
9 // Author: Joerg Mechnich <Joerg.Mechnich@cern.ch> (primary) //
10 // Thomas Kittelmann <Thomas.Kittelmann@cern.ch> //
11 // //
12 // Initial VP1 version: September 2007 //
13 // //
15 
17 
18 #include <Inventor/nodes/SoMaterial.h>
19 
20 // The code for the conversion table can be generated from ROOT with
21 // the following script:
22 
23 /*
24 {
25  unsigned int indexMax = 200;
26  TColor* color;
27  cout << "const double SurfaceToSoNode::s_colorConversionTable[][3] = " << endl
28  << "{" << endl;
29  for( unsigned int i=0; i < indexMax; ++i)
30  {
31  color = gROOT->GetColor(i);
32  cout << " { "
33  << color->GetRed() << ", "
34  << color->GetGreen() << ", "
35  << color->GetBlue() << " }," << endl;
36  }
37  cout << "}" << endl;
38 
39  cout << "const unsigned int SurfaceToSoNode::s_colorConversionTableSize = "
40  << indexMax << ";" << endl;
41 }
42 */
43 
44 const double
46 {
47  { 1, 1, 1 },
48  { 0, 0, 0 },
49  { 1, 0, 0 },
50  { 0, 1, 0 },
51  { 0, 0, 1 },
52  { 1, 1, 0 },
53  { 1, 0, 1 },
54  { 0, 1, 1 },
55  { 0.35, 0.83, 0.33 },
56  { 0.35, 0.33, 0.85 },
57  { 0.999, 0.999, 0.999 },
58  { 0.754, 0.715, 0.676 },
59  { 0.3, 0.3, 0.3 },
60  { 0.4, 0.4, 0.4 },
61  { 0.5, 0.5, 0.5 },
62  { 0.6, 0.6, 0.6 },
63  { 0.7, 0.7, 0.7 },
64  { 0.8, 0.8, 0.8 },
65  { 0.9, 0.9, 0.9 },
66  { 0.95, 0.95, 0.95 },
67  { 0.8, 0.78, 0.67 },
68  { 0.8, 0.78, 0.67 },
69  { 0.76, 0.75, 0.66 },
70  { 0.73, 0.71, 0.64 },
71  { 0.7, 0.65, 0.59 },
72  { 0.72, 0.64, 0.61 },
73  { 0.68, 0.6, 0.55 },
74  { 0.61, 0.56, 0.51 },
75  { 0.53, 0.4, 0.34 },
76  { 0.69, 0.81, 0.78 },
77  { 0.52, 0.76, 0.64 },
78  { 0.54, 0.66, 0.63 },
79  { 0.51, 0.62, 0.55 },
80  { 0.68, 0.74, 0.78 },
81  { 0.48, 0.56, 0.6 },
82  { 0.46, 0.54, 0.57 },
83  { 0.41, 0.51, 0.59 },
84  { 0.43, 0.48, 0.52 },
85  { 0.49, 0.6, 0.82 },
86  { 0.5, 0.5, 0.61 },
87  { 0.67, 0.65, 0.75 },
88  { 0.83, 0.81, 0.53 },
89  { 0.87, 0.73, 0.53 },
90  { 0.74, 0.62, 0.51 },
91  { 0.78, 0.6, 0.49 },
92  { 0.75, 0.51, 0.47 },
93  { 0.81, 0.37, 0.38 },
94  { 0.67, 0.56, 0.58 },
95  { 0.65, 0.47, 0.48 },
96  { 0.58, 0.41, 0.44 },
97  { 0.83, 0.35, 0.33 },
98  { 0.573333, 0, 1 },
99  { 0.48, 0, 1 },
100  { 0.386667, 0, 1 },
101  { 0.293333, 0, 1 },
102  { 0.2, 0, 1 },
103  { 0.106667, 0, 1 },
104  { 0.0133331, 0, 1 },
105  { 0, 0.0800001, 1 },
106  { 0, 0.173333, 1 },
107  { 0, 0.266667, 1 },
108  { 0, 0.36, 1 },
109  { 0, 0.453333, 1 },
110  { 0, 0.546667, 1 },
111  { 0, 0.64, 1 },
112  { 0, 0.733333, 1 },
113  { 0, 0.826667, 1 },
114  { 0, 0.92, 1 },
115  { 0, 1, 0.986667 },
116  { 0, 1, 0.893333 },
117  { 0, 1, 0.8 },
118  { 0, 1, 0.706667 },
119  { 0, 1, 0.613333 },
120  { 0, 1, 0.52 },
121  { 0, 1, 0.426667 },
122  { 0, 1, 0.333333 },
123  { 0, 1, 0.24 },
124  { 0, 1, 0.146667 },
125  { 0, 1, 0.0533333 },
126  { 0.0399999, 1, 0 },
127  { 0.133333, 1, 0 },
128  { 0.226667, 1, 0 },
129  { 0.32, 1, 0 },
130  { 0.413333, 1, 0 },
131  { 0.506667, 1, 0 },
132  { 0.6, 1, 0 },
133  { 0.693333, 1, 0 },
134  { 0.786667, 1, 0 },
135  { 0.88, 1, 0 },
136  { 0.973333, 1, 0 },
137  { 1, 0.933333, 0 },
138  { 1, 0.84, 0 },
139  { 1, 0.746667, 0 },
140  { 1, 0.653333, 0 },
141  { 1, 0.56, 0 },
142  { 1, 0.466667, 0 },
143  { 1, 0.373333, 0 },
144  { 1, 0.28, 0 },
145  { 1, 0.186667, 0 },
146  { 1, 0.0933333, 0 },
147  { 1, 0, 0 },
148  { 0, 0, 0 },
149  { 0.7, 0, 0 },
150  { 0, 0.7, 0 },
151  { 0, 0, 0.7 },
152  { 0.7, 0.7, 0 },
153  { 0.7, 0, 0.7 },
154  { 0, 0.7, 0.7 },
155  { 0.183667, 0.647667, 0.164333 },
156  { 0.171244, 0.151098, 0.674902 },
157  { 0.999, 0.999, 0.999 },
158  { 0.568853, 0.5005, 0.432147 },
159  { 0.21, 0.21, 0.21 },
160  { 0.28, 0.28, 0.28 },
161  { 0.35, 0.35, 0.35 },
162  { 0.42, 0.42, 0.42 },
163  { 0.49, 0.49, 0.49 },
164  { 0.56, 0.56, 0.56 },
165  { 0.63, 0.63, 0.63 },
166  { 0.665, 0.665, 0.665 },
167  { 0.633585, 0.596943, 0.395415 },
168  { 0.633585, 0.596943, 0.395415 },
169  { 0.58269, 0.565552, 0.41131 },
170  { 0.548, 0.517556, 0.411 },
171  { 0.521451, 0.457859, 0.381549 },
172  { 0.541925, 0.430761, 0.389075 },
173  { 0.503182, 0.413727, 0.357818 },
174  { 0.436545, 0.392, 0.347455 },
175  { 0.371, 0.28, 0.238 },
176  { 0.411, 0.639, 0.582 },
177  { 0.298667, 0.597333, 0.448 },
178  { 0.357, 0.483, 0.4515 },
179  { 0.345494, 0.445506, 0.381862 },
180  { 0.420445, 0.529111, 0.601556 },
181  { 0.328696, 0.394435, 0.427304 },
182  { 0.319619, 0.379082, 0.401381 },
183  { 0.287, 0.357, 0.413 },
184  { 0.301, 0.336, 0.364 },
185  { 0.239217, 0.385406, 0.677783 },
186  { 0.340483, 0.340483, 0.436517 },
187  { 0.441, 0.408333, 0.571667 },
188  { 0.699125, 0.669375, 0.252875 },
189  { 0.767667, 0.539, 0.212333 },
190  { 0.571667, 0.431667, 0.303333 },
191  { 0.621082, 0.401877, 0.267918 },
192  { 0.580282, 0.317513, 0.273718 },
193  { 0.63461, 0.19139, 0.201463 },
194  { 0.492, 0.369, 0.391364 },
195  { 0.472182, 0.311818, 0.320727 },
196  { 0.406, 0.287, 0.308 },
197  { 0.647667, 0.183667, 0.164333 },
198  { 0, 0, 0 },
199  { 1, 0.2, 0.2 },
200  { 0.2, 1, 0.2 },
201  { 0.2, 0.2, 1 },
202  { 1, 1, 0.2 },
203  { 1, 0.2, 1 },
204  { 0.2, 1, 1 },
205  { 0.529524, 0.876952, 0.515048 },
206  { 0.537073, 0.522829, 0.893171 },
207  { 1, 1, 1 },
208  { 0.877432, 0.858, 0.838568 },
209  { 0.36, 0.36, 0.36 },
210  { 0.48, 0.48, 0.48 },
211  { 0.6, 0.6, 0.6 },
212  { 0.72, 0.72, 0.72 },
213  { 0.84, 0.84, 0.84 },
214  { 0.96, 0.96, 0.96 },
215  { 1, 1, 1 },
216  { 1, 1, 1 },
217  { 0.910943, 0.902038, 0.853057 },
218  { 0.910943, 0.902038, 0.853057 },
219  { 0.877517, 0.872414, 0.826483 },
220  { 0.847429, 0.836127, 0.796571 },
221  { 0.809014, 0.777183, 0.738986 },
222  { 0.831164, 0.782925, 0.764836 },
223  { 0.782234, 0.727792, 0.693766 },
224  { 0.709273, 0.672, 0.634727 },
225  { 0.626391, 0.48354, 0.417609 },
226  { 0.876, 0.924, 0.912 },
227  { 0.690667, 0.845333, 0.768 },
228  { 0.678, 0.762, 0.741 },
229  { 0.637287, 0.718713, 0.666897 },
230  { 0.853037, 0.880593, 0.898963 },
231  { 0.602087, 0.663304, 0.693913 },
232  { 0.57468, 0.637691, 0.66132 },
233  { 0.528, 0.608, 0.672 },
234  { 0.529263, 0.574526, 0.610737 },
235  { 0.683652, 0.751884, 0.888348 },
236  { 0.624719, 0.624719, 0.707281 },
237  { 0.824, 0.813333, 0.866667 },
238  { 0.90225, 0.89075, 0.72975 },
239  { 0.930667, 0.856, 0.749333 },
240  { 0.826667, 0.746667, 0.673333 },
241  { 0.856548, 0.739178, 0.667452 },
242  { 0.828205, 0.663282, 0.635795 },
243  { 0.864683, 0.551317, 0.558439 },
244  { 0.775429, 0.700571, 0.714182 },
245  { 0.739091, 0.604909, 0.612364 },
246  { 0.663717, 0.524283, 0.548889 },
247 };
248 
249 const unsigned int
251 
253 {
254  std::map<unsigned int, SoMaterial*>::const_iterator it;
255  for( it = m_materialCache.begin(); it != m_materialCache.end(); ++it)
256  {
257  it->second->unref();
258  }
259 }
260 
261 SoMaterial*
262 ColorCodeConverter::lookup( unsigned int colorCode)
263 {
264  SoMaterial* ret = nullptr;
265  //sroe: coverity 16515, original was "if (colorCode > s_colorConversionTableSize)"
266  //which still allows colorCode = 200, which is out-of-bounds.
267  if( colorCode >= s_colorConversionTableSize)
268  {
269  // if color code is out of bounds choose red as default color
270  colorCode = red; //red is defined as =2 in the header
271  }
272 
273  std::map<unsigned int, SoMaterial*>::const_iterator it = m_materialCache.find( colorCode);
274  if( it != m_materialCache.end())
275  {
276  ret = it->second;
277  }
278  else
279  {
280  ret = new SoMaterial;
281  ret->diffuseColor.setValue( s_colorConversionTable[colorCode][0],
282  s_colorConversionTable[colorCode][1],
283  s_colorConversionTable[colorCode][2]);
284  ret->ref();
285  m_materialCache[colorCode] = ret;
286  }
287 
288  return ret;
289 }
skel.it
it
Definition: skel.GENtoEVGEN.py:423
ColorCodeConverter::s_colorConversionTable
static const double s_colorConversionTable[][3]
Definition: ColorCodeConverter.h:44
ColorCodeConverter::lookup
SoMaterial * lookup(unsigned int colorCode)
Definition: ColorCodeConverter.cxx:262
ColorCodeConverter::m_materialCache
std::map< unsigned int, SoMaterial * > m_materialCache
Definition: ColorCodeConverter.h:42
ColorCodeConverter.h
ColorCodeConverter::~ColorCodeConverter
~ColorCodeConverter()
Definition: ColorCodeConverter.cxx:252
ret
T ret(T t)
Definition: rootspy.cxx:260
ColorCodeConverter::red
static const unsigned int red
Definition: ColorCodeConverter.h:28
ColorCodeConverter::s_colorConversionTableSize
static const unsigned int s_colorConversionTableSize
Definition: ColorCodeConverter.h:45