Commit 95bc2364 authored by Janet Barrett's avatar Janet Barrett
Browse files

Fixed crop program so it wipes out input cube after successive runs in the...

Fixed crop program so it wipes out input cube after successive runs in the GUI. Added more tests. Fixes #1500.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@5716 41f8697f-d340-4b68-9986-7bafba869bb8
parent ba523a9d
Loading
Loading
Loading
Loading
+31 −25
Changes for isis/src/base/apps/crop/crop.cpp: 31 added lines, 25 removed lines.
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ using namespace Isis;
int ss, sl, sb;
int ns, nl, nb;
int sinc, linc;
Cube cube;
Cube *cube = NULL;
LineManager *in = NULL;

void crop(Buffer &out);
@@ -32,49 +32,50 @@ void IsisMain() {
  UserInterface &ui = Application::GetUserInterface();
  QString from = ui.GetAsString("FROM");
  CubeAttributeInput inAtt(from);
  cube.setVirtualBands(inAtt.bands());
  cube = new Cube();
  cube->setVirtualBands(inAtt.bands());
  from = ui.GetFileName("FROM");
  cube.open(from);
  cube->open(from);

  // Determine the sub-area to extract
  ss = ui.GetInteger("SAMPLE");
  sl = ui.GetInteger("LINE");
  sb = 1;

  int origns = cube.sampleCount();
  int orignl = cube.lineCount();
  int es = cube.sampleCount();
  int origns = cube->sampleCount();
  int orignl = cube->lineCount();
  int es = cube->sampleCount();
  if (ui.WasEntered("NSAMPLES")) es = ss + ui.GetInteger("NSAMPLES") - 1;
  int el = cube.lineCount();
  int el = cube->lineCount();
  if (ui.WasEntered("NLINES")) el = sl + ui.GetInteger("NLINES") - 1;
  int eb = cube.bandCount();
  int eb = cube->bandCount();

  sinc = ui.GetInteger("SINC");
  linc = ui.GetInteger("LINC");

  // Make sure starting positions fall within the cube
  if (ss > cube.sampleCount()) {
    cube.close();
  if (ss > cube->sampleCount()) {
    cube->close();
    QString msg = "[SAMPLE] exceeds number of samples in the [FROM] cube";
    throw IException(IException::User, msg, _FILEINFO_);
  }

  if (sl > cube.lineCount()) {
    cube.close();
  if (sl > cube->lineCount()) {
    cube->close();
    QString msg = "[LINE] exceeds number of lines in the [FROM] cube";
    throw IException(IException::User, msg, _FILEINFO_);
  }

  // Make sure the number of elements do not fall outside the cube
  if (es > cube.sampleCount()) {
    cube.close();
  if (es > cube->sampleCount()) {
    cube->close();
    QString msg = "[SAMPLE+NSAMPLES-1] exceeds number of ";
    msg += "samples in the [FROM] cube";
    throw IException(IException::User, msg, _FILEINFO_);
  }

  if (el > cube.lineCount()) {
    cube.close();
  if (el > cube->lineCount()) {
    cube->close();
    QString msg = "[LINE+NLINES-1] exceeds number of ";
    msg += "lines in the [FROM] cube";
    throw IException(IException::User, msg, _FILEINFO_);
@@ -96,7 +97,7 @@ void IsisMain() {
  p.ClearInputCubes();

  // propagate tables manually
  Pvl &inLabels = *cube.label();
  Pvl &inLabels = *cube->label();

  // Loop through the labels looking for object = Table
  for(int labelObj = 0; labelObj < inLabels.objects(); labelObj++) {
@@ -122,7 +123,7 @@ void IsisMain() {
    /* Deal with associations, sample first
    if(table.IsSampleAssociated()) {
      int numDeleted = 0;
      for(int samp = 0; samp < cube.sampleCount(); samp++) {
      for(int samp = 0; samp < cube->sampleCount(); samp++) {
        // This tests checks to see if we would include this sample.
        //   samp - (ss-1)) / sinc must be a whole number less than ns.
        if((samp - (ss-1)) % sinc != 0 || (samp - (ss-1)) / sinc >= ns || (samp - (ss-1)) < 0) {
@@ -135,7 +136,7 @@ void IsisMain() {
    // Deal with line association
    if(table.IsLineAssociated()) {
      int numDeleted = 0;
      for(int line = 0; line < cube.lineCount(); line++) {
      for(int line = 0; line < cube->lineCount(); line++) {
        // This tests checks to see if we would include this line.
        //   line - (sl-1)) / linc must be a whole number less than nl.
        if((line - (sl-1)) % linc != 0 || (line - (sl-1)) / linc >= nl || (line - (sl-1)) < 0) {
@@ -166,7 +167,7 @@ void IsisMain() {
  }

  // Create a buffer for reading the input cube
  in = new LineManager(cube);
  in = new LineManager(*cube);

  // Crop the input cube
  p.StartProcess(crop);
@@ -189,13 +190,18 @@ void IsisMain() {

  // Update the Mapping, Instrument, and AlphaCube groups in the output
  // cube label
  SubArea s;
  s.SetSubArea(orignl, origns, sl, ss, el, es, linc, sinc);
  s.UpdateLabel(&cube, ocube, results);
  SubArea *s;
  s = new SubArea;
  s->SetSubArea(orignl, origns, sl, ss, el, es, linc, sinc);
  s->UpdateLabel(cube, ocube, results);
  delete s;
  s = NULL;

  // Cleanup
  p.EndProcess();
  cube.close();
  cube->close();
  delete cube;
  cube = NULL;

  // Write the results to the log
  Application::Log(results);
@@ -206,7 +212,7 @@ void crop(Buffer &out) {
  // Read the input line
  int iline = sl + (out.Line() - 1) * linc;
  in->SetLine(iline, sb);
  cube.read(*in);
  cube->read(*in);

  // Loop and move appropriate samples
  for(int i = 0; i < out.size(); i++) {
+5 −0
Changes for isis/src/base/apps/crop/crop.xml: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -97,6 +97,11 @@
      samples does not divide evenly by the linc or sinc values there will be one additional
      line or sample in the output cube.
    </change>
    <change name="Janet Barrett" date="2014-02-10">
      Delete input cube between successive runs of the program. This makes sure that the
      projection information is initialized each time the program is run in the GUI.
      Fixes #1500.
    </change>
  </history>

  <oldName>
+11 −0
Changes for isis/src/base/apps/crop/tsts/simp/Makefile: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
APPNAME = crop

simp.txt.IGNORELINES = Bytes StartByte ByteOrder TileSamples TileLines

include $(ISISROOT)/make/isismake.tsts

commands:
	$(APPNAME) from=$(INPUT)/mapsimp.cub to=$(OUTPUT)/mapsimpcrop.cub \
	  sample=818 nsamples=300 sinc=1 line=2070 nlines=300 linc=1 > /dev/null;
	catlab from=$(OUTPUT)/mapsimpcrop.cub > $(OUTPUT)/simp.txt;
	rm $(OUTPUT)/mapsimpcrop.cub;
+11 −0
Changes for isis/src/base/apps/crop/tsts/sinu/Makefile: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
APPNAME = crop

sinu.txt.IGNORELINES = Bytes StartByte ByteOrder TileSamples TileLines

include $(ISISROOT)/make/isismake.tsts

commands:
	$(APPNAME) from=$(INPUT)/mapsinu.cub to=$(OUTPUT)/mapsinucrop.cub \
	  sample=818 nsamples=300 sinc=1 line=2070 nlines=300 linc=1 > /dev/null;
	catlab from=$(OUTPUT)/mapsinucrop.cub > $(OUTPUT)/sinu.txt;
	rm $(OUTPUT)/mapsinucrop.cub;