SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma once
  2. #include <regex>
  3. #include <string>
  4. #include <experimental/filesystem>
  5.  
  6.  
  7. class Sequencer
  8. {
  9. public:
  10.  
  11.     //////////////////////
  12.     // CTors / DTor
  13.     Sequencer(std::string const first_frame_in): first_frame_name(first_frame_in)
  14.     {
  15.         bool result = std::regex_search(first_frame_name, first_frame_regex_results, match_pattern);
  16.         prefix = first_frame_regex_results[1];
  17.         std::string frame = first_frame_regex_results[2];
  18.         ext = first_frame_regex_results[3];
  19.         first_frame = std::stoi(frame);
  20.         digit_padding = frame.length();
  21.         current_frame = first_frame;
  22.         out_prefix = "_signature";
  23.         file_delim = ".";
  24.  
  25.         get_last_frame();
  26.     }
  27.  
  28.     ~Sequencer() {}
  29.  
  30.     Sequencer(Sequencer const&) = delete;
  31.     void operator=(Sequencer const&) = delete;
  32.  
  33.  
  34.     bool get_next_frame(std::string &next_frame, std::string &name_out)
  35.     {
  36.         if (current_frame <= last_frame)
  37.         {
  38.             tmp_num = add_padding(current_frame);
  39.             next_frame = prefix + file_delim + tmp_num + file_delim + ext;
  40.             name_out = prefix + out_prefix + file_delim + tmp_num + file_delim + "ppm";
  41.             current_frame++;
  42.             return true;
  43.         }
  44.         else
  45.         {
  46.             name_out = "";
  47.             next_frame = "";
  48.             return false;
  49.         }
  50.     }
  51.  
  52.  
  53. private:
  54.  
  55.     void get_last_frame()
  56.     {
  57.         bool test = true;
  58.         std::string tmpname;
  59.         unsigned int i = current_frame + 1;
  60.         do
  61.         {
  62.             tmpname = "C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.0\3_Imaging\MovieHasher\data\" + prefix + file_delim + add_padding(i) + file_delim + ext;
  63.             test = std::experimental::filesystem::exists(tmpname);
  64.             if (test)
  65.                 i++;
  66.             else
  67.                 i--;
  68.         } while (test);
  69.         last_frame = i;
  70.     }
  71.  
  72.     std::string add_padding(int frame_num_in)
  73.     {
  74.         std::string outval = std::to_string(frame_num_in);
  75.  
  76.         int length = outval.length();
  77.         while (length < digit_padding)
  78.         {
  79.             outval = "0" + outval;
  80.             length = outval.length();
  81.         }
  82.  
  83.         return outval;
  84.     }
  85.  
  86.     std::string first_frame_name;
  87.     std::regex match_pattern = std::regex("([a-zA-Z]*).([0-9]*).(\w{3})");
  88.     std::smatch first_frame_regex_results;
  89.     std::string prefix, ext, out_prefix, tmp_num, file_delim;
  90.     int first_frame;
  91.     int last_frame;
  92.     int digit_padding;
  93.     int current_frame;
  94.  
  95. };
  96.      
  97. ////////////////////////
  98. // INCLUDES
  99.  
  100. //// System
  101. #include <iostream>
  102. #include <string>
  103.  
  104. //// User Defined
  105. #include "../../Sequencer.h"
  106.  
  107. int main(int argc, char **argv)
  108. {
  109.     std::string image_filename = "prefix.00000.ext";
  110.     std::string out_filename = "prefix_signature.00000.ppm";
  111.     Sequencer sequencer(image_filename);
  112.  
  113.     bool tmp = true;
  114.     do
  115.     {
  116.         tmp = sequencer.get_next_frame(image_filename, out_filename);
  117.         if (tmp)
  118.             std::cout << image_filename << ", " << out_filename << std::endl;
  119.     } while (tmp);
  120.  
  121.     return 0;
  122. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top