GLVis  v4.2
Accurate and flexible finite element visualization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
palettes.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2022, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3 // LICENSE and NOTICE for details. LLNL-CODE-443271.
4 //
5 // This file is part of the GLVis visualization tool and library. For more
6 // information and source code availability see https://glvis.org.
7 //
8 // GLVis is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11 
12 #ifndef GLVIS_PALETTES_HPP
13 #define GLVIS_PALETTES_HPP
14 #include "gl/types.hpp"
15 #include <vector>
16 #include <array>
17 
19 {
20 public:
21  PaletteState();
23  void Init();
25  void UseDiscrete() { use_smooth = 0; }
27  void UseSmooth() { use_smooth = 1; }
29  int GetSmoothSetting() { return use_smooth; }
31  void SetIndex(int num) { curr_palette = num; }
32  int GetCurrIndex() const { return curr_palette; }
33  void NextIndex();
34  void PrevIndex();
35  int ChoosePalette();
36  int SelectNewRGBPalette();
38  const double* GetData() const;
40  int GetSize(int pal = -1) const;
42  int GetNumColors(int pal = -1) const
43  { return PaletteNumColors ? PaletteNumColors : GetSize(pal); }
45  void SetNumColors(int numColors) { PaletteNumColors = numColors; }
46  int GetRepeatTimes() const { return RepeatPaletteTimes; }
47  void SetRepeatTimes(int rpt) { RepeatPaletteTimes = rpt; }
48 
49  void SetUseLogscale(bool logscale) { use_logscale = logscale; }
50  bool GetUseLogscale() { return use_logscale; }
51  double GetColorCoord(double val, double min, double max);
52  void GetColorFromVal(double val, float* rgba);
53 
54  GLuint GetColorTexture() const
55  { return palette_tex[curr_palette][use_smooth]; }
56  GLuint GetAlphaTexture() const { return alpha_tex; }
57  void GenerateAlphaTexture(float matAlpha, float matAlphaCenter);
58 private:
59  void ToTextureDiscrete(double * palette, size_t plt_size, GLuint tex);
60  void ToTextureSmooth(double * palette, size_t plt_size, GLuint tex);
61  using TexHandle = gl3::resource::TextureHandle;
62 
63  std::vector<std::array<TexHandle,2>> palette_tex;
64  TexHandle alpha_tex;
65 
66  int curr_palette = 2;
67  int use_smooth = 0;
68  int RepeatPaletteTimes = 1;
69  int PaletteNumColors = 0;
70 
71  bool use_logscale = false;
72 
73  bool first_init;
74  int MaxTextureSize;
75  GLenum alpha_channel;
76  GLenum rgba_internal;
77 };
78 
79 #endif
int ChoosePalette()
Definition: palettes.cpp:7503
int GetSize(int pal=-1) const
Gets the total number of colors in the current palette color array.
Definition: palettes.cpp:7815
int GetNumColors(int pal=-1) const
Gets the number of colors used in the current palette color array.
Definition: palettes.hpp:42
const double * GetData() const
Gets the data in the palette color array.
Definition: palettes.cpp:7810
void GetColorFromVal(double val, float *rgba)
Definition: palettes.cpp:7785
int SelectNewRGBPalette()
Definition: palettes.cpp:7869
int GetCurrIndex() const
Definition: palettes.hpp:32
void SetRepeatTimes(int rpt)
Definition: palettes.hpp:47
int GetRepeatTimes() const
Definition: palettes.hpp:46
void PrevIndex()
Definition: palettes.cpp:7863
double GetColorCoord(double val, double min, double max)
Definition: palettes.cpp:7763
void NextIndex()
Definition: palettes.cpp:7858
GLuint GetColorTexture() const
Definition: palettes.hpp:54
GLuint GetAlphaTexture() const
Definition: palettes.hpp:56
Handle< texCleanup > TextureHandle
Definition: types.hpp:113
void SetIndex(int num)
Sets the palette texture to bind.
Definition: palettes.hpp:31
void Init()
Initializes the palette textures.
Definition: palettes.cpp:7694
int GetSmoothSetting()
Gets whether the smooth texture is being used (1 = true)
Definition: palettes.hpp:29
void UseSmooth()
Binds the smooth version of the current palette texture.
Definition: palettes.hpp:27
void SetNumColors(int numColors)
Sets the number of colors to use in the current palette color array.
Definition: palettes.hpp:45
bool GetUseLogscale()
Definition: palettes.hpp:50
void GenerateAlphaTexture(float matAlpha, float matAlphaCenter)
Definition: palettes.cpp:7824
void UseDiscrete()
Binds the discrete version of the current palette texture.
Definition: palettes.hpp:25
void SetUseLogscale(bool logscale)
Definition: palettes.hpp:49