Skip to content

Commit

Permalink
Merge pull request #289 from GLVis/more-color-palettes
Browse files Browse the repository at this point in the history
Color palettes
  • Loading branch information
tzanio authored Dec 11, 2024
2 parents 419914c + 359b1cb commit 5813267
Show file tree
Hide file tree
Showing 21 changed files with 28,849 additions and 7,785 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
https://glvis.org


Version 4.3.3 (development)
===========================

- Added more flexible representations for color palette and textures, enabling
specification at both compile and run time. Run time palettes are specified
with a file and the command line argument -pal <palette_filename>.

- Added 78 new optional color-vision deficiency friendly and perceptually
uniform color palettes. See the files share/palettes-crameri.txt and
share/palettes-cet.txt.

- Palettes can now also be specified with explicit alpha channels. See the
example file share/palettes-variable-opacity.txt.

- Fixed a bug where discrete textures would not repeat.


Version 4.3.2 released on Sep 27, 2024
======================================

Expand Down
2 changes: 2 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ their own respective licenses which can be found in their code and attached
license files. These software products and their licenses are as follows:

* GL2PS (linalg/gl2ps.{h,c}) -- Custom 1-clause license
* Additional color palettes (share/palettes-crameri.txt) -- MIT license
* Additional color palettes (share/palettes-cet.txt) -- CC BY 4.0 license
11 changes: 10 additions & 1 deletion glvis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ void ExecuteScriptCommand()
scr >> rpt_times;
cout << "Script: palette_repeat: " << rpt_times << endl;
vs->palette.SetRepeatTimes(rpt_times);
vs->palette.Init();
vs->palette.GenerateTextures();
MyExpose();
}
else if (word == "toggle_attributes")
Expand Down Expand Up @@ -1325,6 +1325,7 @@ int main (int argc, char *argv[])
bool save_stream = false;
const char *stream_file = string_none;
const char *script_file = string_none;
const char *palette_file = string_none;
const char *font_name = string_default;
int portnum = 19916;
int multisample = GetMultisample();
Expand Down Expand Up @@ -1358,6 +1359,8 @@ 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",
"Palette file.");
args.AddOption(&arg_keys, "-k", "--keys",
"Execute key shortcut commands in the GLVis window.");
args.AddOption(&stream_state.fix_elem_orient, "-fo", "--fix-orientations",
Expand Down Expand Up @@ -1487,6 +1490,12 @@ int main (int argc, char *argv[])
}
SetUseHiDPI(enable_hidpi);

// Load in palette file, if specified
if (palette_file != string_none)
{
BasePalettes.Load(palette_file);
}

GLVisGeometryRefiner.SetType(geom_ref_type);

string data_type;
Expand Down
2 changes: 2 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ list(APPEND SOURCES
material.cpp
openglvis.cpp
palettes.cpp
palettes_base.cpp
sdl.cpp
sdl_helper.cpp
sdl_main.cpp
Expand All @@ -45,6 +46,7 @@ list(APPEND HEADERS
material.hpp
openglvis.hpp
palettes.hpp
palettes_base.hpp
sdl.hpp
sdl_helper.hpp
sdl_main.hpp
Expand Down
2 changes: 1 addition & 1 deletion lib/gltf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ int glTF_Builder::writeFile()
gltf << " ],\n\n";

// https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html#reference-sampler
// see also: PaletteState::{ToTextureDiscrete(),ToTextureSmooth()}
// see also: Texture::Generate()
gltf << " \"samplers\" : [";
for (size_t i = 0; i != samplers.size(); ++i)
{
Expand Down
14 changes: 2 additions & 12 deletions lib/openglvis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ VisualizationScene::VisualizationScene()
light_mat_idx = 3;
use_light = true;

palette.Init();
palette.GenerateTextures();
}

VisualizationScene::~VisualizationScene() {}
Expand Down Expand Up @@ -479,7 +479,7 @@ VisualizationScene::AddPaletteMaterial(glTF_Builder &bld)
/* wrapT: */ glTF_Builder::wrap_type::CLAMP_TO_EDGE);
// create palette image
const int palette_size = palette.GetNumColors();
vector<array<float,4>> palette_data(palette_size);
vector<array<float,4>> palette_data = palette.GetPalette()->GetData();
#if 0
glGetTextureImage(
palette.GetColorTexture(), 0,
Expand All @@ -491,16 +491,6 @@ VisualizationScene::AddPaletteMaterial(glTF_Builder &bld)
glGetTexImage(GL_TEXTURE_2D, 0,
gl3::GLDevice::useLegacyTextureFmts() ? GL_RGBA : GL_RGBA32F,
GL_FLOAT, palette_data.data());
#else
const double *palette_data_raw = palette.GetData();
for (int i = 0; i < palette_size; ++i)
{
for (int j = 0; j < 3; ++j)
{
palette_data[i][j] = (float) palette_data_raw[j + 3*i];
}
palette_data[i][3] = 1.0f;
}
#endif
auto palette_img =
bld.addImage(
Expand Down
Loading

0 comments on commit 5813267

Please sign in to comment.