Isis 3 Programmer Reference
VecFilter.cpp
Go to the documentation of this file.
1 
21 #include <float.h>
22 #include <string>
23 #include <vector>
24 #include "VecFilter.h"
25 #include "IException.h"
26 #include "IString.h"
27 
28 using namespace std;
29 const int MARKER = -999999;
30 namespace Isis {
32  VecFilter::VecFilter() {}
33 
35  VecFilter::~VecFilter() {};
36 
48  vector<double> VecFilter::LowPass(vector<double> invec, int boxsize) {
49  vector<double> outvec;
50 
51  // Clear the output vector
52  //outvec.resize(0);
53 
54  // Boxcar size must be odd and greater than 1
55  if((boxsize % 2) == 0) {
56  string m = "Boxcar size must be odd and greater than 1 in [VecFilter::LowPass]";
57  throw IException(IException::Programmer, m, _FILEINFO_);
58  }
59 
60  // Perform lowpass filter
61  int halfwidth = boxsize / 2;
62  int vecsize = (int)invec.size() - 1;
63  for(int i = 0; i <= vecsize; i++) {
64  int i1 = i - halfwidth;
65  if(i1 < 0) i1 = 0;
66  int i2 = i + halfwidth;
67  if(i2 > vecsize) i2 = vecsize;
68  int npts = 0;
69  double sum = 0.0;
70  for(int j = i1; j <= i2; j++) {
71  if(invec[j] != 0.0) {
72  sum = sum + invec[j];
73  npts++;
74  }
75  }
76  if(npts > 0) {
77  outvec.push_back(sum / npts);
78  }
79  else {
80  outvec.push_back(0.0);
81  }
82  }
83  return outvec;
84  }
85 
96  vector<double> VecFilter::HighPass(vector<double> invec1, vector<double> invec2) {
97  vector<double> outvec;
98 
99  // Both vectors must be the same size
100  if(invec1.size() != invec2.size()) {
101  string m = "Both vectors must be the same size in [VecFilter::HighPass]";
102  throw IException(IException::Programmer, m, _FILEINFO_);
103  }
104 
105  int vecsize = (int)invec1.size() - 1;
106  for(int i = 0; i <= vecsize; i++) {
107  if(invec1[i] != 0.0 && invec2[i] != 0.0) {
108  outvec.push_back(invec1[i] - invec2[i]);
109  }
110  else {
111  outvec.push_back(0.0);
112  }
113  }
114  return outvec;
115  }
116 
134  vector<double> VecFilter::HighPass(vector<double> pdInVector1, vector<double> pdInVector2,
135  vector<int> piValidPntsVector, int piMaxPoints, const QString & psMode)
136  {
137  vector<double> dOutVector;
138 
139  // Both vectors must be the same size
140  if(pdInVector1.size() != pdInVector2.size()) {
141  string m = "Both vectors must be the same size in [VecFilter::HighPass]";
142  throw IException(IException::Programmer, m, _FILEINFO_);
143  }
144 
145  int iSize = (int)pdInVector1.size();
146  for(int i = 0; i < iSize; i++) {
147  if(pdInVector1[i] != 0.0 && pdInVector2[i] != 0.0 && piValidPntsVector[i]==piMaxPoints) {
148  if(psMode == "SUBTRACT") {
149  dOutVector.push_back(pdInVector1[i] - pdInVector2[i]);
150  }
151  else {
152  dOutVector.push_back(pdInVector1[i] / pdInVector2[i]);
153  }
154  }
155  else {
156  dOutVector.push_back(MARKER);
157  }
158  }
159  return dOutVector;
160  }
161 
162 } // end namespace isis
Namespace for the standard library.
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31