polaroid-pp

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

commit 10ce0204e2097222efdc05494597794ecaa8abdd
parent 54af8a8b5624b7aed043162e01a923a6951cbbf5
Author: Fabian Wermelinger <fabianw@mavt.ethz.ch>
Date:   Fri,  1 Jul 2016 10:13:41 +0200

slice ID for reading is now specified by sf or si, direction as x, y or z

Diffstat:
Mapps/polaroidCamera/LineExtractor.h | 4++--
Mapps/polaroidCamera/SceneProcessor.cpp | 9++-------
Minclude/Polaroid.h | 5+++--
Minclude/Types.h | 7++++---
Msrc/Polaroid.cpp | 50+++++++++++++++++++++++++++++++-------------------
5 files changed, 42 insertions(+), 33 deletions(-)

diff --git a/apps/polaroidCamera/LineExtractor.h b/apps/polaroidCamera/LineExtractor.h @@ -41,7 +41,7 @@ public: const int fixed = (wf >= 0) ? static_cast<int>(width*wf) : wi; assert(fixed < width); std::ostringstream buf; - buf << "-line_sliceID=" << data.get_sliceID() << "_sliceDir=" << data.get_sliceDir(); + buf << "-line_sliceDir=" << data.get_sliceDir() << "_sliceID=" << data.get_sliceID(); buf << "_sliceWidthID=" << fixed; photo.make_new(basename+buf.str()+photo.suffix(), height); @@ -55,7 +55,7 @@ public: const int fixed = (hf >= 0) ? static_cast<int>(height*hf) : hi; assert(fixed < height); std::ostringstream buf; - buf << "-line_sliceID=" << data.get_sliceID() << "_sliceDir=" << data.get_sliceDir(); + buf << "-line_sliceDir=" << data.get_sliceDir() << "_sliceID=" << data.get_sliceID(); buf << "_sliceHeightID=" << fixed; photo.make_new(basename+buf.str()+photo.suffix(), width); diff --git a/apps/polaroidCamera/SceneProcessor.cpp b/apps/polaroidCamera/SceneProcessor.cpp @@ -56,17 +56,12 @@ void SceneProcessor::_prepare_cam() void SceneProcessor::_load_cam(Polaroid& cam, const char* const fname) const { - const double fraction = m_parser("-fraction").asDouble(0.5); - const int direction = m_parser("-direction").asInt(0); - const int channel = m_parser("-channel").asInt(0); - const bool byte_swap = m_parser("-swap").asBool(false); - const int wavelet_type = m_parser("-wtype").asInt(1); const string input_type = m_parser("-input").asString("hdf5"); if (input_type == "hdf5") - cam.load_hdf5(fname, fraction, direction, channel); + cam.load_hdf5(fname, m_parser); else if (input_type == "wavelet") - cam.load_wavelet(fname, fraction, direction, channel, byte_swap, wavelet_type); + cam.load_wavelet(fname, m_parser); else { if (m_mpi.isroot()) diff --git a/include/Polaroid.h b/include/Polaroid.h @@ -8,6 +8,7 @@ #include "Types.h" #include "Cartridge.h" +#include "ArgumentParser.h" class PhotoPaper; @@ -35,8 +36,8 @@ public: } // scene loader - void load_hdf5(const char* filename, const double fraction, const int dir, const int channel=0); - void load_wavelet(const char* filename, const double fraction, const int dir, const int channel=0, const bool doswapping=false, const int wtype=1); + void load_hdf5(const char* filename, ArgumentParser& parser); + void load_wavelet(const char* filename, ArgumentParser& parser); // capture scene inline void capture(PhotoPaper& photo) diff --git a/include/Types.h b/include/Types.h @@ -17,7 +17,8 @@ class Slice2D Real* m_data; int m_max3Ddim; - int m_sliceID, m_sliceDir; + int m_sliceID; + char m_sliceDir; public: Slice2D() : m_width(0), m_height(0), m_N(0), m_data(nullptr) {} @@ -76,8 +77,8 @@ public: inline int get_max3Ddim() const { return m_max3Ddim; } inline void set_sliceID(const int d) { m_sliceID = d; } inline int get_sliceID() const { return m_sliceID; } - inline void set_sliceDir(const int d) { m_sliceDir = d; } - inline int get_sliceDir() const { return m_sliceDir; } + inline void set_sliceDir(const char d) { m_sliceDir = d; } + inline char get_sliceDir() const { return m_sliceDir; } }; typedef Slice2D<0,0,0,0> Slice; diff --git a/src/Polaroid.cpp b/src/Polaroid.cpp @@ -21,9 +21,14 @@ using namespace std; #define ID3(ix, iy, iz, NX, NY) ((ix) + (NX) * ((iy) + (NY) * (iz))) -void Polaroid::load_hdf5(const char* filename, const double fraction, const int dir, const int channel) +void Polaroid::load_hdf5(const char* filename, ArgumentParser& parser) { #ifdef _USE_HDF_ + const double sf = parser("-sf").asDouble(0.5); // slice fraction (default) + const int si = parser("-si").asInt(-1); // slice index (need to specify) + const char direction = parser("-sd").asString("x")[0]; // slice normal direction + const int channel = parser("-channel").asInt(0); // data channel + /* open data */ hid_t file_id, dataset_id, dataspace_id, file_dataspace_id; hsize_t* dims; @@ -58,28 +63,28 @@ void Polaroid::load_hdf5(const char* filename, const double fraction, const int status = H5Fclose(file_id); /* extract plane */ - m_data.set_sliceDir(dir); - if (0 == dir) // y-z plane + m_data.set_sliceDir(direction); + if ('x' == direction) // y-z plane { - const int fixed = static_cast<int>(maxDim[0]*fraction); + const int fixed = (si >= 0) ? si : static_cast<int>(maxDim[0]*sf); m_data.set_sliceID(fixed); m_data.resize(maxDim[1], maxDim[2]); for (int h=0; h < m_data.height(); ++h) for (int w=0; w < m_data.width(); ++w) m_data(w,h) = data[channel + NCH * ID3(fixed,w,h,maxDim[0], maxDim[1])]; } - else if (1 == dir) // x-z plane + else if ('y' == direction) // x-z plane { - const int fixed = static_cast<int>(maxDim[1]*fraction); + const int fixed = (si >= 0) ? si : static_cast<int>(maxDim[1]*sf); m_data.set_sliceID(fixed); m_data.resize(maxDim[0], maxDim[2]); for (int h=0; h < m_data.height(); ++h) for (int w=0; w < m_data.width(); ++w) m_data(w,h) = data[channel + NCH * ID3(w,fixed,h,maxDim[0], maxDim[1])]; } - else if (2 == dir) // x-y plane + else if ('z' == direction) // x-y plane { - const int fixed = static_cast<int>(maxDim[2]*fraction); + const int fixed = (si >= 0) ? si : static_cast<int>(maxDim[2]*sf); m_data.set_sliceID(fixed); m_data.resize(maxDim[0], maxDim[1]); for (int h=0; h < m_data.height(); ++h) @@ -88,7 +93,7 @@ void Polaroid::load_hdf5(const char* filename, const double fraction, const int } else { - fprintf(stderr, "ERROR: Direction '%d' unsupported.", dir); + fprintf(stderr, "ERROR: Direction '%c' unsupported.", direction); abort(); } @@ -100,11 +105,18 @@ void Polaroid::load_hdf5(const char* filename, const double fraction, const int #endif /* _USE_HDF_ */ } -void Polaroid::load_wavelet(const char* filename, const double fraction, const int dir, const int channel, const bool doswapping, const int wtype) +void Polaroid::load_wavelet(const char* filename, ArgumentParser& parser) { #ifdef _USE_CUBISMZ_ + const double sf = parser("-sf").asDouble(0.5); // slice fraction (default) + const int si = parser("-si").asInt(-1); // slice index (need to specify) + const char direction = parser("-sd").asString("x")[0]; // slice normal direction + const int channel = parser("-channel").asInt(0); // data channel + const bool byte_swap = parser("-swap").asBool(false); + const int wavelet_type = parser("-wtype").asInt(1); + const string fname(filename); - Reader_WaveletCompression myreader(fname, doswapping, wtype); + Reader_WaveletCompression myreader(fname, byte_swap, wavelet_type); myreader.load_file(); const int NBX = myreader.xblocks(); const int NBY = myreader.yblocks(); @@ -116,10 +128,10 @@ void Polaroid::load_wavelet(const char* filename, const double fraction, const i Real blockdata[_BLOCKSIZE_][_BLOCKSIZE_][_BLOCKSIZE_]; /* extract plane */ - m_data.set_sliceDir(dir); - if (0 == dir) // y-z plane + m_data.set_sliceDir(direction); + if ('x' == direction) // y-z plane { - const int fixed = static_cast<int>(maxDim[0]*fraction); + const int fixed = (si >= 0) ? si : static_cast<int>(maxDim[0]*sf); m_data.set_sliceID(fixed); m_data.resize(maxDim[1], maxDim[2]); @@ -138,9 +150,9 @@ void Polaroid::load_wavelet(const char* filename, const double fraction, const i } } } - else if (1 == dir) // x-z plane + else if ('y' == direction) // x-z plane { - const int fixed = static_cast<int>(maxDim[1]*fraction); + const int fixed = (si >= 0) ? si : static_cast<int>(maxDim[1]*sf); m_data.set_sliceID(fixed); m_data.resize(maxDim[0], maxDim[2]); @@ -159,9 +171,9 @@ void Polaroid::load_wavelet(const char* filename, const double fraction, const i } } } - else if (2 == dir) // x-y plane + else if ('z' == direction) // x-y plane { - const int fixed = static_cast<int>(maxDim[2]*fraction); + const int fixed = (si >= 0) ? si : static_cast<int>(maxDim[2]*sf); m_data.set_sliceID(fixed); m_data.resize(maxDim[0], maxDim[1]); @@ -182,7 +194,7 @@ void Polaroid::load_wavelet(const char* filename, const double fraction, const i } else { - fprintf(stderr, "ERROR: Direction '%d' unsupported.", dir); + fprintf(stderr, "ERROR: Direction '%c' unsupported.", direction); abort(); }