Commit 2e63da5e authored by Kaitlyn Lee's avatar Kaitlyn Lee
Browse files

Quick changes.

parent 38503271
Loading
Loading
Loading
Loading
+47 −42
Original line number Diff line number Diff line
@@ -19,19 +19,21 @@ using namespace Isis;
const int FLOAT_MIN = -16777215;
const int FLOAT_MAX = 16777216;

void findTrackBand(UserInterface ui, QString &copyBands, QString &trackBand);
void createMosaicCube(UserInterface ui, QString bands);
void createTrackCube(UserInterface ui, QString trackingBand);
void findTrackBand(QString inputName, QString &copyBands, QString &trackBand);
void createMosaicCube(QString inputName, QString outputName, QString bands);
void createTrackCube(QString inputName, QString ouputName, QString trackBand);
void copyPixels(Buffer &in, Buffer &out);
void copyTrackPixels(Buffer &in, Buffer &out);

void IsisMain() {
  UserInterface &ui = Application::GetUserInterface();
  QString inputName = ui.GetFileName("FROM");
  QString outputName = ui.GetFileName("TO");
  QString copyBands;
  QString trackBand;
  findTrackBand(ui, copyBands, trackBand);
  createMosaicCube(ui, copyBands);
  createTrackCube(ui, trackBand);
  findTrackBand(inputName, copyBands, trackBand);
  createMosaicCube(inputName, outputName, copyBands);
  createTrackCube(inputName, outputName, trackBand);
}


