Revision 8c49506593ec98a48775b3771f3b537a1b974c45 authored by Timur Pocheptsov on 26 March 2014, 16:41:21 UTC, committed by Timur Pocheptsov on 26 March 2014, 16:41:21 UTC
1 parent 6fbc5a9
customcolorgl.h
//Author: Timur Pocheptsov, 02/03/2014.
#ifndef CUSTOMCOLORGL_INCLUDED
#define CUSTOMCOLORGL_INCLUDED
#include <algorithm>
#ifndef ROOT_TError //'ROOT-style' inclusion guards.
#include "TError.h"
#endif
#ifndef ROOT_Rtypes
#include "Rtypes.h"
#endif
#ifndef ROOT_TROOT
#include "TROOT.h"
#endif
namespace ROOT {
namespace GLTutorials {
//Type T is some integer type - either Int_t or a Color_t as you wish.
//___________________________________________________________
template <typename T>
inline T FindFreeCustomColorIndex(T start = 1000)
{
if (!gROOT) {
//AH??? WHAT??? Should never happen! :)
::Error("FindFreeCustomColorIndex", "gROOT is null");
return -1;
}
//Some (probably stupid) assumption about the TColor -
//I'm trying to find some 'free' index in the range [1000, 10000).
//Int_t(1000) - well, to make some exotic platform happy (if Int_t != int).
for (Int_t i = std::max(start, T(1000)); i < 10000; ++i)
if (!gROOT->GetColor(i))
return i;
::Error("FindFreeCustomColorIndex", "no index found");
return -1;
}
//
//___________________________________________________________
template <typename T, unsigned N>
inline unsigned FindFreeCustomColorIndices(T (&indices)[N])
{
//All or none.
T tmp[N] = {};
tmp[0] = FindFreeCustomColorIndex<T>();
if (tmp[0] == -1)//Not found.
return 0;
unsigned nFound = 0;
for (nFound = 1; nFound < N; ++nFound) {
tmp[nFound] = FindFreeCustomColorIndex(tmp[nFound - 1] + 1);//the next free color index.
if (tmp[nFound] == -1)
break;
}
if (nFound == N)
std::copy(tmp, tmp + N, indices);
return nFound;
}
}//GLTutorials
}//ROOT
#endif
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...