// Gather general statistics on a particular band of a cube Isis::Statistics GatherStatistics(Cube &icube, const int band, double sampPercent, std::string maxCubeStr) { // Create our progress message iString curCubeStr (g_imageIndex+1); std::string statMsg = ""; if (icube.Bands() == 1) { statMsg = "Calculating Statistics for Band 1 in Cube " + curCubeStr + " of " + maxCubeStr; } else { iString curBandStr (band); iString maxBandStr (icube.Bands()); statMsg = "Calculating Statistics for Band " + curBandStr + " of " + maxBandStr + " in Cube " + curCubeStr + " of " + maxCubeStr; } int linc = (int) (100.0 / sampPercent + 0.5); // Calculate our line incrementer // Make sure band is valid if ((band <= 0) || (band > icube.Bands())) { string msg = "Invalid band in method [GatherStatistics]"; throw Isis::iException::Message(Isis::iException::Programmer,msg,_FILEINFO_); } // Construct a line buffer manager and a statistics object Isis::LineManager line (icube); Isis::Progress progress; progress.SetText(statMsg); // Calculate the number of steps for the Progress object, and add an extra // step if the total lines and incrementer do not divide evenly int maxSteps = icube.Lines() / linc; if (icube.Lines() % linc != 0) maxSteps += 1; progress.SetMaximumSteps(maxSteps); progress.CheckStatus(); // Add data to Statistics object by line Isis::Statistics stats; int i=1; while (i<=icube.Lines()) { line.SetLine(i,band); icube.Read(line); stats.AddData (line.DoubleBuffer(), line.size()); // Make sure we consider the last line if (i+linc > icube.Lines() && i != icube.Lines()) { i = icube.Lines(); progress.AddSteps(1); } else i += linc; // Increment the current line by our incrementer progress.CheckStatus(); } return stats; }
/** * This method invokes the process on a line by line basis * * @param funct (Isis::Buffer &in, Isis::Buffer &out, Isis::QuickFilter &filter) * Name of your processing function * * @throws Isis::IException::Programmer */ void ProcessByQuickFilter::StartProcess(void funct(Isis::Buffer &in, Isis::Buffer &out, Isis::QuickFilter &filter)) { // Error checks ... there must be one input and output if(InputCubes.size() != 1) { string m = "StartProcess only supports exactly one input file"; throw IException(IException::Programmer, m, _FILEINFO_); } if(OutputCubes.size() != 1) { string m = "StartProcess only supports exactly one output file"; throw IException(IException::Programmer, m, _FILEINFO_); } // The lines in the input and output must match if(InputCubes[0]->lineCount() != OutputCubes[0]->lineCount()) { string m = "The lines in the input and output cube must match"; throw IException(IException::Programmer, m, _FILEINFO_); } // The samples in the input and output must match if(InputCubes[0]->sampleCount() != OutputCubes[0]->sampleCount()) { string m = "The samples in the input and output cube must match"; throw IException(IException::Programmer, m, _FILEINFO_); } // The bands in the input and output must match if(InputCubes[0]->bandCount() != OutputCubes[0]->bandCount()) { string m = "The bands in the input and output cube must match"; throw IException(IException::Programmer, m, _FILEINFO_); } // Construct line buffer managers Isis::LineManager *topline = new Isis::LineManager(*InputCubes[0]); Isis::LineManager *iline = new Isis::LineManager(*InputCubes[0]); Isis::LineManager *botline = new Isis::LineManager(*InputCubes[0]); Isis::LineManager *oline = new Isis::LineManager(*OutputCubes[0]); int lines = InputCubes[0]->lineCount(); int samples = InputCubes[0]->sampleCount(); int bands = InputCubes[0]->bandCount(); // See if we need to get parameters from the user if(p_getParametersFromUser) GetFilterParameters(); // Make sure the boxcar widht and height aren't too big for the image if(lines * 2 - 1 < p_boxcarLines) { string msg = "Boxcar height is too big for cube size"; throw IException(IException::User, msg, _FILEINFO_); } if(samples * 2 - 1 < p_boxcarSamples) { string msg = "Boxcar width is too big for cube size"; throw IException(IException::User, msg, _FILEINFO_); } InputCubes[0]->addCachingAlgorithm(new FilterCachingAlgorithm(3)); // Create the filter object Isis::QuickFilter filter(samples, p_boxcarSamples, p_boxcarLines); filter.SetMinMax(p_low, p_high); filter.SetMinimumPixels(p_minimum); // Loop for each band p_progress->SetMaximumSteps(lines * bands); p_progress->CheckStatus(); for(int band = 1; band <= bands; band++) { // Preload the filter filter.Reset(); int top = 1 - filter.HalfHeight(); int bot; for(bot = top; bot <= (1 + filter.HalfHeight()); bot++) { int iline = bot; if(bot <= 0) iline = (-1 * bot + 2); botline->SetLine(iline, band); InputCubes[0]->read(*botline); filter.AddLine(botline->DoubleBuffer()); } bot = 1 + filter.HalfHeight() + 1; // Loop for each line for(int line = 1; line <= lines; line++) { // Process a line iline->SetLine(line, band); oline->SetLine(line, band); InputCubes[0]->read(*iline); funct(*iline, *oline, filter); OutputCubes[0]->write(*oline); // Remove the top line if(top >= 1) { topline->SetLine(top, band); } else { topline->SetLine(-1 * top + 2, band); } InputCubes[0]->read(*topline); filter.RemoveLine(topline->DoubleBuffer()); top++; // Add the next line p_progress->CheckStatus(); if(line == lines) continue; if(bot <= InputCubes[0]->lineCount()) { botline->SetLine(bot, band); } else { botline->SetLine(lines - (bot - lines), band); } InputCubes[0]->read(*botline); filter.AddLine(botline->DoubleBuffer()); bot++; // Update the progress } } // Free buffers before returning delete topline; delete iline; delete botline; delete oline; }