Unverified Commit 340f4122 authored by Kaitlyn Lee's avatar Kaitlyn Lee Committed by GitHub
Browse files

Adds image data to the default cube fixture and enlarge tests (#3840)

* refactored enlarge.

* Added setinputcube call.

* Removed return from setinputcube.

* Removed print.

* Added fixture for adding image data to a cube.

* Need to add changed files to a different machine.

* Changed SetOutputCube call so we can pass in the ui object.

* Added enlarge tests.

* Removed Makefile tests.

* Added CubeAttribute.

* Fixed typo.

* Refactored opening input cube
parent ffa861eb
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -74,6 +74,15 @@
    <change name="Sharmila Prasad" date="2011-09-15">
      Fixed issue 0000280 - enlarge fails when run with a batchlist
    </change>
    <change name="Kaitlyn Lee" date="2020-04-09">
      The SetOutputCube method from Process we were originally using called
      Application::GetUserInterface(), but this became a problem when trying to 
      call enlarge(), or run the application, programmatically since we are no
      longer using Application in the application's cpp file. Changed the call
      to the one that takes in a CubeAttribute object. Also, removed the check
      to see if an invalid interpolation method was passed in since the UserInterface
      class checks and throws the exception and it was unreachable code.
    </change>
  </history>

  <category>
+100 −0
Original line number Diff line number Diff line
#include "enlarge_app.h"

#include "CubeAttribute.h"
#include "Enlarge.h"
#include "IException.h"
#include "ProcessRubberSheet.h"

using namespace std;
using namespace Isis;
namespace Isis{

  void enlarge(UserInterface &ui, Pvl *log) {
    Cube icube;
    CubeAttributeInput inAtt = ui.GetInputAttribute("FROM");
    if (inAtt.bands().size() != 0) {
      icube.setVirtualBands(inAtt.bands());
    }
    icube.open(ui.GetFileName("FROM"));
    enlarge(&icube, ui, log);
  }

  void enlarge(Cube *icube, UserInterface &ui, Pvl *log) {
    ProcessRubberSheet p;
    p.SetInputCube(icube);

    // Input number of samples, lines, and bands
    int ins = icube->sampleCount();
    int inl = icube->lineCount();
    int inb = icube->bandCount();
    
    // Output samples and lines
    int ons, onl;

    // Scaling factors
    double sampleScale, lineScale;

    if(ui.GetString("MODE") == "SCALE") {
      // Retrieve the provided scaling factors
      sampleScale = ui.GetDouble("SSCALE");
      lineScale   = ui.GetDouble("LSCALE");

      // Calculate the output size. If there is a fractional pixel, round up
      ons = (int)ceil(ins * sampleScale);
      onl = (int)ceil(inl * lineScale);
    }
    else {
      // Retrieve the provided sample/line dimensions in the output
      ons = ui.GetInteger("ONS");
      onl = ui.GetInteger("ONL");

      // Calculate the scaling factors
      sampleScale = (double)ons / (double)ins;
      lineScale   = (double)onl / (double)inl;
    }

    // Ensure that the calculated number of output samples and lines is greater
    // than the input
    if(ons < ins || onl < inl) {
      string msg = "Number of output samples/lines must be greater than or equal";
      msg = msg + " to the input samples/lines.";
      throw IException(IException::User, msg, _FILEINFO_);
    }

    // Set up the interpolator
    Interpolator *interp;
    if(ui.GetString("INTERP") == "NEARESTNEIGHBOR") {
      interp = new Interpolator(Interpolator::NearestNeighborType);
    }
    else if(ui.GetString("INTERP") == "BILINEAR") {
      interp = new Interpolator(Interpolator::BiLinearType);
    }
    else {  // CUBICCONVOLUTION
      interp = new Interpolator(Interpolator::CubicConvolutionType);
    }
    
    // Allocate the output file, the number of bands does not change in the output
    QString outputFileName = ui.GetFileName("TO");
    CubeAttributeOutput &att = ui.GetOutputAttribute("TO");
    Cube *ocube = p.SetOutputCube(outputFileName, att, ons, onl, inb);
    
    // Set up the transform object with the calculated scale and number of
    // output pixels
    //Transform *transform = new Enlarge(icube, sampleScale, lineScale);
    Enlarge *transform = new Enlarge(icube, sampleScale, lineScale);
    p.StartProcess(*transform, *interp);
    PvlGroup resultsGrp = transform->UpdateOutputLabel(ocube);

    // Cleanup
    icube->close();
    ocube->close();
    p.EndProcess();

    delete transform;
    delete interp;

    // Write the results to the log
    log->addGroup(resultsGrp);
  }
}
+14 −0
Original line number Diff line number Diff line
#ifndef enlarge_app_h
#define enlarge_app_h


#include "Cube.h"
#include "Pvl.h"
#include "UserInterface.h"

namespace Isis{
  extern void enlarge(Cube *icube, UserInterface &ui, Pvl *log);
  extern void enlarge(UserInterface &ui, Pvl *log);
}

#endif
+16 −82
Original line number Diff line number Diff line
#include "Isis.h"

#include "Enlarge.h"
#include "IException.h"
#include "ProcessRubberSheet.h"
#include "enlarge_app.h"

#include "Application.h"
#include "Pvl.h"

using namespace std;
using namespace Isis;

void IsisMain() {
  ProcessRubberSheet p;

  // Open the input cube
  Cube *icube = p.SetInputCube("FROM");

  // Input number of samples, lines, and bands
  int ins = icube->sampleCount();
  int inl = icube->lineCount();
  int inb = icube->bandCount();

  // Output samples and lines
  int ons, onl;

  // Scaling factors
  double sampleScale, lineScale;

  UserInterface &ui = Application::GetUserInterface();
  if(ui.GetString("MODE") == "SCALE") {
    // Retrieve the provided scaling factors
    sampleScale = ui.GetDouble("SSCALE");
    lineScale   = ui.GetDouble("LSCALE");

    // Calculate the output size. If there is a fractional pixel, round up
    ons = (int)ceil(ins * sampleScale);
    onl = (int)ceil(inl * lineScale);
  Pvl appLog;
  try {
    enlarge(ui, &appLog);
  }
  else {
    // Retrieve the provided sample/line dimensions in the output
    ons = ui.GetInteger("ONS");
    onl = ui.GetInteger("ONL");

    // Calculate the scaling factors
    sampleScale = (double)ons / (double)ins;
    lineScale   = (double)onl / (double)inl;
  catch (...) {
    for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) {
      Application::Log(*grpIt);
    }

  // Ensure that the calculated number of output samples and lines is greater
  // than the input
  if(ons < ins || onl < inl) {
    string msg = "Number of output samples/lines must be greater than or equal";
    msg = msg + " to the input samples/lines.";
    throw IException(IException::User, msg, _FILEINFO_);
    throw;
  }
  
  // Set up the interpolator
  Interpolator *interp;
  if(ui.GetString("INTERP") == "NEARESTNEIGHBOR") {
    interp = new Interpolator(Interpolator::NearestNeighborType);
  for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) {
    Application::Log(*grpIt);
  }
  else if(ui.GetString("INTERP") == "BILINEAR") {
    interp = new Interpolator(Interpolator::BiLinearType);
}
 No newline at end of file
  else if(ui.GetString("INTERP") == "CUBICCONVOLUTION") {
    interp = new Interpolator(Interpolator::CubicConvolutionType);
  }
  else {
    QString msg = "Unknown value for INTERP [" +
                  ui.GetString("INTERP") + "]";
    throw IException(IException::Programmer, msg, _FILEINFO_);
  }

  // Allocate the output file, the number of bands does not change in the output
  Cube *ocube = p.SetOutputCube("TO", ons, onl, inb);

  // Set up the transform object with the calculated scale and number of
  // output pixels
  //Transform *transform = new Enlarge(icube, sampleScale, lineScale);
  Enlarge *transform = new Enlarge(icube, sampleScale, lineScale);
  p.StartProcess(*transform, *interp);
  PvlGroup resultsGrp = transform->UpdateOutputLabel(ocube);

  // Cleanup
  icube->close();
  ocube->close();
  p.EndProcess();

  delete transform;
  delete interp;

  // Write the results to the log
  Application::Log(resultsGrp);
}
+0 −4
Original line number Diff line number Diff line
BLANKS = "%-6s"    
LENGTH = "%-40s"

include $(ISISROOT)/make/isismake.tststree
Loading