/* This file is part of the OpenLB library
*
* Copyright (C) 2007 Jonas Latt
* E-mail contact: info@openlb.net
* The most recent release of OpenLB can be downloaded at
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef COLORMAPS_H
#define COLORMAPS_H
#include
#include
namespace olb {
namespace graphics {
template
struct ScalarFunction {
virtual ~ScalarFunction() { }
virtual T operator() (T x) const =0;
virtual ScalarFunction* clone() const=0;
};
template
class LinearFunction : public ScalarFunction {
public:
LinearFunction(T x1_, T x2_, T y1_, T y2_);
T operator() (T x) const override;
LinearFunction* clone() const override;
private:
T x1, x2, y1, y2;
};
template
class PowerLawFunction : public ScalarFunction {
public:
PowerLawFunction(T x1_, T x2_, T y1_, T y2_, T b_);
T operator() (T x) const override;
PowerLawFunction* clone() const override;
private:
T x1, x2, y1, y2;
T b;
};
template
struct Piece {
Piece(T closedBegin_, T openEnd_) : closedBegin(closedBegin_), openEnd(openEnd_)
{
}
T closedBegin, openEnd;
};
template
class PiecewiseFunction : public ScalarFunction {
public:
PiecewiseFunction() { }
~PiecewiseFunction() override;
PiecewiseFunction(PiecewiseFunction const& rhs);
PiecewiseFunction& operator=(PiecewiseFunction const& rhs);
void swap(PiecewiseFunction& rhs);
void addPiece(Piece piece, ScalarFunction* f);
T operator() (T x) const override;
PiecewiseFunction* clone() const override;
private:
std::vector > pieces;
std::vector*> functions;
};
template
struct rgb {
rgb(T r_, T g_, T b_) : r(r_), g(g_), b(b_)
{
}
T r,g,b;
};
template
class ColorMap {
public:
ColorMap(PiecewiseFunction const& red_,
PiecewiseFunction const& green_,
PiecewiseFunction const& blue_);
rgb get(T x) const;
private:
PiecewiseFunction red, green, blue;
};
namespace mapGenerators {
template PiecewiseFunction generateEarthRed();
template PiecewiseFunction generateEarthGreen();
template PiecewiseFunction generateEarthBlue();
template PiecewiseFunction generateWaterRed();
template PiecewiseFunction generateWaterGreen();
template PiecewiseFunction generateWaterBlue();
template PiecewiseFunction generateAirRed();
template PiecewiseFunction generateAirGreen();
template PiecewiseFunction generateAirBlue();
template PiecewiseFunction generateFireRed();
template PiecewiseFunction generateFireGreen();
template PiecewiseFunction generateFireBlue();
template PiecewiseFunction generateLeeLooRed();
template PiecewiseFunction generateLeeLooGreen();
template PiecewiseFunction generateLeeLooBlue();
template ColorMap generateMap(std::string mapName);
} // namespace mapGenerators
} // namespace graphics
} // namespace olb
#endif