43 p_lis = Isis::LOW_INSTR_SAT8;
44 p_lrs = Isis::LOW_REPR_SAT8;
45 p_his = Isis::HIGH_INSTR_SAT8;
46 p_hrs = Isis::HIGH_REPR_SAT8;
63 void Stretch::AddPair(
const double input,
const double output) {
65 if(input <= p_input[p_pairs-1]) {
66 string msg =
"Input pairs must be in ascending order";
71 p_input.push_back(input);
72 p_output.push_back(output);
84 double Stretch::Map(
const double value)
const {
95 if(p_input.size() == 0)
return value;
98 if(value < p_input[0]) {
109 if(value > p_input[p_pairs-1]) {
121 if(value == p_input[0])
return p_output[0];
122 if(value == p_input[p_pairs-1])
return p_output[p_pairs-1];
126 int end = p_pairs - 1;
127 while(start != end) {
128 int middle = (start + end) / 2;
130 if(middle == start) {
133 else if(value < p_input[middle]) {
144 double slope = (p_output[end] - p_output[start]) / (p_input[end] - p_input[start]);
145 return slope * (value - p_input[end]) + p_output[end];
160 std::pair<double, double> Stretch::NextPair(QString &pairs) {
161 std::pair<double, double> io;
165 pairs = pairs.simplified().trimmed();
167 if (pairs.contains(
":")) {
170 QString firstPair = pairList.takeFirst();
172 QStringList firstPairValues = firstPair.split(
":");
174 if (firstPairValues.count() == 2) {
175 io.first =
toDouble(firstPairValues.first());
176 io.second =
toDouble(firstPairValues.last());
178 pairs = pairList.join(
" ");
196 void Stretch::Parse(
const QString &pairs) {
202 std::pair<double, double> pear;
204 QString p = pairs.simplified().trimmed();
205 p.replace(QRegExp(
"[\\s]*:"),
":");
206 p.replace(QRegExp(
":[\\s]*"),
":");
207 QStringList pairList = p.split(
" ", QString::SkipEmptyParts);
210 foreach(QString singlePair, pairList) {
211 pear = Stretch::NextPair(singlePair);
212 Stretch::AddPair(pear.first, pear.second);
240 std::pair<double, double> pear;
244 std::vector<double> converted;
247 while(p.size() > 0) {
248 pear = Stretch::NextPair(p);
249 pear.first = hist->
Percent(pear.first);
254 bool collision =
false;
256 while(!collision && k < converted.size()) {
257 if(pear.first == converted[k]) {
265 Stretch::AddPair(pear.first, pear.second);
266 converted.push_back(pear.first);
272 throw IException(e, IException::User,
"Invalid stretch pairs [" +
283 QString Stretch::Text()
const {
285 if(p_pairs < 0)
return "";
288 for(
int i = 0; i < p_pairs; i++) {
302 double Stretch::Input(
int index)
const {
303 if(index >= p_pairs || index < 0) {
306 return p_input[index];
317 double Stretch::Output(
int index)
const {
318 if(index >= p_pairs || index < 0) {
321 return p_output[index];
338 void Stretch::Load(QString &file, QString &grpName) {
362 if(inputs.
size() != outputs.
size()) {
363 QString msg =
"Invalid Pvl file: The number of Input values must equal the number of Output values";
366 for(
int i = 0; i < inputs.
size(); i++) {
382 void Stretch::Save(QString &file, QString &grpName) {
388 void Stretch::Save(
Isis::Pvl &pvl, QString &grpName) {
392 for(
int i = 0; i < Pairs(); i++) {
393 inputs.addValue(
toString(Input(i)));
394 outputs.addValue(
toString(Output(i)));
407 void Stretch::CopyPairs(
const Stretch &other) {
bool IsLisPixel(const double d)
Returns if the input pixel is low instrument saturation.
const double Null
Value for an Isis Null pixel.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
Namespace for the standard library.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
bool IsValidPixel(const double d)
Returns if the input pixel is valid.
double toDouble(const QString &string)
Global function to convert from a string to a double.
bool IsHisPixel(const double d)
Returns if the input pixel is high instrument saturation.
bool IsHrsPixel(const double d)
Returns if the input pixel is high representation saturation.
int size() const
Returns the number of values stored in this keyword.
int p_pairs
Number of stretch pairs.
Container of a cube histogram.
Contains multiple PvlContainers.
#define _FILEINFO_
Macro for the filename and line number.
A single keyword-value pair.
double Percent(const double percent) const
Computes and returns the value at X percent of the histogram.
Container for cube-like labels.
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
std::vector< double > p_input
Array for input side of stretch pairs.
Namespace for ISIS/Bullet specific routines.
bool IsNullPixel(const double d)
Returns if the input pixel is null.
void write(const QString &file)
Opens and writes PVL information to a file and handles the end of line sequence.
std::vector< double > p_output
Array for output side of stretch pairs.