Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
justinlaughlin committed Nov 5, 2024
1 parent cb45902 commit 05ed4fc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 30 deletions.
2 changes: 1 addition & 1 deletion glvis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#include "mfem.hpp"
#include "lib/palettes.hpp"
#include "lib/base_palettes.hpp"
// #include "lib/base_palettes.hpp"
#include "lib/visual.hpp"
#include "lib/stream_reader.hpp"

Expand Down
18 changes: 9 additions & 9 deletions lib/base_palettes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ struct Palette {
return make_shared<Palette>(*this);
}

double* as_array() const {
double* as_rgb_array() const {
size_t N = colors.size();
double* arr = new double[N * 4];
double* arr = new double[N * 3];
for (size_t i = 0; i < N; ++i) {
arr[i * 4 + 0] = colors[i].r;
arr[i * 4 + 1] = colors[i].g;
arr[i * 4 + 2] = colors[i].b;
arr[i * 4 + 3] = colors[i].a;
arr[i * 3 + 0] = colors[i].r;
arr[i * 3 + 1] = colors[i].g;
arr[i * 3 + 2] = colors[i].b;
// arr[i * 4 + 3] = colors[i].a;
}
return arr;
}
Expand Down Expand Up @@ -150,10 +150,10 @@ class PaletteRegistry {

// get by index
shared_ptr<Palette> get(size_t index) const {
if (1 <= index && index <= NumPalettes()) {
return palettes[index-1];
if (0 <= index && index <= NumPalettes()-1) {
return palettes[index];
}
cout << "Palette (index = " << index << ") out of range. Available palettes:" << endl;
cout << "Palette (index = " << index+1 << ") out of range. Available palettes:" << endl;
this->printSummary();
return palettes[NumPalettes()-1];
}
Expand Down
27 changes: 7 additions & 20 deletions lib/palettes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,7 @@ int PaletteState::ChoosePalette()
char buffer[buflen];
int pal;
cout << "Choose a palette:\n";
for (pal = 0; pal < Palettes->NumPalettes(); pal++)
{
cout << setw(4) << pal+1 << ") " << "FIXME";//RGB_Palettes_Names[pal];
if ((pal+1)%5 == 0)
{
cout << '\n';
}
}
Palettes->printSummary();
cout << "\n ---> [" << curr_palette+1 << "] " << flush;

cin.getline (buffer, buflen);
Expand Down Expand Up @@ -211,7 +204,9 @@ PaletteState::PaletteState()
// : palettes(palettes)
// , palette_tex(palettes->size())
: first_init(false)
{}
, Palettes(&BasePalettes)
, palette_tex(BasePalettes.NumPalettes())
{}

void PaletteState::SetPaletteRegistry(PaletteRegistry* Palettes)
{
Expand All @@ -224,6 +219,7 @@ void PaletteState::Init()
{
if (!first_init)
{

glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxTextureSize);
if (MaxTextureSize < 4096)
{
Expand Down Expand Up @@ -343,9 +339,9 @@ double * PaletteState::GetData(int pidx)
// return RGB_Palettes[curr_palette];
if (pidx == -1)
{
return Palettes->get(curr_palette)->as_array();
return Palettes->get(curr_palette)->as_rgb_array();
}
return Palettes->get(pidx)->as_array();
return Palettes->get(pidx)->as_rgb_array();
}

void PaletteState::GenerateAlphaTexture(float matAlpha, float matAlphaCenter)
Expand Down Expand Up @@ -412,12 +408,3 @@ int PaletteState::GetSize(int pidx) const {
}
return Palettes->get(pidx)->size();
}

// int PaletteState::GetSize(int pal) const
// {
// if (pal == -1)
// {
// return RGB_Palettes_Sizes[curr_palette];
// }
// return RGB_Palettes_Sizes[pal];
// }

0 comments on commit 05ed4fc

Please sign in to comment.