@@ -41,18 +43,15 @@ void IsisMain() {
 * We store the indices in QStrings because we use them as cube attributes when
 * we process the mosaic and tracking cubes.
 *
 * @param ui        The user interface
 * @param inputName The name of the input cube with the tracking band
 * @param copyBands Indices of the bands to copy over to the mosaic cube
 * @param trackBand Index of the tracking band
 */
void findTrackBand(UserInterface ui, QString &copyBands, QString &trackBand) {
  Cube inputCube = Cube(ui.GetFileName("FROM"));
  Pvl *inputLabel = inputCube.label();

  if (inputLabel->hasObject("IsisCube")) {
    PvlObject &cubeObject = inputLabel->findObject("IsisCube");
    if (cubeObject.hasGroup("BandBin")) {
      PvlGroup &bandBinGroup = cubeObject.findGroup("BandBin");
void findTrackBand(QString inputName, QString &copyBands, QString &trackBand) {
  Cube inputCube = Cube(inputName);
  if (inputCube.hasGroup("BandBin")) {
    PvlGroup &bandBinGroup = inputCube.group("BandBin");
    try {
      PvlKeyword &currentKeyword = bandBinGroup[0];
      for (int i = 0; i < currentKeyword.size(); i++) {
        if (currentKeyword[i] != "TRACKING") {
@@ -64,9 +63,18 @@ void findTrackBand(UserInterface ui, QString &copyBands, QString &trackBand) {
        }
      }
    }
    catch (IException &e) {
      QString msg = "The input cube [" + inputName + "] does not have any keywords";
      msg += " in the BandBin group. Make sure TRACKING is a keyword in the BandBin group.";
      throw IException(IException::Programmer, msg, _FILEINFO_);
    }
  }
  else {
    QString msg = "The input cube [" + inputName + "] does not have a BandBin group.";
    throw IException(IException::Programmer, msg, _FILEINFO_);
  }
  if (trackBand == "") {
    QString msg = "The input cube [" + ui.GetFileName("FROM") + "] does not have a tracking band.";
    QString msg = "The input cube [" + inputName + "] does not have a tracking band.";
    msg += " If you want to create a tracking cube, run a mosaic program.";
    throw IException(IException::Programmer, msg, _FILEINFO_);
  }
@@ -78,45 +86,40 @@ void findTrackBand(UserInterface ui, QString &copyBands, QString &trackBand) {
 * Then, removes the tracking table from the mosaic label and adds a group pointing
 * to the tracking cube.
 *
 * @param ui    The user interface
 * @param inputName The name of the input cube
 * @param ouputName The name of the output cube
 * @param bands     The indices of the bands that are not the tracking band
 */
void createMosaicCube(UserInterface ui, QString bands) {
void createMosaicCube(QString inputName, QString outputName, QString bands) {
  ProcessByLine p;
  CubeAttributeInput inAtt = CubeAttributeInput("+" + bands);
  p.SetInputCube(ui.GetFileName("FROM"), inAtt);
  p.SetInputCube(inputName, inAtt);
  p.SetOutputCube("TO");
  p.StartProcess(copyPixels);
  p.EndProcess();

  Cube mosaicCube;
  try {
    mosaicCube.open(ui.GetFileName("TO"),"rw");
    mosaicCube.open(outputName,"rw");
  }
  catch (IException &e) {
    throw IException(IException::User,
                     "Unable to open the file [" + ui.GetFileName("TO") + "] as a cube.",
                     "Unable to open the file [" + outputName + "] as a cube.",
                     _FILEINFO_);
  }
  Pvl *mosaicLabel = mosaicCube.label();

  if (mosaicLabel->hasObject("Table")) {
    PvlObject &tableObject = mosaicLabel->findObject("Table");
    if (tableObject.hasKeyword("Name")) {
      PvlKeyword &tableName = tableObject.findKeyword("Name", Pvl::Traverse);
      if (tableName[0] == "InputImages") {
        mosaicLabel->deleteObject("Table");
      }
    }
  if (!mosaicCube.deleteBlob("Table", "InputImages")) {
    QString msg = "The input cube [" + inputName + "] does not have a tracking table.";
    throw IException(IException::Programmer, msg, _FILEINFO_);
  }

  // Add Tracking Group to the mosaic cube
  PvlGroup trackingGroup = PvlGroup("Tracking");
  PvlKeyword trackingName = PvlKeyword("Filename");
  FileName cubeName = FileName(ui.GetFileName("TO"));
  FileName cubeName = FileName(outputName);
  trackingName.setValue(cubeName.baseName() + "_tracking.cub"); //Strip off path and add _tracking
  trackingGroup.addKeyword(trackingName);
  mosaicLabel->addGroup(trackingGroup);
  mosaicCube.putGroup(trackingGroup);

  mosaicCube.close();
}
@@ -127,25 +130,27 @@ void createMosaicCube(UserInterface ui, QString bands) {
 * Then, goes through each pixel and subtracts the input cube's pixel type's min value
 * because ProcesMosaic used to add the min value to each pixel.
 *
 * @param ui           The user interface
 * @param inputName    The name of the input cube
 * @param ouputName    The name of the output cube
 * @param trackingBand The index of the tracking band
 */
void createTrackCube(UserInterface ui, QString trackBand) {
void createTrackCube(QString inputName, QString ouputName, QString trackBand) {
  ProcessByLine p;

  CubeAttributeInput inAtt = CubeAttributeInput("+" + trackBand);
  p.SetInputCube(ui.GetFileName("FROM"), inAtt);
  p.SetInputCube(inputName, inAtt);

  FileName cubeName = FileName(ui.GetFileName("TO"));
  FileName cubeName = FileName(ouputName);
  // Strip off any extensions and add _tracking
  QString trackingName = cubeName.path() + "/" + cubeName.baseName() + "_tracking.cub";
  Cube inputCube = Cube(ui.GetFileName("FROM"));
  Cube inputCube = Cube(inputName);
  int numSample = inputCube.sampleCount();
  int numLine = inputCube.lineCount();

  QString outAttString = "+UNSIGNEDINTEGER+" + QString::number(VALID_MINUI4) + ":";
  outAttString += QString::number(VALID_MAXUI4);
  CubeAttributeOutput outAtt = CubeAttributeOutput(outAttString);
  CubeAttributeOutput outAtt;
  outAtt.setPixelType(UnsignedInteger);
  outAtt.setMinimum(VALID_MINUI4);
  outAtt.setMaximum(VALID_MAXUI4);

  p.SetOutputCube(trackingName, outAtt, numSample, numLine);