This repository contains a number of somewhat connected utilities which originated in the development of the svm-order-params project, but are independent from this application. It's components are split amongs several headers:
color.hpp
: Provides acolormap::color
class representing a grayscale, RGB, or RGBA color, including the ability to mix colors.map.hpp
: Provides thecolormap::map
, a functor that maps real numbers to a color by interpolating between colors at pre-defined support points.palettes.hpp
: Defines a variety of ready-to-usecolormap::map
s, mostly inspired by ColorBrewer and the gnuplot-palettes repository by Gnuplotting (a.k.a. Hagen Wierstorf). The palettes are exposed through a global variablecolormap::palettes
, astd::map
that maps names (std::string
s) tocolormap::map
s.itadpt/map_iterator_adapter.hpp
: Defines an iterator adapter that lazily applies a functor on a base iterator upon dereferenciation. Notable API are the non-member functionsmap_iterator(BaseIterator, Functor&)
which returns amap_iterator_adapter<BaseIterator, Functor>
, andmap(Container const&, Functor&)
which returns a quasi-container objectmapped<Container, Functor>
.
grid.hpp
: Provides a classcolormap::grid
which represents multidimensional uniform grids which can be initialized very easily and are cheap and iterable.pixmap.hpp
: Provides a classcolormap::pixmap
which can write iterators overcolor
s to disk in PPM (or PGM) format, both in binary, and in ASCII form.
To install colormaps use the following commands:
$ git clone https://github.com/JulianWww/colormap
$ mkdir build && cd build
$ cmake ..
$ make install
than include using:
find_package(colormap INTERFACE)
and add as a library to your project. Tested for:
- Unix
The following code snippet showcases some of the features of the headers in this
repository. For a compilable example, see test/mandelbrot.cpp
.
using namespace colormap;
// set up the grid: 701 x 401 grid points (pixels) representing the region
// [-2.5, 1] x [-1, 1].
grid<2, major_order::col> g { {701, {-2.5, 1.}}, {401, {-1., 1.}} };
using grid_point_t = typename decltype(g)::grid_point_type;
// set up the functor to be visualized on the grid, e.g. the mandelbrot set
auto mandelbrot = [] (grid_point_t c_arr) { /* omitted */ };
// Iterator adapter mapping grid points to function values.
// Result is a `mapped` object that behave like a container.
auto val = itadpt::map(g, mandelbrot);
// find the maximum value
double max = *std::max_element(val.begin(), val.end());
// get a colormap and rescale it
auto pal = palettes.at("inferno").rescale(1, max);
// and use it to map the values to colors
auto pix = itadpt::map(val, pal);
// Construct a PPM object from the `mapped` object `pix`. Color space is
// inferred from color type of pix. "inferno" is an RGB palette, so `pmap`
// will represent a PPM image. For a grayscale colormap, it would result in
// a PGM image.
pixmap<decltype(pix.begin())> pmap(pix.begin(), g.shape());
std::ofstream os("appleman." + pmap.file_extension(),
std::ios_base::binary);
pmap.write_binary(os);
produces the image appleman.ppm
:
Copyright (C) 2018-2019 Jonas Greitemann
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.