polaroid-pp

Schlieren and contour plot tool
git clone https://git.0xfab.ch/polaroid-pp.git
Log | Files | Refs | Submodules | README | LICENSE

BoundedLogNormalizerCartridge.h (1686B)


      1 // File       : BoundedLogNormalizerCartridge.h
      2 // Date       : Fri 29 Apr 2016 09:39:39 AM CEST
      3 // Author     : Fabian Wermelinger
      4 // Description: Bounded Log Data Normalizer Cartridge
      5 // Copyright 2016 ETH Zurich. All Rights Reserved.
      6 #ifndef BOUNDEDLOGNORMALIZERCARTRIDGE_H_QF9H4ZPF
      7 #define BOUNDEDLOGNORMALIZERCARTRIDGE_H_QF9H4ZPF
      8 
      9 #include <cassert>
     10 #include <algorithm>
     11 #include <cmath>
     12 #include "BoundedNormalizerCartridge.h"
     13 
     14 class BoundedLogNormalizerCartridge : public BoundedNormalizerCartridge
     15 {
     16 public:
     17     BoundedLogNormalizerCartridge(ArgumentParser& parser) : BoundedNormalizerCartridge(parser) {}
     18 
     19     virtual void capture(PhotoPaper& photo, Slice& data)
     20     {
     21         const Real upper = m_parser("-upper_bound").asDouble(10.0);
     22         const Real lower = m_parser("-lower_bound").asDouble(1.0);
     23 
     24         photo.make_new(photo.get_name()+"-boundedLogNormalizer", data.width(), data.height());
     25 
     26         // set description
     27         string desc("2D_Bounded_Log_Normalized");
     28         photo.set_description(desc.c_str());
     29 
     30         // compute min/max for shader
     31         const Real dataMinInv = 1.0/lower;
     32         const Real fac = 1.0/log(upper*dataMinInv);
     33         assert(!isnan(dataMinInv));
     34         assert(!isnan(fac));
     35 
     36         // pixel shader
     37         for (int h=0; h < data.height(); ++h)
     38             for (int w=0; w < data.width(); ++w)
     39             {
     40                 const Real bound = std::max(static_cast<Real>(0.0), std::min(static_cast<Real>(1.0), log(data(w,h)*dataMinInv)*fac));
     41                 assert(!isnan(bound));
     42                 photo.set_pixel(bound, w, h);
     43             }
     44 
     45         photo.write();
     46     }
     47 };
     48 
     49 #endif /* BOUNDEDLOGNORMALIZERCARTRIDGE_H_QF9H4ZPF */