Logo ROOT  
Reference Guide
customcolorgl.h
Go to the documentation of this file.
1//Author: Timur Pocheptsov, 02/03/2014.
2
3#ifndef CUSTOMCOLORGL_INCLUDED
4#define CUSTOMCOLORGL_INCLUDED
5
6#include <algorithm>
7
8#include "TError.h"
9#include "TROOT.h"
10
11namespace ROOT {
12namespace GLTutorials {
13
14//Type T is some integer type - either Int_t or a Color_t as you wish.
15
16//___________________________________________________________
17template <typename T>
18inline T FindFreeCustomColorIndex(T start = 1000)
19{
20 if (!gROOT) {
21 //AH??? WHAT??? Should never happen! :)
22 ::Error("FindFreeCustomColorIndex", "gROOT is null");
23 return -1;
24 }
25 //Some (probably stupid) assumption about the TColor -
26 //I'm trying to find some 'free' index in the range [1000, 10000).
27 //Int_t(1000) - well, to make some exotic platform happy (if Int_t != int).
28 for (Int_t i = std::max(start, T(1000)), e = 10000; i < e; ++i)
29 if (!gROOT->GetColor(i))
30 return i;
31
32 ::Error("FindFreeCustomColorIndex", "no index found");
33
34 return -1;
35}
36
37//
38//___________________________________________________________
39template <typename T, unsigned N>
41{
42 //All or none.
43 T tmp[N] = {};
44 tmp[0] = FindFreeCustomColorIndex<T>();
45 if (tmp[0] == -1)//Not found.
46 return 0;
47
48 unsigned nFound = 1;
49 for (; nFound < N; ++nFound) {
50 tmp[nFound] = FindFreeCustomColorIndex(tmp[nFound - 1] + 1);//the next free color index.
51 if (tmp[nFound] == -1)
52 break;
53 }
54
55 if (nFound == N)
56 std::copy(tmp, tmp + N, indices);
57
58 return nFound;
59}
60
61}//GLTutorials
62}//ROOT
63
64#endif
#define e(i)
Definition: RSha256.hxx:103
int Int_t
Definition: RtypesCore.h:41
void Error(const char *location, const char *msgfmt,...)
#define N
#define gROOT
Definition: TROOT.h:415
T FindFreeCustomColorIndex(T start=1000)
Definition: customcolorgl.h:18
unsigned FindFreeCustomColorIndices(T(&indices)[N])
Definition: customcolorgl.h:40
double T(double x)
Definition: ChebyshevPol.h:34
VSD Structures.
Definition: StringConv.hxx:21