diff --git a/isis/src/base/objs/Blob/Blob.cpp b/isis/src/base/objs/Blob/Blob.cpp index ba1d0e9124..44b40f6847 100644 --- a/isis/src/base/objs/Blob/Blob.cpp +++ b/isis/src/base/objs/Blob/Blob.cpp @@ -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> keywords) { + void Blob::Find(const Pvl &pvl, const QMap keywords) { bool found = false; try { // Search for the blob name @@ -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::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; @@ -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> keywords) { + void Blob::Read(const QString &file, const QMap keywords) { // Expand the filename QString temp(FileName(file).expanded()); @@ -283,7 +286,7 @@ namespace Isis { * * @throws iException::Io - Unable to open file */ - void Blob::Read(const QString &file, const Pvl &pvlLabels, const QList> keywords) { + void Blob::Read(const QString &file, const Pvl &pvlLabels, const QMap keywords) { // Expand the filename QString temp(FileName(file).expanded()); @@ -317,7 +320,7 @@ namespace Isis { * * @throws iException::Io - Unable to open file */ - void Blob::Read(const Pvl &pvl, std::istream &istm, const QList> keywords){ + void Blob::Read(const Pvl &pvl, std::istream &istm, const QMap keywords){ try { Find(pvl, keywords); ReadInit(); diff --git a/isis/src/base/objs/Blob/Blob.h b/isis/src/base/objs/Blob/Blob.h index 258ed8e2de..cea2bf3105 100644 --- a/isis/src/base/objs/Blob/Blob.h +++ b/isis/src/base/objs/Blob/Blob.h @@ -79,19 +79,19 @@ namespace Isis { int Size() const; PvlObject &Label(); - void Read(const QString &file, const QList> - keywords=QList>()); + void Read(const QString &file, const QMap + keywords=QMap()); void Read(const QString &file, const Pvl &pvlLabels, - const QList> keywords = QList>()); + const QMap keywords = QMap()); virtual void Read(const Pvl &pvl, std::istream &is, - const QList> keywords = QList>()); + const QMap keywords = QMap()); 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> keywords = QList>()); + void Find(const Pvl &pvl, const QMap keywords = QMap()); virtual void ReadInit(); virtual void ReadData(std::istream &is); virtual void WriteInit(); diff --git a/isis/src/base/objs/Cube/Cube.cpp b/isis/src/base/objs/Cube/Cube.cpp index 6352f741c6..1a1b0ff9a9 100644 --- a/isis/src/base/objs/Cube/Cube.cpp +++ b/isis/src/base/objs/Cube/Cube.cpp @@ -791,7 +791,7 @@ namespace Isis { * * @return (type)return description */ - void Cube::read(Blob &blob, const QList> keywords) const { + void Cube::read(Blob &blob, const QMap 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_); @@ -805,8 +805,6 @@ namespace Isis { QMutexLocker locker2(m_ioHandler->dataFileMutex()); blob.Read(cubeFile.toString(), *label(), keywords); } - // add optional argument QList>, default to empty - // or add new function with this signature. /** diff --git a/isis/src/base/objs/Cube/Cube.h b/isis/src/base/objs/Cube/Cube.h index f302dfa28f..aa1ac65cad 100644 --- a/isis/src/base/objs/Cube/Cube.h +++ b/isis/src/base/objs/Cube/Cube.h @@ -28,7 +28,7 @@ // This is needed for the QVariant macro #include #include -#include +#include #include @@ -260,7 +260,7 @@ namespace Isis { void reopen(QString access = "r"); void read(Blob &blob, - const QList> keywords = QList>()) const; + const QMap keywords = QMap()) const; void read(Buffer &rbuf) const; void write(Blob &blob, bool overwrite=true); void write(Buffer &wbuf); diff --git a/isis/src/base/objs/CubeStretch/CubeStretch.cpp b/isis/src/base/objs/CubeStretch/CubeStretch.cpp index 31c189abd1..a57b0b30ec 100644 --- a/isis/src/base/objs/CubeStretch/CubeStretch.cpp +++ b/isis/src/base/objs/CubeStretch/CubeStretch.cpp @@ -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 & 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 { @@ -11,7 +29,7 @@ namespace Isis { */ CubeStretch::CubeStretch() { m_name = "DefaultStretch"; - m_type = "DefaultLinear"; + m_type = "Default"; m_bandNumber = 1; } @@ -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) { } @@ -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. */ @@ -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; } diff --git a/isis/src/base/objs/CubeStretch/CubeStretch.h b/isis/src/base/objs/CubeStretch/CubeStretch.h index 3ea7563910..8f88532642 100644 --- a/isis/src/base/objs/CubeStretch/CubeStretch.h +++ b/isis/src/base/objs/CubeStretch/CubeStretch.h @@ -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 & 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 * @@ -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); diff --git a/isis/src/base/objs/CubeStretch/CubeStretch.truth b/isis/src/base/objs/CubeStretch/CubeStretch.truth deleted file mode 100644 index 8eecd6f37e..0000000000 --- a/isis/src/base/objs/CubeStretch/CubeStretch.truth +++ /dev/null @@ -1,64 +0,0 @@ -Pairs as Text: 0.0:1.0 0.25:50.0 1.0:100.0 -Number of Pairs = 3 -First Input Value = 0 -First Output Value = 1 - -Stretch(0.0): 1 -Stretch(0.125): 25.5 -Stretch(0.25): 50 -Stretch(0.625): 75 -Stretch(1.0): 100 - -Stretch(-0.1): -1.79769e+308 -Stretch(1.1): -1.79769e+308 - -Stretch(Null): 1 -Stretch(Lis): 2 -Stretch(Lrs): 3 -Stretch(His): 4 -Stretch(Hrs): 5 - -Stretch(-0.1): 3 -Stretch(1.1): 5 - -Stretch(-0.1): 6 -Stretch(1.1): 7 - -Test ClearPairs method -ClearPairs() -Pairs = 0 - - -Testing Parse -127.5 - -**USER ERROR** Invalid stretch pairs [0:0 50:0 49:255 255:255]. -**PROGRAMMER ERROR** Input pairs must be in ascending order. -**USER ERROR** Invalid stretch pairs [-5xyzzy:0 50:0 100:255 255:255]. -**ERROR** Failed to convert string [-5xyzzy] to a double. - -Testing new Parse that takes %'s for input side of pairs -75 - -**USER ERROR** Invalid stretch pairs [0:0 50:0 49:255 100:255]. -**PROGRAMMER ERROR** Input pairs must be in ascending order. -**USER ERROR** Invalid stretch pairs [-5:10]. -**PROGRAMMER ERROR** Argument percent outside of the range 0 to 100 in [Histogram::Percent]. -**USER ERROR** Invalid stretch pairs [121:215]. -**PROGRAMMER ERROR** Argument percent outside of the range 0 to 100 in [Histogram::Percent]. -**USER ERROR** Invalid stretch pairs [-5xyzzy:0 50:0 100:255]. -**ERROR** Failed to convert string [-5xyzzy] to a double. -0, 255 -100, 100 -255, 0 -testing save -0, 255 -100, 100 -255, 0 -testing copy pairs -original stretch pairs -0, 0 -255, 255 -copy stretch pairs -0, 0 -255, 255 diff --git a/isis/src/base/objs/CubeStretch/unitTest.cpp b/isis/src/base/objs/CubeStretch/unitTest.cpp deleted file mode 100644 index 282cd4ae07..0000000000 --- a/isis/src/base/objs/CubeStretch/unitTest.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include - -#include "CubeStretch.h" -#include "Preference.h" - -using namespace Isis; - -int main() { - Preference::Preferences(true); - - CubeStretch cubeStretch; - std::cout << "Created a cubStretch without immediately failing."; -} diff --git a/isis/src/base/objs/StretchBlob/StretchBlob.cpp b/isis/src/base/objs/StretchBlob/StretchBlob.cpp index d6c14b91b0..6401c4f0d7 100644 --- a/isis/src/base/objs/StretchBlob/StretchBlob.cpp +++ b/isis/src/base/objs/StretchBlob/StretchBlob.cpp @@ -1,7 +1,25 @@ /** - * NEEDED? + * @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 & 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 #include diff --git a/isis/src/base/objs/StretchBlob/StretchBlob.h b/isis/src/base/objs/StretchBlob/StretchBlob.h index 1dc03c5d0c..f16388cee7 100644 --- a/isis/src/base/objs/StretchBlob/StretchBlob.h +++ b/isis/src/base/objs/StretchBlob/StretchBlob.h @@ -1,7 +1,26 @@ #ifndef StretchBlob_h #define StretchBlob_h /** - * Still needed? + * @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 & 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 "Blob.h" @@ -14,10 +33,10 @@ namespace Isis { * * @ingroup Utility * - * @author 2020-07-28 Kristin Berry Stuart Sides + * @author 2020-07-28 Kristin Berry and Stuart Sides * * @internal - * @history 2020-07-28 Kristin Berry Stuart Sides - Original Version + * @history 2020-07-28 Kristin Berry and Stuart Sides - Original Version */ class StretchBlob : public Isis::Blob { public: diff --git a/isis/src/base/objs/StretchBlob/StretchBlob.truth b/isis/src/base/objs/StretchBlob/StretchBlob.truth deleted file mode 100644 index 8b13789179..0000000000 --- a/isis/src/base/objs/StretchBlob/StretchBlob.truth +++ /dev/null @@ -1 +0,0 @@ - diff --git a/isis/src/base/objs/StretchBlob/unitTest.cpp b/isis/src/base/objs/StretchBlob/unitTest.cpp deleted file mode 100644 index 82a131827f..0000000000 --- a/isis/src/base/objs/StretchBlob/unitTest.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include - -#include "StretchBlob.h" -#include "Preference.h" - -using namespace Isis; - -int main() { - Preference::Preferences(true); - - StretchBlob s; - - std::cout << "Creating a StretchBlob without immediate failure!" << std::endl; - - return 0; -} diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp index 5aa14a3a15..6575cb628f 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "CubeViewport.h" #include "Stretch.h" @@ -24,7 +25,7 @@ namespace Isis { setWindowTitle("Advanced Stretch Tool"); - QHBoxLayout *layout = new QHBoxLayout(); + QVBoxLayout *layout = new QVBoxLayout(); setLayout(layout); } @@ -54,17 +55,27 @@ namespace Isis { Stretch &bluStretch, Histogram &bluHist) { destroyCurrentStretches(); + QHBoxLayout* rgbLayout = new QHBoxLayout(); + p_redStretch = new AdvancedStretch(redHist, redStretch, "Red", QColor(Qt::red)); - layout()->addWidget(p_redStretch); + rgbLayout->addWidget(p_redStretch); p_grnStretch = new AdvancedStretch(grnHist, grnStretch, "Green", QColor(Qt::green)); - layout()->addWidget(p_grnStretch); + rgbLayout->addWidget(p_grnStretch); p_bluStretch = new AdvancedStretch(bluHist, bluStretch, "Blue", QColor(Qt::blue)); - layout()->addWidget(p_bluStretch); + rgbLayout->addWidget(p_bluStretch); + + ((QVBoxLayout*)layout())->addLayout(rgbLayout); + + QFrame* line = new QFrame(); + line->setFrameShape(QFrame::HLine); + line->setFrameShadow(QFrame::Sunken); + ((QVBoxLayout*)layout())->addWidget(line); + updateGeometry(); connect(p_redStretch, SIGNAL(stretchChanged()), @@ -73,6 +84,26 @@ namespace Isis { this, SIGNAL(stretchChanged())); connect(p_bluStretch, SIGNAL(stretchChanged()), this, SIGNAL(stretchChanged())); + + // Add buttons for save/load/delete stretch to RGB stretches + QPushButton *saveToCubeButton = new QPushButton("Save Stretch Pairs to Cube..."); + saveToCubeButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + connect(saveToCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(saveToCube())); + + QPushButton *deleteFromCubeButton = new QPushButton("Delete Stretch Pairs from Cube..."); + deleteFromCubeButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + connect(deleteFromCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(deleteFromCube())); + + QPushButton *loadStretchButton = new QPushButton("Restore Saved Stretch from Cube..."); + loadStretchButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + connect(loadStretchButton, SIGNAL(clicked(bool)), this, SIGNAL(loadStretch())); + + QHBoxLayout* buttonLayout = new QHBoxLayout(); + + buttonLayout->addWidget(saveToCubeButton); + buttonLayout->addWidget(deleteFromCubeButton); + buttonLayout->addWidget(loadStretchButton); + ((QBoxLayout*)layout())->addLayout(buttonLayout); } /** diff --git a/isis/src/qisis/objs/StretchTool/BinaryStretchType.cpp b/isis/src/qisis/objs/StretchTool/BinaryStretchType.cpp index 6e04a212ef..27c39687e0 100644 --- a/isis/src/qisis/objs/StretchTool/BinaryStretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/BinaryStretchType.cpp @@ -377,7 +377,12 @@ namespace Isis { } - CubeStretch BinaryStretchType::getCubeStretch() { + /** + * Gets the CubeStretch for this Binary Stretch + * + * @return CubeStretch + */ + CubeStretch BinaryStretchType::getStretch() { CubeStretch cubeStretch(*p_stretch, "Binary"); return cubeStretch; } diff --git a/isis/src/qisis/objs/StretchTool/BinaryStretchType.h b/isis/src/qisis/objs/StretchTool/BinaryStretchType.h index bca9b1a9ae..8c48dc990e 100644 --- a/isis/src/qisis/objs/StretchTool/BinaryStretchType.h +++ b/isis/src/qisis/objs/StretchTool/BinaryStretchType.h @@ -35,7 +35,7 @@ namespace Isis { const QString &name, const QColor &color); ~BinaryStretchType(); - virtual CubeStretch getCubeStretch(); + virtual CubeStretch getStretch(); virtual void setStretch(Stretch); private slots: diff --git a/isis/src/qisis/objs/StretchTool/LinearStretchType.cpp b/isis/src/qisis/objs/StretchTool/LinearStretchType.cpp index c524026abf..943c904a75 100644 --- a/isis/src/qisis/objs/StretchTool/LinearStretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/LinearStretchType.cpp @@ -255,13 +255,14 @@ namespace Isis { } } - Stretch LinearStretchType::getStretch() { - return *p_stretch; - } - CubeStretch LinearStretchType::getCubeStretch() { + /** + * Returns the CubeStretch for this LinearStretch + * + * @return CubeStretch + */ + CubeStretch LinearStretchType::getStretch() { CubeStretch cubeStretch(*p_stretch, "Linear"); return cubeStretch; } - } diff --git a/isis/src/qisis/objs/StretchTool/LinearStretchType.h b/isis/src/qisis/objs/StretchTool/LinearStretchType.h index ec9f77ef43..951f6fe39a 100644 --- a/isis/src/qisis/objs/StretchTool/LinearStretchType.h +++ b/isis/src/qisis/objs/StretchTool/LinearStretchType.h @@ -34,8 +34,7 @@ namespace Isis { const QString &name, const QColor &color); ~LinearStretchType(); - virtual Stretch getStretch(); - virtual CubeStretch getCubeStretch(); + virtual CubeStretch getStretch(); virtual void setStretch(Stretch); private slots: diff --git a/isis/src/qisis/objs/StretchTool/ManualStretchType.cpp b/isis/src/qisis/objs/StretchTool/ManualStretchType.cpp index 360e90c42d..ee4ca50cd3 100644 --- a/isis/src/qisis/objs/StretchTool/ManualStretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/ManualStretchType.cpp @@ -151,7 +151,13 @@ namespace Isis { return stretch; } - CubeStretch ManualStretchType::getCubeStretch() { + +/** + * Gets the current CubeStretch for this ManualStretch. + * + * @return CubeStretch + */ + CubeStretch ManualStretchType::getStretch() { CubeStretch cubeStretch(*p_stretch, "Manual"); return cubeStretch; } diff --git a/isis/src/qisis/objs/StretchTool/ManualStretchType.h b/isis/src/qisis/objs/StretchTool/ManualStretchType.h index cf3dd6044d..62c160f29d 100644 --- a/isis/src/qisis/objs/StretchTool/ManualStretchType.h +++ b/isis/src/qisis/objs/StretchTool/ManualStretchType.h @@ -37,7 +37,7 @@ namespace Isis { const QString &name, const QColor &color); ~ManualStretchType(); - virtual CubeStretch getCubeStretch(); + virtual CubeStretch getStretch(); virtual void setStretch(Stretch); private slots: diff --git a/isis/src/qisis/objs/StretchTool/SawtoothStretchType.cpp b/isis/src/qisis/objs/StretchTool/SawtoothStretchType.cpp index 8dc5c89b81..965f972c00 100644 --- a/isis/src/qisis/objs/StretchTool/SawtoothStretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/SawtoothStretchType.cpp @@ -310,7 +310,13 @@ namespace Isis { p_widthEdit->text().toDouble()); } - CubeStretch SawtoothStretchType::getCubeStretch() { + + /** + * Gets the CubeStretch for this Sawtooth Stretch. + * + * @return CubeStretch + */ + CubeStretch SawtoothStretchType::getStretch() { CubeStretch cubeStretch(*p_stretch, "Sawtooth"); return cubeStretch; } diff --git a/isis/src/qisis/objs/StretchTool/SawtoothStretchType.h b/isis/src/qisis/objs/StretchTool/SawtoothStretchType.h index 3d0f6aaa3c..cfee0846a7 100644 --- a/isis/src/qisis/objs/StretchTool/SawtoothStretchType.h +++ b/isis/src/qisis/objs/StretchTool/SawtoothStretchType.h @@ -38,7 +38,7 @@ namespace Isis { const QString &name, const QColor &color); ~SawtoothStretchType(); - virtual CubeStretch getCubeStretch(); + virtual CubeStretch getStretch(); virtual void setStretch(Stretch); private slots: diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index ecbc96b981..a15c5ebc2c 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -347,7 +347,7 @@ namespace Isis { } } } - //Otherwise it is in color mode + // Otherwise it is in color mode else if(!cvp->isGray() && !cvp->redBuffer()->working() && !cvp->greenBuffer()->working() && @@ -410,7 +410,6 @@ namespace Isis { Cube* icube = cvp->cube(); Pvl* lab = icube->label(); - QStringList namelist; // Create a list of existing Stretch names @@ -462,9 +461,17 @@ namespace Isis { } bool ok; - QString stretchName = QInputDialog::getItem((QWidget*)parent(), tr("Load Stretch"), - tr("Name of Stretch to Load:"), namelist, 0, - false, &ok); + QString stretchName; + // Only display load stretch dialog if there are stretches saved to the cube + if (namelist.size() >=1) { + stretchName = QInputDialog::getItem((QWidget *)parent(), tr("Load Stretch"), + tr("Name of Stretch to Load:"), namelist, 0, + false, &ok); + } + else { + QMessageBox::information((QWidget *)parent(), "Information", + "There are no saved stretches to restore."); + } if (ok) { if (cvp->isGray()) { @@ -481,21 +488,18 @@ namespace Isis { StretchBlob greenStretchBlob(stretchName); StretchBlob blueStretchBlob(stretchName); - QPair keywordValue = {"BandNumber", QString::number(cvp->redBand())}; - QList> keywordValueList; - keywordValueList.append(keywordValue); + QMap keywordValueRed; + keywordValueRed["BandNumber"] = QString::number(cvp->redBand()); - QPair keywordValueGreen = {"BandNumber", QString::number(cvp->greenBand())}; - QList> keywordValueListGreen; - keywordValueListGreen.append(keywordValueGreen); + QMap keywordValueGreen; + keywordValueGreen["BandNumber"] = QString::number(cvp->greenBand()); - QPair keywordValueBlue = {"BandNumber", QString::number(cvp->blueBand())}; - QList> keywordValueListBlue; - keywordValueListBlue.append(keywordValueBlue); + QMap keywordValueBlue; + keywordValueBlue["BandNumber"] = QString::number(cvp->blueBand()); - icube->read(redStretchBlob, keywordValueList); - icube->read(greenStretchBlob, keywordValueListGreen); - icube->read(blueStretchBlob, keywordValueListBlue); + icube->read(redStretchBlob, keywordValueRed); + icube->read(greenStretchBlob, keywordValueGreen); + icube->read(blueStretchBlob, keywordValueBlue); CubeStretch redStretch = redStretchBlob.getStretch(); CubeStretch greenStretch = greenStretchBlob.getStretch(); @@ -536,9 +540,18 @@ namespace Isis { } bool ok; - QString toDelete = QInputDialog::getItem((QWidget*)parent(), tr("Delete Stretch"), - tr("Name of Stretch to Delete:"), namelist, 0, - false, &ok); + QString toDelete; + // Only display list of stretches to delete if there are stretches saved to the cube + if (namelist.size() >= 1) { + toDelete = QInputDialog::getItem((QWidget *)parent(), tr("Delete Stretch"), + tr("Name of Stretch to Delete:"), namelist, 0, + false, &ok); + } + else { + QMessageBox::information((QWidget *)parent(), "Information", + "There are no saved stretches to delete."); + } + if (ok) { if (icube->isReadOnly()) { try { @@ -592,6 +605,40 @@ namespace Isis { bool ok; QString name; + // + // At this time, it is NOT possible to save an RGB stretch with the same band number + // multiple times, if the saved stretch for each is different. If the saved stretch is the same + // this is okay. + // + // For example, r=1, g=1, b=1, with the same stretch for each is okay + // r=1, g=1, b=2, where the stretches for band 1 are the same, is okay + // r=1, g=1, b=1, where the the stretches for band 1 are different (red stretch != + // green stretch) + // + if (!cvp->isGray()) { + CubeStretch redStretch, greenStretch, blueStretch; + if (m_advancedStretch->isVisible()) { + redStretch = m_advancedStretch->getRedStretch(); + greenStretch = m_advancedStretch->getGrnStretch(); + blueStretch = m_advancedStretch->getBluStretch(); + } + else { + redStretch = cvp->redStretch(); + greenStretch = cvp->greenStretch(); + blueStretch = cvp->blueStretch(); + } + int redBand = redStretch.getBandNumber(); + int greenBand = greenStretch.getBandNumber(); + int blueBand = blueStretch.getBandNumber(); + + if (((redBand == greenBand) && !(redStretch == greenStretch)) || + ((redBand == blueBand) && !(redBand == blueBand)) || + ((greenBand == blueBand) && !(greenBand == blueBand))) { + QMessageBox::information((QWidget *)parent(), "Error", "Sorry, cannot save RGB stretches which include the same band multiple times, but have different stretches for each"); + return; + } + } + // "Get the name for the stretch" dialog QString text = QInputDialog::getText(m_advancedStretch, tr("Save Stretch"), tr("Enter a name to save the stretch as:"), QLineEdit::Normal, diff --git a/isis/src/qisis/objs/StretchTool/StretchType.cpp b/isis/src/qisis/objs/StretchTool/StretchType.cpp index 3112a22d5e..f5cb511208 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchType.cpp @@ -186,7 +186,7 @@ namespace Isis { Stretch stretch = getStretch(); - //Add the pairs to the file + // Add the pairs to the file stream << stretch.Text() << endl; outfile.close(); @@ -198,11 +198,7 @@ namespace Isis { * * @return Stretch */ - Stretch StretchType::getStretch() { - return *p_stretch; - } - - CubeStretch StretchType::getCubeStretch() { + CubeStretch StretchType::getStretch() { CubeStretch cubeStretch(*p_stretch); return cubeStretch; } diff --git a/isis/src/qisis/objs/StretchTool/StretchType.h b/isis/src/qisis/objs/StretchTool/StretchType.h index 29f6960fae..eb5165c580 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.h +++ b/isis/src/qisis/objs/StretchTool/StretchType.h @@ -45,8 +45,7 @@ namespace Isis { virtual ~StretchType(); - virtual Stretch getStretch(); - virtual CubeStretch getCubeStretch(); + virtual CubeStretch getStretch(); /** * Children must re-implement this to update their stretch pairs and GUI * elements appropriately. This could be called with a diff --git a/isis/tests/CubeStretchTest.cpp b/isis/tests/CubeStretchTest.cpp new file mode 100644 index 0000000000..0e22333fa9 --- /dev/null +++ b/isis/tests/CubeStretchTest.cpp @@ -0,0 +1,58 @@ +#include "Stretch.h" +#include "CubeStretch.h" +#include "IException.h" + +#include +#include + +#include + +TEST(CubeStretch, DefaultConstructor) { + Isis::CubeStretch cubeStretch; + EXPECT_STREQ(cubeStretch.getName().toLatin1().data(), "DefaultStretch"); + EXPECT_STREQ(cubeStretch.getType().toLatin1().data(), "Default"); + EXPECT_EQ(cubeStretch.getBandNumber(), 1); +} + +TEST(CubeStretch, ConstructorWithName) { + Isis::CubeStretch cubeStretch("name"); + EXPECT_STREQ(cubeStretch.getName().toLatin1().data(), "name"); + EXPECT_STREQ(cubeStretch.getType().toLatin1().data(), "Default"); + EXPECT_EQ(cubeStretch.getBandNumber(), 1); +} + + +TEST(CubeStretch, ConstructorAllArge) { + Isis::CubeStretch cubeStretch("name", "type", 99); + EXPECT_STREQ(cubeStretch.getName().toLatin1().data(), "name"); + EXPECT_STREQ(cubeStretch.getType().toLatin1().data(), "type"); + EXPECT_EQ(cubeStretch.getBandNumber(), 99); +} + +TEST(CubeStretch, Equality) { + Isis::CubeStretch cubeStretch99("name", "type", 99); + Isis::CubeStretch cubeStretch9("name", "type", 9); + Isis::CubeStretch cubeStretchOtherName("othername", "type", 9); + + EXPECT_FALSE(cubeStretch99 == cubeStretch9); + EXPECT_FALSE(cubeStretch9 == cubeStretchOtherName); +} + +TEST(CubeStretch, GetSetType) { + Isis::CubeStretch cubeStretch("name", "type", 99); + cubeStretch.setType("NewType"); + EXPECT_STREQ(cubeStretch.getType().toLatin1().data(), "NewType"); +} + +TEST(CubeStretch, GetSetName) { + Isis::CubeStretch cubeStretch("name", "type", 99); + cubeStretch.setName("NewName"); + EXPECT_STREQ(cubeStretch.getName().toLatin1().data(), "NewName"); +} + +TEST(CubeStretch, GetSetBandNumber) { + Isis::CubeStretch cubeStretch("name", "type", 99); + cubeStretch.setBandNumber(50); + EXPECT_EQ(cubeStretch.getBandNumber(), 50); +} + diff --git a/isis/tests/StretchBlobTest.cpp b/isis/tests/StretchBlobTest.cpp new file mode 100644 index 0000000000..cb5eb9c14c --- /dev/null +++ b/isis/tests/StretchBlobTest.cpp @@ -0,0 +1,57 @@ +#include "CubeStretch.h" +#include "StretchBlob.h" +#include "IException.h" +#include "Cube.h" +#include "TestUtilities.h" +#include "Fixtures.h" + +#include +#include + +#include +#include "gmock/gmock.h" + +using namespace Isis; + +TEST(StretchBlob, Constructors) { + // Default + StretchBlob stretchBlob; + + // Set Name + StretchBlob nameStretchBlob("name"); + + // Set Stretch + CubeStretch cubeStretch("CetStretch", "defaultType", 1); + StretchBlob stretchStretchBlob(cubeStretch); + + EXPECT_STREQ(stretchBlob.Name().toLatin1().data(), "CubeStretch"); + EXPECT_STREQ(stretchBlob.Type().toLatin1().data(), "Stretch"); + + EXPECT_STREQ(nameStretchBlob.Name().toLatin1().data(), "name"); + EXPECT_STREQ(nameStretchBlob.Type().toLatin1().data(), "Stretch"); + + EXPECT_STREQ(stretchStretchBlob.Name().toLatin1().data(), "CubeStretch"); + EXPECT_STREQ(stretchStretchBlob.Type().toLatin1().data(), "Stretch"); +}; + +TEST_F(DefaultCube, StretchBlobWriteRead) { + // Set up Stretch to write + QString stretchName = "TestStretch"; + CubeStretch cubeStretch("TestStretch", "defaultType", 1); + + // add pair(s) + cubeStretch.AddPair(0.0, 1.0); + cubeStretch.AddPair(0.25, 50.0); + cubeStretch.AddPair(1.0, 100.0); + Isis::StretchBlob stretchBlob(cubeStretch); + + // Write to Cube + testCube->write(stretchBlob); + + // Set up stretch and blob to restore to + StretchBlob restoreBlob(stretchName); + testCube->read(restoreBlob); + CubeStretch restoredStretch = stretchBlob.getStretch(); + + EXPECT_TRUE(restoredStretch == cubeStretch); +};