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) {