Commit 424d010e authored by Kristin Berry's avatar Kristin Berry
Browse files

Tracking information from input cubes is now not propagated to the output cube...

Tracking information from input cubes is now not propagated to the output cube in cubeit. Fixes #800

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@6289 41f8697f-d340-4b68-9986-7bafba869bb8
parent a8f48e5d
Loading
Loading
Loading
Loading
+97 −7
Original line number Diff line number Diff line
@@ -27,19 +27,69 @@ void IsisMain() {
  Process p;
  UserInterface &ui = Application::GetUserInterface();
  FileList cubeList(ui.GetFileName("FROMLIST"));
  FileList newcubeList; //cubes with at least 1 non-TRACKING band
  QList<vector<QString> > newVirtualBands; //non-TRACKING bands to propagate

  //Results group to contain information about unpropagated TRACKING bands
  PvlGroup results("Results"); 

  // Loop through the list
  int nsamps(0), nlines(0), nbands(0);
  PvlGroup outBandBin("BandBin");
  try {
    for(int i = 0; i < cubeList.size(); i++) {
      vector<QString> newBands; 
      Cube cube;
      CubeAttributeInput inatt(cubeList[i].original()); 
      vector<QString> bands = inatt.bands();
      cube.setVirtualBands(bands);
      cube.open(cubeList[i].toString()); 

      if(i == 0) {
      if( cube.hasTable("InputImages") ) {
        //search through band bin group of input cube for "TRACKING"
        PvlObject cubeLabel =cube.label()->findObject("IsisCube");
        PvlGroup bandbin = cubeLabel.findGroup("BandBin");

        //Different cubes use either FilterName or FilterNumber in the BandBin group
        //to refer to the same thing: a list of the numbers/names of each band, in order
        PvlKeyword filterName; 
        if( bandbin.hasKeyword("FilterName") ){
          filterName = bandbin.findKeyword("FilterName"); 
        }
        else if ( bandbin.hasKeyword("FilterNumber")) {
          filterName = bandbin.findKeyword("FilterNumber"); 
        } 
        else {
            QString msg = "The BandBin group of a cube with tracking information [" +
                        cubeList[i].toString() + "] does not have a FilterName or a FilterNumber.";
          throw IException(IException::Unknown, msg, _FILEINFO_);
        }

        for (int j = 0; j < filterName.size(); j++) {
          if (filterName[j] != "TRACKING") {
            newBands.push_back(QString::number(j+1)); 
          } 
          else {
            QString msg = "TRACKING band not propagated from " + cubeList[i].toString();
            results += PvlKeyword("UnpropagatedBand", msg);
          }
        }

        //if there are some bands that aren't TRACKING, set the cube to use those
        if (newBands.size() > 0) {
          cube.close(); 
          cube.setVirtualBands(newBands); 
          cube.open(cubeList[i].toString()); 
        }
        //if the only provided bands are TRACKING, don't use this cube at all
        else {
          cube.close(); 
          continue;
        }
      }

      //initialize ns, nl, nb if we're at our first non-tracking cube
      if(newcubeList.size() == 0) { 
        nsamps = cube.sampleCount();
        nlines = cube.lineCount();
        nbands = cube.bandCount();
@@ -73,6 +123,12 @@ void IsisMain() {
        }
      }
      cube.close();
      newVirtualBands.append(newBands); 
      newcubeList.append(cubeList[i]);
    }
    //Only write out results group if we added something to it. 
    if (results.hasKeyword("UnpropagatedBand")) {
      Application::Log(results); 
    }
  }
  catch(IException &e) {
@@ -80,6 +136,12 @@ void IsisMain() {
    throw IException(e, IException::User, msg, _FILEINFO_);
  }

  //if literally everything is a TRACKING band, throw an error, since we don't prop. TRACKING bands
  if (newcubeList.size() == 0) {
    QString msg = "Only TRACKING bands supplied in [" + ui.GetFileName("FROMLIST") + "]";
    throw IException(IException::User, msg, _FILEINFO_);
  }

  // Setup to propagate from the first input cube
  ProcessByLine p2;
  CubeAttributeInput inatt;
@@ -102,7 +164,7 @@ void IsisMain() {
      throw IException(IException::User, msg, _FILEINFO_);
    }
  }
  p2.SetInputCube(cubeList[index].toString(), inatt);
  p2.SetInputCube(newcubeList[index].toString(), inatt);

  // Create the output cube
  Cube *ocube = p2.SetOutputCube("TO", nsamps, nlines, nbands);
@@ -115,20 +177,46 @@ void IsisMain() {
  if(outBandBin.keywords() > 0) {
    ocube->putGroup(outBandBin);
  }

  // Delete any tracking tables from the input label if necessary
  if (ocube->hasTable("InputImages")) {
    ocube->deleteBlob("Table", "InputImages"); 
  }

  p2.EndProcess(); 
  
 // Now loop and mosaic in each cube
  int sband = 1;
  for(int i = 0; i < cubeList.size(); i++) {
  for(int i = 0; i < newcubeList.size(); i++) {
    ProcessMosaic m;
    m.SetBandBinMatch(false);

    Progress *prog = m.Progress();
    prog->SetText("Adding band " + toString((int)i + 1) +
                  " of " + toString(nbands));
    prog->SetText("Adding bands from Cube " + toString((int)i + 1) +
                  " of " + toString(newcubeList.size()));
    m.SetOutputCube("TO");
    CubeAttributeInput attrib(cubeList[i].original()); 
    Cube *icube = m.SetInputCube(cubeList[i].toString(), attrib);

    //update attributes to the input cube
    CubeAttributeInput attrib; 

    if (newVirtualBands.at(i).size() == 0) {
      
      attrib.addAttributes(newcubeList[i]);

    } else {

      for(unsigned k=0; k < newVirtualBands.at(i).size(); k++) {
        attrib.addAttribute(newVirtualBands.at(i)[k]); 
      }
    }
 
    Cube *icube = m.SetInputCube(newcubeList[i].toString(), attrib);

    // Delete any tracking tables from the input cube if necessary
    if (icube->hasTable("InputImages")) {
      icube->deleteBlob("Table", "InputImages"); 
    }
    
    m.SetImageOverlay(ProcessMosaic::PlaceImagesOnTop);
    m.StartProcess(1, 1, sband);
    sband += icube->bandCount();
@@ -154,3 +242,5 @@ void helperButtonLog() {
    Application::GuiLog(line);
  }
}

+28 −7
Original line number Diff line number Diff line
@@ -2,15 +2,32 @@

<application name="cubeit" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Application/application.xsd">
  <brief>
    Stacks cubes in individual files into one cube
    Stacks individual cubes into one cube
  </brief>

  <description>
    This program will stack a series of cubes into a single cube.  It
    requires a file containing a list of cubes to stack and the order
    of the file is used to generate the stacking order.  Each cube
    must have the same spatial dimensions (e.g., samples and lines).
    The BandBin group will be constructed.
  <p>
    This program will stack a series of cubes into a single output cube.  
    You can use cubeit to combine individual color bands to create
    a multi-band cube. 
  </p>
  <p>
    A text-based file that contains a list of cubes to stack must be
    entered in the FROMLIST. Each cube must have the same spatial dimensions 
    (e.g., samples and lines). The BandBin group, which is used to store information 
    regarding each band in the cube, will be constructed.
  </p>
   <p>
   The order of the file is used to generate the stacking order. Cubes are automatically placed 
   down as cubeit reads the list from top-to-bottom. You can change the order to make certain 
   cubes appear in front of or behind other cubes by modifying the list order. 
   </p>
    <p>
    By default, any tracking information stored within an input cube (for example, as generated by automos, mapmos, etc.) 
    is not propagated to the output cube, since, in most cases, this tracking information is no longer relevant to 
    the output cube. 
    </p>

  </description>

  <category>
@@ -55,6 +72,9 @@
     <change name="Kristin Berry" date="2014-05-20">
       Fixed handing of input attributes so that the specified input band(s) are included in the output cube. 
     </change>
     <change name="Kristin Berry" date="2015-07-22">
       Modified so that tracking information in the input cubes is not propagated to the output cube.
     </change>
     </history>

  <groups>
@@ -67,7 +87,8 @@
        </brief>
        <description>
          Each file in this list, one per line, will be added to
          the output cube in the order they appear.
          the output cube in the order they appear. The last file
	  in the list must followed by a blank line. 
        </description>
        <filter>
          *.lis
+47 −0
Original line number Diff line number Diff line
#This test will print errors thrown by cubeit when given 
#input cubes of different sizes or nothing but TRAKCING bands
APPNAME = cubeit

include $(ISISROOT)/make/isismake.tsts

commands:
#    TEST A: pass in a list of cubes with different sizes
	echo -e "Different sized cubes:" > $(OUTPUT)/error_temp.txt;
	if [ `$(APPNAME) \
	  fromlist=$(INPUT)/input.lis \
	  to=$(OUTPUT)/error.cub \
	  2>> $(OUTPUT)/error_temp.txt > /dev/null` ]; \
	  then true; \
	fi;

#    TEST B: pass in a list of cubes with only TRACKING bands
	echo -e "Only TRACKING bands:" >> $(OUTPUT)/error_temp.txt;
	ls $(INPUT)/*TRACKING.cub >> $(OUTPUT)/tracking.lis;
	if [ `$(APPNAME) \
	  fromlist=$(OUTPUT)/tracking.lis \
	  to=$(OUTPUT)/error2.cub \
	  2>> $(OUTPUT)/error_temp.txt > /dev/null` ]; \
	  then true; \
	fi;

#    TEST C: pass in a cube with a TRACKING band but ill-formed BandBin Group
	echo -e "TRACKING and broken BandBin:" >> $(OUTPUT)/error_temp.txt;
	ls $(INPUT)/*.cub >> $(OUTPUT)/broken.lis;
	if [ `$(APPNAME) \
	  fromlist=$(OUTPUT)/broken.lis \
	  to=$(OUTPUT)/error3.cub \
	  2>> $(OUTPUT)/error_temp.txt > /dev/null` ]; \
	  then true; \
	fi;

#    Remove Paths
	$(SED) 's+\[/.*/input/+\[input/+' $(OUTPUT)/error_temp.txt > $(OUTPUT)/error_temp2.txt;
	$(SED) 's+\[/.*/output/+\[output/+' $(OUTPUT)/error_temp.txt > $(OUTPUT)/error.txt;

#    Cleanup
	$(RM) $(OUTPUT)/error_temp.txt; 
	$(RM) $(OUTPUT)/error_temp2.txt; 
	$(RM) $(OUTPUT)/tracking.lis; 
	$(RM) $(OUTPUT)/broken.lis; 

+12 −0
Original line number Diff line number Diff line
APPNAME = cubeit

include $(ISISROOT)/make/isismake.tsts

commands:
	ls $(INPUT)/*.cub > $(OUTPUT)/inputBandbinList.lis; \
	$(APPNAME) fromlist=$(OUTPUT)/inputBandbinList.lis \
	to=$(OUTPUT)/cubeitBandBinTruth.cub > /dev/null;  \
	catlab from=$(OUTPUT)/cubeitBandBinTruth.cub      \
	to=$(OUTPUT)/labels.pvl > /dev/null; 
	$(RM) $(OUTPUT)/inputBandbinList.lis; 		\
+12 −0
Original line number Diff line number Diff line
APPNAME = cubeit

include $(ISISROOT)/make/isismake.tsts

commands:
	ls $(INPUT)/*.cub > $(OUTPUT)/inputPropLab.lis; \
	$(APPNAME) proplab=$(INPUT)/isisTruthDifferentLabel.cub   \
	fromlist=$(OUTPUT)/inputPropLab.lis              \
	to=$(OUTPUT)/cubeitProplabTruth.cub > /dev/null;
	catlab from=$(OUTPUT)/cubeitProplabTruth.cub      \
	to=$(OUTPUT)/labels.pvl > /dev/null; 
	$(RM) $(OUTPUT)/inputPropLab.lis;  	\
Loading