Unverified Commit 4c7d776f authored by acpaquette's avatar acpaquette Committed by GitHub
Browse files

Isis2ascii Header Update (#3903)

* Updated the isis2ascii header to be more CSV friendly

* Changed isis2ascii header from colmnar data to be more header like

* Updated app and added gtests

* Updated special pixel test and added fixture based on feedback
parent a59e4192
Loading
Loading
Loading
Loading
+115 −0
Original line number Diff line number Diff line
#include "isis2ascii.h"

using namespace std;

namespace Isis {
  // Global declarations
  void isis2ascii(Buffer &in);
  ofstream fout;
  /**
   * @brief The SpecialPixelFunctor class
   *
   * This class is used to convert ISIS cubes into ascii format with
   * specified values for the special pixels in the cube.  The main purpose
   * for the class was to reduce global variables.
   *
   * @author 2016-06-15 Adam Paquette
   *
   * @internal
   *   @history 2016-06-15 Adam Paquette - Original Version
   *
   */

  class SpecialPixelFunctor{

  public:
      explicit SpecialPixelFunctor(QString null,
                                   QString hrs,
                                   QString his,
                                   QString lrs,
                                   QString lis) :
          null(null), hrs(hrs), his(his), lrs(lrs), lis(lis) {}

      void operator() (Buffer &in) const {
          for(int i = 0; i < in.size(); i++) {
            fout.width(13);        //  Width must be set everytime
            if(IsSpecial(in[i])) {
              if(IsNullPixel(in[i])) fout << null;
              if(IsHrsPixel(in[i])) fout << hrs;
              if(IsHisPixel(in[i])) fout << his;
              if(IsLrsPixel(in[i])) fout << lrs;
              if(IsLisPixel(in[i])) fout << lis;
            }
            else {
              fout << in[i];
            }
          }
          fout << endl;
      }
  private:
      QString null;
      QString hrs;
      QString his;
      QString lrs;
      QString lis;
  };

  void isis2ascii(UserInterface &ui) {
    Cube icube;
    icube.open(ui.GetFileName("FROM"));

    isis2ascii(&icube, ui);
  }

  void isis2ascii(Cube *icube, UserInterface &ui) {
    // Create a process by line object
    QString null;
    QString hrs;
    QString his;
    QString lrs;
    QString lis;

    ProcessByLine p;

    // Get the size of the cube
    p.SetInputCube(icube);

    //  Open output text file
    QString to = ui.GetFileName("TO", "txt");
    fout.open(to.toLatin1().data());

    // Print header if needed
    if(ui.GetBoolean("HEADER")) {
      fout << "Input_Cube " << icube->fileName() << endl;
      fout << "Samples " << icube->sampleCount() << endl;
      fout << "Lines " << icube->lineCount() << endl;
      fout << "Bands " << icube->bandCount() << endl;
    }

    //Determine special pixel values
    if (ui.GetBoolean("SETPIXELVALUES")) {
      null = ui.GetString("NULLVALUE");
      hrs = ui.GetString("HRSVALUE");
      his = ui.GetString("HISVALUE");
      lrs = ui.GetString("LRSVALUE");
      lis = ui.GetString("LISVALUE");
    }
    else {
      null = "NULL";
      hrs = "HRS";
      his = "HIS";
      lrs = "LRS";
      lis = "LIS";
    }

    SpecialPixelFunctor isis2ascii(null, hrs, his, lrs, lis);

    fout << std::setprecision(7);

    // List the cube
    p.ProcessCubeInPlace(isis2ascii, false);
    p.EndProcess();

    fout.close();
  }
}
+17 −0
Original line number Diff line number Diff line
#ifndef isis2ascii_h
#define isis2ascii_h

#include <iomanip>

#include "FileName.h"
#include "ProcessByLine.h"
#include "SpecialPixel.h"
#include "UserInterface.h"
#include "Cube.h"

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

#endif
+3 −104
Original line number Diff line number Diff line
#include "Isis.h"

#include <iomanip>

#include "FileName.h"
#include "ProcessByLine.h"
#include "SpecialPixel.h"
#include "isis2ascii.h"
#include "Application.h"

using namespace std;
using namespace Isis;

// Global declarations
void isis2ascii(Buffer &in);
ofstream fout;
/**
 * @brief The SpecialPixelFunctor class
 *
 * This class is used to convert ISIS cubes into ascii format with
 * specified values for the special pixels in the cube.  The main purpose
 * for the class was to reduce global variables.
 *
 * @author 2016-06-15 Adam Paquette
 *
 * @internal
 *   @history 2016-06-15 Adam Paquette - Original Version
 *
 */

class SpecialPixelFunctor{

public:
    explicit SpecialPixelFunctor(QString null,
                                 QString hrs,
                                 QString his,
                                 QString lrs,
                                 QString lis) :
        null(null), hrs(hrs), his(his), lrs(lrs), lis(lis) {}

    void operator() (Buffer &in) const {
        for(int i = 0; i < in.size(); i++) {
          fout.width(13);        //  Width must be set everytime
          if(IsSpecial(in[i])) {
            if(IsNullPixel(in[i])) fout << null;
            if(IsHrsPixel(in[i])) fout << hrs;
            if(IsHisPixel(in[i])) fout << his;
            if(IsLrsPixel(in[i])) fout << lrs;
            if(IsLisPixel(in[i])) fout << lis;
          }
          else {
            fout << in[i];
          }
        }
        fout << endl;
    }
private:
    QString null;
    QString hrs;
    QString his;
    QString lrs;
    QString lis;
};

void IsisMain() {
  // Create a process by line object
  QString null;
  QString hrs;
  QString his;
  QString lrs;
  QString lis;

  ProcessByLine p;

  // Get the size of the cube
  Cube *icube = p.SetInputCube("FROM");

  //  Open output text file
  UserInterface &ui = Application::GetUserInterface();
  QString to = ui.GetFileName("TO", "txt");
  fout.open(to.toLatin1().data());

  // Print header if needed
  if(ui.GetBoolean("HEADER")) {
    fout << "Input Cube:  " << icube->fileName() << endl;
    fout << "Samples:Lines:Bands:  " << icube->sampleCount() << ":" <<
         icube->lineCount() << ":" << icube->bandCount() << endl;
  }

  //Determine special pixel values
  if (ui.GetBoolean("SETPIXELVALUES")) {
    null = ui.GetString("NULLVALUE");
    hrs = ui.GetString("HRSVALUE");
    his = ui.GetString("HISVALUE");
    lrs = ui.GetString("LRSVALUE");
    lis = ui.GetString("LISVALUE");
  }
  else {
    null = "NULL";
    hrs = "HRS";
    his = "HIS";
    lrs = "LRS";
    lis = "LIS";
  }

  SpecialPixelFunctor isis2ascii(null, hrs, his, lrs, lis);
  
  fout << std::setprecision(7);
  
  // List the cube
  p.ProcessCubeInPlace(isis2ascii, false);
  p.EndProcess();

  fout.close();
  isis2ascii(ui);
}
+2 −2
Original line number Diff line number Diff line
APPNAME = isis2ascii

include $(ISISROOT)/make/isismake.tsts
vesta64ascii.txt.SKIPLINES = 1
isisTruthAsciiUser.txt.SKIPLINES = 1


commands:
+49 −1
Original line number Diff line number Diff line
#include "Fixtures.h"
#include "LineManager.h"

#include "SpecialPixel.h"

namespace Isis {

@@ -37,6 +37,54 @@ namespace Isis {
    }
  }

  void SpecialSmallCube::SetUp() {
    TempTestingFiles::SetUp();

    testCube = new Cube();
    testCube->setDimensions(10, 10, 10);
    testCube->create(tempDir.path() + "/small.cub");

    // Use a line manager to update select lines with ISIS special pixel values
    LineManager line(*testCube);
    double pixelValue = 0.0;
    int lineNum = 0;
    for(line.begin(); !line.end(); line++) {
      for(int i = 0; i < line.size(); i++) {
        if (lineNum == 2) {
          line[i] = NULL8;
        }
        else if (lineNum == 3) {
          line[i] = LOW_REPR_SAT8;
        }
        else if (lineNum == 4) {
          line[i] = HIGH_REPR_SAT8;
        }
        else if (lineNum == 5) {
          line[i] = LOW_INSTR_SAT8;
        }
        else if (lineNum == 6) {
          line[i] = HIGH_INSTR_SAT8;
        }
        else {
          line[i] = (double) pixelValue++;
        }
      }
      lineNum++;
      testCube->write(line);
    }

  }

  void SpecialSmallCube::TearDown() {
    if (testCube->isOpen()) {
      testCube->close();
    }

    if (testCube) {
      delete testCube;
    }
  }


  void DefaultCube::SetUp() {
    TempTestingFiles::SetUp();
Loading