polaroid-pp

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

LogNormalizerCartridge.h (1502B)


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