Select Git revision
Forked from
gmsh / gmsh
Source project has a limited visibility.
gl2pgf.cpp 24.15 KiB
// Gmsh - Copyright (C) 1997-2017 C. Geuzaine, J.-F. Remacle
//
// See the LICENSE.txt file for license information. Please report all
// bugs and problems to the public mailing list <gmsh@onelab.info>.
//
// Contributed by Sebastian Eiser
#include <stdlib.h>
#include <stdio.h>
#include "GmshConfig.h"
#include "PixelBuffer.h"
#include "OS.h"
#include "Context.h"
#include "PView.h"
#include "PViewData.h"
#include "Numeric.h"
#include "Options.h"
#include "StringUtils.h"
#include "gl2png.h"
static int assembleColmapStr(const int num, const int intType, int &samples,
std::string &ret)
{
GmshColorTable * ct = GetColorTable(num); // i
ret.assign("\\pgfplotsset{\ncolormap={gmshcolormap}{%% note: "
"Only needed once if colorbars do not change\n");
samples = (int) opt_view_nb_iso(num, GMSH_GET, 0);
double step = 0.;
switch (intType){
case 2: samples=64; break; // continuous is approximated by 64 samples
case 3: break; // filled (sampled colorbar)
case 1: break; // iso lines
case 4: // numericals
default:
return 1;
}
step = (double) (1.*ct->size)/(samples-1.);
int r, g, b, a;
unsigned int idx;
char tmp[265];
for (unsigned int j=0; j < (unsigned int) samples-1; j++ /*j+=4*/) {
idx = (unsigned int)j*step;
//printf("j=%d, idx=%d step=%f\n", j, idx, step);
r = CTX::instance()->unpackRed(ct->table[idx]);
g = CTX::instance()->unpackGreen(ct->table[idx]);
b = CTX::instance()->unpackBlue(ct->table[idx]);
a = CTX::instance()->unpackAlpha(ct->table[idx]);
if (a != 255)
Msg::Warning("PGF export does not handle transparent colormaps");
sprintf(tmp, "rgb255=(%d,%d,%d) ",r,g,b);
ret.append(tmp);
if (intType != 2) // sampled
// reinsert, because then the end color is interpreted correctly
// for shader=flat mean
ret.append(tmp);
}
//endpoint
r = CTX::instance()->unpackRed(ct->table[ct->size-1]);
g = CTX::instance()->unpackGreen(ct->table[ct->size-1]);
b = CTX::instance()->unpackBlue(ct->table[ct->size-1]);
sprintf(tmp, "rgb255=(%d,%d,%d) ",r,g,b);
ret.append(tmp);
if (intType != 2) // sampled
// reinsert, because then the end color is interpreted correctly
// for shader=flat mean
ret.append(tmp);