polaroid-pp

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

SceneProcessor.h (2395B)


      1 // File       : SceneProcessor.h
      2 // Date       : Thu 28 Apr 2016 05:08:33 PM CEST
      3 // Author     : Fabian Wermelinger
      4 // Description: Scene Processing
      5 // Copyright 2016 ETH Zurich. All Rights Reserved.
      6 #ifndef SCENEPROCESSOR_H_UWGYBVIW
      7 #define SCENEPROCESSOR_H_UWGYBVIW
      8 
      9 #include <vector>
     10 #include <string>
     11 #include <sstream>
     12 #include <set>
     13 
     14 #include "ArgumentParser.h"
     15 #include "OrganizerMPI.h"
     16 #include "Polaroid.h"
     17 #include "Cartridges.h"
     18 #include "PhotoFormats.h"
     19 
     20 class SceneProcessor
     21 {
     22 private:
     23     ArgumentParser& m_parser;
     24     OrganizerMPI& m_mpi;
     25     Cartridge* m_cartridge;
     26     PhotoPaper* m_photo;
     27 
     28     // helper
     29     void _prepare_cam();
     30     void _load_cam(Polaroid& cam, const char* const fname) const;
     31     inline void _dispose()
     32     {
     33         if (m_cartridge) delete m_cartridge;
     34         if (m_photo) delete m_photo;
     35         m_cartridge = nullptr;
     36         m_photo = nullptr;
     37     }
     38 
     39     std::vector<std::string> _splitpath(const std::string& str, const char delim='/')
     40     {
     41         std::vector<std::string> result;
     42         const std::set<char> delimiters{delim};
     43         std::string path("");
     44 
     45         char const* pch = str.c_str();
     46         char const* start = pch;
     47         int shift = 0;
     48         for(; *pch; ++pch)
     49         {
     50             if (delimiters.find(*pch) != delimiters.end())
     51             {
     52                 if (start != pch)
     53                 {
     54                     std::string subpath(start, pch);
     55                     path += subpath;
     56                     start = pch;
     57                     shift = 1;
     58                 }
     59             }
     60         }
     61         result.push_back(path);
     62         result.push_back(start+shift);
     63         return result;
     64     }
     65 
     66     std::string _outpath(const std::string& input, const char delim='/')
     67     {
     68         const std::vector<std::string> splitp = _splitpath(input, delim);
     69         std::ostringstream output;
     70         if (m_parser.exist("outpath"))
     71             output << m_parser("outpath").asString() << delim << splitp[1];
     72         else
     73             output << splitp[1];
     74         return output.str();
     75     }
     76 
     77 public:
     78     SceneProcessor(ArgumentParser& parser, OrganizerMPI& mpi) : m_parser(parser), m_mpi(mpi), m_cartridge(nullptr), m_photo(nullptr) {}
     79     ~SceneProcessor() { _dispose(); }
     80 
     81     void process1212(const std::vector<std::string>& scenes);
     82     void process1122(const std::vector<std::string>& scenes);
     83 };
     84 
     85 #endif /* SCENEPROCESSOR_H_UWGYBVIW */