polaroid-pp

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

commit 1e05f88eea700b279b9152a5883e1f6168cbc89d
parent f9c99a0849b47897509b3cfe723476a55282148d
Author: Fabian Wermelinger <fabianw@mavt.ethz.ch>
Date:   Mon, 11 Jul 2016 00:14:19 +0200

implemented vector magnitude

Diffstat:
Msrc/Polaroid.cpp | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 55 insertions(+), 10 deletions(-)

diff --git a/src/Polaroid.cpp b/src/Polaroid.cpp @@ -3,6 +3,7 @@ // Author : Fabian Wermelinger // Description: Polaroid Implementation // Copyright 2016 ETH Zurich. All Rights Reserved. +#include <cassert> #include <cmath> #include <algorithm> #include <string> @@ -28,6 +29,7 @@ void Polaroid::load_hdf5(const char* filename, ArgumentParser& parser) 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 magnitude = parser("-magnitude").asBool(false); // vector magnitude (only if NCH == 3) /* open data */ hid_t file_id, dataset_id, dataspace_id, file_dataspace_id; @@ -62,6 +64,8 @@ void Polaroid::load_hdf5(const char* filename, ArgumentParser& parser) status = H5Sclose(file_dataspace_id); status = H5Fclose(file_id); + assert(channel < NCH); + /* extract plane */ m_data.set_sliceDir(direction); if ('x' == direction) // y-z plane @@ -69,27 +73,69 @@ void Polaroid::load_hdf5(const char* filename, ArgumentParser& parser) 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])]; + if (magnitude && NCH == 3) + { + for (int h=0; h < m_data.height(); ++h) + for (int w=0; w < m_data.width(); ++w) + { + const Real a = data[0 + NCH * ID3(fixed,w,h,maxDim[0], maxDim[1])]; + const Real b = data[1 + NCH * ID3(fixed,w,h,maxDim[0], maxDim[1])]; + const Real c = data[2 + NCH * ID3(fixed,w,h,maxDim[0], maxDim[1])]; + m_data(w,h) = std::sqrt(a*a + b*b + c*c); + } + } + else + { + 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 ('y' == direction) // x-z plane { 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])]; + if (magnitude && NCH == 3) + { + for (int h=0; h < m_data.height(); ++h) + for (int w=0; w < m_data.width(); ++w) + { + const Real a = data[0 + NCH * ID3(w,fixed,h,maxDim[0], maxDim[1])]; + const Real b = data[1 + NCH * ID3(w,fixed,h,maxDim[0], maxDim[1])]; + const Real c = data[2 + NCH * ID3(w,fixed,h,maxDim[0], maxDim[1])]; + m_data(w,h) = std::sqrt(a*a + b*b + c*c); + } + } + else + { + 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 ('z' == direction) // x-y plane { 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) - for (int w=0; w < m_data.width(); ++w) - m_data(w,h) = data[channel + NCH * ID3(w,h,fixed,maxDim[0], maxDim[1])]; + if (magnitude && NCH == 3) + { + for (int h=0; h < m_data.height(); ++h) + for (int w=0; w < m_data.width(); ++w) + { + const Real a = data[0 + NCH * ID3(w,h,fixed,maxDim[0], maxDim[1])]; + const Real b = data[1 + NCH * ID3(w,h,fixed,maxDim[0], maxDim[1])]; + const Real c = data[2 + NCH * ID3(w,h,fixed,maxDim[0], maxDim[1])]; + m_data(w,h) = std::sqrt(a*a + b*b + c*c); + } + } + else + { + 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,h,fixed,maxDim[0], maxDim[1])]; + } } else { @@ -111,7 +157,6 @@ void Polaroid::load_wavelet(const char* filename, ArgumentParser& parser) 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);