commit d8926f87aa0f78c2044bb67fc34b627c22631615
parent 98e45aaa912cd2377dab1118eac693044c5648d5
Author: Fabian Wermelinger <fabianw@mavt.ethz.ch>
Date: Mon, 8 May 2017 12:11:17 -0700
added another shader option to schlieren rendering
use -blend to enable a blended shader variant, which smooths out extreme
values and attempts to "homogenize" colormap
Diffstat:
1 file changed, 28 insertions(+), 5 deletions(-)
diff --git a/apps/polaroidCamera/SchlierenCartridge.h b/apps/polaroidCamera/SchlierenCartridge.h
@@ -9,6 +9,7 @@
#include <cstdio>
#include <algorithm>
#include <cmath>
+#include <functional>
#include "Cartridge.h"
#include "GammaCorrection.h"
@@ -30,9 +31,10 @@ public:
virtual void capture(PhotoPaper& photo, Slice& data)
{
- const Real ka = m_parser("-ka").asDouble(1.0);
- const Real k0 = m_parser("-k0").asDouble(0.0);
- const Real k1 = m_parser("-k1").asDouble(1.0);
+ const Real ka0 = m_parser("-ka0").asDouble(1.0);
+ const Real ka1 = m_parser("-ka1").asDouble(1.0);
+ // const Real k0 = m_parser("-k0").asDouble(0.0);
+ // const Real k1 = m_parser("-k1").asDouble(1.0);
GammaCorrection gammaCorrect(m_parser);
photo.make_new(photo.get_name()+"-schlieren", data.width(), data.height());
@@ -49,13 +51,34 @@ public:
m_dataMax = data.max();
}
const Real dataMaxInv = 1.0/m_dataMax;
+ const Real dataMaxInv_log = 1.0/std::log(m_dataMax+1.0);
+
+ // const Real fac = -ka0/(k1 - k0);
+ // auto exp_shader = [&](const Real x) { return std::exp(fac*(x*dataMaxInv - k0)); };
+
+ auto exp_shader = [&](const Real x) { return std::exp(-ka0*x*dataMaxInv); };
+
+ auto exp_shader_log = [&](const Real x)
+ {
+ const Real psi = std::log(x+1.0) * dataMaxInv_log;
+ return std::exp(-ka1*psi);
+ };
+
+ auto blend_shaders = [&](const Real x)
+ {
+ const Real beta = (x-m_dataMin)/(m_dataMax-m_dataMin);
+ return beta*exp_shader(x) + (1.0-beta)*exp_shader_log(x);
+ };
+
+ std::function<Real(const Real)> _shader = exp_shader;
+ if (m_parser("-blend").asBool(false))
+ _shader = blend_shaders;
// apply shader
- const Real fac = -ka/(k1 - k0);
for (int h=0; h < data.height(); ++h)
for (int w=0; w < data.width(); ++w)
{
- const Real phi = std::exp(fac*(data(w,h)*dataMaxInv - k0));
+ const Real phi = _shader(data(w,h));
photo.set_pixel(gammaCorrect(phi), w, h);
}