Isis 3 Programmer Reference
ProcessByQuickFilter.cpp
Go to the documentation of this file.
1 
22 #include "ProcessByQuickFilter.h"
23 
24 #include "Application.h"
25 #include "FilterCachingAlgorithm.h"
26 #include "IException.h"
27 #include "LineManager.h"
28 #include "Preference.h"
29 #include "QuickFilter.h"
30 
31 using namespace std;
32 
33 namespace Isis {
34 
36  ProcessByQuickFilter::ProcessByQuickFilter() : Isis::Process() {
37  SetFilterParameters(0, 0);
39  }
40 
50  funct(Isis::Buffer &in, Isis::Buffer &out, Isis::QuickFilter &filter)) {
51  // Error checks ... there must be one input and output
52  if(InputCubes.size() != 1) {
53  string m = "StartProcess only supports exactly one input file";
55  }
56 
57  if(OutputCubes.size() != 1) {
58  string m = "StartProcess only supports exactly one output file";
60  }
61 
62  // The lines in the input and output must match
63  if(InputCubes[0]->lineCount() != OutputCubes[0]->lineCount()) {
64  string m = "The lines in the input and output cube must match";
66  }
67 
68  // The samples in the input and output must match
69  if(InputCubes[0]->sampleCount() != OutputCubes[0]->sampleCount()) {
70  string m = "The samples in the input and output cube must match";
72  }
73 
74  // The bands in the input and output must match
75  if(InputCubes[0]->bandCount() != OutputCubes[0]->bandCount()) {
76  string m = "The bands in the input and output cube must match";
78  }
79 
80  // Construct line buffer managers
85 
86  int lines = InputCubes[0]->lineCount();
87  int samples = InputCubes[0]->sampleCount();
88  int bands = InputCubes[0]->bandCount();
89 
90  // See if we need to get parameters from the user
92 
93  // Make sure the boxcar widht and height aren't too big for the image
94  if(lines * 2 - 1 < p_boxcarLines) {
95  string msg = "Boxcar height is too big for cube size";
97  }
98 
99  if(samples * 2 - 1 < p_boxcarSamples) {
100  string msg = "Boxcar width is too big for cube size";
102  }
103 
104  InputCubes[0]->addCachingAlgorithm(new FilterCachingAlgorithm(3));
105 
106  // Create the filter object
108  filter.SetMinMax(p_low, p_high);
109  filter.SetMinimumPixels(p_minimum);
110 
111  // Loop for each band
112  p_progress->SetMaximumSteps(lines * bands);
114  for(int band = 1; band <= bands; band++) {
115  // Preload the filter
116  filter.Reset();
117  int top = 1 - filter.HalfHeight();
118  int bot;
119  for(bot = top; bot <= (1 + filter.HalfHeight()); bot++) {
120  int iline = bot;
121  if(bot <= 0) iline = (-1 * bot + 2);
122  botline->SetLine(iline, band);
123  InputCubes[0]->read(*botline);
124  filter.AddLine(botline->DoubleBuffer());
125  }
126  bot = 1 + filter.HalfHeight() + 1;
127 
128  // Loop for each line
129  for(int line = 1; line <= lines; line++) {
130  // Process a line
131  iline->SetLine(line, band);
132  oline->SetLine(line, band);
133 
134  InputCubes[0]->read(*iline);
135  funct(*iline, *oline, filter);
136  OutputCubes[0]->write(*oline);
137 
138  // Remove the top line
139  if(top >= 1) {
140  topline->SetLine(top, band);
141  }
142  else {
143  topline->SetLine(-1 * top + 2, band);
144  }
145 
146  InputCubes[0]->read(*topline);
147  filter.RemoveLine(topline->DoubleBuffer());
148  top++;
149 
150  // Add the next line
152  if(line == lines) continue;
153 
154  if(bot <= InputCubes[0]->lineCount()) {
155  botline->SetLine(bot, band);
156  }
157  else {
158  botline->SetLine(lines - (bot - lines), band);
159  }
160 
161  InputCubes[0]->read(*botline);
162  filter.AddLine(botline->DoubleBuffer());
163  bot++;
164 
165  // Update the progress
166  }
167  }
168 
169  // Free buffers before returning
170  delete topline;
171  delete iline;
172  delete botline;
173  delete oline;
174  }
175 
195  void ProcessByQuickFilter::SetFilterParameters(int samples, int lines,
196  double low, double high, int minimum) {
197  p_getParametersFromUser = false;
198  p_boxcarSamples = samples;
199  p_boxcarLines = lines;
200  p_low = low;
201  p_high = high;
202  p_minimum = minimum;
203  }
204 
207  // Get boxcar size
210 
211  // Get valid pixel range
212  p_low = -DBL_MAX;
213  p_high = DBL_MAX;
214  if(Application::GetUserInterface().WasEntered("LOW")) {
216  }
217 
218  if(Application::GetUserInterface().WasEntered("HIGH")) {
220  }
221 
222  // Get valid pixel count
223  p_minimum = 0;
224  if(Application::GetUserInterface().WasEntered("MINIMUM")) {
226  }
227  }
228 } // end namespace isis
bool SetLine(const int line, const int band=1)
Positions the buffer at the requested line and returns a status indicator if the set was succesful or...
Definition: LineManager.cpp:60
Buffer for reading and writing cube data.
Definition: Buffer.h:69
double * DoubleBuffer() const
Returns the value of the shape buffer.
Definition: Buffer.h:154
void Reset()
Reset all accumulators and counters to zero.
Definition: QuickFilter.cpp:95
void SetFilterParameters(int samples, int lines, double low=-DBL_MAX, double high=DBL_MAX, int minimum=0)
This method allows the programmer to set the filter parameters.
void SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process.
Definition: Progress.cpp:101
static UserInterface & GetUserInterface()
Returns the UserInterface object.
This algorithm is designed for applications that use ProcessByQuickFilter or very similar I/O pattern...
int p_minimum
Minimum number of valid pixels in the sample-by-line boxcar in order for statistical computations to ...
std::vector< Isis::Cube * > OutputCubes
A vector of pointers to allocated Cube objects.
Definition: Process.h:206
Namespace for the standard library.
double p_high
Maximum valid pixel value to include in statistical computations of the boxcar.
void GetFilterParameters()
This method allows the user to input the filter parameters.
bool p_getParametersFromUser
Flag to indicate whether or not to get parameters from the user.
void SetMinimumPixels(const int minimumValid)
This method is used to set the minimum number of valid pixels in the boxcar.
This error is for when a programmer made an API call that was illegal.
Definition: IException.h:162
int p_boxcarSamples
Number of samples in the boxcar.
double p_low
Minimum valid pixel value to include in statistical computations of the boxcar.
int p_boxcarLines
Number of lines in the boxcar.
void CheckStatus()
Checks and updates the status.
Definition: Progress.cpp:121
Buffer manager, for moving through a cube in lines.
Definition: LineManager.h:55
int HalfHeight() const
Returns the half the height of the boxcar rounded down because the boxcar size is odd...
void SetMinMax(const double minimum, const double maximum)
This method is used to set the minimum/maximum valid values.
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:40
A type of error that could only have occurred due to a mistake on the user&#39;s part (e...
Definition: IException.h:142
double GetDouble(const QString &paramName) const
Allows the retrieval of a value for a parameter of type "double".
Definition: IsisAml.cpp:907
Container for boxcar statistics.
Definition: QuickFilter.h:66
void AddLine(const double *buf)
Add an array of doubles to the accumulators and counters.
int GetInteger(const QString &paramName) const
Allows the retrieval of a value for a parameter of type "integer".
Definition: IsisAml.cpp:823
void RemoveLine(const double *buf)
Remove an array of doubles from the accumulators and counters.
Isis::Progress * p_progress
Pointer to a Progress object.
Definition: Process.h:160
virtual void StartProcess(void funct(Isis::Buffer &in, Isis::Buffer &out, Isis::QuickFilter &filter))
This method invokes the process on a line by line basis.
Isis exception class.
Definition: IException.h:107
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
Base class for all cube processing derivatives.
Definition: Process.h:158
std::vector< Isis::Cube * > InputCubes
A vector of pointers to opened Cube objects.
Definition: Process.h:200