Skip to content

Commit

Permalink
Cleaning up lose ends on Stretch Refactor (#3970)
Browse files Browse the repository at this point in the history
* Stretch refactor inital move of Blob out of Stretch and creation of StretchBlob and CubeStretch classes

* Cleanup and move setting of name into CubeStretch class

* Add band numbers initial work

* Added the ability to save the band number to the stretch blob and also only list saved stretches with current band number to restore/delete

* Moves primary save/load/delete to StretchTool from AdvancedStretchTool. Buttons in AdvancedStretchTool work as previously

* Get RGB stretches working, first draft

* Add CubeStretch and StretchBlob

* Update Blob.cpp

Commented the new parameter for Find

* Update saved stretches for RGB from the advanced stretch tool

* Remove couts and cleanup merge

* Re-remove save/load/restore buttons from RGB StretchType panels

* Update button name from Load to Restore

* Remove unused color/grayscale type from StretchBlob output, clean up redundant functions, improve method names

* Update button location for AdvancedStretchTool

* Switch Blob and Cube Reader filter list from QList<QPair> to QMap

* Add documentation to new classes, update to not allow you to select or delete a saved stretch if none exist, and add pop up box for multiband with same band but different stretch no-supported.

* Add gtests and delete old-style tests

* Add missing StretchBlob test

* Update Blob.cpp

Co-authored-by: Stuart Sides <[email protected]>
  • Loading branch information
krlberry and scsides authored Aug 11, 2020
1 parent b7aff8c commit 4e44358
Show file tree
Hide file tree
Showing 26 changed files with 417 additions and 178 deletions.
15 changes: 9 additions & 6 deletions isis/src/base/objs/Blob/Blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ namespace Isis {
* when there are multiple blobs with the same name, but different keywords that
* define the exact blob (see Stretch with a band number)
*/
void Blob::Find(const Pvl &pvl, const QList<QPair<QString,QString>> keywords) {
void Blob::Find(const Pvl &pvl, const QMap<QString, QString> keywords) {
bool found = false;
try {
// Search for the blob name
Expand All @@ -191,12 +191,15 @@ namespace Isis {
QString curName = obj["Name"];
curName = curName.toUpper();
if (blobName == curName) {

if (keywords.size() >= 1) {
found = true;
for (int i=0; i < keywords.size(); i++) {
if(obj.hasKeyword(keywords[i].first) && (keywords[i].second != obj[keywords[i].first])) {
QMap<QString, QString>::const_iterator i = keywords.constBegin();
while (i != keywords.constEnd()) {
if (obj.hasKeyword(i.key()) && (i.value() != obj[i.key()])) {
found = false;
}
++i;
}
if (found) {
p_blobPvl = obj;
Expand Down Expand Up @@ -259,7 +262,7 @@ namespace Isis {
* @throws iException::Io - Unable to open file
* @throws iException::Pvl - Invalid label format
*/
void Blob::Read(const QString &file, const QList<QPair<QString,QString>> keywords) {
void Blob::Read(const QString &file, const QMap<QString,QString> keywords) {
// Expand the filename
QString temp(FileName(file).expanded());

Expand All @@ -283,7 +286,7 @@ namespace Isis {
*
* @throws iException::Io - Unable to open file
*/
void Blob::Read(const QString &file, const Pvl &pvlLabels, const QList<QPair<QString,QString>> keywords) {
void Blob::Read(const QString &file, const Pvl &pvlLabels, const QMap<QString,QString> keywords) {
// Expand the filename
QString temp(FileName(file).expanded());

Expand Down Expand Up @@ -317,7 +320,7 @@ namespace Isis {
*
* @throws iException::Io - Unable to open file
*/
void Blob::Read(const Pvl &pvl, std::istream &istm, const QList<QPair<QString,QString>> keywords){
void Blob::Read(const Pvl &pvl, std::istream &istm, const QMap<QString,QString> keywords){
try {
Find(pvl, keywords);
ReadInit();
Expand Down
10 changes: 5 additions & 5 deletions isis/src/base/objs/Blob/Blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ namespace Isis {
int Size() const;
PvlObject &Label();

void Read(const QString &file, const QList<QPair<QString,QString>>
keywords=QList<QPair<QString,QString>>());
void Read(const QString &file, const QMap<QString,QString>
keywords=QMap<QString,QString>());
void Read(const QString &file, const Pvl &pvlLabels,
const QList<QPair<QString,QString>> keywords = QList<QPair<QString,QString>>());
const QMap<QString,QString> keywords = QMap<QString,QString>());
virtual void Read(const Pvl &pvl, std::istream &is,
const QList<QPair<QString,QString>> keywords = QList<QPair<QString,QString>>());
const QMap<QString,QString> keywords = QMap<QString,QString>());

void Write(const QString &file);
void Write(Pvl &pvl, std::fstream &stm,
const QString &detachedFileName = "", bool overwrite=true);

protected:
void Find(const Pvl &pvl, const QList<QPair<QString,QString>> keywords = QList<QPair<QString,QString>>());
void Find(const Pvl &pvl, const QMap<QString,QString> keywords = QMap<QString,QString>());
virtual void ReadInit();
virtual void ReadData(std::istream &is);
virtual void WriteInit();
Expand Down
4 changes: 1 addition & 3 deletions isis/src/base/objs/Cube/Cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ namespace Isis {
*
* @return (type)return description
*/
void Cube::read(Blob &blob, const QList<QPair<QString,QString>> keywords) const {
void Cube::read(Blob &blob, const QMap<QString,QString> keywords) const {
if (!isOpen()) {
string msg = "The cube is not opened so you can't read a blob from it";
throw IException(IException::Programmer, msg, _FILEINFO_);
Expand All @@ -805,8 +805,6 @@ namespace Isis {
QMutexLocker locker2(m_ioHandler->dataFileMutex());
blob.Read(cubeFile.toString(), *label(), keywords);
}
// add optional argument QList<QPair<QString, QString>>, default to empty
// or add new function with this signature.


/**
Expand Down
4 changes: 2 additions & 2 deletions isis/src/base/objs/Cube/Cube.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// This is needed for the QVariant macro
#include <QMetaType>
#include <QList>
#include <QPair>
#include <QMap>

#include <nlohmann/json.hpp>

Expand Down Expand Up @@ -260,7 +260,7 @@ namespace Isis {
void reopen(QString access = "r");

void read(Blob &blob,
const QList<QPair<QString,QString>> keywords = QList<QPair<QString,QString>>()) const;
const QMap<QString,QString> keywords = QMap<QString,QString>()) const;
void read(Buffer &rbuf) const;
void write(Blob &blob, bool overwrite=true);
void write(Buffer &wbuf);
Expand Down
96 changes: 82 additions & 14 deletions isis/src/base/objs/CubeStretch/CubeStretch.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
/**
* Do we still need this??
* @file
* $Revision: 1.19 $
* $Date: 2010/03/22 19:44:53 $
*
* Unless noted otherwise, the portions of Isis written by the USGS are
* public domain. See individual third-party library and package descriptions
* for intellectual property information, user agreements, and related
* information.
*
* Although Isis has been used by the USGS, no warranty, expressed or
* implied, is made by the USGS as to the accuracy and functioning of such
* software and related material nor shall the fact of distribution
* constitute any such warranty, and no responsibility is assumed by the
* USGS in connection therewith.
*
* For additional information, launch
* $ISISROOT/doc//documents/Disclaimers/Disclaimers.html
* in a browser or see the Privacy &amp; Disclaimers page on the Isis website,
* http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on
* http://www.usgs.gov/privacy.html.
*/

#include "CubeStretch.h"

namespace Isis {
Expand All @@ -11,7 +29,7 @@ namespace Isis {
*/
CubeStretch::CubeStretch() {
m_name = "DefaultStretch";
m_type = "DefaultLinear";
m_type = "Default";
m_bandNumber = 1;
}

Expand All @@ -20,23 +38,23 @@ namespace Isis {
* Constructs a Stretch object with default mapping of special pixel values to
* themselves and a provided name.
*
* @param name Name to use for Stretch
* @param name Name to use for CubeStretch
*/
CubeStretch::CubeStretch(QString name) : m_name(name) {
m_type = "DefaultLinear";
m_type = "Default";
m_bandNumber = 1;
}


/**
* Constructs a Stretch object with default mapping of special pixel values to
* Constructs a CubeStretch object with default mapping of special pixel values to
* themselves and a provided name, and a provided stretch type
*
* @param name Name to use for Stretch
* @param type Type of stretch
*/
CubeStretch::CubeStretch(QString name, QString stretchType, int bandNumber) : m_name(name), m_type(stretchType) {
m_bandNumber = bandNumber;
CubeStretch::CubeStretch(QString name, QString stretchType, int bandNumber) : m_name(name),
m_type(stretchType), m_bandNumber(bandNumber) {
}


Expand All @@ -45,23 +63,44 @@ namespace Isis {
}


// semi-copy constructor
/**
* Constructs a CubeStretch object from a normal Stretch.
*
* @param Stretch Stretch to construct the CubeStretch from.
*/
CubeStretch::CubeStretch(Stretch const& stretch): Stretch(stretch) {
m_name = "Unknown";
m_name = "DefaultStretch";
m_bandNumber = 1;
m_type = "Default";
}



// semi-copy constructor
/**
* Constructs a CubeStretch object from a normal Stretch.
*
* @param Stretch Stretch to construct the CubeStretch from.
*/
CubeStretch::CubeStretch(Stretch const& stretch, QString stretchType): Stretch(stretch), m_type(stretchType) {
m_name = "Unknown";
m_name = "DefaultName";
m_bandNumber = 1;
}


/**
* Check if the CubeStretches are equal
*
* @param stretch2 The stretch to compare with
*
* @return bool True if stretches are equal. Else, false.
*/
bool CubeStretch::operator==(CubeStretch& stretch2) {
return (getBandNumber() == stretch2.getBandNumber()) &&
(getName() == stretch2.getName()) &&
(Text() == stretch2.Text());
}

/**
* Get the Type of Stretch. This is only used by the AdvancedStretchTool.
* Get the Type of Stretch.
*
* @return QString Type of Stretch.
*/
Expand All @@ -70,22 +109,51 @@ namespace Isis {
}


/**
* Set the type of Stretch.
*
* @param QString Type of Stretch.
*/
void CubeStretch::setType(QString stretchType){
m_type = stretchType;
}


/**
* Set the Stretch name.
*
* @param QString name for stretch
*/
void CubeStretch::setName(QString name){
m_name = name;
}


/**
* Get the Stretch name.
*
* @return QString name of stretch
*/
QString CubeStretch::getName(){
return m_name;
}


/**
* Get the band number for the stretch.
*
* @return int band number
*/
int CubeStretch::getBandNumber() {
return m_bandNumber;
}


/**
* Set the band number for the stretch.
*
* @param int band number
*/
void CubeStretch::setBandNumber(int bandNumber) {
m_bandNumber = bandNumber;
}
Expand Down
30 changes: 26 additions & 4 deletions isis/src/base/objs/CubeStretch/CubeStretch.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
#ifndef CubeStretch_h
#define CubeStretch_h

/**
* Do we still need the big block of info up here?
*/
* @file
* $Revision: 1.17 $
* $Date: 2010/03/22 19:44:53 $
*
* Unless noted otherwise, the portions of Isis written by the USGS are
* public domain. See individual third-party library and package descriptions
* for intellectual property information, user agreements, and related
* information.
*
* Although Isis has been used by the USGS, no warranty, expressed or
* implied, is made by the USGS as to the accuracy and functioning of such
* software and related material nor shall the fact of distribution
* constitute any such warranty, and no responsibility is assumed by the
* USGS in connection therewith.
*
* For additional information, launch
* $ISISROOT/doc//documents/Disclaimers/Disclaimers.html
* in a browser or see the Privacy &amp; Disclaimers page on the Isis website,
* http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on
* http://www.usgs.gov/privacy.html.
*/

#include "Stretch.h"
#include "StretchBlob.h"

namespace Isis {
/**
* @brief Stores stretch information for a cube.
* @brief Stores stretch information for a cube. Stores stretch pairs,
* band number associated with the stretch, and the stretch type from
* the Advanced Stretch Tool (or 'Default' if not specified)
*
* @ingroup Utility
*
Expand All @@ -30,6 +50,8 @@ namespace Isis {
CubeStretch(Stretch const& stretch, QString type);
CubeStretch(Stretch const& stretch, QString type, QString name, int bandNumber=1);

bool operator==(CubeStretch& stretch2);

QString getType();
void setType(QString stretchType);

Expand Down
64 changes: 0 additions & 64 deletions isis/src/base/objs/CubeStretch/CubeStretch.truth

This file was deleted.

Loading

0 comments on commit 4e44358

Please sign in to comment.