26 Reduce::Reduce(
Isis::Cube *pInCube,
const double sampleScale,
const double lineScale)
37 miEndLine = mInCube->lineCount();
39 miInputSamples= mInCube->sampleCount();
40 miInputLines = mInCube->lineCount();
41 miInputBands = mInCube->bandCount();
44 mdSampleScale = sampleScale;
45 mdLineScale = lineScale;
48 miOutputSamples = (int)((
double)miInputSamples / mdSampleScale + 0.5);
49 miOutputLines = (int)((
double)miInputLines / mdLineScale + 0.5);
52 m_iPortal =
new Isis::Portal(miInputSamples, 1, mInCube->pixelType());
81 void Reduce::setInputBoundary(
int startSample,
int endSample,
int startLine,
int endLine){
82 miStartSample = startSample;
83 miEndSample = endSample;
84 miInputSamples = endSample - startSample + 1;
86 miStartLine = startLine;
88 miInputLines = endLine - startLine + 1;
92 miOutputSamples = (int)((
double)miInputSamples / mdSampleScale + 0.5);
93 miOutputLines = (int)((
double)miInputLines / mdLineScale + 0.5);
126 subArea.
SetSubArea(mInCube->lineCount(), mInCube->sampleCount(), miStartLine, miStartSample,
127 miEndLine, miEndSample, mdLineScale, mdSampleScale);
128 subArea.
UpdateLabel(mInCube, pOutCube, resultsGrp);
141 int readLine = (int)(mdLine + 0.5);
143 m_iPortal->SetPosition(miStartSample, readLine, miBandIndex);
144 mInCube->read(*m_iPortal);
147 for(
int os = 0; os < miOutputSamples; os++) {
148 out[os] = (*m_iPortal)[(int)((
double) os * mdSampleScale)];
151 if(out.
Line() == miOutputLines) {
156 mdLine += mdLineScale;
168 double rline = (double)out.
Line() * mdLineScale;
170 if(out.
Line() == 1 && out.
Band() == 1) {
171 mdIncTab =
new double[miOutputSamples];
172 mdSum =
new double[miOutputSamples];
173 mdNpts =
new double[miOutputSamples];
174 mdSum2 =
new double[miOutputSamples];
175 mdNpts2 =
new double[miOutputSamples];
178 for(
int osamp = 0; osamp < miOutputSamples; osamp++) {
179 mdIncTab[osamp] = ((double)osamp + 1.) * mdSampleScale;
183 mdNpts2[osamp] = 0.0;
185 mdIncTab[miOutputSamples-1] = miInputSamples;
188 while(mdLine <= rline) {
189 if((
int)mdLine <= miInputLines) {
190 m_iPortal->SetPosition(miStartSample, mdLine, miBandIndex);
191 mInCube->read(*m_iPortal);
194 for(
int osamp = 0; osamp < out.
size(); osamp++) {
195 while((
double)isamp <= mdIncTab[osamp]) {
198 mdSum[osamp] += (*m_iPortal)[isamp-1];
199 mdNpts[osamp] += 1.0;
204 double sdel = (double) isamp - mdIncTab[osamp];
205 if(isamp > miInputSamples)
continue;
208 mdSum[osamp] += (*m_iPortal)[isamp-1] * (1.0 - sdel);
209 mdNpts[osamp] += (1.0 - sdel);
210 if(osamp + 1 < miOutputSamples) {
211 mdSum[osamp+1] += (*m_iPortal)[isamp-1] * sdel;
212 mdNpts[osamp+1] += sdel;
220 if(mdLine <= miInputLines) {
221 m_iPortal->SetPosition(miStartSample, mdLine, miBandIndex);
222 mInCube->read(*m_iPortal);
224 double ldel = (double)mdLine - rline;
225 double ldel2 = 1.0 - ldel;
227 for(
int osamp = 0; osamp < miOutputSamples; osamp++) {
228 while(isamp <= mdIncTab[osamp]) {
230 mdSum[osamp] += (*m_iPortal)[isamp-1] * ldel2;
231 mdNpts[osamp] += ldel2;
232 mdSum2[osamp] += (*m_iPortal)[isamp-1] * ldel;
233 mdNpts2[osamp] += ldel;
238 double sdel = (double) isamp - mdIncTab[osamp];
239 if(isamp > miInputSamples)
continue;
241 mdSum[osamp] += (*m_iPortal)[isamp-1] * (1.0 - sdel) * ldel2;
242 mdNpts[osamp] += (1.0 - sdel) * ldel2;
243 if(osamp + 1 < miOutputSamples) {
244 mdSum[osamp+1] += (*m_iPortal)[isamp-1] * sdel * ldel2;
245 mdNpts[osamp+1] += sdel * ldel2;
247 mdSum2[osamp] += (*m_iPortal)[isamp-1] * (1.0 - sdel) * ldel;
248 mdNpts2[osamp] += (1.0 - sdel) * ldel;
249 if(osamp + 1 < miOutputSamples) {
250 mdSum2[osamp+1] += (*m_iPortal)[isamp-1] * sdel * ldel;
251 mdNpts2[osamp+1] += sdel * ldel;
257 if(mdLine < miInputLines) mdLine++;
259 double npix = mdSampleScale * mdLineScale;
260 for(
int osamp = 0; osamp < miOutputSamples; osamp++) {
261 if(mdNpts[osamp] > npix * mdValidPer) {
262 out[osamp] = mdSum[osamp] / mdNpts[osamp];
265 if(msReplaceMode ==
"NEAREST") {
266 out[osamp] = (*m_iPortal)[(int)(mdIncTab[osamp] + 0.5) - 1];
272 mdSum[osamp] = mdSum2[osamp];
273 mdNpts[osamp] = mdNpts2[osamp];
275 mdNpts2[osamp] = 0.0;
278 if(out.
Line() == miOutputLines && out.
Band() != miInputBands) {
281 for(
int osamp = 0; osamp < miOutputSamples; osamp++) {
285 mdNpts2[osamp] = 0.0;
289 if(out.
Line() == miOutputLines && out.
Band() == miInputBands) {
Buffer for reading and writing cube data.
const double Null
Value for an Isis Null pixel.
int Band(const int index=0) const
Returns the band position associated with a shape buffer index.
Buffer for containing a two dimensional section of an image.
Namespace for the standard library.
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
bool IsValidPixel(const double d)
Returns if the input pixel is valid.
int size() const
Returns the total number of pixels in the shape buffer.
void SetSubArea(const int orignl, const int origns, const int sl, const int ss, const int el, const int es, const double linc, const double sinc)
Defines the subarea.
Contains multiple PvlContainers.
A single keyword-value pair.
int Line(const int index=0) const
Returns the line position associated with a shape buffer index.
Apply corrections to a cube label for subarea extraction.
void UpdateLabel(Cube *icube, Cube *ocube, PvlGroup &results)
Modifies a label for a file containing a subarea.
Namespace for ISIS/Bullet specific routines.
IO Handler for Isis Cubes.