9 #include "SpecialPixel.h"
32 Reduce::Reduce(
Isis::Cube *pInCube,
const double sampleScale,
const double lineScale)
43 miEndLine = mInCube->lineCount();
45 miInputSamples= mInCube->sampleCount();
46 miInputLines = mInCube->lineCount();
47 miInputBands = mInCube->bandCount();
50 mdSampleScale = sampleScale;
51 mdLineScale = lineScale;
54 miOutputSamples = (int)((
double)miInputSamples / mdSampleScale + 0.5);
55 miOutputLines = (int)((
double)miInputLines / mdLineScale + 0.5);
58 m_iPortal =
new Isis::Portal(miInputSamples, 1, mInCube->pixelType());
87 void Reduce::setInputBoundary(
int startSample,
int endSample,
int startLine,
int endLine){
88 miStartSample = startSample;
89 miEndSample = endSample;
90 miInputSamples = endSample - startSample + 1;
92 miStartLine = startLine;
94 miInputLines = endLine - startLine + 1;
98 miOutputSamples = (int)((
double)miInputSamples / mdSampleScale + 0.5);
99 miOutputLines = (int)((
double)miInputLines / mdLineScale + 0.5);
132 subArea.
SetSubArea(mInCube->lineCount(), mInCube->sampleCount(), miStartLine, miStartSample,
133 miEndLine, miEndSample, mdLineScale, mdSampleScale);
134 subArea.
UpdateLabel(mInCube, pOutCube, resultsGrp);
147 int readLine = (int)(mdLine + 0.5);
149 m_iPortal->SetPosition(miStartSample, readLine, miBandIndex);
150 mInCube->read(*m_iPortal);
153 for(
int os = 0; os < miOutputSamples; os++) {
154 out[os] = (*m_iPortal)[(int)((
double) os * mdSampleScale)];
157 if(out.
Line() == miOutputLines) {
162 mdLine += mdLineScale;
174 double rline = (double)out.
Line() * mdLineScale;
176 if(out.
Line() == 1 && out.
Band() == 1) {
177 mdIncTab =
new double[miOutputSamples];
178 mdSum =
new double[miOutputSamples];
179 mdNpts =
new double[miOutputSamples];
180 mdSum2 =
new double[miOutputSamples];
181 mdNpts2 =
new double[miOutputSamples];
184 for(
int osamp = 0; osamp < miOutputSamples; osamp++) {
185 mdIncTab[osamp] = ((double)osamp + 1.) * mdSampleScale;
189 mdNpts2[osamp] = 0.0;
191 mdIncTab[miOutputSamples-1] = miInputSamples;
194 while(mdLine <= rline) {
195 if((
int)mdLine <= miInputLines) {
196 m_iPortal->SetPosition(miStartSample, mdLine, miBandIndex);
197 mInCube->read(*m_iPortal);
200 for(
int osamp = 0; osamp < out.
size(); osamp++) {
201 while((
double)isamp <= mdIncTab[osamp]) {
204 mdSum[osamp] += (*m_iPortal)[isamp-1];
205 mdNpts[osamp] += 1.0;
210 double sdel = (double) isamp - mdIncTab[osamp];
211 if(isamp > miInputSamples)
continue;
214 mdSum[osamp] += (*m_iPortal)[isamp-1] * (1.0 - sdel);
215 mdNpts[osamp] += (1.0 - sdel);
216 if(osamp + 1 < miOutputSamples) {
217 mdSum[osamp+1] += (*m_iPortal)[isamp-1] * sdel;
218 mdNpts[osamp+1] += sdel;
226 if(mdLine <= miInputLines) {
227 m_iPortal->SetPosition(miStartSample, mdLine, miBandIndex);
228 mInCube->read(*m_iPortal);
230 double ldel = (double)mdLine - rline;
231 double ldel2 = 1.0 - ldel;
233 for(
int osamp = 0; osamp < miOutputSamples; osamp++) {
234 while(isamp <= mdIncTab[osamp]) {
236 mdSum[osamp] += (*m_iPortal)[isamp-1] * ldel2;
237 mdNpts[osamp] += ldel2;
238 mdSum2[osamp] += (*m_iPortal)[isamp-1] * ldel;
239 mdNpts2[osamp] += ldel;
244 double sdel = (double) isamp - mdIncTab[osamp];
245 if(isamp > miInputSamples)
continue;
247 mdSum[osamp] += (*m_iPortal)[isamp-1] * (1.0 - sdel) * ldel2;
248 mdNpts[osamp] += (1.0 - sdel) * ldel2;
249 if(osamp + 1 < miOutputSamples) {
250 mdSum[osamp+1] += (*m_iPortal)[isamp-1] * sdel * ldel2;
251 mdNpts[osamp+1] += sdel * ldel2;
253 mdSum2[osamp] += (*m_iPortal)[isamp-1] * (1.0 - sdel) * ldel;
254 mdNpts2[osamp] += (1.0 - sdel) * ldel;
255 if(osamp + 1 < miOutputSamples) {
256 mdSum2[osamp+1] += (*m_iPortal)[isamp-1] * sdel * ldel;
257 mdNpts2[osamp+1] += sdel * ldel;
263 if(mdLine < miInputLines) mdLine++;
265 double npix = mdSampleScale * mdLineScale;
266 for(
int osamp = 0; osamp < miOutputSamples; osamp++) {
267 if(mdNpts[osamp] > npix * mdValidPer) {
268 out[osamp] = mdSum[osamp] / mdNpts[osamp];
271 if(msReplaceMode ==
"NEAREST") {
272 out[osamp] = (*m_iPortal)[(int)(mdIncTab[osamp] + 0.5) - 1];
278 mdSum[osamp] = mdSum2[osamp];
279 mdNpts[osamp] = mdNpts2[osamp];
281 mdNpts2[osamp] = 0.0;
284 if(out.
Line() == miOutputLines && out.
Band() != miInputBands) {
287 for(
int osamp = 0; osamp < miOutputSamples; osamp++) {
291 mdNpts2[osamp] = 0.0;
295 if(out.
Line() == miOutputLines && out.
Band() == miInputBands) {