diff --git a/glvis.cpp b/glvis.cpp index 8c5721d3..01e02eae 100644 --- a/glvis.cpp +++ b/glvis.cpp @@ -169,7 +169,7 @@ bool GLVisInitVis(StreamCollection input_streams) vs->Zoom(1.8); // Use the 'bone' palette when visualizing a 2D mesh only (otherwise // the 'jet-like' palette is used in 2D, see vssolution.cpp). - vs->palette.SetIndex(4); + vs->palette.SetFallbackIndex(4); } } else if (stream_state.mesh->SpaceDimension() == 3) @@ -186,13 +186,13 @@ bool GLVisInitVis(StreamCollection input_streams) if (stream_state.mesh->Dimension() == 3) { // Use the 'white' palette when visualizing a 3D volume mesh only - vss->palette.SetIndex(11); + vss->palette.SetFallbackIndex(11); vss->SetLightMatIdx(4); } else { // Use the 'bone' palette when visualizing a surface mesh only - vss->palette.SetIndex(4); + vss->palette.SetFallbackIndex(4); } // Otherwise, the 'vivid' palette is used in 3D see vssolution3d.cpp vss->ToggleDrawAxes(); @@ -1417,6 +1417,7 @@ int main (int argc, char *argv[]) const char *stream_file = string_none; const char *script_file = string_none; const char *palette_file = string_none; + const char *palette_init = string_none; const char *font_name = string_default; int portnum = 19916; int multisample = GetMultisample(); @@ -1468,8 +1469,10 @@ int main (int argc, char *argv[]) "Number of digits used for processor ranks in file names."); args.AddOption(&script_file, "-run", "--run-script", "Run a GLVis script file."); - args.AddOption(&palette_file, "-pal", "--palettes", + args.AddOption(&palette_file, "-pfile", "--palette-file", "Palette file."); + args.AddOption(&palette_init, "-pal", "--palette", + "Initial palette."); args.AddOption(&arg_keys, "-k", "--keys", "Execute key shortcut commands in the GLVis window."); args.AddOption(&stream_state.fix_elem_orient, "-fo", "--fix-orientations", @@ -1627,6 +1630,11 @@ int main (int argc, char *argv[]) BasePalettes.Load(palette_file); } + if (palette_init != string_none) + { + BasePalettes.SetDefault(palette_init); + } + GLVisGeometryRefiner.SetType(geom_ref_type); string data_type; diff --git a/lib/aux_js.cpp b/lib/aux_js.cpp index 7fad3f3b..a502d7e9 100644 --- a/lib/aux_js.cpp +++ b/lib/aux_js.cpp @@ -126,7 +126,7 @@ void display(std::stringstream & commands, const int w, const int h) vs->Zoom(1.8); // Use the 'bone' palette when visualizing a 2D mesh only (otherwise // the 'jet-like' palette is used in 2D, see vssolution.cpp). - vs->palette.SetIndex(4); + vs->palette.SetFallbackIndex(4); } } else if (stream_state.mesh->SpaceDimension() == 3) @@ -143,13 +143,13 @@ void display(std::stringstream & commands, const int w, const int h) if (stream_state.mesh->Dimension() == 3) { // Use the 'white' palette when visualizing a 3D volume mesh only - vs->palette.SetIndex(11); + vs->palette.SetFallbackIndex(11); vss->SetLightMatIdx(4); } else { // Use the 'bone' palette when visualizing a surface mesh only - vs->palette.SetIndex(4); + vs->palette.SetFallbackIndex(4); } // Otherwise, the 'vivid' palette is used in 3D see vssolution3d.cpp diff --git a/lib/palettes.cpp b/lib/palettes.cpp index 898599bf..8e165026 100644 --- a/lib/palettes.cpp +++ b/lib/palettes.cpp @@ -171,6 +171,18 @@ void PaletteState::SetIndex(int num) cout << "Palette: " << num << ") " << Palettes->Get(curr_palette)->name << endl; } +bool PaletteState::UseDefaultIndex() +{ + int num = Palettes->GetDefault(); + if ((num >= 0) && (num < Palettes->NumPalettes())) + { + curr_palette = num; + cout << "Palette: " << num << ") " << Palettes->Get(curr_palette)->name << endl; + return true; + } + return false; +} + void PaletteState::NextIndex() { SetIndex((curr_palette + 1) % Palettes->NumPalettes()); diff --git a/lib/palettes.hpp b/lib/palettes.hpp index ba1a6322..e9417b14 100644 --- a/lib/palettes.hpp +++ b/lib/palettes.hpp @@ -29,6 +29,11 @@ class PaletteState int GetSmoothSetting() { return use_smooth; } /// Sets the palette texture to bind. void SetIndex(int num); + /// Use the default index if set + bool UseDefaultIndex(); + /// If default index is not set, sets to this index. + /// Used for setting recommend palettes + void SetFallbackIndex(int idx) { if (!UseDefaultIndex()) { SetIndex(idx); } }; int GetCurrIndex() const { return curr_palette; } void NextIndex(); void PrevIndex(); diff --git a/lib/palettes_base.cpp b/lib/palettes_base.cpp index 1393c2d2..0cd92d2c 100644 --- a/lib/palettes_base.cpp +++ b/lib/palettes_base.cpp @@ -392,6 +392,23 @@ Palette* PaletteRegistry::Get(const string& name) const return palettes.back().get(); } +void PaletteRegistry::SetDefault(const string& name) +{ + const int idx = GetIndexByName(name); + if (idx < 0) + { + cout << "Palette (name = " << name << ") not found. Available palettes:" + << endl; + PrintSummary(); + } + else + { + default_palette = idx; + cout << "Default palette set to: " << default_palette << ") " + << Get(default_palette)->name << endl; + } +} + void PaletteRegistry::PrintSummary(ostream& os) const { for (int i = 0; i < NumPalettes(); i++) diff --git a/lib/palettes_base.hpp b/lib/palettes_base.hpp index 7ecd437f..bbd3584f 100644 --- a/lib/palettes_base.hpp +++ b/lib/palettes_base.hpp @@ -177,6 +177,7 @@ class PaletteRegistry /// Find the index of a palette by name int GetIndexByName(const string& name) const; + int default_palette = -1; // index of the default palette public: /// Empty constructor @@ -201,6 +202,12 @@ class PaletteRegistry /// Get a palette pointer by name; if not found, returns last palette Palette* Get(const string& name) const; + /// Set the index of the default palette by name + void SetDefault(const string& name); + + /// Get the index of the default palette + int GetDefault() const { return default_palette; }; + /// Prints a summary (index + name) of all palettes void PrintSummary(ostream& os = cout) const; diff --git a/lib/vssolution.cpp b/lib/vssolution.cpp index 246f88c0..f80eb945 100644 --- a/lib/vssolution.cpp +++ b/lib/vssolution.cpp @@ -467,7 +467,7 @@ void VisualizationSceneSolution::Init() VisualizationSceneScalarData::Init(); // Calls FindNewBox() !!! - palette.SetIndex(2); // use the 'jet-like' palette in 2D + palette.SetFallbackIndex(2); // use the 'jet-like' palette in 2D double eps = 1e-6; // move the cutting plane a bit to avoid artifacts CuttingPlane = new Plane(-1.0,0.0,0.0,(0.5-eps)*bb.x[0]+(0.5+eps)*bb.x[1]); diff --git a/lib/vssolution3d.cpp b/lib/vssolution3d.cpp index 4d927da8..ecfda716 100644 --- a/lib/vssolution3d.cpp +++ b/lib/vssolution3d.cpp @@ -751,7 +751,7 @@ void VisualizationSceneSolution3d::Init() node_pos = new double[mesh->GetNV()]; - palette.SetIndex(12); // use the 'vivid' palette in 3D + palette.SetFallbackIndex(12); // use the 'vivid' palette in 3D double eps = 1e-6; // move the cutting plane a bit to avoid artifacts CuttingPlane = new Plane(-1.0,0.0,0.0,(0.5-eps)*bb.x[0]+(0.5+eps)*bb.x[1]);