Isis 3 Programmer Reference
ProcessByQuickFilter.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "ProcessByQuickFilter.h"
8
9#include "Application.h"
10#include "FilterCachingAlgorithm.h"
11#include "IException.h"
12#include "LineManager.h"
13#include "Preference.h"
14#include "QuickFilter.h"
15
16using namespace std;
17
18namespace Isis {
19
25
35 funct(Isis::Buffer &in, Isis::Buffer &out, Isis::QuickFilter &filter)) {
36 // Error checks ... there must be one input and output
37 if(InputCubes.size() != 1) {
38 string m = "StartProcess only supports exactly one input file";
39 throw IException(IException::Programmer, m, _FILEINFO_);
40 }
41
42 if(OutputCubes.size() != 1) {
43 string m = "StartProcess only supports exactly one output file";
44 throw IException(IException::Programmer, m, _FILEINFO_);
45 }
46
47 // The lines in the input and output must match
48 if(InputCubes[0]->lineCount() != OutputCubes[0]->lineCount()) {
49 string m = "The lines in the input and output cube must match";
50 throw IException(IException::Programmer, m, _FILEINFO_);
51 }
52
53 // The samples in the input and output must match
54 if(InputCubes[0]->sampleCount() != OutputCubes[0]->sampleCount()) {
55 string m = "The samples in the input and output cube must match";
56 throw IException(IException::Programmer, m, _FILEINFO_);
57 }
58
59 // The bands in the input and output must match
60 if(InputCubes[0]->bandCount() != OutputCubes[0]->bandCount()) {
61 string m = "The bands in the input and output cube must match";
62 throw IException(IException::Programmer, m, _FILEINFO_);
63 }
64
65 // Construct line buffer managers
70
71 int lines = InputCubes[0]->lineCount();
72 int samples = InputCubes[0]->sampleCount();
73 int bands = InputCubes[0]->bandCount();
74
75 // See if we need to get parameters from the user
77
78 // Make sure the boxcar widht and height aren't too big for the image
79 if(lines * 2 - 1 < p_boxcarLines) {
80 string msg = "Boxcar height is too big for cube size";
81 throw IException(IException::User, msg, _FILEINFO_);
82 }
83
84 if(samples * 2 - 1 < p_boxcarSamples) {
85 string msg = "Boxcar width is too big for cube size";
86 throw IException(IException::User, msg, _FILEINFO_);
87 }
88
89 InputCubes[0]->addCachingAlgorithm(new FilterCachingAlgorithm(3));
90
91 // Create the filter object
93 filter.SetMinMax(p_low, p_high);
95
96 // Loop for each band
97 p_progress->SetMaximumSteps(lines * bands);
99 for(int band = 1; band <= bands; band++) {
100 // Preload the filter
101 filter.Reset();
102 int top = 1 - filter.HalfHeight();
103 int bot;
104 for(bot = top; bot <= (1 + filter.HalfHeight()); bot++) {
105 int iline = bot;
106 if(bot <= 0) iline = (-1 * bot + 2);
107 botline->SetLine(iline, band);
108 InputCubes[0]->read(*botline);
109 filter.AddLine(botline->DoubleBuffer());
110 }
111 bot = 1 + filter.HalfHeight() + 1;
112
113 // Loop for each line
114 for(int line = 1; line <= lines; line++) {
115 // Process a line
116 iline->SetLine(line, band);
117 oline->SetLine(line, band);
118
119 InputCubes[0]->read(*iline);
120 funct(*iline, *oline, filter);
121 OutputCubes[0]->write(*oline);
122
123 // Remove the top line
124 if(top >= 1) {
125 topline->SetLine(top, band);
126 }
127 else {
128 topline->SetLine(-1 * top + 2, band);
129 }
130
131 InputCubes[0]->read(*topline);
132 filter.RemoveLine(topline->DoubleBuffer());
133 top++;
134
135 // Add the next line
137 if(line == lines) continue;
138
139 if(bot <= InputCubes[0]->lineCount()) {
140 botline->SetLine(bot, band);
141 }
142 else {
143 botline->SetLine(lines - (bot - lines), band);
144 }
145
146 InputCubes[0]->read(*botline);
147 filter.AddLine(botline->DoubleBuffer());
148 bot++;
149
150 // Update the progress
151 }
152 }
153
154 // Free buffers before returning
155 delete topline;
156 delete iline;
157 delete botline;
158 delete oline;
159 }
160
180 void ProcessByQuickFilter::SetFilterParameters(int samples, int lines,
181 double low, double high, int minimum) {
183 p_boxcarSamples = samples;
184 p_boxcarLines = lines;
185 p_low = low;
186 p_high = high;
187 p_minimum = minimum;
188 }
189
192 // Get boxcar size
193 p_boxcarSamples = Application::GetUserInterface().GetInteger("SAMPLES");
194 p_boxcarLines = Application::GetUserInterface().GetInteger("LINES");
195
196 // Get valid pixel range
197 p_low = -DBL_MAX;
198 p_high = DBL_MAX;
199 if(Application::GetUserInterface().WasEntered("LOW")) {
200 p_low = Application::GetUserInterface().GetDouble("LOW");
201 }
202
203 if(Application::GetUserInterface().WasEntered("HIGH")) {
204 p_high = Application::GetUserInterface().GetDouble("HIGH");
205 }
206
207 // Get valid pixel count
208 p_minimum = 0;
209 if(Application::GetUserInterface().WasEntered("MINIMUM")) {
210 p_minimum = Application::GetUserInterface().GetInteger("MINIMUM");
211 }
212 }
213} // end namespace isis
static UserInterface & GetUserInterface()
Returns the UserInterface object.
Buffer for reading and writing cube data.
Definition Buffer.h:53
This algorithm is designed for applications that use ProcessByQuickFilter or very similar I/O pattern...
Isis exception class.
Definition IException.h:91
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition IException.h:126
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
Buffer manager, for moving through a cube in lines.
Definition LineManager.h:39
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.
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.
int p_boxcarLines
Number of lines in the boxcar.
void GetFilterParameters()
This method allows the user to input the filter parameters.
int p_boxcarSamples
Number of samples in the boxcar.
bool p_getParametersFromUser
Flag to indicate whether or not to get parameters from the user.
double p_high
Maximum valid pixel value to include in statistical computations of the boxcar.
double p_low
Minimum valid pixel value to include in statistical computations of the boxcar.
ProcessByQuickFilter()
Constructs a FilterProcess object.
int p_minimum
Minimum number of valid pixels in the sample-by-line boxcar in order for statistical computations to ...
Base class for all cube processing derivatives.
Definition Process.h:143
std::vector< Isis::Cube * > InputCubes
A vector of pointers to opened Cube objects.
Definition Process.h:185
Isis::Progress * p_progress
Pointer to a Progress object.
Definition Process.h:145
std::vector< Isis::Cube * > OutputCubes
A vector of pointers to allocated Cube objects.
Definition Process.h:191
void SetMaximumSteps(const int steps)
This sets the maximum number of steps in the process.
Definition Progress.cpp:85
void CheckStatus()
Checks and updates the status.
Definition Progress.cpp:105
Container for boxcar statistics.
Definition QuickFilter.h:50
void AddLine(const double *buf)
Add an array of doubles to the accumulators and counters.
void SetMinMax(const double minimum, const double maximum)
This method is used to set the minimum/maximum valid values.
void SetMinimumPixels(const int minimumValid)
This method is used to set the minimum number of valid pixels in the boxcar.
int HalfHeight() const
Returns the half the height of the boxcar rounded down because the boxcar size is odd.
void RemoveLine(const double *buf)
Remove an array of doubles from the accumulators and counters.
void Reset()
Reset all accumulators and counters to zero.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
Namespace for the standard library.