Unverified Commit 87c8432b authored by robotprogrammer22's avatar robotprogrammer22 Committed by GitHub
Browse files

Stretch functional tests (#4154)



* stretch updates

* pull request changes

* modified setoutputcube to remove seg fault

* merge with dev + fixed bug

* updating test files

* modified stretch app

* updated mvix

* modified setoutputcube functions with null ui parameter

* modified stretch test and reverted changes involving setoutputcube

* modified setoutputcube function call

* made new setoutputcube for stretch

* added +1 back to user interface, removed duplicate test

* pull request changes

Co-authored-by: default avatarKelvin <kelvinrr@icloud.com>
parent 936e6fcf
Loading
Loading
Loading
Loading
+15 −73
Original line number Diff line number Diff line
#include "Isis.h"
#include "TextFile.h"
#include "Statistics.h"
#include "ProcessByLine.h"
#include "SpecialPixel.h"
#include "Stretch.h"
#include "PvlGroup.h"
#include "PvlKeyword.h"

#include "Application.h"
#include "UserInterface.h"

#include "stretch_app.h"

using namespace std;
using namespace Isis;

void stretch(Buffer &in, Buffer &out);
Stretch str;
Statistics stats;

void IsisMain() {
  ProcessByLine p;
  Cube *inCube = p.SetInputCube("FROM");

  UserInterface &ui = Application::GetUserInterface();

  QString pairs;

  // first just get the pairs from where ever and worry about
  // whether they are dn values or %'s later
  if(ui.GetBoolean("READFILE")) {
    FileName pairsFileName = ui.GetFileName("INPUTFILE");
    TextFile pairsFile;
    pairsFile.SetComment("#");
    pairsFile.Open(pairsFileName.expanded());

    // concat all non-comment lines into one string (pairs)
    QString line = "";
    while(pairsFile.GetLine(line, true)) {
      pairs += " " + line;
    }
    pairs += line;
  }
  else {
    if(ui.WasEntered("PAIRS"))
      pairs = ui.GetString("PAIRS");
  Pvl results;
  try{
      stretch(ui, &results);
  }

  if(ui.GetBoolean("USEPERCENTAGES")) {
    str.Parse(pairs, inCube->histogram());
  catch(...){
      for (int resultIndex = 0; resultIndex < results.groups(); resultIndex++) {
          Application::Log(results.group(resultIndex));
      }
  else
    str.Parse(pairs);

  // Setup new mappings for special pixels if necessary
  if(ui.WasEntered("NULL"))
    str.SetNull(StringToPixel(ui.GetString("NULL")));
  if(ui.WasEntered("LIS"))
    str.SetLis(StringToPixel(ui.GetString("LIS")));
  if(ui.WasEntered("LRS"))
    str.SetLrs(StringToPixel(ui.GetString("LRS")));
  if(ui.WasEntered("HIS"))
    str.SetHis(StringToPixel(ui.GetString("HIS")));
  if(ui.WasEntered("HRS"))
    str.SetHrs(StringToPixel(ui.GetString("HRS")));

  p.SetOutputCube("TO");

  // Start the processing
  p.StartProcess(stretch);
  p.EndProcess();

  PvlKeyword dnPairs = PvlKeyword("StretchPairs");
  dnPairs.addValue(str.Text());

  PvlGroup results = PvlGroup("Results");
  results.addKeyword(dnPairs);

  Application::Log(results);

      throw;
  }

// Line processing routine
void stretch(Buffer &in, Buffer &out) {
  for(int i = 0; i < in.size(); i++) {
    out[i] = str.Map(in[i]);
  for (int resultIndex = 0; resultIndex < results.groups(); resultIndex++) {
      Application::Log(results.group(resultIndex));
  }
}
+94 −0
Original line number Diff line number Diff line
#include "TextFile.h"
#include "Statistics.h"
#include "ProcessByLine.h"
#include "SpecialPixel.h"
#include "Stretch.h"
#include "PvlGroup.h"
#include "PvlKeyword.h"

#include "stretch_app.h"

namespace Isis {
  void stretchProcess(Buffer &in, Buffer &out);
  Stretch str;
  Statistics stats;

  void stretch(UserInterface &ui, Pvl *log) {
    Cube *cubeFile = new Cube();
    CubeAttributeInput inAtt = ui.GetInputAttribute("FROM");
    if (inAtt.bands().size() != 0) {
      cubeFile->setVirtualBands(inAtt.bands());
    }
    cubeFile->open(ui.GetFileName("FROM"), "r");

    QString pairs;

    // first just get the pairs from where ever and worry about
    // whether they are dn values or %'s later
    if(ui.GetBoolean("READFILE")) {
      FileName pairsFileName = ui.GetFileName("INPUTFILE");
      TextFile pairsFile;
      pairsFile.SetComment("#");
      pairsFile.Open(pairsFileName.expanded());

      // concat all non-comment lines into one string (pairs)
      QString line = "";
      while(pairsFile.GetLine(line, true)) {
        pairs += " " + line;
      }
      pairs += line;
    }
    else {
      if(ui.WasEntered("PAIRS"))
        pairs = ui.GetString("PAIRS");
    }

    stretch(cubeFile, pairs, ui, log);
  }

  void stretch(Cube *inCube, QString &pairs, UserInterface &ui, Pvl *log) {
    ProcessByLine p;
    p.SetInputCube(inCube);

    if(ui.GetBoolean("USEPERCENTAGES")) {
      str.Parse(pairs, inCube->histogram());
    }
    else
      str.Parse(pairs);

    // Setup new mappings for special pixels if necessary
    if(ui.WasEntered("NULL"))
      str.SetNull(StringToPixel(ui.GetString("NULL")));
    if(ui.WasEntered("LIS"))
      str.SetLis(StringToPixel(ui.GetString("LIS")));
    if(ui.WasEntered("LRS"))
      str.SetLrs(StringToPixel(ui.GetString("LRS")));
    if(ui.WasEntered("HIS"))
      str.SetHis(StringToPixel(ui.GetString("HIS")));
    if(ui.WasEntered("HRS"))
      str.SetHrs(StringToPixel(ui.GetString("HRS")));

    p.SetOutputCubeStretch("TO", &ui);

    // Start the processing
    p.StartProcess(stretchProcess);
    p.EndProcess();

    PvlKeyword dnPairs = PvlKeyword("StretchPairs");
    dnPairs.addValue(str.Text());

    PvlGroup results = PvlGroup("Results");
    results.addKeyword(dnPairs);

    if (log){
      log->addGroup(results);
    }
  }

  // Line processing routine
  void stretchProcess(Buffer &in, Buffer &out) {
    for(int i = 0; i < in.size(); i++) {
      out[i] = str.Map(in[i]);
    }
  }
}
+14 −0
Original line number Diff line number Diff line
#ifndef stretch_app_h
#define stretch_app_h

#include "PvlGroup.h"
#include "PvlKeyword.h"
#include "UserInterface.h"

namespace Isis {
  extern void stretch(UserInterface &ui, Pvl *log=nullptr);

  extern void stretch(Cube *inCube, QString &pairs, UserInterface &ui, Pvl *log=nullptr);
}

#endif
+84 −4
Original line number Diff line number Diff line
@@ -277,6 +277,38 @@ namespace Isis {
    return SetOutputCube(parameter, ns, nl, nb);
  }

  /**
   * Allocates a user-specified output cube whose size matches the first input
   * cube.
   *
   * @return Cube*
   *
   * @param parameter User specified output file. For example, "TO" is a popular
   *                  user parameter. If the user specified TO=output.cub, then
   *                  this routine would allocate the file output.cub with size
   *                  specified by the first opened input cube. The output pixel
   *                  type will be propagated from the first loaded input cube or
   *                  will use the value in the application XML file for
   *                  pixelType.
   *
   * @param ui A user interface used to get the attributes needed for SetOutputCube.
   *
   * @throws Isis::iException::Message
   */
  Isis::Cube *Process::SetOutputCubeStretch(const QString &parameter, UserInterface *ui) {
    // Make sure we have an input cube to get a default size from
    if(InputCubes.size() == 0) {
      QString message = "No input images have been selected ... therefore";
      message += "the output image size can not be determined";
      throw IException(IException::Programmer, message, _FILEINFO_);
    }

    int nl = InputCubes[0]->lineCount();
    int ns = InputCubes[0]->sampleCount();
    int nb = InputCubes[0]->bandCount();
    return SetOutputCubeStretch(parameter, ns, nl, nb, ui);
  }

  /**
   * Allocates a user specified output cube whose size is specified by the
   * programmer.
@@ -308,11 +340,59 @@ namespace Isis {
              << ",nb=" << nb << "]";
      throw IException(IException::Programmer, message.str().c_str(), _FILEINFO_);
    }
    QString fname = Application::GetUserInterface().GetFileName(parameter);
    Isis::CubeAttributeOutput &atts = Application::GetUserInterface().GetOutputAttribute(parameter);
    QString fname;
    Isis::CubeAttributeOutput atts;
    fname = Application::GetUserInterface().GetFileName(parameter);
    atts = Application::GetUserInterface().GetOutputAttribute(parameter);
    return SetOutputCube(fname, atts, ns, nl, nb);
}

/**
 * Allocates a user specified output cube whose size is specified by the
 * programmer.
 *
 * @return Cube*
 *
 * @param parameter User specified output file. For example, "TO" is a popular
 *                  user parameter. If the user specified TO=output.cub, then
 *                  this routine would allocate the file output.cub with size
 *                  specified by the first opened input cube. The output pixel
 *                  type will be propagated from the first loaded input cube or
 *                  will use the value in the application XML file for
 *                  pixelType.
 *
 * @param ns Number of samples to allocate
 *
 * @param nl Number of lines to allocate
 *
 * @param nb Number of bands to allocate
 *
 * @param ui A user interface used to get the attributes needed. If null, the
 *           user interface will be obtained from the application.
 *
 * @throws Isis::iException::Message
 */
Isis::Cube *Process::SetOutputCubeStretch(const QString &parameter, const int ns,
                                   const int nl, const int nb, UserInterface *ui) {
  // Make sure we have good dimensions
  if((ns <= 0) || (nl <= 0) || (nb <= 0)) {
    ostringstream message;
    message << "Invalid cube size specifications [ns=" << ns << ",nl=" << nl
            << ",nb=" << nb << "]";
    throw IException(IException::Programmer, message.str().c_str(), _FILEINFO_);
  }
  QString fname;
  Isis::CubeAttributeOutput atts;
  if(ui==nullptr){
    fname = Application::GetUserInterface().GetFileName(parameter);
    atts = Application::GetUserInterface().GetOutputAttribute(parameter);
  }
  else{
    fname = ui->GetFileName(parameter);
    atts = ui->GetOutputAttribute(parameter);
  }
  return SetOutputCube(fname, atts, ns, nl, nb);
}

  /**
   * Allocates a output cube whose name and size is specified by the programmer.
+3 −0
Original line number Diff line number Diff line
@@ -241,8 +241,11 @@ namespace Isis {


      virtual Isis::Cube *SetOutputCube(const QString &parameter);
      virtual Isis::Cube *SetOutputCubeStretch(const QString &parameter, UserInterface *ui=nullptr);
      virtual Isis::Cube *SetOutputCube(const QString &parameter, const int nsamps,
                                const int nlines, const int nbands = 1);
      virtual Isis::Cube *SetOutputCubeStretch(const QString &parameter, const int nsamps,
                                const int nlines, const int nbands = 1, UserInterface *ui=nullptr);
      virtual Isis::Cube *SetOutputCube(const QString &fname,
                                const Isis::CubeAttributeOutput &att,
                                const int nsamps, const int nlines,
Loading