Unverified Commit 7a7ef6fb authored by Kelvin Rodriguez's avatar Kelvin Rodriguez Committed by GitHub
Browse files

added apollocal tests (#4117)

* added apollocal tests

* added apollocal test

* added ap conversions

* pointer dumb, now smart
parent 85d96b13
Loading
Loading
Loading
Loading
+76 −0
Original line number Diff line number Diff line
#include "CubeAttribute.h"
#include "ProcessByTile.h"
#include "Pvl.h"
#include "PvlTranslationTable.h"
#include "SpecialPixel.h"
#include "UserInterface.h"

#include "apollocal.h"

using namespace std;


namespace Isis {
  void cal(vector<Buffer *> &in, 
         vector<Buffer *> &out);

  
  void apollocal(UserInterface &ui) {
    Cube cube(ui.GetFileName("FROM"), "r");
    apollocal(&cube, ui);
  }
  
  
  void apollocal(Cube *inCube, UserInterface &ui) {
    // We will be processing by line
    ProcessByTile p;
    p.SetTileSize(128, 128);
  
    p.SetInputCube(inCube);
  
    PvlGroup &dataDir =
        Preference::Preferences().findGroup("DataDirectory");
    PvlTranslationTable tTable("$ISISROOT/appdata/translations/MissionName2DataDir.trn");
    QString missionDir = dataDir[tTable.Translate("MissionName",
        (inCube->group("Instrument")).findKeyword("SpacecraftName")[0])][0];
    QString camera =
        (inCube->group("Instrument")).findKeyword("InstrumentId")[0];
  
    CubeAttributeInput cai;
    p.SetInputCube(missionDir + "/calibration/" + camera + "_flatfield.cub", cai);
  
    CubeAttributeOutput cao;
    cao.setPixelType(Real);
    p.SetOutputCube(
        FileName(ui.GetAsString("TO")).expanded(),
        cao, inCube->sampleCount(), inCube->lineCount(),
        inCube->bandCount());
  
    p.StartProcess(cal);
    p.EndProcess();
  }


  void cal(vector<Buffer *> &in, vector<Buffer *> &out) {
    Buffer &inp = *in[0];      // Input Cube
    Buffer &fff = *in[1];      // Flat Field File
    Buffer &outp = *out[0];    // Output Cube
  
    
    // Loop for each pixel in the line.
    for (int i=0; i<inp.size(); i++) {
      if (IsSpecial(inp[i])) {
        outp[i] = inp[i];
      }
      else if (IsSpecial(fff[i])) {
        outp[i] = Null;
      }
      else {
        // Log Filter the film negative (and multiply by 2^16/16 to maintain the range of values)
        outp[i] = 65535.0*(1.0 - log(65536 - inp[i])/log(2.0)/16.0);
        outp[i] -=  1300.0;    // subtract dark current
        outp[i] /= fff[i];    // divide flat field to remove vignetting effects
      }
    }
  }
}
 No newline at end of file
+12 −0
Original line number Diff line number Diff line
#ifndef apollocal_h // Change this to your app name in all lower case suffixed with _h (e.g. campt_h, cam2map_h etc.)
#define apollocal_h

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

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

#endif
 No newline at end of file
+5 −60
Original line number Diff line number Diff line
#include "Isis.h"

#include "CubeAttribute.h"
#include "ProcessByTile.h"
#include "Pvl.h"
#include "PvlTranslationTable.h"
#include "SpecialPixel.h"
#include "Application.h"
#include "apollocal.h"

using namespace std;
using namespace Isis;

void cal(vector<Buffer *> &in, 
         vector<Buffer *> &out);

void IsisMain() {
  // We will be processing by line
  ProcessByTile p;
  p.SetTileSize(128, 128);

  Cube *inCube = p.SetInputCube("FROM");

  PvlGroup &dataDir =
      Preference::Preferences().findGroup("DataDirectory");
  PvlTranslationTable tTable("$ISISROOT/appdata/translations/MissionName2DataDir.trn");
  QString missionDir = dataDir[tTable.Translate("MissionName",
      (inCube->group("Instrument")).findKeyword("SpacecraftName")[0])][0];
  QString camera =
      (inCube->group("Instrument")).findKeyword("InstrumentId")[0];

  CubeAttributeInput cai;
  p.SetInputCube(missionDir + "/calibration/" + camera + "_flatfield.cub", cai);

  CubeAttributeOutput cao;
  cao.setPixelType(Real);
  p.SetOutputCube(
      FileName(Application::GetUserInterface().GetAsString("TO")).expanded(),
      cao, inCube->sampleCount(), inCube->lineCount(),
      inCube->bandCount());

  p.StartProcess(cal);
  p.EndProcess();
}


void cal(vector<Buffer *> &in, vector<Buffer *> &out) {
  Buffer &inp = *in[0];      // Input Cube
  Buffer &fff = *in[1];      // Flat Field File
  Buffer &outp = *out[0];    // Output Cube

  
  // Loop for each pixel in the line.
  for (int i=0; i<inp.size(); i++) {
    if (IsSpecial(inp[i])) {
      outp[i] = inp[i];
    }
    else if (IsSpecial(fff[i])) {
      outp[i] = Null;
    }
    else {
      // Log Filter the film negative (and multiply by 2^16/16 to maintain the range of values)
      outp[i] = 65535.0*(1.0 - log(65536 - inp[i])/log(2.0)/16.0);
      outp[i] -=  1300.0;    // subtract dark current
      outp[i] /= fff[i];    // divide flat field to remove vignetting effects
    }
  }
  UserInterface &ui = Application::GetUserInterface();
  apollocal(ui);
}
 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 −8
Original line number Diff line number Diff line
APPNAME = apollocal

include $(ISISROOT)/make/isismake.tsts

commands:
	$(APPNAME) FROM=$(INPUT)/apollowarptrimmed.cub \
	TO=$(OUTPUT)/apollocaltrimmed.cub > /dev/null;
Loading