polaroid-pp

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

commit 940363b7dfde730726f9215383afb3cb7c1114ca
parent 15508d726bbd6dddddf4b313f4bd9c5a86621d14
Author: Fabian Wermelinger <fabianw@mavt.ethz.ch>
Date:   Thu, 30 Jun 2016 15:54:27 +0200

added 1D line data extractor

Diffstat:
Aapps/polaroidCamera/LineExtractor.h | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+), 0 deletions(-)

diff --git a/apps/polaroidCamera/LineExtractor.h b/apps/polaroidCamera/LineExtractor.h @@ -0,0 +1,72 @@ +// File : LineExtractor.h +// Date : Thu 30 Jun 2016 02:12:10 PM CEST +// Author : Fabian Wermelinger +// Description: Straight Line extraction tool +// Copyright 2016 ETH Zurich. All Rights Reserved. +#ifndef LINEEXTRACTOR_H_R2VFDR8H +#define LINEEXTRACTOR_H_R2VFDR8H + +#include <string> +#include <sstream> +#include <cassert> +#include <algorithm> +#include <iostream> +#include "Cartridge.h" + +class LineExtractor: public Cartridge +{ +public: + LineExtractor(ArgumentParser& parser) : Cartridge(parser) {} + + virtual void capture(PhotoPaper& photo, Slice& data) + { + assert(photo.suffix() == std::string(".dat")); + + const int width = data.width(); + const int height = data.height(); + + const Real wf = m_parser("-wf").asDouble(-1.0); + const int wi = m_parser("-wi").asInt(-1); + const Real hf = m_parser("-hf").asDouble(-1.0); + const int hi = m_parser("-hi").asInt(-1); + + // set description + string desc("1D_Line"); + photo.set_description(desc.c_str()); + + if ((wf >= 0 && wi < 0) || (wi >= 0 && wf < 0)) + { + 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 << "_sliceWidthID=" << fixed; + photo.make_new(photo.get_name()+buf.str(), height); + + // extract line + for (int h=0; h < height; ++h) + photo.set_pixel(data(fixed,h), h); + photo.write(); + } + else if ((hf >= 0 && hi < 0) || (hi >= 0 && hf < 0)) + { + 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 << "_sliceHeightID=" << fixed; + photo.make_new(photo.get_name()+buf.str(), width); + + // extract line + for (int w=0; w < width; ++w) + photo.set_pixel(data(w,fixed), w); + photo.write(); + } + else + std::cerr << "No seed point specified for line extraction... Skipping this one" << std:: endl; + } + + virtual void compute(Slice& data) {} +}; + +#endif /* LINEEXTRACTOR_H_R2VFDR8H */