polaroid-pp

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

PhotoASCII.cpp (1064B)


      1 // File       : PhotoASCII.cpp
      2 // Date       : Thu 30 Jun 2016 04:14:56 PM CEST
      3 // Author     : Fabian Wermelinger
      4 // Description: 1D ASCII paper Implementation
      5 // Copyright 2016 ETH Zurich. All Rights Reserved.
      6 #include <cassert>
      7 #include <fstream>
      8 #include "PhotoASCII.h"
      9 
     10 using namespace std;
     11 
     12 void PhotoASCII::make_new(const string name, const int N, const int dummy)
     13 {
     14     m_fname = name;
     15     m_data.clear();
     16     m_data.resize(N);
     17 }
     18 
     19 void PhotoASCII::resize(const int N, const int dummy)
     20 {
     21     m_data.clear();
     22     m_data.resize(N);
     23 }
     24 
     25 void PhotoASCII::write()
     26 {
     27     ofstream asciiout(m_fname.c_str());
     28     asciiout.setf(std::ios::scientific, std::ios::floatfield);
     29     asciiout.precision(12);
     30     if (!m_data.empty())
     31     {
     32         const Real h = 1.0/m_data.size();
     33         for (size_t i = 0; i < m_data.size(); ++i)
     34             asciiout << h*(i+0.5) << '\t' << m_data[i] << endl;
     35     }
     36     asciiout.close();
     37 }
     38 
     39 void PhotoASCII::set_pixel(const double phi, const int i, const int dummy)
     40 {
     41     assert(i < static_cast<int>(data.size()));
     42     m_data[i] = phi;
     43 }