Unverified Commit faa2ce61 authored by Amy Stamile's avatar Amy Stamile Committed by GitHub
Browse files

Segment App and Test Conversion (#4328)

* Segment App and Test Conversion

* Removal of Makefile Tests
parent ad9c4d23
Loading
Loading
Loading
Loading
+2 −40
Original line number Diff line number Diff line
#include "Isis.h"

#include "Application.h"
#include "Cube.h"
#include "ProgramLauncher.h"
#include "segment.h"

using namespace std;
using namespace Isis;

void IsisMain() {

  //Get user parameters
  UserInterface &ui = Application::GetUserInterface();
  FileName inFile = ui.GetFileName("FROM");
  int numberOfLines = ui.GetInteger("NL");
  int lineOverlap   = ui.GetInteger("OVERLAP");

  //Throws exception if user is dumb
  if(lineOverlap >= numberOfLines) {
    throw IException(IException::User, "The Line Overlap (OVERLAP) must be less than the Number of Lines (LN).", _FILEINFO_);
  }

  //Opens the cube
  Cube cube;
  cube.open(inFile.expanded());

  //Loops through, cropping as desired
  int cropNum = 1;
  int startLine = 1;
  bool hasReachedEndOfCube = false;
  while(startLine <= cube.lineCount()  &&  not hasReachedEndOfCube) {
    //! Sets up the proper paramaters for running the crop program
    QString parameters = "FROM=" + inFile.expanded() +
                         " TO=" + inFile.path() + "/" + inFile.baseName() + ".segment" + toString(cropNum) + ".cub"
                         + " LINE=" + toString(startLine) + " NLINES=";

    if(startLine + numberOfLines > cube.lineCount()) {
      parameters += toString(cube.lineCount() - (startLine - 1));
      hasReachedEndOfCube = true;
    }
    else {
      parameters += toString(numberOfLines);
    }
    ProgramLauncher::RunIsisProgram("crop", parameters);
    //The starting line for next crop
    startLine = 1 + cropNum * (numberOfLines - lineOverlap);
    cropNum++;
  }
  segment(ui);
}
+52 −0
Original line number Diff line number Diff line
#include "Application.h"
#include "Cube.h"
#include "ProgramLauncher.h"

#include "segment.h"

using namespace std;

namespace Isis {

  void segment(UserInterface &ui) {
    Cube *incube = new Cube();
    incube->open(ui.GetFileName("FROM"));
    segment(incube, ui);
  }

  void segment(Cube *cube, UserInterface &ui) {

    //Get user parameters
    FileName inFile = ui.GetFileName("FROM");
    int numberOfLines = ui.GetInteger("NL");
    int lineOverlap   = ui.GetInteger("OVERLAP");

    //Throws exception if user is dumb
    if(lineOverlap >= numberOfLines) {
      throw IException(IException::User, "The Line Overlap (OVERLAP) must be less than the Number of Lines (LN).", _FILEINFO_);
    }

    //Loops through, cropping as desired
    int cropNum = 1;
    int startLine = 1;
    bool hasReachedEndOfCube = false;
    while(startLine <= cube->lineCount()  &&  not hasReachedEndOfCube) {
      //! Sets up the proper paramaters for running the crop program
      QString parameters = "FROM=" + inFile.expanded() +
                           " TO=" + inFile.path() + "/" + inFile.baseName() + ".segment" + toString(cropNum) + ".cub"
                           + " LINE=" + toString(startLine) + " NLINES=";

      if(startLine + numberOfLines > cube->lineCount()) {
        parameters += toString(cube->lineCount() - (startLine - 1));
        hasReachedEndOfCube = true;
      }
      else {
        parameters += toString(numberOfLines);
      }
      ProgramLauncher::RunIsisProgram("crop", parameters);
      //The starting line for next crop
      startLine = 1 + cropNum * (numberOfLines - lineOverlap);
      cropNum++;
    }
  }
}
+12 −0
Original line number Diff line number Diff line
#ifndef segment_h
#define segment_h

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

namespace Isis {
  extern void segment(Cube *cube, UserInterface &ui);
  extern void segment(UserInterface &ui);
}

#endif
+0 −4
Original line number Diff line number Diff line
BLANKS = "%-6s"    
LENGTH = "%-40s"

include $(ISISROOT)/make/isismake.tststree
+0 −8
Original line number Diff line number Diff line
APPNAME = segment

include $(ISISROOT)/make/isismake.tsts

commands:
	cp $(INPUT)/peaks.cub $(OUTPUT)/out.cub;
	$(APPNAME) from=$(OUTPUT)/out.cub \
	NL=531 OVERLAP=88 > /dev/null;
Loading