|
|
57bda0 |
|
|
|
57bda0 |
#ifndef RASTER_H
|
|
|
57bda0 |
#define RASTER_H
|
|
|
57bda0 |
|
|
|
57bda0 |
|
|
|
57bda0 |
#include <cassert></cassert>
|
|
|
57bda0 |
|
|
|
57bda0 |
#include "track.h"
|
|
|
57bda0 |
|
|
|
57bda0 |
|
|
|
57bda0 |
class TouchPoint;
|
|
|
57bda0 |
typedef std::vector<touchpoint> TouchPointList;</touchpoint>
|
|
|
57bda0 |
|
|
|
57bda0 |
|
|
|
d2b2b5 |
class Painter {
|
|
|
d2b2b5 |
public:
|
|
|
d2b2b5 |
virtual ~Painter() { }
|
|
|
d2b2b5 |
virtual Real get_min_height() const = 0;
|
|
|
d2b2b5 |
virtual Vector2 get_radius_xy() const = 0;
|
|
|
d2b2b5 |
virtual Real get_height_xy(const Vector2 &offset) const = 0;
|
|
|
d2b2b5 |
};
|
|
|
d2b2b5 |
|
|
|
d2b2b5 |
|
|
|
57bda0 |
class Raster {
|
|
|
57bda0 |
private:
|
|
|
57bda0 |
Real *data;
|
|
|
57bda0 |
int width;
|
|
|
57bda0 |
int height;
|
|
|
57bda0 |
|
|
|
57bda0 |
public:
|
|
|
57bda0 |
explicit Raster(int width = 0, int height = 0, Real value = 0):
|
|
|
57bda0 |
data(), width(), height()
|
|
|
57bda0 |
{ resize(width, height, value); }
|
|
|
57bda0 |
|
|
|
57bda0 |
~Raster() { reset(); }
|
|
|
57bda0 |
|
|
|
57bda0 |
void fill(Real value) {
|
|
|
57bda0 |
if (data)
|
|
|
57bda0 |
for(Real *i = data, *e = i + width*height; i < e; ++i)
|
|
|
57bda0 |
*i = value;
|
|
|
57bda0 |
}
|
|
|
57bda0 |
|
|
|
57bda0 |
void resize(int width, int height, Real value = 0) {
|
|
|
57bda0 |
if (data) delete[] data;
|
|
|
57bda0 |
data = 0;
|
|
|
57bda0 |
this->width = this->height = 0;
|
|
|
57bda0 |
|
|
|
57bda0 |
if (width > 0 && height > 0) {
|
|
|
57bda0 |
this->width = width;
|
|
|
57bda0 |
this->height = height;
|
|
|
57bda0 |
this->data = new Real[width*height];
|
|
|
57bda0 |
fill(value);
|
|
|
57bda0 |
}
|
|
|
57bda0 |
}
|
|
|
57bda0 |
|
|
|
57bda0 |
void reset() { resize(0, 0); }
|
|
|
57bda0 |
|
|
|
57bda0 |
int get_width() const { return width; }
|
|
|
57bda0 |
int get_height() const { return height; }
|
|
|
57bda0 |
|
|
|
57bda0 |
const Real* get_data() const { return data; }
|
|
|
57bda0 |
const Real* operator[](int row) const
|
|
|
57bda0 |
{ assert(data); return data + row*width; }
|
|
|
57bda0 |
|
|
|
57bda0 |
Real* get_data() { return data; }
|
|
|
57bda0 |
Real* operator[](int row)
|
|
|
57bda0 |
{ assert(data); return data + row*width; }
|
|
|
57bda0 |
|
|
|
57bda0 |
Real get(int x, int y, Real def = 0) const
|
|
|
57bda0 |
{ return x >= 0 && y >= 0 && x < width && y < height ? (*this)[y][x] : def; }
|
|
|
57bda0 |
void set(int x, int y, Real value)
|
|
|
57bda0 |
{ if (x >= 0 && y >= 0 && x < width && y < height) (*this)[y][x] = value; }
|
|
|
57bda0 |
|
|
|
d2b2b5 |
void touch(const Painter &painter, const Vector2 &position, int index, TouchPointList &points);
|
|
|
57bda0 |
};
|
|
|
57bda0 |
|
|
|
57bda0 |
|
|
|
57bda0 |
class TouchPoint {
|
|
|
57bda0 |
public:
|
|
|
57bda0 |
int index;
|
|
|
57bda0 |
int row;
|
|
|
57bda0 |
int col;
|
|
|
57bda0 |
Real prev;
|
|
|
57bda0 |
Real next;
|
|
|
57bda0 |
|
|
|
57bda0 |
TouchPoint(int index = 0, int row = 0, int col = 0, Real prev = 0, Real next = 0):
|
|
|
57bda0 |
index(index), row(row), col(col), prev(prev), next(next) { }
|
|
|
57bda0 |
|
|
|
57bda0 |
void apply_next(Raster &raster) const
|
|
|
57bda0 |
{ raster.set(col, row, next); }
|
|
|
57bda0 |
void apply_prev(Raster &raster) const
|
|
|
57bda0 |
{ raster.set(col, row, prev); }
|
|
|
57bda0 |
};
|
|
|
57bda0 |
|
|
|
57bda0 |
|
|
|
0a0ecd |
class FlatRaster {
|
|
|
0a0ecd |
public:
|
|
|
0a0ecd |
Real x0;
|
|
|
0a0ecd |
Real x1;
|
|
|
0a0ecd |
Real y0;
|
|
|
0a0ecd |
Real y1;
|
|
|
0a0ecd |
Real min_value;
|
|
|
0a0ecd |
Real max_value;
|
|
|
0a0ecd |
Raster raster;
|
|
|
0a0ecd |
|
|
|
0a0ecd |
explicit FlatRaster(
|
|
|
0a0ecd |
int xpixels = 0,
|
|
|
0a0ecd |
int ypixels = 0,
|
|
|
0a0ecd |
Real x0 = 0,
|
|
|
0a0ecd |
Real x1 = 1,
|
|
|
0a0ecd |
Real y0 = 0,
|
|
|
0a0ecd |
Real y1 = 1,
|
|
|
0a0ecd |
Real min_value = 0,
|
|
|
0a0ecd |
Real max_value = 1
|
|
|
0a0ecd |
):
|
|
|
0a0ecd |
x0(x0),
|
|
|
0a0ecd |
x1(x1),
|
|
|
0a0ecd |
y0(y0),
|
|
|
0a0ecd |
y1(y1),
|
|
|
0a0ecd |
min_value(min_value),
|
|
|
0a0ecd |
max_value(max_value),
|
|
|
0a0ecd |
raster(xpixels, ypixels, min_value)
|
|
|
0a0ecd |
{ }
|
|
|
0a0ecd |
|
|
|
0a0ecd |
Vector4 color_by_distance(Real d) const;
|
|
|
0a0ecd |
void draw() const;
|
|
|
0a0ecd |
};
|
|
|
0a0ecd |
|
|
|
0a0ecd |
|
|
|
d2b2b5 |
class PolarRaster {
|
|
|
d2b2b5 |
public:
|
|
|
d2b2b5 |
Real x0;
|
|
|
d2b2b5 |
Real x1;
|
|
|
d2b2b5 |
Real min_value;
|
|
|
d2b2b5 |
Real max_value;
|
|
|
d2b2b5 |
Raster raster;
|
|
|
d2b2b5 |
|
|
|
d2b2b5 |
explicit PolarRaster(
|
|
|
d2b2b5 |
int xpixels = 0,
|
|
|
d2b2b5 |
int ypixels = 0,
|
|
|
d2b2b5 |
Real x0 = 0,
|
|
|
d2b2b5 |
Real x1 = 1,
|
|
|
d2b2b5 |
Real min_value = 0,
|
|
|
d2b2b5 |
Real max_value = 1
|
|
|
d2b2b5 |
):
|
|
|
d2b2b5 |
x0(x0),
|
|
|
d2b2b5 |
x1(x1),
|
|
|
d2b2b5 |
min_value(min_value),
|
|
|
d2b2b5 |
max_value(max_value),
|
|
|
d2b2b5 |
raster(xpixels, ypixels, min_value)
|
|
|
d2b2b5 |
{ }
|
|
|
d2b2b5 |
|
|
|
d2b2b5 |
Vector4 color_by_distance(Real d) const;
|
|
|
d2b2b5 |
void draw() const;
|
|
|
d2b2b5 |
};
|
|
|
d2b2b5 |
|
|
|
d2b2b5 |
|
|
|
57bda0 |
#endif
|