12#ifndef DUMUX_RASTER_IMAGE_WRITER_HH 
   13#define DUMUX_RASTER_IMAGE_WRITER_HH 
   25#include <dune/common/exceptions.hh> 
   45    template<
class ValueType>
 
   46    static void write(
const std::string& writeFileName,
 
   47                      Result<ValueType>& img,
 
   48                      const bool useDuneGridOrdering = 
true)
 
   51        writeRasterImageFile_(writeFileName, img, useDuneGridOrdering);
 
 
   54    template<
class ValueType>
 
   55    static void write(
const std::string& writeFileName,
 
   56                      const std::size_t& nCols,
 
   57                      const std::size_t& nRows,
 
   58                      const std::string& magicNumber,
 
   59                      const std::string& type,
 
   60                      const std::string& encoding,
 
   61                      const std::vector<ValueType>& img,
 
   62                      const bool useDuneGridOrdering = 
true)
 
   65        HeaderData headerData;
 
   66        headerData.
nCols = nCols;
 
   67        headerData.
nRows = nRows;
 
   69        Result<ValueType> result(std::move(img), std::move(headerData));
 
   71        writeRasterImageFile_(writeFileName, result, useDuneGridOrdering);
 
 
   85        for (std::size_t i = 0; i < result.size(); i += result.
header().nCols)
 
   86            std::swap_ranges((result.begin() + i), (result.begin() + i + result.
header().
nCols), (tmp.end() - i - result.
header().
nCols));
 
 
   92    static void writeRasterImageFile_(
const std::string& writeFileName,
 
   94                                      const bool useDuneGridOrdering = 
true)
 
   97        if (useDuneGridOrdering)
 
  101        std::ofstream outfile(writeFileName, std::ios::trunc);
 
  102        outfile << result.header().format.magicNumber << 
"\n";
 
  103        outfile << result.header().nCols << 
" " << result.header().nRows << 
"\n";
 
  104        if ((result.header().format.magicNumber == 
"P2") || (result.header().format.magicNumber == 
"P5"))
 
  106            for (
int i = 0; i < result.size(); i++)
 
  107                outfile << result[i] << 
"\n";
 
  111            for (
int i = 0; i < result.size(); i++)
 
  113                if (i % result.header().nCols == 0) 
 
  115                outfile << result[i];
 
 
The return type of the reading functions. Holds the actual pixel values and the header data.
Definition rasterimagedata.hh:48
const HeaderData & header() const
Returns the header data.
Definition rasterimagedata.hh:70
A simple reader class for the Netpbm format (https://en.wikipedia.org/wiki/Netpbm_format)....
Definition rasterimagewriter.hh:37
static void applyDuneGridOrdering(Result< T > &result)
Change the ordering of the pixels according to Dune's convention, shifting the origin from upper left...
Definition rasterimagewriter.hh:82
static void write(const std::string &writeFileName, const std::size_t &nCols, const std::size_t &nRows, const std::string &magicNumber, const std::string &type, const std::string &encoding, const std::vector< ValueType > &img, const bool useDuneGridOrdering=true)
Definition rasterimagewriter.hh:55
static void write(const std::string &writeFileName, Result< ValueType > &img, const bool useDuneGridOrdering=true)
Definition rasterimagewriter.hh:46
A data class for raster image information.
Helpers for working with strings.