Commit 9124365a authored by Jesse Mapel's avatar Jesse Mapel
Browse files

PROG: Added statistics output to camtest. Fixes #2413

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@7241 41f8697f-d340-4b68-9986-7bafba869bb8
parent 6f89c5a7
Loading
Loading
Loading
Loading
+119 −18
Original line number Diff line number Diff line
@@ -2,14 +2,14 @@
#include "ProcessByLine.h"
#include "Camera.h"
#include "SpecialPixel.h"
#include "Pvl.h"

using namespace std;
using namespace Isis;

// Globals and prototypes
Camera *cam;

void doIt(Buffer &in, Buffer &out);
//void doIt(Buffer &in, Buffer &out);

enum OutputType {
  Lat,
@@ -17,40 +17,140 @@ enum OutputType {
  Err,
  Samp,
  Line
} OutputFormat;
};

class CamTestFunctor {
public:
  CamTestFunctor() {};
  ~CamTestFunctor() {};  
  void setCamera(Camera* cam);
  void setOutType(OutputType outType);
  void setResults(Statistics* results);
  void operator()(Buffer &in, Buffer &out) const;
  
private:
  Camera* m_cam;
  OutputType m_outType;
  Statistics* m_resultsStats;
};

void IsisMain() {
  UserInterface &ui = Application::GetUserInterface();

  ProcessByLine p;
  ProcessByBrick p;

  // Open the input cube
  Cube *icube = p.SetInputCube("FROM");
  cam = icube->camera();
  Cube *iCube = p.SetInputCube("FROM");
  Camera *cam = iCube->camera();
  p.SetOutputCube("TO");
  
  // Set to process by line
  p.SetBrickSize(iCube->sampleCount(), 1, 1);
  
  IString format = ui.GetString("FORMAT");

  OutputType outFormat = Lat;
  if (format == "LAT") {
    OutputFormat = Lat;
    outFormat = Lat;
  }
  else if (format == "LON") {
    OutputFormat = Lon;
    outFormat = Lon;
  }
  else if (format == "ERR") {
    OutputFormat = Err;
    outFormat = Err;
  }
  else if (format == "SAMP") {
    OutputFormat = Samp;
    outFormat = Samp;
  }
  else if (format == "LINE") {
    OutputFormat = Line;
    outFormat = Line;
  }

  // Create process functor
  CamTestFunctor func;
  func.setCamera(cam);
  func.setOutType(outFormat);
  Statistics resultsStats;
  func.setResults(&resultsStats);
  
  p.ProcessCube(func, false);
  
  // Collect results
  PvlGroup results = PvlGroup("CamTestResults");
  results += PvlKeyword("FailedConversionsToLatLong", toString(resultsStats.LrsPixels()));
  results += PvlKeyword("FailedConversionsToSampleLine", toString(resultsStats.HrsPixels()));
  results += PvlKeyword("SuccessfulConversions", toString(resultsStats.ValidPixels()));
  if (outFormat == Err) {
    results += PvlKeyword("Average", toString(resultsStats.Average()));
    results += PvlKeyword("StandardDeviation", toString(resultsStats.StandardDeviation()));
    results += PvlKeyword("Minimum", toString(resultsStats.Minimum()));
    results += PvlKeyword("Maximum", toString(resultsStats.Maximum()));
  }
  
  p.StartProcess(doIt);
  // Log output results
  Application::Log(results);
  
  p.EndProcess();
}

// Functor Definitions
  
void CamTestFunctor::setCamera(Camera* cam) {
  m_cam = cam;
}

void CamTestFunctor::setOutType(OutputType outType) {
  m_outType = outType;
}

void CamTestFunctor::setResults(Statistics* resultsStats) {
  m_resultsStats = resultsStats;
}

void CamTestFunctor::operator()(Buffer &in, Buffer &out) const {
  if (in.Line() == 1) {
    m_cam->SetBand(in.Band());
  }

  double line = in.Line();
  for (int samp = 0; samp < in.SampleDimension(); samp++) {
    double sample = in.Sample(samp);
    if (!m_cam->SetImage(sample, line)) {
      out[samp] = Lrs;
      continue;
    }

    if (m_outType == Lat) {
      out[samp] = m_cam->UniversalLatitude();
    }
    else if (m_outType == Lon) {
      out[samp] = m_cam->UniversalLongitude();
    }
    else {
      if (!m_cam->SetUniversalGround(m_cam->UniversalLatitude(), m_cam->UniversalLongitude())) {
        out[samp] = Hrs;
        continue;
      }


      if (m_outType == Samp) {
        out[samp] = m_cam->Sample();
      }
      else if (m_outType == Line) {
        out[samp] = m_cam->Line();
      }
      else {
        double deltaS = m_cam->Sample() - sample;
        double deltaL = m_cam->Line()   - line;
        out[samp] = sqrt(deltaS * deltaS + deltaL * deltaL);
      }

    }
  }
  
  m_resultsStats->AddData(out.DoubleBuffer(), out.size());
}
/* Old Processing Routine
// Line processing routine
void doIt(Buffer &in, Buffer &out) {
  if(in.Line() == 1) {
@@ -93,3 +193,4 @@ void doIt(Buffer &in, Buffer &out) {
    }
  }
}
*/
 No newline at end of file
+11 −1
Original line number Diff line number Diff line
@@ -11,7 +11,12 @@
      special pixel values.  If a call to SetImage(sample, line) fails, the 
      output image is set to the Low Representation Saturation (Lrs) special 
      value.  Failures in calls to SetUniversalGround(lat, lon) are set to High 
      Representation Saturation (Hrs) value.
      Representation Saturation (Hrs) value.  The number of pixels for which
      SetImage(sample, line) fails is output as FailedConversionsToLatLong.
      The number of pixels for which SetImage(sample, line) succeeded but then
      SetUniversalGround(lat, lon) failed is output as
      FailedConversionsToSampleLine.  If ERROR is chosen for FORMAT, then
      statistics on the error will also be output.
    </description>

  <category>
@@ -33,6 +38,11 @@
          and SetUniversalGround (Hrs) to special pixel values so they are 
          distinguishable.  Documented this behaviour.
      </change>
      <change name="Jesse Mapel" date="2016-03-25">
	Now outputs statistics on the number of failed calls to SetImage and
	SetUniversalGround.  For FROMAT=ERROR, statistics on the
	error are also output.
      </change>
  </history>

  <groups>