Unverified Commit eee70a99 authored by Tim Giroux's avatar Tim Giroux Committed by GitHub
Browse files

Add gtests for camrange (#4056)

* camrange gtest

* Update FunctionalTestsCamrange.cpp

* Update camrange.h

* Update camrange.cpp

* remove old tests
parent 31418322
Loading
Loading
Loading
Loading
+116 −0
Original line number Diff line number Diff line
#include "UserInterface.h"
#include "Camera.h"
#include "Target.h"
#include "Distance.h"
#include "Process.h"
#include "Pvl.h"

#include "camrange.h"

using namespace Isis;

namespace Isis {
  
  void camrange(UserInterface &ui, Pvl *log) {
    Cube *cube = new Cube( ui.GetFileName("FROM"), "r");
    camrange(cube, ui, log);
  }

  void camrange(Cube *incube, UserInterface &ui, Pvl *log) {
    Process p;

    // Set the input image, get the camera model, and a basic mapping
    // group
    Camera *cam = incube->camera();
    Pvl mapping;
    cam->BasicMapping(mapping);
    PvlGroup &mapgrp = mapping.findGroup("Mapping");

    // Setup the log->results by first adding the filename
    // Get the radii
    Distance radii[3];
    cam->radii(radii);
    Target *camTarget = cam->target();
    PvlGroup target("Target");
    target += PvlKeyword("From", ui.GetFileName("FROM"));
    target += PvlKeyword("TargetName", camTarget->name());
    target += PvlKeyword("RadiusA", toString(radii[0].meters()), "meters");
    target += PvlKeyword("RadiusB", toString(radii[1].meters()), "meters");
    target += PvlKeyword("RadiusC", toString(radii[2].meters()), "meters");

    // Get resolution
    PvlGroup res("PixelResolution");
    double lowres = cam->LowestImageResolution();
    double hires = cam->HighestImageResolution();
    res += PvlKeyword("Lowest", toString(lowres), "meters");
    res += PvlKeyword("Highest", toString(hires), "meters");

    // Get the universal ground range
    PvlGroup ugr("UniversalGroundRange");
    double minlat, maxlat, minlon, maxlon;
    cam->GroundRange(minlat, maxlat, minlon, maxlon, mapping);
    ugr += PvlKeyword("LatitudeType", "Planetocentric");
    ugr += PvlKeyword("LongitudeDirection", "PositiveEast");
    ugr += PvlKeyword("LongitudeDomain", "360");
    ugr += PvlKeyword("MinimumLatitude", toString(minlat));
    ugr += PvlKeyword("MaximumLatitude", toString(maxlat));
    ugr += PvlKeyword("MinimumLongitude", toString(minlon));
    ugr += PvlKeyword("MaximumLongitude", toString(maxlon));

    // Get the ographic latitude range
    mapgrp.addKeyword(PvlKeyword("LatitudeType", "Planetographic"),
                      Pvl::Replace);
    cam->GroundRange(minlat, maxlat, minlon, maxlon, mapping);
    PvlGroup ogr("LatitudeRange");
    ogr += PvlKeyword("LatitudeType", "Planetographic");
    ogr += PvlKeyword("MinimumLatitude", toString(minlat));
    ogr += PvlKeyword("MaximumLatitude", toString(maxlat));

    // Get positive west longitude coordinates in 360 domain
    mapgrp.addKeyword(PvlKeyword("LongitudeDirection", "PositiveWest"),
                      Pvl::Replace);
    cam->GroundRange(minlat, maxlat, minlon, maxlon, mapping);
    PvlGroup pos360("PositiveWest360");
    pos360 += PvlKeyword("LongitudeDirection", "PositiveWest");
    pos360 += PvlKeyword("LongitudeDomain", "360");
    pos360 += PvlKeyword("MinimumLongitude", toString(minlon));
    pos360 += PvlKeyword("MaximumLongitude", toString(maxlon));

    // Get positive east longitude coordinates in 180 domain
    mapgrp.addKeyword(PvlKeyword("LongitudeDirection", "PositiveEast"),
                      Pvl::Replace);
    mapgrp.addKeyword(PvlKeyword("LongitudeDomain", "180"),
                      Pvl::Replace);
    cam->GroundRange(minlat, maxlat, minlon, maxlon, mapping);
    PvlGroup pos180("PositiveEast180");
    pos180 += PvlKeyword("LongitudeDirection", "PositiveEast");
    pos180 += PvlKeyword("LongitudeDomain", "180");
    pos180 += PvlKeyword("MinimumLongitude", toString(minlon));
    pos180 += PvlKeyword("MaximumLongitude", toString(maxlon));

    // Get positive west longitude coordinates in 180 domain
    mapgrp.addKeyword(PvlKeyword("LongitudeDirection", "PositiveWest"),
                      Pvl::Replace);
    cam->GroundRange(minlat, maxlat, minlon, maxlon, mapping);
    PvlGroup neg180("PositiveWest180");
    neg180 += PvlKeyword("LongitudeDirection", "PositiveWest");
    neg180 += PvlKeyword("LongitudeDomain", "180");
    neg180 += PvlKeyword("MinimumLongitude", toString(minlon));
    neg180 += PvlKeyword("MaximumLongitude", toString(maxlon));

    log->addGroup(target);
    log->addGroup(res);
    log->addGroup(ugr);
    log->addGroup(ogr);
    log->addGroup(pos360);
    log->addGroup(pos180);
    log->addGroup(neg180);

    // Write the log->file if requested
    if(ui.WasEntered("TO")) {
      log->write(ui.GetFileName("TO", "txt"));
    }

    p.EndProcess();
  }
}
+13 −0
Original line number Diff line number Diff line
#ifndef camrange_h
#define camrange_h

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

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

#endif
+16 −107
Original line number Diff line number Diff line
#include "Isis.h"

#include "Camera.h"
#include "Distance.h"
#include "Application.h"
#include "Process.h"
#include "Pvl.h"
#include "Target.h"
#include "UserInterface.h"

#include "camrange.h"

using namespace std;
using namespace Isis;

void IsisMain() {
  Process p;

  // Set the input image, get the camera model, and a basic mapping
  // group
  Cube *icube = p.SetInputCube("FROM");
  Camera *cam = icube->camera();
  Pvl mapping;
  cam->BasicMapping(mapping);
  PvlGroup &mapgrp = mapping.findGroup("Mapping");

  // Setup the output results by first adding the filename
  UserInterface &ui = Application::GetUserInterface();

  // Get the radii
  Distance radii[3];
  cam->radii(radii);
  PvlGroup target("Target");
  target += PvlKeyword("From", ui.GetFileName("FROM"));
  target += PvlKeyword("TargetName", cam->target()->name());
  target += PvlKeyword("RadiusA", toString(radii[0].meters()), "meters");
  target += PvlKeyword("RadiusB", toString(radii[1].meters()), "meters");
  target += PvlKeyword("RadiusC", toString(radii[2].meters()), "meters");

  // Get resolution
  PvlGroup res("PixelResolution");
  double lowres = cam->LowestImageResolution();
  double hires = cam->HighestImageResolution();
  res += PvlKeyword("Lowest", toString(lowres), "meters");
  res += PvlKeyword("Highest", toString(hires), "meters");

  // Get the universal ground range
  PvlGroup ugr("UniversalGroundRange");
  double minlat, maxlat, minlon, maxlon;
  cam->GroundRange(minlat, maxlat, minlon, maxlon, mapping);
  ugr += PvlKeyword("LatitudeType", "Planetocentric");
  ugr += PvlKeyword("LongitudeDirection", "PositiveEast");
  ugr += PvlKeyword("LongitudeDomain", "360");
  ugr += PvlKeyword("MinimumLatitude", toString(minlat));
  ugr += PvlKeyword("MaximumLatitude", toString(maxlat));
  ugr += PvlKeyword("MinimumLongitude", toString(minlon));
  ugr += PvlKeyword("MaximumLongitude", toString(maxlon));

  // Get the ographic latitude range
  mapgrp.addKeyword(PvlKeyword("LatitudeType", "Planetographic"),
                    Pvl::Replace);
  cam->GroundRange(minlat, maxlat, minlon, maxlon, mapping);
  PvlGroup ogr("LatitudeRange");
  ogr += PvlKeyword("LatitudeType", "Planetographic");
  ogr += PvlKeyword("MinimumLatitude", toString(minlat));
  ogr += PvlKeyword("MaximumLatitude", toString(maxlat));

  // Get positive west longitude coordinates in 360 domain
  mapgrp.addKeyword(PvlKeyword("LongitudeDirection", "PositiveWest"),
                    Pvl::Replace);
  cam->GroundRange(minlat, maxlat, minlon, maxlon, mapping);
  PvlGroup pos360("PositiveWest360");
  pos360 += PvlKeyword("LongitudeDirection", "PositiveWest");
  pos360 += PvlKeyword("LongitudeDomain", "360");
  pos360 += PvlKeyword("MinimumLongitude", toString(minlon));
  pos360 += PvlKeyword("MaximumLongitude", toString(maxlon));

  // Get positive east longitude coordinates in 180 domain
  mapgrp.addKeyword(PvlKeyword("LongitudeDirection", "PositiveEast"),
                    Pvl::Replace);
  mapgrp.addKeyword(PvlKeyword("LongitudeDomain", "180"),
                    Pvl::Replace);
  cam->GroundRange(minlat, maxlat, minlon, maxlon, mapping);
  PvlGroup pos180("PositiveEast180");
  pos180 += PvlKeyword("LongitudeDirection", "PositiveEast");
  pos180 += PvlKeyword("LongitudeDomain", "180");
  pos180 += PvlKeyword("MinimumLongitude", toString(minlon));
  pos180 += PvlKeyword("MaximumLongitude", toString(maxlon));

  // Get positive west longitude coordinates in 180 domain
  mapgrp.addKeyword(PvlKeyword("LongitudeDirection", "PositiveWest"),
                    Pvl::Replace);
  cam->GroundRange(minlat, maxlat, minlon, maxlon, mapping);
  PvlGroup neg180("PositiveWest180");
  neg180 += PvlKeyword("LongitudeDirection", "PositiveWest");
  neg180 += PvlKeyword("LongitudeDomain", "180");
  neg180 += PvlKeyword("MinimumLongitude", toString(minlon));
  neg180 += PvlKeyword("MaximumLongitude", toString(maxlon));

  // Write it to the log
  Application::Log(target);
  Application::Log(res);
  Application::Log(ugr);
  Application::Log(ogr);
  Application::Log(pos360);
  Application::Log(pos180);
  Application::Log(neg180);

  // Write the output file if requested
  if(ui.WasEntered("TO")) {
    Pvl temp;
    temp.addGroup(target);
    temp.addGroup(res);
    temp.addGroup(ugr);
    temp.addGroup(ogr);
    temp.addGroup(pos360);
    temp.addGroup(pos180);
    temp.addGroup(neg180);
    temp.write(ui.GetFileName("TO", "txt"));
  Pvl appLog;
  try {
    camrange(ui, &appLog);
  }
  catch (...) {
    for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) {
      Application::Log(*grpIt);
    }
    throw;
  }

  p.EndProcess();
  for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) {
    Application::Log(*grpIt);
  }
}
+0 −4
Original line number Diff line number Diff line
BLANKS = "%-6s"    
LENGTH = "%-40s"

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

include $(ISISROOT)/make/isismake.tsts

commands:
	$(APPNAME) from= $(INPUT)/ab102401.cub \
	  to=$(OUTPUT)/camrangeTruth1.txt > /dev/null;
	$(MV) $(OUTPUT)/camrangeTruth1.txt \
	$(OUTPUT)/camrangeTruth1.pvl > /dev/null;
Loading