polaroid-pp

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

LineExtractor.h (2518B)


      1 // File       : LineExtractor.h
      2 // Date       : Thu 30 Jun 2016 02:12:10 PM CEST
      3 // Author     : Fabian Wermelinger
      4 // Description: Straight Line extraction tool
      5 // Copyright 2016 ETH Zurich. All Rights Reserved.
      6 #ifndef LINEEXTRACTOR_H_R2VFDR8H
      7 #define LINEEXTRACTOR_H_R2VFDR8H
      8 
      9 #include <string>
     10 #include <sstream>
     11 #include <cassert>
     12 #include <algorithm>
     13 #include <iostream>
     14 #include "Cartridge.h"
     15 
     16 class LineExtractor: public Cartridge
     17 {
     18 public:
     19     LineExtractor(ArgumentParser& parser) : Cartridge(parser) {}
     20 
     21     virtual void capture(PhotoPaper& photo, Slice& data)
     22     {
     23         assert(photo.suffix() == std::string(".dat"));
     24 
     25         const int width = data.width();
     26         const int height = data.height();
     27 
     28         const Real wf = m_parser("-wf").asDouble(-1.0);
     29         const int wi  = m_parser("-wi").asInt(-1);
     30         const Real hf = m_parser("-hf").asDouble(-1.0);
     31         const int hi  = m_parser("-hi").asInt(-1);
     32 
     33         // set description
     34         string desc("1D_Line");
     35         photo.set_description(desc.c_str());
     36 
     37         const std::string basename(photo.get_name());
     38 
     39         if ((wf >= 0 && wi < 0) || (wi >= 0 && wf < 0))
     40         {
     41             const int fixed = (wf >= 0) ? static_cast<int>(width*wf) : wi;
     42             assert(fixed < width);
     43             std::ostringstream buf;
     44             buf << "-line_sliceDir=" << data.get_sliceDir() << "_sliceID=" << data.get_sliceID();
     45             buf << "_sliceWidthID=" << fixed;
     46             photo.make_new(basename+buf.str()+photo.suffix(), height);
     47 
     48             // extract line
     49             for (int h=0; h < height; ++h)
     50                 photo.set_pixel(data(fixed,h), h);
     51             photo.write();
     52         }
     53         if ((hf >= 0 && hi < 0) || (hi >= 0 && hf < 0))
     54         {
     55             const int fixed = (hf >= 0) ? static_cast<int>(height*hf) : hi;
     56             assert(fixed < height);
     57             std::ostringstream buf;
     58             buf << "-line_sliceDir=" << data.get_sliceDir() << "_sliceID=" << data.get_sliceID();
     59             buf << "_sliceHeightID=" << fixed;
     60             photo.make_new(basename+buf.str()+photo.suffix(), width);
     61 
     62             // extract line
     63             for (int w=0; w < width; ++w)
     64                 photo.set_pixel(data(w,fixed), w);
     65             photo.write();
     66         }
     67         if ((wf < 0 && wi < 0) && (hi < 0 && hf < 0))
     68             std::cerr << "No seed point specified for line extraction... Skipping this one" << std:: endl;
     69     }
     70 
     71     virtual void compute(Slice& data) {}
     72 };
     73 
     74 #endif /* LINEEXTRACTOR_H_R2VFDR8H */