Hold preset information in simple struct

Creating all the presets as vtkm::cont::ColorTable objects and passing
them back was problematic. It caused state to be shared and caused
issues when deallocating after the device deallocation methods were
finalized. Instead, make a simple struct and build new color tables on
the fly.
This commit is contained in:
Kenneth Moreland 2018-11-11 17:30:11 -07:00
parent 70e10459c7
commit 8984e74e8c

@ -122,14 +122,43 @@ bool IStringEqual(const std::string& str1, const std::string& str2)
return true;
}
VTKM_CONT const std::vector<std::pair<vtkm::cont::ColorTable::Preset, vtkm::cont::ColorTable>>
GetColorTablePresetsVector()
struct ColorTablePreset
{
using PresetPair = std::pair<vtkm::cont::ColorTable::Preset, vtkm::cont::ColorTable>;
vtkm::cont::ColorTable::Preset Preset;
std::string Name;
vtkm::cont::ColorSpace ColorSpace;
vtkm::Vec<double, 3> NanColor;
std::vector<double> RGBPoints;
std::vector<double> AlphaPoints;
VTKM_CONT
ColorTablePreset(vtkm::cont::ColorTable::Preset preset,
std::string&& name,
vtkm::cont::ColorSpace colorSpace,
vtkm::Vec<double, 3>&& nanColor,
std::vector<double>&& rgbPoints,
std::vector<double>&& alphaPoints = { 0.0, 1.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0 })
: Preset(preset)
, Name(std::move(name))
, ColorSpace(std::move(colorSpace))
, NanColor(std::move(nanColor))
, RGBPoints(std::move(rgbPoints))
, AlphaPoints(std::move(alphaPoints))
{
}
VTKM_CONT vtkm::cont::ColorTable MakePreset() const
{
return vtkm::cont::ColorTable(
this->Name, this->ColorSpace, this->NanColor, this->RGBPoints, this->AlphaPoints);
}
};
VTKM_CONT const std::vector<ColorTablePreset> GetColorTablePresetsVector()
{
// clang-format off
static std::vector<PresetPair> presets = {
PresetPair{ vtkm::cont::ColorTable::Preset::COOL_TO_WARM, {
static std::vector<ColorTablePreset> presets = {
{ vtkm::cont::ColorTable::Preset::COOL_TO_WARM,
"Cool to Warm",
vtkm::cont::ColorSpace::DIVERGING,
{ 1, 1, 0 },
@ -138,9 +167,8 @@ GetColorTablePresetsVector()
0.5, 0.865, 0.865, 0.865,
1, 0.705882352941, 0.0156862745098, 0.149019607843
}
}
},
PresetPair{vtkm::cont::ColorTable::Preset::COOL_TO_WARM_EXTENDED, {
{ vtkm::cont::ColorTable::Preset::COOL_TO_WARM_EXTENDED,
"Cool to Warm Extended",
vtkm::cont::ColorSpace::LAB,
{ 0.25, 0, 0 },
@ -181,9 +209,8 @@ GetColorTablePresetsVector()
0.96875, 0.4, 0.054902, 0.192157,
1, 0.34902, 0.070588, 0.211765
}
}
},
PresetPair{vtkm::cont::ColorTable::Preset::VIRIDIS, {
{ vtkm::cont::ColorTable::Preset::VIRIDIS,
"Viridis",
vtkm::cont::ColorSpace::LAB,
{ 1, 0, 0 },
@ -445,9 +472,8 @@ GetColorTablePresetsVector()
0.996078, 0.943486, 0.911273, 0.101474,
1.000000, 0.952999, 0.912545, 0.110859
}
}
},
PresetPair{vtkm::cont::ColorTable::Preset::INFERNO, {
{ vtkm::cont::ColorTable::Preset::INFERNO,
"Inferno",
vtkm::cont::ColorSpace::LAB,
{ 0, 1, 0 },
@ -709,9 +735,8 @@ GetColorTablePresetsVector()
0.996078, 0.952737, 0.998796, 0.626535,
1.000000, 0.959400, 1.002963, 0.640626
}
}
},
PresetPair{vtkm::cont::ColorTable::Preset::PLASMA, {
{ vtkm::cont::ColorTable::Preset::PLASMA,
"Plasma",
vtkm::cont::ColorSpace::LAB,
{ 0, 1, 0 },
@ -973,9 +998,8 @@ GetColorTablePresetsVector()
0.996078, 0.896560, 0.975612, 0.096681,
1.000000, 0.894058, 0.982254, 0.081069
}
}
},
PresetPair{vtkm::cont::ColorTable::Preset::BLACK_BODY_RADIATION, {
{ vtkm::cont::ColorTable::Preset::BLACK_BODY_RADIATION,
"Black-Body Radiation",
vtkm::cont::ColorSpace::RGB,
{ 0, 0.498039215686, 1 },
@ -985,16 +1009,14 @@ GetColorTablePresetsVector()
0.8, 0.901960784314, 0.901960784314, 0,
1, 1, 1, 1
}
}
},
PresetPair{vtkm::cont::ColorTable::Preset::X_RAY, {
{ vtkm::cont::ColorTable::Preset::X_RAY,
"X Ray",
vtkm::cont::ColorSpace::RGB,
{ 1, 0, 0 },
{ 0, 1, 1, 1, 1, 0, 0, 0 }
}
},
PresetPair{vtkm::cont::ColorTable::Preset::GREEN, {
{ vtkm::cont::ColorTable::Preset::GREEN,
"Green",
vtkm::cont::ColorSpace::LAB,
{ 0.25, 0, 0 },
@ -1021,9 +1043,8 @@ GetColorTablePresetsVector()
0.95, 0.960784, 0.949020, 0.670588,
1.00, 1.000000, 0.984314, 0.901961
}
}
},
PresetPair{vtkm::cont::ColorTable::Preset::BLACK_BLUE_WHITE, {
{ vtkm::cont::ColorTable::Preset::BLACK_BLUE_WHITE,
"Black - Blue - White",
vtkm::cont::ColorSpace::RGB,
{ 1, 1, 0 },
@ -1033,9 +1054,8 @@ GetColorTablePresetsVector()
0.666, 0, 0.501960784314, 1,
1, 1, 1, 1
}
}
},
PresetPair{vtkm::cont::ColorTable::Preset::BLUE_TO_ORANGE, {
{ vtkm::cont::ColorTable::Preset::BLUE_TO_ORANGE,
"Blue to Orange",
vtkm::cont::ColorSpace::LAB,
{ 0.25, 0, 0 },
@ -1087,9 +1107,8 @@ GetColorTablePresetsVector()
0.967095, 0.400000, 0.003922, 0.101961,
1.000000, 0.188235, 0.000000, 0.070588
}
}
},
PresetPair{vtkm::cont::ColorTable::Preset::GRAY_TO_RED, {
{vtkm::cont::ColorTable::Preset::GRAY_TO_RED,
"Gray to Red",
vtkm::cont::ColorSpace::LAB,
{ 0, 0.498039215686, 1 },
@ -1112,9 +1131,8 @@ GetColorTablePresetsVector()
0.941177, 0.576932, 0.055363, 0.149250,
1.000000, 0.403922, 0.000000, 0.121569
}
}
},
PresetPair{vtkm::cont::ColorTable::Preset::COLD_AND_HOT, {
{ vtkm::cont::ColorTable::Preset::COLD_AND_HOT,
"Cold and Hot",
vtkm::cont::ColorSpace::RGB,
{ 1, 1, 0 },
@ -1125,9 +1143,8 @@ GetColorTablePresetsVector()
0.55, 1, 0, 0,
1, 1, 1, 0
}
}
},
PresetPair{vtkm::cont::ColorTable::Preset::BLUE_GREEN_ORANGE, {
{ vtkm::cont::ColorTable::Preset::BLUE_GREEN_ORANGE,
"Blue - Green - Orange",
vtkm::cont::ColorSpace::LAB,
{ 0.25, 0.0, 0.0 },
@ -1183,9 +1200,8 @@ GetColorTablePresetsVector()
0.975,0.478431,0.082353,0.047059,
1.0,0.45098,0.007843,0.0
}
}
},
PresetPair{vtkm::cont::ColorTable::Preset::YELLOW_GRAY_BLUE, {
{ vtkm::cont::ColorTable::Preset::YELLOW_GRAY_BLUE,
"Yellow - Gray - Blue",
vtkm::cont::ColorSpace::LAB,
{ 0.25, 0, 0 },
@ -1246,9 +1262,8 @@ GetColorTablePresetsVector()
0.983412, 0.807843, 0.901961, 0.960784,
1.000000, 0.890196, 0.956863, 0.984314
}
}
},
PresetPair{vtkm::cont::ColorTable::Preset::RAINBOW_UNIFORM, {
{ vtkm::cont::ColorTable::Preset::RAINBOW_UNIFORM,
"Rainbow Uniform",
vtkm::cont::ColorSpace::RGB,
{ 1, 0, 0 },
@ -1297,9 +1312,8 @@ GetColorTablePresetsVector()
0.976190,0.741299,0.046667,0.386167,
1.000000,0.683700,0.050000,0.413900
}
}
},
PresetPair{vtkm::cont::ColorTable::Preset::JET, {
{ vtkm::cont::ColorTable::Preset::JET,
"Jet",
vtkm::cont::ColorSpace::RGB,
{ 0.25, 0, 0 },
@ -1312,9 +1326,8 @@ GetColorTablePresetsVector()
0.873016, 1, 0, 0,
1, 0.5, 0, 0
}
}
},
PresetPair{vtkm::cont::ColorTable::Preset::RAINBOW_DESATURATED, {
{ vtkm::cont::ColorTable::Preset::RAINBOW_DESATURATED,
"Rainbow Desaturated",
vtkm::cont::ColorSpace::RGB,
{ 1, 1, 0 },
@ -1329,7 +1342,6 @@ GetColorTablePresetsVector()
1, 0.878431372549, 0.301960784314, 0.301960784314
}
}
}
};
// clang-format on
@ -1351,11 +1363,11 @@ bool LoadColorTablePreset(vtkm::cont::ColorTable::Preset preset, vtkm::cont::Col
{
preset = DEFAULT_PRESET;
}
for (auto&& presetPair : GetColorTablePresetsVector())
for (auto&& ctPreset : GetColorTablePresetsVector())
{
if (presetPair.first == preset)
if (ctPreset.Preset == preset)
{
table = presetPair.second;
table = ctPreset.MakePreset();
return true;
}
}
@ -1365,9 +1377,9 @@ bool LoadColorTablePreset(vtkm::cont::ColorTable::Preset preset, vtkm::cont::Col
VTKM_CONT_EXPORT std::set<std::string> GetPresetNames()
{
std::set<std::string> names;
for (auto&& presetPair : GetColorTablePresetsVector())
for (auto&& ctPreset : GetColorTablePresetsVector())
{
names.insert(presetPair.second.GetName());
names.insert(ctPreset.Name);
}
names.insert("Default");
return names;
@ -1379,11 +1391,11 @@ VTKM_CONT_EXPORT bool LoadColorTablePreset(std::string name, vtkm::cont::ColorTa
{
return LoadColorTablePreset(DEFAULT_PRESET, table);
}
for (auto&& presetPair : GetColorTablePresetsVector())
for (auto&& ctPreset : GetColorTablePresetsVector())
{
if (IStringEqual(name, presetPair.second.GetName()))
if (IStringEqual(name, ctPreset.Name))
{
table = presetPair.second;
table = ctPreset.MakePreset();
return true;
}
}