Isis 3 Programmer Reference
VecFilter.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 
8 #include <float.h>
9 #include <string>
10 #include <vector>
11 #include "VecFilter.h"
12 #include "IException.h"
13 #include "IString.h"
14 
15 using namespace std;
16 const int MARKER = -999999;
17 namespace Isis {
19  VecFilter::VecFilter() {}
20 
22  VecFilter::~VecFilter() {};
23 
35  vector<double> VecFilter::LowPass(vector<double> invec, int boxsize) {
36  vector<double> outvec;
37 
38  // Clear the output vector
39  //outvec.resize(0);
40 
41  // Boxcar size must be odd and greater than 1
42  if((boxsize % 2) == 0) {
43  string m = "Boxcar size must be odd and greater than 1 in [VecFilter::LowPass]";
44  throw IException(IException::Programmer, m, _FILEINFO_);
45  }
46 
47  // Perform lowpass filter
48  int halfwidth = boxsize / 2;
49  int vecsize = (int)invec.size() - 1;
50  for(int i = 0; i <= vecsize; i++) {
51  int i1 = i - halfwidth;
52  if(i1 < 0) i1 = 0;
53  int i2 = i + halfwidth;
54  if(i2 > vecsize) i2 = vecsize;
55  int npts = 0;
56  double sum = 0.0;
57  for(int j = i1; j <= i2; j++) {
58  if(invec[j] != 0.0) {
59  sum = sum + invec[j];
60  npts++;
61  }
62  }
63  if(npts > 0) {
64  outvec.push_back(sum / npts);
65  }
66  else {
67  outvec.push_back(0.0);
68  }
69  }
70  return outvec;
71  }
72 
83  vector<double> VecFilter::HighPass(vector<double> invec1, vector<double> invec2) {
84  vector<double> outvec;
85 
86  // Both vectors must be the same size
87  if(invec1.size() != invec2.size()) {
88  string m = "Both vectors must be the same size in [VecFilter::HighPass]";
89  throw IException(IException::Programmer, m, _FILEINFO_);
90  }
91 
92  int vecsize = (int)invec1.size() - 1;
93  for(int i = 0; i <= vecsize; i++) {
94  if(invec1[i] != 0.0 && invec2[i] != 0.0) {
95  outvec.push_back(invec1[i] - invec2[i]);
96  }
97  else {
98  outvec.push_back(0.0);
99  }
100  }
101  return outvec;
102  }
103 
121  vector<double> VecFilter::HighPass(vector<double> pdInVector1, vector<double> pdInVector2,
122  vector<int> piValidPntsVector, int piMaxPoints, const QString & psMode)
123  {
124  vector<double> dOutVector;
125 
126  // Both vectors must be the same size
127  if(pdInVector1.size() != pdInVector2.size()) {
128  string m = "Both vectors must be the same size in [VecFilter::HighPass]";
129  throw IException(IException::Programmer, m, _FILEINFO_);
130  }
131 
132  int iSize = (int)pdInVector1.size();
133  for(int i = 0; i < iSize; i++) {
134  if(pdInVector1[i] != 0.0 && pdInVector2[i] != 0.0 && piValidPntsVector[i]==piMaxPoints) {
135  if(psMode == "SUBTRACT") {
136  dOutVector.push_back(pdInVector1[i] - pdInVector2[i]);
137  }
138  else {
139  dOutVector.push_back(pdInVector1[i] / pdInVector2[i]);
140  }
141  }
142  else {
143  dOutVector.push_back(MARKER);
144  }
145  }
146  return dOutVector;
147  }
148 
149 } // end namespace isis
Isis::IException
Isis exception class.
Definition: IException.h:91
std
Namespace for the standard library.
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16