43 QuickFilter::QuickFilter(
const int ns,
const int width,
47 string msg =
"Invalid value for [ns] in QuickFilter constructor";
52 string m =
"[Width] must be must be greater than or equal to one in ";
53 m +=
"QuickFilter constructor";
56 else if((width % 2) == 0) {
57 string m =
"[Width] must be must be odd in ";
58 m +=
"QuickFilter constructor";
63 string m =
"[Height] must be must be greater than or equal to one in ";
64 m +=
"QuickFilter constructor";
67 else if((height % 2) == 0) {
68 string m =
"[Height] must be must be odd in ";
69 m +=
"QuickFilter constructor";
74 p_sums =
new double[ns];
75 p_sumsqrs =
new double[ns];
76 p_counts =
new int[ns];
86 p_halfWidth = width / 2;
89 p_halfHeight = height / 2;
95 void QuickFilter::Reset() {
97 for(
int i = 0; i < p_ns; i++) {
113 QuickFilter::~QuickFilter() {
134 void QuickFilter::SetMinMax(
const double minimum,
const double maximum) {
135 if(minimum >= maximum) {
136 string m =
"Minimum must be less than maximum in [QuickFilter::SetMinMax]";
155 void QuickFilter::SetMinimumPixels(
const int pixels) {
157 string m =
"Pixels must be greater than or equal to zero in ";
158 m +=
"[QuickFilter::SetMinimumPixels]";
161 p_minimumPixels = pixels;
162 if(p_minimumPixels > p_width * p_height) {
163 p_minimumPixels = p_width * p_height;
178 void QuickFilter::AddLine(
const double *buf) {
181 if(p_linesAdded > p_height) {
182 string m =
"Number of lines added exceeds boxcar height ... ";
183 m +=
"use RemoveLine before AddLine";
187 for(
int i = 0; i < p_ns; i++) {
189 if(buf[i] < p_minimum)
continue;
190 if(buf[i] > p_maximum)
continue;
192 p_sumsqrs[i] += buf[i] * buf[i];
204 void QuickFilter::RemoveLine(
const double *buf) {
205 for(
int i = 0; i < p_ns; i++) {
207 if(buf[i] < p_minimum)
continue;
208 if(buf[i] > p_maximum)
continue;
210 p_sumsqrs[i] -= buf[i] * buf[i];
229 double QuickFilter::Average(
const int index) {
234 if(p_lastCount < p_minimumPixels)
return Isis::NULL8;
235 if(p_lastCount <= 0)
return Isis::NULL8;
238 return p_lastSum / (double) p_lastCount;
252 double QuickFilter::Variance(
const int index) {
257 if(p_lastCount < p_minimumPixels)
return Isis::NULL8;
258 if(p_lastCount <= 1)
return Isis::NULL8;
261 double temp = p_lastCount * p_lastSumsqr - p_lastSum * p_lastSum;
262 if(temp < 0.0) temp = 0.0;
263 return temp / ((double)(p_lastCount - 1) * (double) p_lastCount);
276 int QuickFilter::Count(
const int index) {
289 int QuickFilter::Width()
const {
299 int QuickFilter::HalfWidth()
const {
308 int QuickFilter::Height()
const {
318 int QuickFilter::HalfHeight()
const {
327 int QuickFilter::Samples()
const {
336 double QuickFilter::Low()
const {
345 double QuickFilter::High()
const {
356 int QuickFilter::MinimumPixels()
const {
357 return p_minimumPixels;
368 void QuickFilter::Compute(
const int index) {
370 if(index == p_lastIndex)
return;
373 int start = index - p_halfWidth;
374 int stop = index + p_halfWidth;
377 if(index == p_lastIndex + 1) {
380 if(start < 0) start = -1 * start;
381 p_lastSum -= p_sums[start];
382 p_lastSumsqr -= p_sumsqrs[start];
383 p_lastCount -= p_counts[start];
386 if(stop >= p_ns) stop = p_ns - (stop - p_ns + 2);
387 p_lastSum += p_sums[stop];
388 p_lastSumsqr += p_sumsqrs[stop];
389 p_lastCount += p_counts[stop];
398 for(
int i = start; i <= stop; i++) {
404 j = p_ns - (i - p_ns + 2);
407 p_lastSum += p_sums[j];
408 p_lastSumsqr += p_sumsqrs[j];
409 p_lastCount += p_counts[j];
Namespace for the standard library.
bool IsValidPixel(const double d)
Returns if the input pixel is valid.
#define _FILEINFO_
Macro for the filename and line number.
Namespace for ISIS/Bullet specific routines.