1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
|
#pragma once
#include "glGrib/World.h"
#include "glGrib/Options.h"
#include "glGrib/Geometry.h"
#include "glGrib/Palette.h"
#include "glGrib/FieldMetadata.h"
#include "glGrib/Buffer.h"
#include "glGrib/Loader.h"
#include "glGrib/String.h"
#include <string>
#include <algorithm>
#include <vector>
namespace glGrib
{
template <int N>
struct FieldPackingType
{
};
template <> struct FieldPackingType<8>
{
typedef unsigned char type;
};
template <> struct FieldPackingType<16>
{
typedef unsigned short type;
};
template <> struct FieldPackingType<32>
{
typedef unsigned int type;
};
template <int N>
class FieldPacked;
template <int N>
class FieldScalar;
class Field : public World
{
public:
static Field * create (const OptionsField &, float, Loader *);
Field (const Field &) = delete;
typedef enum
{
SCALAR=0,
CONTOUR=1,
VECTOR=2,
STREAM=3,
ISOFILL=4,
} kind;
virtual kind getKind () const = 0;
virtual bool useColorBar () const = 0;
virtual Field * clone () const = 0;
void setPaletteOptions (const OptionsPalette & o)
{
palette = glGrib::Palette (o, getNormedMinValue (), getNormedMaxValue ());
}
const std::vector<BufferPtr<float>> & getValues () const
{
return values;
}
virtual const std::vector<float> getValue (int index) const
{
std::vector<float> val;
for (size_t i = 0; i < values.size (); i++)
if (values[i].allocated ())
val.push_back (values[i][index]);
return val;
}
virtual const std::vector<float> getMaxValue () const
{
std::vector<float> val;
for (size_t i = 0; i < meta.size (); i++) val.push_back (meta[i].valmax);
return val;
}
virtual const std::vector<float> getMinValue () const
{
std::vector<float> val;
for (size_t i = 0; i < meta.size (); i++) val.push_back (meta[i].valmin);
return val;
}
virtual float getNormedMinValue () const
{
std::vector<float> val = getMinValue ();
if (val.size () == 1)
return val[0];
float n = 0.0f;
for (size_t i = 0; i < val.size (); i++)
n += val[i] * val[i];
return std::sqrt (n);
}
virtual float getNormedMaxValue () const
{
std::vector<float> val = getMaxValue ();
if (val.size () == 1)
return val[0];
float n = 0.0f;
for (size_t i = 0; i < val.size (); i++)
n += val[i] * val[i];
return std::sqrt (n);
}
void reSize (const View &) override {}
const std::vector<FieldMetadata> & getMeta () const
{
return meta;
}
const OptionsField & getOptions () const
{
opts.palette = palette.getOptions ();
return opts;
}
void setScale (float s) { opts.scale = s; hilo.setScale (s); }
float getScale () const override { return opts.scale; }
const Palette & getPalette () const
{
return palette;
}
void toggleWireframe ()
{
if (opts.scalar.wireframe.on)
{
opts.scalar.wireframe.on = false;
opts.scalar.points.on = true;
}
else if (opts.scalar.points.on)
{
opts.scalar.wireframe.on = false;
opts.scalar.points.on = false;
}
else
{
opts.scalar.wireframe.on = true;
opts.scalar.points.on = false;
}
}
virtual int getSlotMax () const = 0;
float getSlot () const
{
return slot;
}
void saveOptions () const;
private:
class Privatizer
{
};
static void getUserPref (OptionsField *, Loader *, int);
virtual void setup (const Field::Privatizer, Loader *, const OptionsField &, float = 0) = 0;
void setupHilo (BufferPtr<float>);
void renderHilo (const View &) const;
void renderFrame (const View & view) const
{
frame.VAID.render (view);
}
Field () : frame (this) {}
const bool & getVisibleRef () const override
{
return opts.visible.on;
}
class frame_t
{
public:
frame_t (Field * f) : field (f), VAID (this) {}
frame_t & operator= (const frame_t & s)
{
if (this != &s)
VAID = s.VAID;
return *this;
}
void clear ()
{
VAID.clear ();
}
void render (const View &) const;
void setupVertexAttributes () const
{
field->getGeometry ()->bindFrame (0);
}
Field * field = nullptr;
OpenGLVertexArray<frame_t> VAID;
};
String3D<0,1> hilo;
frame_t frame;
private:
float slot = 0.0f;
Palette palette;
mutable OptionsField opts;
std::vector<FieldMetadata> meta;
std::vector<BufferPtr<float>> values;
friend class FieldPacked< 8>;
friend class FieldPacked<16>;
friend class FieldPacked<32>;
friend class FieldVector;
friend class FieldScalar< 8>;
friend class FieldScalar<16>;
friend class FieldScalar<32>;
friend class FieldIsoFill;
friend class FieldStream;
friend class FieldContour;
};
template <int N>
class FieldPacked : public Field
{
public:
using T = typename FieldPackingType<N>::type;
FieldPacked () : Field () {}
FieldPacked (const FieldPacked &) = delete;
private:
void unpack (BufferPtr<float> &, const int, const float,
const float, const float, const OpenGLBufferPtr<T> &);
void pack (const BufferPtr<float> &, const int, const float,
const float, const float, OpenGLBufferPtr<T> &);
void packUnpack (const BufferPtr<float> &, BufferPtr<float> &, const int,
const float, const float, const float);
void loadHeight (OpenGLBufferPtr<T>, Loader *);
void bindHeight (int) const;
OpenGLBufferPtr<T> heightbuffer;
friend class FieldVector;
friend class FieldScalar< 8>;
friend class FieldScalar<16>;
friend class FieldScalar<32>;
friend class FieldIsoFill;
friend class FieldStream;
friend class FieldContour;
};
}
|