Unverified Commit 6acfc314 authored by Kelvin Rodriguez's avatar Kelvin Rodriguez Committed by GitHub
Browse files

Adds new method to contruct cubes (#3675)



* added new methods to Cube, tried to update spiceinit and cube tests

* fixed errors

* tweaks

* syntax errors

* re-added cout line that was suppoed to be there

* updates as per comments

* tempfile.open() lmao

* revert j flag

Co-authored-by: default avatarpaarongiroux <47163875+paarongiroux@users.noreply.github.com>
parent bd5292db
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -36,7 +36,6 @@ namespace Isis {

  void requestSpice(Cube *icube, UserInterface &ui, Pvl *log, Pvl &labels, QString missionName);


  /**
   * Spiceinit a cube in an Application
   *
+51 −5
Original line number Diff line number Diff line
@@ -73,6 +73,52 @@ namespace Isis {
    open(fileName.toString(), access);
  }

  /**
   * Initialize Cube data from a PVL label.
   *
   * @param fileName Name of the cube file to open. Environment
   *     variables in the filename will be automatically expanded.
   * @param label PVL label to use when initializing cube 
   * @param access Defines how the cube will be opened. Either read-only
   *     "r" or read-write "rw".
   */
  void Cube::fromLabel(const FileName &fileName, Pvl &label, QString access) {
    PvlObject cubeLabel = label.findObject("IsisCube");
    PvlGroup dimensions = cubeLabel.findObject("Core").findGroup("Dimensions");
    close();

    setDimensions(dimensions["Samples"],
                          dimensions["Lines"],
                          dimensions["Bands"]);

    create(fileName.expanded());

    for (auto grpIt = cubeLabel.beginGroup(); grpIt!= cubeLabel.endGroup(); grpIt++) {
      putGroup(*grpIt);
    }

    close();
    open(fileName.toString(), access);
  }

  /**
   * Initialize Cube data from a PVL label and JSON ISD.
   *
   * @param fileName Name of the cube file to open. Environment
   *     variables in the filename will be automatically expanded.
   * @param label PVL label to use when initializing cube 
   * @param isd Ale compatible ISD to be used for initing spice data
   * @param access Defines how the cube will be opened. Either read-only
   *     "r" or read-write "rw".
   */
  void Cube::fromIsd(const FileName &fileName, Pvl &label, nlohmann::json &isd, QString access) {
    fromLabel(fileName, label, access);
    attachSpiceFromIsd(isd);

    close();
    open(fileName.toString(), access);
  }


  //! Destroys the Cube object.
  Cube::~Cube() {
+9 −5
Original line number Diff line number Diff line
@@ -173,6 +173,7 @@ namespace Isis {
    public:
      Cube();
      Cube(const FileName &fileName, QString access = "r");
      
      virtual ~Cube();

      /**
@@ -236,6 +237,9 @@ namespace Isis {
        Tile
      };

      void fromIsd(const FileName &fileName, Pvl &label, nlohmann::json &isd, QString access);
      void fromLabel(const FileName &fileName, Pvl &label, QString access);

      bool isOpen() const;
      bool isProjected() const;
      bool isReadOnly() const;
+2 −0
Original line number Diff line number Diff line
@@ -603,6 +603,8 @@ namespace Isis {
              }
            }
          }

          cout << commandline << endl;
          return;
        }

+7 −5
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ using json = nlohmann::json;

using namespace Isis;

TEST_F(TestCube, TestCubeAttachSpiceFromIsd) {
TEST(CubeTest, TestCubeAttachSpiceFromIsd) {
  std::istringstream labelStrm(R"(
    Object = IsisCube
      Object = Core
@@ -208,7 +208,9 @@ TEST_F(TestCube, TestCubeAttachSpiceFromIsd) {
  Pvl label;
  labelStrm >> label;

  createCube(label, isd);
  QTemporaryFile tempFile;
  Cube testCube;
  testCube.fromIsd(tempFile.fileName() + ".cub", label, isd, "rw");

  PvlGroup kernels = testCube.group("Kernels");

Loading