Commit c4e9bbcf authored by Kristin Berry's avatar Kristin Berry
Browse files

Added option to export to pds4 format to isis2pds. Updated supporting classes...

Added option to export to pds4 format to isis2pds. Updated supporting classes to facilitate this. Fixes #5202 and Fixes #5203

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@8278 41f8697f-d340-4b68-9986-7bafba869bb8
parent ecc1331c
Loading
Loading
Loading
Loading
+156 −73
Original line number Diff line number Diff line
#include "Isis.h"
#include "ProcessExportPds.h"
#include "ProcessExportPds4.h"
#include "PvlKeyword.h"
#include "PvlToXmlTranslationManager.h"

using namespace std;
using namespace Isis;

enum Pixtype { NONE, NEG, BOTH };

void setRangeAndPixels(UserInterface &ui, ProcessExportPds &p,
void setRangeAndPixels(UserInterface &ui, ProcessExport &p,
                       double &min, double &max, Pixtype ptype);
void IsisMain() {
  UserInterface &ui = Application::GetUserInterface();

  // Check if input file is indeed, a cube
  if (ui.GetFileName("FROM").right(3) != "cub") {
    QString msg = "Input file [" + ui.GetFileName("FROM") +
                "] does not appear to be a cube";
    throw  IException(IException::User, msg, _FILEINFO_);
  }

  if (ui.GetString("PDSVERSION") == "PDS3") {
    // Set the processing object
    ProcessExportPds p;

    // Setup the input cube
    p.SetInputCube("FROM");

  UserInterface &ui = Application::GetUserInterface();

    if(ui.GetString("STRETCH") == "LINEAR") {
      if(ui.GetString("BITTYPE") != "32BIT")
        p.SetInputRange();
@@ -93,12 +104,84 @@ void IsisMain() {
    results += PvlKeyword("ValidMin", toString(min));
    results += PvlKeyword("ValidMax", toString(max));
    Application::Log(results);
  }
  else {
    // Setup the process and set the input cube
    ProcessExportPds4 process;
    Cube *icube = process.SetInputCube("FROM");

    PvlObject *label= icube->label();
    if (!label->hasObject("IsisCube")) {
      QString msg = "Input file [" + ui.GetFileName("FROM") +
                  "] does not appear to be an ISIS3 cube.";
      throw  IException(IException::User, msg, _FILEINFO_);
    }
    
    QString outFile = ui.GetFileName("TO");
    
    if(ui.GetString("STRETCH") == "LINEAR") {
      if(ui.GetString("BITTYPE") != "32BIT")
        process.SetInputRange();
    }
    if(ui.GetString("STRETCH") == "MANUAL")
      process.SetInputRange(ui.GetDouble("MINIMUM"), ui.GetDouble("MAXIMUM"));

    double min = -DBL_MAX;
    double max = DBL_MAX;

    if(ui.GetString("BITTYPE") == "8BIT") {
      process.SetOutputType(Isis::UnsignedByte);
      min = 0.0;
      max = 255.0;
      setRangeAndPixels(ui, process, min, max, BOTH);
    }
    else if(ui.GetString("BITTYPE") == "S16BIT") {
      process.SetOutputType(Isis::SignedWord);
      min = -32768.0;
      max = 32767.0;
      setRangeAndPixels(ui, process, min, max, NEG);
    }
    else if(ui.GetString("BITTYPE") == "U16BIT") {
      process.SetOutputType(Isis::UnsignedWord);
      min = 0.0;
      max = 65535.0;
      setRangeAndPixels(ui, process, min, max, BOTH);
    }
    else {
      process.SetOutputType(Isis::Real);
      process.SetOutputNull(Isis::NULL4);
      process.SetOutputLrs(Isis::LOW_REPR_SAT4);
      process.SetOutputLis(Isis::LOW_INSTR_SAT4);
      process.SetOutputHrs(Isis::HIGH_REPR_SAT4);
      process.SetOutputHis(Isis::HIGH_INSTR_SAT4);
      setRangeAndPixels(ui, process, min, max, NONE);
    }

    if(ui.GetString("ENDIAN") == "MSB")
      process.SetOutputEndian(Isis::Msb);
    else if(ui.GetString("ENDIAN") == "LSB")
      process.SetOutputEndian(Isis::Lsb);

    // Records what it did to the print.prt file
    PvlGroup results("DNs Used");
    results += PvlKeyword("Null", toString(process.OutputNull()));
    results += PvlKeyword("LRS", toString(process.OutputLrs()));
    results += PvlKeyword("LIS", toString(process.OutputLis()));
    results += PvlKeyword("HIS", toString(process.OutputHis()));
    results += PvlKeyword("HRS", toString(process.OutputHrs()));
    results += PvlKeyword("ValidMin", toString(min));
    results += PvlKeyword("ValidMax", toString(max));
    Application::Log(results);

    process.StandardPds4Label();
    process.WritePds4(outFile);
  }

  return;
}

//Sets up special pixels and valid pixel ranges
void setRangeAndPixels(UserInterface &ui, ProcessExportPds &p, double &min, double &max, Pixtype ptype) {
void setRangeAndPixels(UserInterface &ui, ProcessExport &p, double &min, double &max, Pixtype ptype) {
  if(ptype == NEG) {
    if(ui.GetBoolean("NULL")) {
      p.SetOutputNull(min++);
+44 −7
Original line number Diff line number Diff line
@@ -2,11 +2,12 @@

<application name="isis2pds" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://isis.astrogeology.usgs.gov/Schemas/Application/application.xsd">
  <brief>
    Convert from cube to pds format
    Convert from ISIS3 cube to PDS 3 or PDS 4 format
  </brief>

  <description>
   Program to convert cubes to pds image files.
   Program to convert cubes to PDS3 or PDS4 image files.
   For PDS4, If available, Instrument and  Mapping information will be written to the detached output PDS4 formatted xml label file.  
  </description>

  <category>
@@ -22,12 +23,16 @@
      Added the Label Type capability (param)
    </change>
    <change name="Kristin Berry" date="2014-06-06">
      Changed to assume that radii without units in the input Isis cube are in meters, map scales without units are in meters/pixel, and map resolutions without units are in pixels/degree.
      Changed to assume that radii without units in the input Isis cube are in meters, map scales without units are in meters/pixel, and
       map resolutions without units are in pixels/degree.
    </change>
    <change name="Makayla Shepherd and Ian Humphrey" date="2017-05-17">
      Added CHECKSUM parameter to optionally generate and attach an MD5 checksum to the exported
      image label. This checksum is generated from the image data. Fixes #1013.
    </change>
    <change name="Jeannie Backer, Mayayla Shepard, and Kristin Berry" date="2017-10-27">
       Added PDS4 output option. Previously, this application converted ISIS3 cubes to PDS3 format only. 
    </change>
    </history>

  <groups>
@@ -53,7 +58,8 @@
          Output pds image
        </brief>
        <description>
          The resulting pds file.
          The resulting pds file. For PDS4, a detached label of the same name with the file extension .xml 
          will be created in the same directory.
        </description>
        <filter>
          *.img
@@ -61,6 +67,36 @@
      </parameter>
    </group>

    <group name="PDS Format Version">
      <parameter name="PDSVERSION">
        <type>string</type>
         <default><item>PDS3</item></default>
	 <brief>Version of PDS to output</brief>
	 <description>
	     Changes which version of PDS file format
	     to output in.
	 </description>
	 <list>
	     <option value="PDS3">
		 <brief>Convert ISIS3 cube to PDS3 format</brief>
		 <description>
		     Convert ISIS3 cube to PDS3 format.
		 </description>
	     </option>
	     <option value="PDS4">
		 <brief>Convert ISIS3 cube to PDS4 format</brief>
		 <description>
		     Convert ISIS3 cube to PDS4 format.
		  </description>
		  <exclusions>
		      <item>LABTYPE</item>
		      <item>CHECKSUM</item>
		  </exclusions>
	     </option>
	 </list>
      </parameter>
    </group>

    <group name="Output Settings">
    <parameter name="LABTYPE">
        <type>string</type>
@@ -87,6 +123,7 @@
          </option>
        </list>
      </parameter>

      <parameter name="BITTYPE">
        <type>string</type>
        <default>
+12 −0
Original line number Diff line number Diff line
APPNAME = isis2pds

include $(ISISROOT)/make/isismake.tsts

commands:
	$(APPNAME) from=$(INPUT)/dawnEqui1.cub to=$(OUTPUT)/dawnEqui.img pdsversion=pds4 > /dev/null;

	# Change the output xml file to a txt file for test comparison
	mv $(OUTPUT)/dawnEqui.xml $(OUTPUT)/dawnEqui.txt > /dev/null;

	$(RM) $(OUTPUT)/dawnEqui.img > /dev/null; 
+22 −21
Original line number Diff line number Diff line
@@ -174,14 +174,14 @@ namespace Isis {
 *                          <li>the value to check for</li>
 *                        </ol>
 *
 * @throws IException::Unknown "Malformed dependency specification."
 * @throws IException::Unknown "Specification does not have two components
 * @throws IException::Programmer "Malformed dependency specification."
 * @throws IException::Programmer "Specification does not have two components
 *                                 separated by [@], the type of dependency and
 *                                 the name-value pair.
 * @throws IException::Unknown "Dependency type specification is invalid.
 * @throws IException::Programmer "Dependency type specification is invalid.
 *                                 Valid types are [att] and [tag]"
 * @throws IException::Unknown "Name-value specification does not have two
 *                              components separated by [:]."
 * @throws IException::Programmer "Name-value specification does not have two
 *                              components separated by [|]."
 *
 */
QStringList LabelTranslationManager::parseSpecification(QString specification) const {
@@ -190,18 +190,19 @@ QStringList LabelTranslationManager::parseSpecification(QString specification) c

  try {
    QStringList typeSplit = specification.split("@", QString::SkipEmptyParts); 
    QStringList colonSplit = specification.split(":", QString::SkipEmptyParts);
    if (typeSplit.size() == 2) { //handle tag@elementname:value
    QStringList barSplit = specification.split("|", QString::SkipEmptyParts);
   
    if (typeSplit.size() == 2) { //handle tag@elementname|value
      if (typeSplit[0].toLower() != "att" &&
          typeSplit[0].toLower() != "tag" &&
          typeSplit[0].toLower() != "new") {
        QString msg = "Dependency type specification [" + typeSplit[0] +
                      "] is invalid. Valid types are [att], [tag] and [new]";
        throw IException(IException::Unknown, msg, _FILEINFO_);
        throw IException(IException::Programmer, msg, _FILEINFO_);
      }
      parsedSpecification.append(typeSplit[0].toLower());

      QStringList nameValueSplit = typeSplit[1].split(":", QString::SkipEmptyParts);
      QStringList nameValueSplit = typeSplit[1].split("|", QString::SkipEmptyParts);
      if (nameValueSplit.size() == 2) {
        parsedSpecification.append(nameValueSplit);
      }
@@ -210,24 +211,24 @@ QStringList LabelTranslationManager::parseSpecification(QString specification) c
      }
      else { //nameValueSplit is an unexpected value
        QString msg = "Malformed dependency specification [" + specification + "].";
        throw IException(IException::Unknown, msg, _FILEINFO_);
        throw IException(IException::Programmer, msg, _FILEINFO_);
      }
    }
    else if (colonSplit.size() == 2) { //handle elementname:value
      parsedSpecification = colonSplit;
    else if (barSplit.size() == 2) { //handle elementname|value
      parsedSpecification = barSplit;
    }
    else if (colonSplit.size() == 1 && typeSplit.size() == 1) { //handle value with no "@" or ":" characters
      parsedSpecification = colonSplit;
    else if (barSplit.size() == 1 && typeSplit.size() == 1) { //handle value with no "@" or "|" characters
      parsedSpecification = barSplit;
    }
    else { //nameValueSplit is an unexpected value
      QString msg = " [" + specification + "] has unexpected number of '@' or ':' delimiters";
      throw IException(IException::Unknown,msg, _FILEINFO_);
      QString msg = " [" + specification + "] has unexpected number of '@' or '|' delimiters";
      throw IException(IException::Programmer,msg, _FILEINFO_);
    }
  }

  catch (IException &e) {
    QString msg = "Malformed dependency specification [" + specification + "].";
    throw IException(e, IException::Unknown, msg, _FILEINFO_);
    throw IException(e, IException::Programmer, msg, _FILEINFO_);
  }

  return parsedSpecification;
+4 −0
Original line number Diff line number Diff line
@@ -51,6 +51,10 @@ namespace Isis {
   *                          Fixes #4584.
   *  @history 2017-05-26 Cole Neubauer - Moved parseDependancy from children
   *                          class. Fixes #5167.
   *  @history 2017-10-26 Kristin Berry - Modified parseSpecification to switch
   *                          from parsing translation table dependency specifications of the form
   *                          name:value to strings of the form name|value. Colons are
   *                          now used for namespaces only.
   */
  class LabelTranslationManager : public PvlTranslationTable {
    public:
Loading