10#include <QRegularExpression>
15#include "SpecialPixel.h"
16#include "IException.h"
28 p_lis = Isis::LOW_INSTR_SAT8;
29 p_lrs = Isis::LOW_REPR_SAT8;
30 p_his = Isis::HIGH_INSTR_SAT8;
31 p_hrs = Isis::HIGH_REPR_SAT8;
52 string msg =
"Input pairs must be in ascending order";
53 throw IException(IException::Programmer, msg, _FILEINFO_);
72 if(!Isis::IsValidPixel(value)) {
73 if(Isis::IsNullPixel(value))
return p_null;
74 if(Isis::IsHisPixel(value))
return p_his;
75 if(Isis::IsHrsPixel(value))
return p_hrs;
76 if(Isis::IsLisPixel(value))
return p_lis;
81 if(
p_input.size() == 0)
return value;
113 while(start != end) {
114 int middle = (start + end) / 2;
116 if(middle == start) {
119 else if(value <
p_input[middle]) {
147 std::pair<double, double> io;
151 pairs = pairs.simplified().trimmed();
153 if (pairs.contains(
":")) {
156 QString firstPair = pairList.takeFirst();
158 QStringList firstPairValues = firstPair.split(
":");
160 if (firstPairValues.count() == 2) {
161 io.first = toDouble(firstPairValues.first());
162 io.second = toDouble(firstPairValues.last());
164 pairs = pairList.join(
" ");
188 std::pair<double, double> pear;
190 QString p = pairs.simplified().trimmed();
191 p.replace(QRegularExpression(
"[\\s]*:"),
":");
192 p.replace(QRegularExpression(
":[\\s]*"),
":");
193 QStringList pairList = p.split(
" ", Qt::SkipEmptyParts);
196 foreach(QString singlePair, pairList) {
201 catch(IException &e) {
202 throw IException(e, IException::User,
"Invalid stretch pairs [" + pairs +
"]", _FILEINFO_);
226 std::pair<double, double> pear;
230 std::vector<double> converted;
233 while(p.size() > 0) {
235 pear.first = hist->
Percent(pear.first);
240 bool collision =
false;
242 while(!collision && k < converted.size()) {
243 if(pear.first == converted[k]) {
252 converted.push_back(pear.first);
257 catch(IException &e) {
258 throw IException(e, IException::User,
"Invalid stretch pairs [" +
259 pairs +
"]", _FILEINFO_);
274 for(
int i = 0; i <
p_pairs; i++) {
289 if(index >=
p_pairs || index < 0) {
304 if(index >=
p_pairs || index < 0) {
344 PvlGroup grp = pvl.findGroup(grpName, Isis::PvlObject::Traverse);
345 PvlKeyword inputs = grp.findKeyword(
"Input");
346 PvlKeyword outputs = grp.findKeyword(
"Output");
348 if(inputs.size() != outputs.size()) {
349 QString msg =
"Invalid Pvl file: The number of Input values must equal the number of Output values";
350 throw IException(IException::User, msg, _FILEINFO_);
352 for(
int i = 0; i < inputs.size(); i++) {
353 AddPair(toDouble(inputs[i]), toDouble(outputs[i]));
368 void Stretch::Save(QString &file, QString &grpName) {
374 void Stretch::Save(Isis::Pvl &pvl, QString &grpName) {
375 PvlGroup *grp =
new PvlGroup(grpName);
376 PvlKeyword inputs(
"Input");
377 PvlKeyword outputs(
"Output");
378 for(
int i = 0; i <
Pairs(); i++) {
382 grp->addKeyword(inputs);
383 grp->addKeyword(outputs);
Container of a cube histogram.
double Percent(const double percent) const
Computes and returns the value at X percent of the histogram.
void CopyPairs(const Stretch &other)
Copies the stretch pairs from another Stretch object, but maintains special pixel values.
void Parse(const QString &pairs)
Parses a string of the form "i1:o1 i2:o2...iN:oN" where each i:o represents an input:output pair.
void AddPair(const double input, const double output)
Adds a stretch pair to the list of pairs.
int p_pairs
Number of stretch pairs.
double p_null
Mapping of input NULL values go to this value (default NULL)
Stretch()
Constructs a Stretch object with default mapping of special pixel values to themselves.
std::pair< double, double > NextPair(QString &pairs)
Given a string containing stretch pairs for example "0:0 50:0 100:255 255:255" evaluate the first pai...
std::vector< double > p_output
Array for output side of stretch pairs.
double p_lrs
Mapping of input LRS values go to this value (default LRS)
double Output(const int index) const
Returns the value of the output side of the stretch pair at the specified index.
double p_minimum
By default this value is set to p_lrs.
double Input(const int index) const
Returns the value of the input side of the stretch pair at the specified index.
double p_maximum
By default this value is set to p_hrs.
std::vector< double > p_input
Array for input side of stretch pairs.
double p_hrs
Mapping of input HRS values go to this value (default HRS)
double p_his
Mapping of input HIS values go to this value (default HIS)
double Map(const double value) const
Maps an input value to an output value based on the stretch pairs and/or special pixel mappings.
int Pairs() const
Returns the number of stretch pairs.
void Load(Pvl &pvl, QString &grpName)
Loads the stretch pairs from the pvl file into the Stretch object.
double p_lis
Mapping of input LIS values go to this value (default LIS)
QString Text() const
Converts stretch pair to a string.
This is free and unencumbered software released into the public domain.
QString toString(const LinearAlgebra::Vector &vector, int precision)
A global function to format LinearAlgebra::Vector as a QString with the given precision.
Namespace for the standard library.