Unverified Commit 15b8c54e authored by Kelvin Rodriguez's avatar Kelvin Rodriguez Committed by GitHub
Browse files

Ringsautomos tests added (#4155)

* added ring automos tests

* uuuugh

* comments

* fixed typo

* messing up your branchm not even once
parent 2831509a
Loading
Loading
Loading
Loading
+40 −116
Original line number Diff line number Diff line
#define GUIHELPERS

#include "Isis.h"
#include "ProcessMapMosaic.h"

#include "Application.h"
#include "FileList.h"
#include "IException.h"
#include "SpecialPixel.h"
#include "RingPlaneProjection.h"
#include "ProjectionFactory.h"

using namespace std;
#include "ringsautomos.h" // replace with your new header

using namespace Isis;
using namespace std;

void calcRange(double &minRingRad, double &maxRingRad, double &minRingLon, double &maxRingLon);
void helperButtonCalcRange();
void calcRange(double &minRingRad, double &maxRingRad, double &minRingLon, double &maxRingLon);

map <QString, void *> GuiHelpers() {
  map <QString, void *> helper;
@@ -21,103 +23,50 @@ map <QString, void *> GuiHelpers() {
}

void IsisMain() {
  FileList list;
  UserInterface &ui = Application::GetUserInterface();
  Pvl appLog;

  // Get the list of cubes to mosaic
  list.read(FileName(ui.GetFileName("FROMLIST")));
  // Redundant test.  Already checked in FileList
  // if(list.size() < 1) {
  //   QString msg = "The list file [" + ui.GetFileName("FROMLIST") +"does not contain any data";
  //   throw IException(IException::User, msg, _FILEINFO_);
  // }

  fstream os;
  bool olistFlag = false;
  if (ui.WasEntered("TOLIST")){
    QString olist = ui.GetFileName("TOLIST");
    olistFlag = true;
    os.open(olist.toLatin1().data(), std::ios::out);
  }

  ProcessMapMosaic m;

  // Set the create flag-mosaic is always created in ringsautomos
  m.SetCreateFlag(true);

  // Get the Track Flag
  bool bTrack = ui.GetBoolean("TRACK");
  m.SetTrackFlag(bTrack);

  ProcessMosaic::ImageOverlay overlay = ProcessMosaic::StringToOverlay(
      ui.GetString("PRIORITY"));

  if (overlay == ProcessMapMosaic::UseBandPlacementCriteria) {
    if(ui.GetString("TYPE") == "BANDNUMBER") {
      m.SetBandNumber(ui.GetInteger("NUMBER"));
  try {
    ringsautomos(ui, &appLog);
  }
    else {
      // Key name & value
      m.SetBandKeyword(ui.GetString("KEYNAME"), ui.GetString("KEYVALUE"));
  catch (...) {
    for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) {
      Application::Log(*grpIt);
    }
    // Band Criteria
    m.SetBandUseMaxValue( (ui.GetString("CRITERIA") == "GREATER") );
    throw;
  }
 
  // Priority
  m.SetImageOverlay(overlay);

  CubeAttributeOutput &oAtt = ui.GetOutputAttribute("MOSAIC");
  if(ui.GetString("GRANGE") == "USER") {
    m.RingsSetOutputCube(list,
                    ui.GetDouble("MINRINGRAD"), ui.GetDouble("MAXRINGRAD"),
                    ui.GetDouble("MINRINGLON"), ui.GetDouble("MAXRINGLON"),
                    oAtt, ui.GetFileName("MOSAIC"));
  for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) {
    Application::Log(*grpIt);
  }
  else {
    m.RingsSetOutputCube(list, oAtt, ui.GetFileName("MOSAIC"));
}

  m.SetHighSaturationFlag(ui.GetBoolean("HIGHSATURATION"));
  m.SetLowSaturationFlag(ui.GetBoolean("LOWSATURATION"));
  m.SetNullFlag(ui.GetBoolean("NULL"));

  // Loop for each input file and place it in the output mosaic

  m.SetBandBinMatch(ui.GetBoolean("MATCHBANDBIN"));

  // Get the MatchDEM Flag
  m.SetMatchDEM(ui.GetBoolean("MATCHDEM"));
// Helper function to run calcRange function.
void helperButtonCalcRange() {
  UserInterface &ui = Application::GetUserInterface();
  double minRingRad;
  double maxRingRad;
  double minRingLon;
  double maxRingLon;

  bool mosaicCreated = false;
  for (int i = 0; i < list.size(); i++) {
    if (!m.StartProcess(list[i].toString())) {
      PvlGroup outsiders("Outside");
      outsiders += PvlKeyword("File", list[i].toString());
      Application::Log(outsiders);
    }
    else {
      mosaicCreated = true;
      if(olistFlag) {
        os << list[i].toString() << endl;
      }
    }
    if(mosaicCreated) {
      // Mosaic is already created, use the existing mosaic
      m.SetCreateFlag(false);
    }
  }
  // Logs the input file location in the mosaic
  for (int i = 0; i < m.imagePositions().groups(); i++) {
    Application::Log(m.imagePositions().group(i));
  }
  // Run the function calcRange of calculate range info
  calcRange(minRingRad, maxRingRad, minRingLon, maxRingLon);

  if(olistFlag) {
    os.close();
  // Write ranges to the GUI
  QString use = "USER";
  ui.Clear("GRANGE");
  ui.PutAsString("GRANGE", use);
  ui.Clear("MINRINGRAD");
  ui.PutDouble("MINRINGRAD", minRingRad);
  ui.Clear("MAXRINGRAD");
  ui.PutDouble("MAXRINGRAD", maxRingRad);
  ui.Clear("MINRINGLON");
  ui.PutDouble("MINRINGLON", minRingLon);
  ui.Clear("MAXRINGLON");
  ui.PutDouble("MAXRINGLON", maxRingLon);
}

  m.EndProcess();
}

// Function to calculate the ground range from multiple inputs (list of images)
void calcRange(double &minRingRad, double &maxRingRad, double &minRingLon, double &maxRingLon) {
@@ -163,28 +112,3 @@ void calcRange(double &minRingRad, double &maxRingRad, double &minRingLon, doubl
      delete proj;
  }
}
 No newline at end of file

// Helper function to run calcRange function.
void helperButtonCalcRange() {
  UserInterface &ui = Application::GetUserInterface();
  double minRingRad;
  double maxRingRad;
  double minRingLon;
  double maxRingLon;

  // Run the function calcRange of calculate range info
  calcRange(minRingRad, maxRingRad, minRingLon, maxRingLon);

  // Write ranges to the GUI
  QString use = "USER";
  ui.Clear("GRANGE");
  ui.PutAsString("GRANGE", use);
  ui.Clear("MINRINGRAD");
  ui.PutDouble("MINRINGRAD", minRingRad);
  ui.Clear("MAXRINGRAD");
  ui.PutDouble("MAXRINGRAD", maxRingRad);
  ui.Clear("MINRINGLON");
  ui.PutDouble("MINRINGLON", minRingLon);
  ui.Clear("MAXRINGLON");
  ui.PutDouble("MAXRINGLON", maxRingLon);
}
+111 −0
Original line number Diff line number Diff line
#include "ProcessMapMosaic.h"
#include "FileList.h"
#include "IException.h"
#include "SpecialPixel.h"
#include "RingPlaneProjection.h"
#include "ProjectionFactory.h"

#include "ringsautomos.h"

using namespace std;

namespace Isis {

  void ringsautomos(UserInterface &ui, Pvl *log){
    FileList list;

    // Get the list of cubes to mosaic
    list.read(FileName(ui.GetFileName("FROMLIST")));

    fstream os;
    bool olistFlag = false;
    if (ui.WasEntered("TOLIST")){
      QString olist = ui.GetFileName("TOLIST");
      olistFlag = true;
      os.open(olist.toLatin1().data(), std::ios::out);
    }

    ProcessMapMosaic m;

    // Set the create flag-mosaic is always created in ringsautomos
    m.SetCreateFlag(true);

    // Get the Track Flag
    bool bTrack = ui.GetBoolean("TRACK");
    m.SetTrackFlag(bTrack);

    ProcessMosaic::ImageOverlay overlay = ProcessMosaic::StringToOverlay(
        ui.GetString("PRIORITY"));

    if (overlay == ProcessMosaic::UseBandPlacementCriteria) {
      if(ui.GetString("TYPE") == "BANDNUMBER") {
        m.SetBandNumber(ui.GetInteger("NUMBER"));
      }
      else {
        // Key name & value
        m.SetBandKeyword(ui.GetString("KEYNAME"), ui.GetString("KEYVALUE"));
      }
      // Band Criteria
      m.SetBandUseMaxValue( (ui.GetString("CRITERIA") == "GREATER") );
    }

    // Priority
    m.SetImageOverlay(overlay);

    CubeAttributeOutput &oAtt = ui.GetOutputAttribute("MOSAIC");
    if(ui.GetString("GRANGE") == "USER") {
      m.RingsSetOutputCube(list,
                      ui.GetDouble("MINRINGRAD"), ui.GetDouble("MAXRINGRAD"),
                      ui.GetDouble("MINRINGLON"), ui.GetDouble("MAXRINGLON"),
                      oAtt, ui.GetFileName("MOSAIC"));
    }
    else {
      m.RingsSetOutputCube(list, oAtt, ui.GetFileName("MOSAIC"));
    }

    m.SetHighSaturationFlag(ui.GetBoolean("HIGHSATURATION"));
    m.SetLowSaturationFlag(ui.GetBoolean("LOWSATURATION"));
    m.SetNullFlag(ui.GetBoolean("NULL"));

    // Loop for each input file and place it in the output mosaic

    m.SetBandBinMatch(ui.GetBoolean("MATCHBANDBIN"));

    // Get the MatchDEM Flag
    m.SetMatchDEM(ui.GetBoolean("MATCHDEM"));

    bool mosaicCreated = false;
    for (int i = 0; i < list.size(); i++) {
      if (!m.StartProcess(list[i].toString())) {
        PvlGroup outsiders("Outside");
        outsiders += PvlKeyword("File", list[i].toString());
        if(log) {
          log->addGroup(outsiders);
        }
      }
      else {
        mosaicCreated = true;
        if(olistFlag) {
          os << list[i].toString() << endl;
        }
      }
      if(mosaicCreated) {
        // Mosaic is already created, use the existing mosaic
        m.SetCreateFlag(false);
      }
    }
    // Logs the input file location in the mosaic
    for (int i = 0; i < m.imagePositions().groups(); i++) {
      if(log) {
        log->addGroup(m.imagePositions().group(i));
      }
    }

    if(olistFlag) {
      os.close();
    }

    m.EndProcess();
  }
}
  
 No newline at end of file
+10 −0
Original line number Diff line number Diff line
#ifndef ringsautomos_h 
#define ringsautomos_h

#include "UserInterface.h"

namespace Isis{
  extern void ringsautomos(UserInterface &ui, Pvl *log=nullptr);
}

#endif
 No newline at end of file
+0 −4
Original line number Diff line number Diff line
BLANKS = "%-6s"    
LENGTH = "%-40s"

include $(ISISROOT)/make/isismake.tststree
+0 −33
Original line number Diff line number Diff line
# This case tests the following combination of parameters for ringsautomos
#
# tolist is given
# priority=beneath
# groundrange=user minringlon=0	maxringlon=100	minringrad=8000000	maxringrad=100000000	
# track=true
# matchbandbin=false
# matchdem=true
#
APPNAME = ringsautomos

include $(ISISROOT)/make/isismake.tsts

commands:
	$(LS) $(INPUT)/*.projected.cub > $(OUTPUT)/fromlist.lis;
	$(APPNAME) from=$(OUTPUT)/fromlist.lis \
	  mosaic=$(OUTPUT)/wacMosaic.cub \
	  tolist=$(OUTPUT)/tolist.txt \
	  priority=beneath \
	  grange=user \
	  minringlon= 0 \
	  maxringlon= 100 \
	  minringrad= 8000000 \
	  maxringrad= 100000000 \
	  track=true \
	  matchbandbin=false \
	  matchdem=true \
	  > /dev/null;
	catlab from=$(OUTPUT)/wacMosaic.cub \
	  to=$(OUTPUT)/wacMosaic.pvl > /dev/null;
	$(SED) 's+/.*input/+input/+' $(OUTPUT)/tolist.txt > $(OUTPUT)/tolist_mod.txt 
	$(RM) $(OUTPUT)/fromlist.lis;
	$(RM) $(OUTPUT)/tolist.txt;
Loading