polaroid-pp

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

BoundedNormalizerCartridge.h (1427B)


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