From cd722a0a54e6ebd419e2f4cf04a79dd26645377c Mon Sep 17 00:00:00 2001 From: Kristin Date: Thu, 30 Jul 2020 12:55:46 -0700 Subject: [PATCH 01/19] Stretch refactor inital move of Blob out of Stretch and creation of StretchBlob and CubeStretch classes --- isis/src/base/objs/Stretch/Stretch.cpp | 106 +----------------- isis/src/base/objs/Stretch/Stretch.h | 14 +-- .../objs/StretchTool/AdvancedStretch.cpp | 19 ++-- .../qisis/objs/StretchTool/AdvancedStretch.h | 8 +- .../StretchTool/AdvancedStretchDialog.cpp | 19 +++- .../objs/StretchTool/AdvancedStretchDialog.h | 4 +- .../objs/StretchTool/BinaryStretchType.cpp | 9 +- .../objs/StretchTool/BinaryStretchType.h | 2 + .../objs/StretchTool/LinearStretchType.cpp | 7 +- .../objs/StretchTool/LinearStretchType.h | 2 + .../objs/StretchTool/ManualStretchType.cpp | 9 +- .../objs/StretchTool/ManualStretchType.h | 2 + .../objs/StretchTool/SawtoothStretchType.cpp | 8 +- .../objs/StretchTool/SawtoothStretchType.h | 2 + .../qisis/objs/StretchTool/StretchTool.cpp | 47 +++++--- .../qisis/objs/StretchTool/StretchType.cpp | 6 + isis/src/qisis/objs/StretchTool/StretchType.h | 3 +- 17 files changed, 116 insertions(+), 151 deletions(-) diff --git a/isis/src/base/objs/Stretch/Stretch.cpp b/isis/src/base/objs/Stretch/Stretch.cpp index a16f37379b..a55cfa5b47 100644 --- a/isis/src/base/objs/Stretch/Stretch.cpp +++ b/isis/src/base/objs/Stretch/Stretch.cpp @@ -38,7 +38,7 @@ namespace Isis { * Constructs a Stretch object with default mapping of special pixel values to * themselves. */ - Stretch::Stretch() : Blob("ImageStretch", "Stretch") { + Stretch::Stretch() { p_null = Isis::NULL8; p_lis = Isis::LOW_INSTR_SAT8; p_lrs = Isis::LOW_REPR_SAT8; @@ -47,26 +47,6 @@ namespace Isis { p_minimum = p_lrs; p_maximum = p_hrs; p_pairs = 0; - p_type = "None"; - } - - - /** - * Constructs a Stretch object with default mapping of special pixel values to - * themselves and a provided name. - * - * @param name Name to use for Stretch - */ - Stretch::Stretch(QString name) : Blob(name, "Stretch") { - p_null = Isis::NULL8; - p_lis = Isis::LOW_INSTR_SAT8; - p_lrs = Isis::LOW_REPR_SAT8; - p_his = Isis::HIGH_INSTR_SAT8; - p_hrs = Isis::HIGH_REPR_SAT8; - p_minimum = p_lrs; - p_maximum = p_hrs; - p_pairs = 0; - p_type = "None"; } @@ -430,90 +410,6 @@ namespace Isis { this->p_input = other.p_input; this->p_output = other.p_output; } - - - /** - * Read saved Stretch data from a Cube into this object. - * - * This is called by Blob::Read() and is the actual data reading function - * ultimately called when running something like cube->read(stretch); - * - * @param is input stream containing the saved Stretch information - */ - void Stretch::ReadData(std::istream &is) { - // Set the Stretch Type - p_type = p_blobPvl["StretchType"][0]; - - // Read in the Stretch Pairs - streampos sbyte = p_startByte - 1; - is.seekg(sbyte, std::ios::beg); - if (!is.good()) { - QString msg = "Error preparing to read data from " + p_type + - " [" + p_blobName + "]"; - throw IException(IException::Io, msg, _FILEINFO_); - } - - char *buf = new char[p_nbytes+1]; - memset(buf, 0, p_nbytes + 1); - - is.read(buf, p_nbytes); - - // Read buffer data into a QString so we can call Parse() - std::string stringFromBuffer(buf); - QString qStringFromBuffer = QString::fromStdString(stringFromBuffer); - Parse(qStringFromBuffer); - - delete [] buf; - - if (!is.good()) { - QString msg = "Error reading data from " + p_type + " [" + - p_blobName + "]"; - throw IException(IException::Io, msg, _FILEINFO_); - } - } - - - /** - * Get the Type of Stretch. This is only used by the AdvancedStretchTool. - * - * @return QString Type of Stretch. - */ - QString Stretch::getType(){ - return p_type; - } - - - /** - * Set the Type of Stretch. This is only used by the AdvancedStretchTool. - * - * @param stretchType The type of stretch. - */ - void Stretch::setType(QString stretchType){ - // check to see if valid input - p_type = stretchType; - } - - - /** - * Initializes for writing stretch to cube blob - */ - void Stretch::WriteInit() { - p_nbytes = Text().toStdString().size(); - } - - - /** - * Writes the stretch information to a cube. - * - * This is called by Blob::write() and is ultimately the function - * called when running something like cube->write(stretch); - * - * @param os output stream to write the stretch data to. - */ - void Stretch::WriteData(std::fstream &os) { - os.write(Text().toStdString().c_str(), p_nbytes); - } - } // end namespace isis diff --git a/isis/src/base/objs/Stretch/Stretch.h b/isis/src/base/objs/Stretch/Stretch.h index 5da48bbe74..57820903f2 100644 --- a/isis/src/base/objs/Stretch/Stretch.h +++ b/isis/src/base/objs/Stretch/Stretch.h @@ -26,7 +26,6 @@ #include #include "Pvl.h" #include "Histogram.h" -#include "Blob.h" namespace Isis { /** @@ -71,7 +70,7 @@ namespace Isis { * @history 2020-02-27 Kristin Berry - Updated to inherit from Blob so Stretches can be * saved and restored from cubes. */ - class Stretch : public Isis::Blob { + class Stretch { private: std::vector p_input; //!< Array for input side of stretch pairs std::vector p_output; //!< Array for output side of stretch pairs @@ -90,13 +89,10 @@ namespace Isis { double p_minimum; //! NextPair(QString &pairs); public: Stretch(); - Stretch(QString name); //! Destroys the Stretch object ~Stretch() {}; @@ -182,9 +178,6 @@ namespace Isis { return p_pairs; }; - QString getType(); - void setType(QString type); - double Input(const int index) const; double Output(const int index) const; @@ -196,11 +189,6 @@ namespace Isis { }; void CopyPairs(const Stretch &other); - - protected: - void WriteInit(); - void ReadData(std::istream &is); - void WriteData(std::fstream &os); }; }; diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp index 6b41d0b892..69666ffa80 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp @@ -8,6 +8,7 @@ #include #include "Stretch.h" +#include "CubeStretch.h" #include "IString.h" #include "IException.h" #include "StretchType.h" @@ -103,6 +104,11 @@ namespace Isis { } + CubeStretch AdvancedStretch::getCubeStretch() { + return ((StretchType *)p_stretchTypeStack->currentWidget())->getCubeStretch(); + } + + /** * This is called when the user creates a stretch outside of the * advanced stretch. For example, they do a global stretch. The @@ -125,20 +131,19 @@ namespace Isis { * * @param newStretch saved stretch to restore */ - void AdvancedStretch::restoreSavedStretch(Stretch newStretch) { - QString stretchTypeName = newStretch.getType(); - + void AdvancedStretch::restoreSavedStretch(CubeStretch newStretch) { + QString stretchTypeName = newStretch.getType(); int index = 0; - if (stretchTypeName.compare("LinearStretch") == 0 ) { + if (stretchTypeName.compare("Linear") == 0 ) { index = 0; } - else if (stretchTypeName.compare("SawtoothStretch") == 0 ) { + else if (stretchTypeName.compare("Sawtooth") == 0 ) { index = 1; } - else if (stretchTypeName.compare("BinaryStretch") == 0) { + else if (stretchTypeName.compare("Binary") == 0) { index = 2; } - else if (stretchTypeName.compare("ManualStretch") == 0) { + else if (stretchTypeName.compare("Manual") == 0) { index = 3; } // Fail by defaulting to Linear diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretch.h b/isis/src/qisis/objs/StretchTool/AdvancedStretch.h index 3f49826e3c..66878dd274 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretch.h +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretch.h @@ -14,6 +14,7 @@ namespace Isis { class CubeViewport; class Histogram; class Stretch; + class CubeStretch; /** * @brief Advanced Stretch Dialog @@ -36,16 +37,17 @@ namespace Isis { const QString &, const QColor &); ~AdvancedStretch(); Stretch getStretch(); + CubeStretch getCubeStretch(); void setStretch(Stretch newStretch); - void restoreSavedStretch(Stretch newStretch); + void restoreSavedStretch(CubeStretch newStretch); void setHistogram(const Histogram &newHist); signals: //! Emitted when a new stretch is available void stretchChanged(); void saveToCube(); - void deleteFromCube(); - void loadStretch(); + void deleteFromCube(); + void loadStretch(); private: QStackedWidget *p_stretchTypeStack; //!< StretchType's diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp index 63a05e2fa2..f6f8aba4d5 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp @@ -5,6 +5,7 @@ #include "CubeViewport.h" #include "Stretch.h" +#include "CubeStretch.h" #include "AdvancedStretch.h" namespace Isis { @@ -141,7 +142,7 @@ namespace Isis { * * @param stretch */ - void AdvancedStretchDialog::restoreSavedStretch(Stretch stretch){ + void AdvancedStretchDialog::restoreSavedStretch(CubeStretch stretch){ p_grayStretch->restoreSavedStretch(stretch); } @@ -292,6 +293,22 @@ namespace Isis { } + /** + * This returns the advanced stretch's stretch for gray. + * + * @return Stretch + */ + CubeStretch AdvancedStretchDialog::getGrayCubeStretch() { + if(p_grayStretch) { + return p_grayStretch->getCubeStretch(); + } + else { + QString msg = "Gray mode not enabled, cannot get gray stretch"; + throw IException(IException::Programmer, msg, _FILEINFO_); + } + } + + /** * This returns the advanced stretch's stretch for red. * diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h index 24a41f331e..5d92b52a47 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h @@ -9,6 +9,7 @@ class QWidget; namespace Isis { class Stretch; class Histogram; + class CubeStretch; }; namespace Isis { @@ -48,12 +49,13 @@ namespace Isis { Histogram &grayHist); void updateHistogram(const Histogram &grayHist); bool isRgbMode() const; - void restoreSavedStretch(Stretch stretch); + void restoreSavedStretch(CubeStretch stretch); Stretch getGrayStretch(); Stretch getRedStretch(); Stretch getGrnStretch(); Stretch getBluStretch(); + CubeStretch getGrayCubeStretch(); /** * Returns true if the advanced stretch is enabled diff --git a/isis/src/qisis/objs/StretchTool/BinaryStretchType.cpp b/isis/src/qisis/objs/StretchTool/BinaryStretchType.cpp index 2e67c7011e..6e04a212ef 100644 --- a/isis/src/qisis/objs/StretchTool/BinaryStretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/BinaryStretchType.cpp @@ -10,6 +10,7 @@ #include "HistogramWidget.h" #include "Statistics.h" #include "Stretch.h" +#include "CubeStretch.h" namespace Isis { /** @@ -73,8 +74,6 @@ namespace Isis { sliderWidget->setLayout(sliderLayout); p_mainLayout->addWidget(sliderWidget, 1, 0); - p_stretch->setType("BinaryStretch"); - setLayout(p_mainLayout); setStretch(calculateNewStretch()); } @@ -376,4 +375,10 @@ namespace Isis { return newStretch; } + + + CubeStretch BinaryStretchType::getCubeStretch() { + 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 e659f9f7c5..bca9b1a9ae 100644 --- a/isis/src/qisis/objs/StretchTool/BinaryStretchType.h +++ b/isis/src/qisis/objs/StretchTool/BinaryStretchType.h @@ -11,6 +11,7 @@ class QString; namespace Isis { class Histogram; class Stretch; + class CubeStretch; /** * @brief This handles the advanced binary stretch @@ -34,6 +35,7 @@ namespace Isis { const QString &name, const QColor &color); ~BinaryStretchType(); + virtual CubeStretch getCubeStretch(); 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 66953c5320..c524026abf 100644 --- a/isis/src/qisis/objs/StretchTool/LinearStretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/LinearStretchType.cpp @@ -10,6 +10,7 @@ #include "HistogramWidget.h" #include "Statistics.h" #include "Stretch.h" +#include "CubeStretch.h" namespace Isis { /** @@ -71,7 +72,6 @@ namespace Isis { sliderWidget->setLayout(sliderLayout); p_mainLayout->addWidget(sliderWidget, 1, 0); - p_stretch->setType("LinearStretch"); setLayout(p_mainLayout); setStretch(stretch); @@ -259,4 +259,9 @@ namespace Isis { return *p_stretch; } + CubeStretch LinearStretchType::getCubeStretch() { + 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 b41d46b8ef..ec9f77ef43 100644 --- a/isis/src/qisis/objs/StretchTool/LinearStretchType.h +++ b/isis/src/qisis/objs/StretchTool/LinearStretchType.h @@ -11,6 +11,7 @@ class QString; namespace Isis { class Histogram; class Stretch; + class CubeStretch; /** * @brief This handles the advanced linear stretch @@ -34,6 +35,7 @@ namespace Isis { ~LinearStretchType(); virtual Stretch getStretch(); + virtual CubeStretch getCubeStretch(); 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 2c8d20f697..360e90c42d 100644 --- a/isis/src/qisis/objs/StretchTool/ManualStretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/ManualStretchType.cpp @@ -11,6 +11,7 @@ #include "HistogramWidget.h" #include "Statistics.h" #include "Stretch.h" +#include "CubeStretch.h" namespace Isis { /** @@ -55,8 +56,6 @@ namespace Isis { this, SLOT(readTable())); disconnect(this, SIGNAL(stretchChanged()), this, SLOT(updateTable())); - p_stretch->setType("ManualStretch"); - setLayout(p_mainLayout); setStretch(stretch); } @@ -151,4 +150,10 @@ namespace Isis { return stretch; } + + CubeStretch ManualStretchType::getCubeStretch() { + 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 b7b86b967a..cf3dd6044d 100644 --- a/isis/src/qisis/objs/StretchTool/ManualStretchType.h +++ b/isis/src/qisis/objs/StretchTool/ManualStretchType.h @@ -13,6 +13,7 @@ class QString; namespace Isis { class Stretch; class Histogram; + class CubeStretch; /** * @brief This handles arbitrary user-input stretches @@ -36,6 +37,7 @@ namespace Isis { const QString &name, const QColor &color); ~ManualStretchType(); + virtual CubeStretch getCubeStretch(); 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 2e97c93ed1..8dc5c89b81 100644 --- a/isis/src/qisis/objs/StretchTool/SawtoothStretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/SawtoothStretchType.cpp @@ -10,6 +10,7 @@ #include "HistogramWidget.h" #include "Statistics.h" #include "Stretch.h" +#include "CubeStretch.h" namespace Isis { /** @@ -71,8 +72,6 @@ namespace Isis { sliderWidget->setLayout(sliderLayout); p_mainLayout->addWidget(sliderWidget, 1, 0); - p_stretch->setType("SawtoothStretch"); - setLayout(p_mainLayout); p_widthEdit->setText(QString::number( @@ -310,5 +309,10 @@ namespace Isis { return calculateNewStretch(p_offsetEdit->text().toDouble(), p_widthEdit->text().toDouble()); } + + CubeStretch SawtoothStretchType::getCubeStretch() { + 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 7801f8b114..3d0f6aaa3c 100644 --- a/isis/src/qisis/objs/StretchTool/SawtoothStretchType.h +++ b/isis/src/qisis/objs/StretchTool/SawtoothStretchType.h @@ -10,6 +10,7 @@ class QString; namespace Isis { class Stretch; + class CubeStretch; class Histogram; /** @@ -37,6 +38,7 @@ namespace Isis { const QString &name, const QColor &color); ~SawtoothStretchType(); + virtual CubeStretch getCubeStretch(); 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 466ade83fc..312df1f5bd 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -34,6 +34,9 @@ #include "ViewportMainWindow.h" #include "Workspace.h" +#include "CubeStretch.h" +#include "StretchBlob.h" + using namespace std; namespace Isis { @@ -406,9 +409,10 @@ namespace Isis { false, &ok); if (ok) { - Stretch stretch(stretchName); - icube->read(stretch); - m_advancedStretch->restoreSavedStretch(stretch); + StretchBlob stretchBlob(stretchName); + icube->read(stretchBlob); + CubeStretch cubeStretch = stretchBlob.getStretch(); + m_advancedStretch->restoreSavedStretch(cubeStretch); } } @@ -534,16 +538,33 @@ namespace Isis { } } - Stretch stretch = m_advancedStretch->getGrayStretch(); - - // consider moving into Stretch::WriteInit() - stretch.Label()["Name"] = text; - stretch.Label() += PvlKeyword("StretchType", stretch.getType()); - - // Greyscale is only available option for now - stretch.Label() += PvlKeyword("Color", "Greyscale"); - - icube->write(stretch); +// Stretch stretch = m_advancedStretch->getGrayStretch(); + CubeStretch stretch = m_advancedStretch->getGrayCubeStretch(); + stretch.setName(text); + + StretchBlob stretchBlob(stretch); + +// StretchBlob stretchBlob = stretch.getBlob(); +// +// // consider moving into Stretch::WriteInit() +// // stretch.Label()["Name"] = text; +// // stretch.Label() += PvlKeyword("StretchType", stretch.getType()); +// // +// // // Greyscale is only available option for now +// // stretch.Label() += PvlKeyword("Color", "Greyscale"); +// // +// // icube->write(stretch); +// +// stretchBlob.Label()["Name"] = text; +// stretchBlob.Label() += PvlKeyword("StretchType", stretch.getType()); +// stretchBlob.Label() += PvlKeyword("Color", "Greyscale"); // maybe just the band matters. +// +// icube->write(stretchBlob); +// + stretchBlob.Label()["Name"] = text; + + + icube->write(stretchBlob); // Don't leave open rw -- not optimal. cvp->cube()->reopen("r"); diff --git a/isis/src/qisis/objs/StretchTool/StretchType.cpp b/isis/src/qisis/objs/StretchTool/StretchType.cpp index 2e69622a04..fd6689365a 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchType.cpp @@ -15,6 +15,7 @@ #include "Stretch.h" #include "Histogram.h" #include "HistogramWidget.h" +#include "CubeStretch.h" namespace Isis { /** @@ -198,4 +199,9 @@ namespace Isis { Stretch StretchType::getStretch() { return *p_stretch; } + + CubeStretch StretchType::getCubeStretch() { + 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 d54979dfa5..29f6960fae 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.h +++ b/isis/src/qisis/objs/StretchTool/StretchType.h @@ -7,6 +7,7 @@ namespace Isis { class Stretch; class Cube; class Histogram; + class CubeStretch; } class QTableWidget; @@ -45,7 +46,7 @@ namespace Isis { virtual ~StretchType(); virtual Stretch getStretch(); - + virtual CubeStretch getCubeStretch(); /** * Children must re-implement this to update their stretch pairs and GUI * elements appropriately. This could be called with a From c68530f9544230f0d30df060bf35342d73990afe Mon Sep 17 00:00:00 2001 From: Kristin Date: Thu, 30 Jul 2020 13:24:16 -0700 Subject: [PATCH 02/19] Cleanup and move setting of name into CubeStretch class --- .../qisis/objs/StretchTool/StretchTool.cpp | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index 312df1f5bd..ba7c259e1e 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -538,32 +538,9 @@ namespace Isis { } } -// Stretch stretch = m_advancedStretch->getGrayStretch(); CubeStretch stretch = m_advancedStretch->getGrayCubeStretch(); stretch.setName(text); - StretchBlob stretchBlob(stretch); - -// StretchBlob stretchBlob = stretch.getBlob(); -// -// // consider moving into Stretch::WriteInit() -// // stretch.Label()["Name"] = text; -// // stretch.Label() += PvlKeyword("StretchType", stretch.getType()); -// // -// // // Greyscale is only available option for now -// // stretch.Label() += PvlKeyword("Color", "Greyscale"); -// // -// // icube->write(stretch); -// -// stretchBlob.Label()["Name"] = text; -// stretchBlob.Label() += PvlKeyword("StretchType", stretch.getType()); -// stretchBlob.Label() += PvlKeyword("Color", "Greyscale"); // maybe just the band matters. -// -// icube->write(stretchBlob); -// - stretchBlob.Label()["Name"] = text; - - icube->write(stretchBlob); // Don't leave open rw -- not optimal. From 3d3448eb8f98f0f111961a2a6d949e17adfe432f Mon Sep 17 00:00:00 2001 From: Kristin Date: Fri, 31 Jul 2020 13:45:01 -0700 Subject: [PATCH 03/19] Add band numbers initial work --- isis/src/qisis/objs/StretchTool/StretchTool.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index ba7c259e1e..edec3109da 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -540,6 +540,7 @@ namespace Isis { CubeStretch stretch = m_advancedStretch->getGrayCubeStretch(); stretch.setName(text); + stretch.setBandNumber(cvp->comboIndex()); StretchBlob stretchBlob(stretch); icube->write(stretchBlob); From e492211193c7100f6c52475fb723942d484ffb77 Mon Sep 17 00:00:00 2001 From: Kristin Date: Mon, 3 Aug 2020 11:58:06 -0700 Subject: [PATCH 04/19] 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 --- isis/src/qisis/objs/StretchTool/StretchTool.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index edec3109da..0c38365569 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -398,8 +398,11 @@ namespace Isis { for (objIter=lab->beginObject(); objIterendObject(); objIter++) { if (objIter->name() == "Stretch") { PvlKeyword tempKeyword = objIter->findKeyword("Name"); - QString tempName = tempKeyword[0]; - namelist.append(tempName); + int bandNumber = int(objIter->findKeyword("BandNumber")); + if (cvp->grayBand() == bandNumber) { + QString tempName = tempKeyword[0]; + namelist.append(tempName); + } } } @@ -431,8 +434,11 @@ namespace Isis { for (objIter=lab->beginObject(); objIterendObject(); objIter++) { if (objIter->name() == "Stretch") { PvlKeyword tempKeyword = objIter->findKeyword("Name"); - QString tempName = tempKeyword[0]; - namelist.append(tempName); + int bandNumber = int(objIter->findKeyword("BandNumber")); + if (cvp->grayBand() == bandNumber) { + QString tempName = tempKeyword[0]; + namelist.append(tempName); + } } } @@ -540,7 +546,7 @@ namespace Isis { CubeStretch stretch = m_advancedStretch->getGrayCubeStretch(); stretch.setName(text); - stretch.setBandNumber(cvp->comboIndex()); + stretch.setBandNumber(cvp->grayBand()); StretchBlob stretchBlob(stretch); icube->write(stretchBlob); From 9f93c4f7dad7b0f6b5bc4d5084c79fd9d7be0c19 Mon Sep 17 00:00:00 2001 From: Kristin Date: Tue, 4 Aug 2020 11:59:31 -0700 Subject: [PATCH 05/19] Moves primary save/load/delete to StretchTool from AdvancedStretchTool. Buttons in AdvancedStretchTool work as previously --- .../qisis/objs/CubeViewport/CubeViewport.cpp | 11 +++--- .../qisis/objs/CubeViewport/CubeViewport.h | 7 ++-- .../IndependentCubeViewport.cpp | 5 +-- .../objs/StretchTool/AdvancedStretch.cpp | 6 ++-- .../qisis/objs/StretchTool/StretchTool.cpp | 34 +++++++++++++++++-- 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/isis/src/qisis/objs/CubeViewport/CubeViewport.cpp b/isis/src/qisis/objs/CubeViewport/CubeViewport.cpp index 1a63ddc355..d3625a85ec 100644 --- a/isis/src/qisis/objs/CubeViewport/CubeViewport.cpp +++ b/isis/src/qisis/objs/CubeViewport/CubeViewport.cpp @@ -50,6 +50,7 @@ #include "PvlKeyword.h" #include "PvlObject.h" #include "Stretch.h" +#include "CubeStretch.h" #include "StretchTool.h" #include "Tool.h" #include "UniversalGroundMap.h" @@ -1669,7 +1670,7 @@ namespace Isis { //! Return the gray band stretch - Stretch CubeViewport::grayStretch() const { + CubeStretch CubeViewport::grayStretch() const { return p_gray.getStretch(); } @@ -2405,7 +2406,7 @@ namespace Isis { CubeViewport::BandInfo::BandInfo() : band(1), stretch(NULL) { - stretch = new Stretch; + stretch = new CubeStretch; stretch->SetNull(0.0); stretch->SetLis(0.0); stretch->SetLrs(0.0); @@ -2419,7 +2420,7 @@ namespace Isis { CubeViewport::BandInfo::BandInfo(const CubeViewport::BandInfo &other) : band(other.band) { stretch = NULL; - stretch = new Stretch(*other.stretch); + stretch = new CubeStretch(*other.stretch); } @@ -2431,7 +2432,7 @@ namespace Isis { } - Stretch CubeViewport::BandInfo::getStretch() const { + CubeStretch CubeViewport::BandInfo::getStretch() const { ASSERT_PTR(stretch); return *stretch; @@ -2448,7 +2449,7 @@ namespace Isis { ASSERT_PTR(other.stretch); stretch = NULL; - stretch = new Stretch; + stretch = new CubeStretch; *stretch = *other.stretch; band = other.band; diff --git a/isis/src/qisis/objs/CubeViewport/CubeViewport.h b/isis/src/qisis/objs/CubeViewport/CubeViewport.h index fef22d0774..f9630cc447 100644 --- a/isis/src/qisis/objs/CubeViewport/CubeViewport.h +++ b/isis/src/qisis/objs/CubeViewport/CubeViewport.h @@ -37,6 +37,7 @@ namespace Isis { class Projection; class Pvl; class PvlKeyword; + class CubeStretch; class Stretch; class Tool; class UniversalGroundMap; @@ -174,14 +175,14 @@ namespace Isis { const BandInfo &operator=(BandInfo other); //! @return The Stretch - Stretch getStretch() const; + CubeStretch getStretch() const; //! @param newStretch The new Stretch value void setStretch(const Stretch &newStretch); //! The band int band; private: //! The Stretch - Stretch *stretch; + CubeStretch *stretch; }; //! @param cube The cube to set the CubeViewport window to @@ -339,7 +340,7 @@ namespace Isis { */ double grayPixel(int sample, int line); //! @return The gray Stretch - Stretch grayStretch() const; + CubeStretch grayStretch() const; //! @return The red Stretch Stretch redStretch() const; //! @return The green Stretch diff --git a/isis/src/qisis/objs/IndependentCubeViewport/IndependentCubeViewport.cpp b/isis/src/qisis/objs/IndependentCubeViewport/IndependentCubeViewport.cpp index 0cb5ed8b34..dd11ae0ba8 100644 --- a/isis/src/qisis/objs/IndependentCubeViewport/IndependentCubeViewport.cpp +++ b/isis/src/qisis/objs/IndependentCubeViewport/IndependentCubeViewport.cpp @@ -34,6 +34,7 @@ #include "Projection.h" #include "RingPlaneProjection.h" #include "TProjection.h" +#include "CubeStretch.h" #include "Stretch.h" #include "StretchTool.h" #include "ViewportBuffer.h" @@ -162,7 +163,7 @@ namespace Isis void IndependentCubeViewport::restretch(ViewportBuffer * buffer) { - Stretch globalStretch = grayStretch(); + CubeStretch globalStretch = grayStretch(); globalStretch.CopyPairs(StretchTool::stretchBand(this, StretchTool::Gray)); stretchGray(globalStretch); } @@ -234,7 +235,7 @@ namespace Isis newGlobal.AddPair(DBL_MAX, 255.0); } - globalStretch = new Stretch(newGlobal); + globalStretch = new CubeStretch(newGlobal); if (isVisible()) stretchGray(newGlobal); diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp index 69666ffa80..d9594cf9ea 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp @@ -146,12 +146,10 @@ namespace Isis { else if (stretchTypeName.compare("Manual") == 0) { index = 3; } - // Fail by defaulting to Linear + + // Fail by defaulting to Linear. This is correct for non-Advanced Stretch p_stretchTypeSelection->setCurrentIndex(index); - StretchType *stretchType = (StretchType *) - p_stretchTypeStack->currentWidget(); - stretchType->setStretch(newStretch); } diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index 0c38365569..7ca0cb1f79 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -291,6 +291,16 @@ namespace Isis { connect(m_flashButton, SIGNAL(pressed()), this, SLOT(stretchChanged())); connect(m_flashButton, SIGNAL(released()), this, SLOT(stretchChanged())); + // Buttons migrated out of Advanced Stretch Tool + QPushButton *saveToCubeButton = new QPushButton("Save"); + connect(saveToCubeButton, SIGNAL(clicked(bool)), this, SLOT(saveStretchToCube())); + + QPushButton *deleteFromCubeButton = new QPushButton("Delete"); + connect(deleteFromCubeButton, SIGNAL(clicked(bool)), this, SLOT(deleteFromCube())); + + QPushButton *loadStretchButton = new QPushButton("Load"); + connect(loadStretchButton, SIGNAL(clicked(bool)), this, SLOT(loadStretchFromCube())); + QHBoxLayout *layout = new QHBoxLayout(hbox); layout->setMargin(0); layout->addWidget(m_copyButton); @@ -301,6 +311,13 @@ namespace Isis { layout->addWidget(m_stretchMaxEdit); layout->addWidget(advancedButton); layout->addWidget(m_flashButton); + + // should only display if gray stretch + // Save/Restore strech only supported for Grayscale images. Hide buttons if in RGB. + layout->addWidget(saveToCubeButton); + layout->addWidget(deleteFromCubeButton); + layout->addWidget(loadStretchButton); + layout->addStretch(); // Pushes everything else left in the menu bar hbox->setLayout(layout); @@ -353,6 +370,7 @@ namespace Isis { } } + /** * Update the streches and corresponding histograms for all the * colors Red, Green and Blue for Stretch All Mode. @@ -415,7 +433,11 @@ namespace Isis { StretchBlob stretchBlob(stretchName); icube->read(stretchBlob); CubeStretch cubeStretch = stretchBlob.getStretch(); - m_advancedStretch->restoreSavedStretch(cubeStretch); + if (m_advancedStretch->isVisible()) { + m_advancedStretch->restoreSavedStretch(cubeStretch); + } + cvp->stretchGray(cubeStretch); + emit stretchChanged(); } } @@ -544,7 +566,14 @@ namespace Isis { } } - CubeStretch stretch = m_advancedStretch->getGrayCubeStretch(); + CubeStretch stretch; + if (m_advancedStretch->isVisible()) { + stretch = m_advancedStretch->getGrayCubeStretch(); + } + else { + stretch = cvp->grayStretch(); + } + stretch.setName(text); stretch.setBandNumber(cvp->grayBand()); StretchBlob stretchBlob(stretch); @@ -915,7 +944,6 @@ namespace Isis { m_advancedStretch->updateStretch(cubeViewport()); m_advancedStretch->show(); } - updateTool(); } From f7bac57c88b1c5a2072f5df467d028846cda9de6 Mon Sep 17 00:00:00 2001 From: Kristin Date: Thu, 6 Aug 2020 08:00:39 -0700 Subject: [PATCH 06/19] Get RGB stretches working, first draft --- isis/src/base/objs/Blob/Blob.cpp | 105 +++++++----- isis/src/base/objs/Blob/Blob.h | 16 +- isis/src/base/objs/Cube/Cube.cpp | 11 +- isis/src/base/objs/Cube/Cube.h | 7 +- .../qisis/objs/StretchTool/StretchTool.cpp | 151 +++++++++++++++--- 5 files changed, 211 insertions(+), 79 deletions(-) diff --git a/isis/src/base/objs/Blob/Blob.cpp b/isis/src/base/objs/Blob/Blob.cpp index b286c4e68c..23f8a71794 100644 --- a/isis/src/base/objs/Blob/Blob.cpp +++ b/isis/src/base/objs/Blob/Blob.cpp @@ -176,7 +176,7 @@ namespace Isis { * * @param pvl The Pvl to be searched */ - void Blob::Find(const Pvl &pvl) { + void Blob::Find(const Pvl &pvl, const QList> keywords) { bool found = false; try { // Search for the blob name @@ -187,9 +187,26 @@ namespace Isis { QString curName = obj["Name"]; curName = curName.toUpper(); if (blobName == curName) { - p_blobPvl = obj; - found = true; - break; + 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])) { + std::cout << "FALSE: " << keywords[i].second << ", " << obj[keywords[i].first] << std::endl; + found = false; + } + } + if (found) { + std::cout << "TRUE: " << obj["BandNumber"][0] << std::endl; + p_blobPvl = obj; + found = true; + break; + } + } + else { + p_blobPvl = obj; + found = true; + break; + } } else { if (p_type == "OriginalLabel" && curName == "ORIGINALLABEL") { @@ -240,7 +257,7 @@ namespace Isis { * @throws iException::Io - Unable to open file * @throws iException::Pvl - Invalid label format */ - void Blob::Read(const QString &file) { + void Blob::Read(const QString &file, const QList> keywords) { // Expand the filename QString temp(FileName(file).expanded()); @@ -253,8 +270,7 @@ namespace Isis { QString msg = "Invalid " + p_type + " label format"; throw IException(e, IException::Unknown, msg, _FILEINFO_); } - - Read(file, pvl); + Read(file, pvl, keywords); } /** @@ -265,8 +281,7 @@ namespace Isis { * * @throws iException::Io - Unable to open file */ - void Blob::Read(const QString &file, const Pvl &pvlLabels) { - + void Blob::Read(const QString &file, const Pvl &pvlLabels, const QList> keywords) { // Expand the filename QString temp(FileName(file).expanded()); @@ -280,7 +295,7 @@ namespace Isis { try { // Check pvl and read from the stream - Read(pvlLabels, istm); + Read(pvlLabels, istm, keywords); } catch (IException &e) { istm.close(); @@ -300,9 +315,9 @@ namespace Isis { * * @throws iException::Io - Unable to open file */ - void Blob::Read(const Pvl &pvl, std::istream &istm) { + void Blob::Read(const Pvl &pvl, std::istream &istm, const QList> keywords){ try { - Find(pvl); + Find(pvl, keywords); ReadInit(); if (p_detached != "") { fstream dstm; @@ -323,6 +338,7 @@ namespace Isis { } } + /** * This virtual method for classes that inherit Blob. It is not defined in * the Blob class. @@ -416,7 +432,7 @@ namespace Isis { * the name of the file */ void Blob::Write(Pvl &pvl, std::fstream &stm, - const QString &detachedFileName) { + const QString &detachedFileName, bool overwrite) { // Handle 64-bit I/O WriteInit(); @@ -434,45 +450,50 @@ namespace Isis { p_blobPvl += PvlKeyword("^" + p_type, detachedFileName); } - // See if the blob is already in the file + p_blobPvl["StartByte"] = toString((BigInt)sbyte); p_blobPvl["Bytes"] = toString(p_nbytes); - bool found = false; - for (int i = 0; i < pvl.objects(); i++) { - if (pvl.object(i).name() == p_blobPvl.name()) { - PvlObject &obj = pvl.object(i); - if ((QString)obj["Name"] == (QString)p_blobPvl["Name"]) { - found = true; - - BigInt oldSbyte = obj["StartByte"]; - int oldNbytes = (int) obj["Bytes"]; - - // Does it fit in the old space - if (p_nbytes <= oldNbytes) { - p_blobPvl["StartByte"] = obj["StartByte"]; - sbyte = oldSbyte; - } + + // See if the blob is already in the file + bool found = false; + if (overwrite) { - // Was the old space at the end of the file - else if (((oldSbyte + oldNbytes) == eofbyte) && - (eofbyte >= sbyte)) { - p_blobPvl["StartByte"] = obj["StartByte"]; - sbyte = oldSbyte; - } + for (int i = 0; i < pvl.objects(); i++) { + if (pvl.object(i).name() == p_blobPvl.name()) { + PvlObject &obj = pvl.object(i); + if ((QString)obj["Name"] == (QString)p_blobPvl["Name"]) { + found = true; - // Put it at the requested position/end of the file - else { - // Leave this here for clarity - } + BigInt oldSbyte = obj["StartByte"]; + int oldNbytes = (int) obj["Bytes"]; + + // Does it fit in the old space + if (p_nbytes <= oldNbytes) { + p_blobPvl["StartByte"] = obj["StartByte"]; + sbyte = oldSbyte; + } - obj = p_blobPvl; + // Was the old space at the end of the file + else if (((oldSbyte + oldNbytes) == eofbyte) && + (eofbyte >= sbyte)) { + p_blobPvl["StartByte"] = obj["StartByte"]; + sbyte = oldSbyte; + } + + // Put it at the requested position/end of the file + else { + // Leave this here for clarity + } + + obj = p_blobPvl; + } } } } - // Didn't find the same blob so add it to the labels - if (!found) { + // Didn't find the same blob, or don't want to overwrite, so add it to the labels + if (!found || !overwrite) { pvl.addObject(p_blobPvl); } diff --git a/isis/src/base/objs/Blob/Blob.h b/isis/src/base/objs/Blob/Blob.h index 4286b1fd20..258ed8e2de 100644 --- a/isis/src/base/objs/Blob/Blob.h +++ b/isis/src/base/objs/Blob/Blob.h @@ -24,6 +24,9 @@ */ #include +#include +#include + #include "PvlObject.h" namespace Isis { @@ -76,16 +79,19 @@ namespace Isis { int Size() const; PvlObject &Label(); - void Read(const QString &file); - void Read(const QString &file, const Pvl &pvlLabels); - virtual void Read(const Pvl &pvl, std::istream &is); + void Read(const QString &file, const QList> + keywords=QList>()); + void Read(const QString &file, const Pvl &pvlLabels, + const QList> keywords = QList>()); + virtual void Read(const Pvl &pvl, std::istream &is, + const QList> keywords = QList>()); void Write(const QString &file); void Write(Pvl &pvl, std::fstream &stm, - const QString &detachedFileName = ""); + const QString &detachedFileName = "", bool overwrite=true); protected: - void Find(const Pvl &pvl); + void Find(const Pvl &pvl, const QList> keywords = QList>()); 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 5273e29e74..6352f741c6 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 { + void Cube::read(Blob &blob, const QList> 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_); @@ -803,8 +803,10 @@ namespace Isis { QMutexLocker locker(m_mutex); QMutexLocker locker2(m_ioHandler->dataFileMutex()); - blob.Read(cubeFile.toString(), *label()); + blob.Read(cubeFile.toString(), *label(), keywords); } + // add optional argument QList>, default to empty + // or add new function with this signature. /** @@ -830,7 +832,7 @@ namespace Isis { * * @param blob data to be written */ - void Cube::write(Blob &blob) { + void Cube::write(Blob &blob, bool overwrite) { if (!isOpen()) { string msg = "The cube is not opened so you can't write a blob to it"; throw IException(IException::Programmer, msg, _FILEINFO_); @@ -866,7 +868,8 @@ namespace Isis { stream.seekp(maxbyte, ios::beg); } - blob.Write(*m_label, stream); + // Use default argument of "" for detached stream + blob.Write(*m_label, stream, "", overwrite); } // Write a detached blob diff --git a/isis/src/base/objs/Cube/Cube.h b/isis/src/base/objs/Cube/Cube.h index 595d9683e5..f302dfa28f 100644 --- a/isis/src/base/objs/Cube/Cube.h +++ b/isis/src/base/objs/Cube/Cube.h @@ -27,6 +27,8 @@ // This is needed for the QVariant macro #include +#include +#include #include @@ -257,9 +259,10 @@ namespace Isis { void open(const QString &cfile, QString access = "r"); void reopen(QString access = "r"); - void read(Blob &blob) const; + void read(Blob &blob, + const QList> keywords = QList>()) const; void read(Buffer &rbuf) const; - void write(Blob &blob); + void write(Blob &blob, bool overwrite=true); void write(Buffer &wbuf); void setBaseMultiplier(double base, double mult); diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index 7ca0cb1f79..006c8776ae 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -410,33 +410,104 @@ namespace Isis { Cube* icube = cvp->cube(); Pvl* lab = icube->label(); - // Create a list of existing Stretch names + QStringList namelist; - PvlObject::PvlObjectIterator objIter; - for (objIter=lab->beginObject(); objIterendObject(); objIter++) { - if (objIter->name() == "Stretch") { - PvlKeyword tempKeyword = objIter->findKeyword("Name"); - int bandNumber = int(objIter->findKeyword("BandNumber")); - if (cvp->grayBand() == bandNumber) { - QString tempName = tempKeyword[0]; - namelist.append(tempName); + // Create a list of existing Stretch names + if (cvp->isGray()) { + PvlObject::PvlObjectIterator objIter; + for (objIter=lab->beginObject(); objIterendObject(); objIter++) { + if (objIter->name() == "Stretch") { + PvlKeyword tempKeyword = objIter->findKeyword("Name"); + int bandNumber = int(objIter->findKeyword("BandNumber")); + if (cvp->grayBand() == bandNumber) { + QString tempName = tempKeyword[0]; + namelist.append(tempName); + } } } } + else { + int redBandNumber = cvp->redBand(); + int greenBandNumber = cvp->greenBand(); + int blueBandNumber = cvp->blueBand(); + + QList> tempNameList; + PvlObject::PvlObjectIterator objIter; + for (objIter=lab->beginObject(); objIterendObject(); objIter++) { + if (objIter->name() == "Stretch") { + PvlKeyword tempKeyword = objIter->findKeyword("Name"); + int bandNumber = int(objIter->findKeyword("BandNumber")); + if (bandNumber == redBandNumber || bandNumber == greenBandNumber + || bandNumber == blueBandNumber) { + QString tempName = tempKeyword[0]; + QPair tempElt = {tempName, bandNumber}; + tempNameList.append(tempElt); + namelist.append(tempName); + } + } + // STILL need to do this + // how do we deal with multiple of the same name? + // 2 passes through list? + // with band #s visible restriction (and need all 3 to load... +// namelist = tempNameList; + } + } bool ok; - QString stretchName = QInputDialog::getItem(m_advancedStretch, tr("Load Stretch"), + QString stretchName = QInputDialog::getItem((QWidget*)parent(), tr("Load Stretch"), tr("Name of Stretch to Load:"), namelist, 0, false, &ok); if (ok) { - StretchBlob stretchBlob(stretchName); - icube->read(stretchBlob); - CubeStretch cubeStretch = stretchBlob.getStretch(); - if (m_advancedStretch->isVisible()) { - m_advancedStretch->restoreSavedStretch(cubeStretch); + if (cvp->isGray()) { + StretchBlob stretchBlob(stretchName); + icube->read(stretchBlob); + CubeStretch cubeStretch = stretchBlob.getStretch(); + if (m_advancedStretch->isVisible()) { + m_advancedStretch->restoreSavedStretch(cubeStretch); + } + cvp->stretchGray(cubeStretch); + } + else { + StretchBlob redStretchBlob(stretchName); + StretchBlob greenStretchBlob(stretchName); + StretchBlob blueStretchBlob(stretchName); + + QPair keywordValue = {"BandNumber", QString::number(cvp->redBand())}; + QList> keywordValueList; + keywordValueList.append(keywordValue); + + icube->read(redStretchBlob, keywordValueList); + + QPair keywordValue2 = {"BandNumber", QString::number(cvp->greenBand())}; + QList> keywordValueList2; + keywordValueList2.append(keywordValue2); + + QPair keywordValue3 = {"BandNumber", QString::number(cvp->blueBand())}; + QList> keywordValueList3; + keywordValueList3.append(keywordValue3); + + icube->read(greenStretchBlob, keywordValueList2); + icube->read(blueStretchBlob, keywordValueList3); + + CubeStretch redStretch = redStretchBlob.getStretch(); + CubeStretch greenStretch = greenStretchBlob.getStretch(); + CubeStretch blueStretch = blueStretchBlob.getStretch(); + + qDebug() << "LOADED stretches: "; + qDebug() << redStretch.Text(); + qDebug() << greenStretch.Text(); + qDebug() << blueStretch.Text(); + + // future work +// if (m_advancedStretch->isVisible()) { +// m_advancedStretch->restoreSavedStretch(cubeStretch); +// } + + cvp->stretchRed(redStretch); + cvp->stretchGreen(greenStretch); + cvp->stretchBlue(blueStretch); } - cvp->stretchGray(cubeStretch); emit stretchChanged(); } } @@ -465,7 +536,7 @@ namespace Isis { } bool ok; - QString toDelete = QInputDialog::getItem(m_advancedStretch, tr("Delete Stretch"), + QString toDelete = QInputDialog::getItem((QWidget*)parent(), tr("Delete Stretch"), tr("Name of Stretch to Delete:"), namelist, 0, false, &ok); if (ok) { @@ -566,19 +637,47 @@ namespace Isis { } } - CubeStretch stretch; - if (m_advancedStretch->isVisible()) { - stretch = m_advancedStretch->getGrayCubeStretch(); + // If grey, only one stretch to save + if (cvp->isGray()) { + CubeStretch stretch; + if (m_advancedStretch->isVisible()) { + stretch = m_advancedStretch->getGrayCubeStretch(); + } + else { + stretch = cvp->grayStretch(); + } + + // Write single stretch to cube + stretch.setName(text); + stretch.setBandNumber(cvp->grayBand()); + StretchBlob stretchBlob(stretch); + + // need to set overwrite to false so that multiple stretches with the same name can be added + icube->write(stretchBlob, false); } else { - stretch = cvp->grayStretch(); + // NEED TO ADD SUPPORT FOR ADVANCED STRETCH TOOL + CubeStretch redStretch, greenStretch, blueStretch; + redStretch = cvp->redStretch(); + greenStretch = cvp->greenStretch(); + blueStretch = cvp->blueStretch(); + + redStretch.setName(text); + redStretch.setBandNumber(cvp->redBand()); + StretchBlob redStretchBlob(redStretch); + icube->write(redStretchBlob, false); + + greenStretch.setName(text); + greenStretch.setBandNumber(cvp->greenBand()); + StretchBlob greenStretchBlob(greenStretch); + icube->write(greenStretchBlob, false); + + blueStretch.setName(text); + blueStretch.setBandNumber(cvp->blueBand()); + StretchBlob blueStretchBlob(blueStretch); + icube->write(blueStretchBlob, false); } - stretch.setName(text); - stretch.setBandNumber(cvp->grayBand()); - StretchBlob stretchBlob(stretch); - icube->write(stretchBlob); - // Don't leave open rw -- not optimal. cvp->cube()->reopen("r"); } From 575015583224bca815dd82fb3efa3ef04b8cc20d Mon Sep 17 00:00:00 2001 From: Kristin Date: Thu, 6 Aug 2020 08:01:50 -0700 Subject: [PATCH 07/19] Add CubeStretch and StretchBlob --- .../src/base/objs/CubeStretch/CubeStretch.cpp | 94 ++++++++++++++ isis/src/base/objs/CubeStretch/CubeStretch.h | 50 +++++++ .../base/objs/CubeStretch/CubeStretch.truth | 64 +++++++++ isis/src/base/objs/CubeStretch/Makefile | 7 + isis/src/base/objs/CubeStretch/unitTest.cpp | 13 ++ isis/src/base/objs/StretchBlob/Makefile | 7 + .../src/base/objs/StretchBlob/StretchBlob.cpp | 122 ++++++++++++++++++ isis/src/base/objs/StretchBlob/StretchBlob.h | 42 ++++++ .../base/objs/StretchBlob/StretchBlob.truth | 1 + isis/src/base/objs/StretchBlob/unitTest.cpp | 16 +++ 10 files changed, 416 insertions(+) create mode 100644 isis/src/base/objs/CubeStretch/CubeStretch.cpp create mode 100644 isis/src/base/objs/CubeStretch/CubeStretch.h create mode 100644 isis/src/base/objs/CubeStretch/CubeStretch.truth create mode 100644 isis/src/base/objs/CubeStretch/Makefile create mode 100644 isis/src/base/objs/CubeStretch/unitTest.cpp create mode 100644 isis/src/base/objs/StretchBlob/Makefile create mode 100644 isis/src/base/objs/StretchBlob/StretchBlob.cpp create mode 100644 isis/src/base/objs/StretchBlob/StretchBlob.h create mode 100644 isis/src/base/objs/StretchBlob/StretchBlob.truth create mode 100644 isis/src/base/objs/StretchBlob/unitTest.cpp diff --git a/isis/src/base/objs/CubeStretch/CubeStretch.cpp b/isis/src/base/objs/CubeStretch/CubeStretch.cpp new file mode 100644 index 0000000000..da1dd53c34 --- /dev/null +++ b/isis/src/base/objs/CubeStretch/CubeStretch.cpp @@ -0,0 +1,94 @@ +/** + * Do we still need this?? + */ + +#include "CubeStretch.h" + +namespace Isis { + + /** + * Default constructor + */ + CubeStretch::CubeStretch() { + m_name = "DefaultStretch"; + m_type = "DefaultLinear"; + m_bandNumber = 1; + } + + + /** + * Constructs a Stretch object with default mapping of special pixel values to + * themselves and a provided name. + * + * @param name Name to use for Stretch + */ + CubeStretch::CubeStretch(QString name) : m_name(name) { + m_type = "DefaultLinear"; + m_bandNumber = 1; + } + + + /** + * Constructs a Stretch 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; + } + + + // Default destructor + CubeStretch::~CubeStretch() { + } + + + // semi-copy constructor + CubeStretch::CubeStretch(Stretch const& stretch): Stretch(stretch) { + m_name = "Default"; + m_bandNumber = 1; + m_type = "Default"; + } + + + + // semi-copy constructor + CubeStretch::CubeStretch(Stretch const& stretch, QString stretchType): Stretch(stretch), m_type(stretchType) { + m_name = "unknown"; + m_bandNumber = 1; + } + + /** + * Get the Type of Stretch. This is only used by the AdvancedStretchTool. + * + * @return QString Type of Stretch. + */ + QString CubeStretch::getType(){ + return m_type; + } + + + void CubeStretch::setType(QString stretchType){ + m_type = stretchType; + } + + void CubeStretch::setName(QString name){ + m_name = name; + } + + QString CubeStretch::getName(){ + return m_name; + } + + int CubeStretch::getBandNumber() { + return m_bandNumber; + } + + void CubeStretch::setBandNumber(int bandNumber) { + m_bandNumber = bandNumber; + } +} // end namespace isis + + diff --git a/isis/src/base/objs/CubeStretch/CubeStretch.h b/isis/src/base/objs/CubeStretch/CubeStretch.h new file mode 100644 index 0000000000..3ea7563910 --- /dev/null +++ b/isis/src/base/objs/CubeStretch/CubeStretch.h @@ -0,0 +1,50 @@ +#ifndef CubeStretch_h +#define CubeStretch_h + +/** + * Do we still need the big block of info up here? + */ + +#include "Stretch.h" +#include "StretchBlob.h" + +namespace Isis { + /** + * @brief Stores stretch information for a cube. + * + * @ingroup Utility + * + * @author 2020-07-28 Kristin Berry + * + * @internal + * @history 2020-07-28 Kristin Berry - Original Version + */ + class CubeStretch : public Stretch { + public: + CubeStretch(); + CubeStretch(QString name); + CubeStretch(QString name, QString stretchType, int bandNumber=1); + ~CubeStretch(); + + CubeStretch(Stretch const& stretch); + CubeStretch(Stretch const& stretch, QString type); + CubeStretch(Stretch const& stretch, QString type, QString name, int bandNumber=1); + + QString getType(); + void setType(QString stretchType); + + QString getName(); + void setName(QString name); + + int getBandNumber(); + void setBandNumber(int bandNumber); + + private: + QString m_name; //! The name of the stretch. + QString m_type; //! Type of stretch. This is only currently used in the AdvancedStretchTool. + int m_bandNumber; //! The band number associated with this stretch + }; +}; + +#endif + diff --git a/isis/src/base/objs/CubeStretch/CubeStretch.truth b/isis/src/base/objs/CubeStretch/CubeStretch.truth new file mode 100644 index 0000000000..8eecd6f37e --- /dev/null +++ b/isis/src/base/objs/CubeStretch/CubeStretch.truth @@ -0,0 +1,64 @@ +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/Makefile b/isis/src/base/objs/CubeStretch/Makefile new file mode 100644 index 0000000000..f122bc8822 --- /dev/null +++ b/isis/src/base/objs/CubeStretch/Makefile @@ -0,0 +1,7 @@ +ifeq ($(ISISROOT), $(BLANK)) +.SILENT: +error: + echo "Please set ISISROOT"; +else + include $(ISISROOT)/make/isismake.objs +endif \ No newline at end of file diff --git a/isis/src/base/objs/CubeStretch/unitTest.cpp b/isis/src/base/objs/CubeStretch/unitTest.cpp new file mode 100644 index 0000000000..282cd4ae07 --- /dev/null +++ b/isis/src/base/objs/CubeStretch/unitTest.cpp @@ -0,0 +1,13 @@ +#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/Makefile b/isis/src/base/objs/StretchBlob/Makefile new file mode 100644 index 0000000000..f122bc8822 --- /dev/null +++ b/isis/src/base/objs/StretchBlob/Makefile @@ -0,0 +1,7 @@ +ifeq ($(ISISROOT), $(BLANK)) +.SILENT: +error: + echo "Please set ISISROOT"; +else + include $(ISISROOT)/make/isismake.objs +endif \ No newline at end of file diff --git a/isis/src/base/objs/StretchBlob/StretchBlob.cpp b/isis/src/base/objs/StretchBlob/StretchBlob.cpp new file mode 100644 index 0000000000..fc6211c622 --- /dev/null +++ b/isis/src/base/objs/StretchBlob/StretchBlob.cpp @@ -0,0 +1,122 @@ +/** + * NEEDED? + */ + +#include +#include + +#include "StretchBlob.h" +#include "IException.h" + +using namespace std; +namespace Isis { + + /** + * Default constructor + */ + StretchBlob::StretchBlob() : Blob("CubeStretch", "Stretch") { + m_stretch = new CubeStretch(); + } + + + /** + * Default constructor + */ + StretchBlob::StretchBlob(CubeStretch stretch) : Blob("CubeStretch", "Stretch"){ + m_stretch = new CubeStretch(stretch); + Label()["Name"] = m_stretch->getName(); + Label() += PvlKeyword("StretchType", m_stretch->getType()); + Label() += PvlKeyword("BandNumber", QString::number(m_stretch->getBandNumber())); + Label() += PvlKeyword("Color", "Greyscale"); + } + + + /** + * Construct a StretchBlob with provided name. + * + * @param name Name to use for Stretch + */ + StretchBlob::StretchBlob(QString name) : Blob(name, "Stretch") { + m_stretch = new CubeStretch(name); + } + + + /** + * Default Destructor + */ + StretchBlob::~StretchBlob() { + m_stretch = NULL; + delete m_stretch; + } + + + CubeStretch StretchBlob::getStretch() { + return *m_stretch; + } + + /** + * Read saved Stretch data from a Cube into this object. + * + * This is called by Blob::Read() and is the actual data reading function + * ultimately called when running something like cube->read(stretch); + * + * @param is input stream containing the saved Stretch information + */ + void StretchBlob::ReadData(std::istream &is) { + // Set the Stretch Type + m_stretch->setType(p_blobPvl["StretchType"][0]); + m_stretch->setBandNumber(p_blobPvl["BandNumber"][0].toInt()); + + // Read in the Stretch Pairs + streampos sbyte = p_startByte - 1; + is.seekg(sbyte, std::ios::beg); + if (!is.good()) { + QString msg = "Error preparing to read data from " + m_stretch->getType() + + " [" + p_blobName + "]"; + throw IException(IException::Io, msg, _FILEINFO_); + } + + char *buf = new char[p_nbytes+1]; + memset(buf, 0, p_nbytes + 1); + + is.read(buf, p_nbytes); + + // Read buffer data into a QString so we can call Parse() + std::string stringFromBuffer(buf); + m_stretch->Parse(QString::fromStdString(stringFromBuffer)); + + delete [] buf; + + if (!is.good()) { + QString msg = "Error reading data from " + p_type + " [" + + p_blobName + "]"; + throw IException(IException::Io, msg, _FILEINFO_); + } + } + + + /** + * Initializes for writing stretch to cube blob + */ + void StretchBlob::WriteInit() { + std::cout << "In blob: " << p_blobPvl["BandNumber"][0] << ", " << m_stretch->Text() << std::endl; + p_nbytes = m_stretch->Text().toStdString().size(); + } + + + /** + * Writes the stretch information to a cube. + * + * This is called by Blob::write() and is ultimately the function + * called when running something like cube->write(stretch); + * + * @param os output stream to write the stretch data to. + */ + void StretchBlob::WriteData(std::fstream &os) { + std::cout << "In blob write: " << p_blobPvl["BandNumber"][0] << ", " << m_stretch->Text() << std::endl; + os.write(m_stretch->Text().toStdString().c_str(), p_nbytes); + } + +} // end namespace isis + + diff --git a/isis/src/base/objs/StretchBlob/StretchBlob.h b/isis/src/base/objs/StretchBlob/StretchBlob.h new file mode 100644 index 0000000000..1dc03c5d0c --- /dev/null +++ b/isis/src/base/objs/StretchBlob/StretchBlob.h @@ -0,0 +1,42 @@ +#ifndef StretchBlob_h +#define StretchBlob_h +/** + * Still needed? + */ + +#include "Blob.h" +#include "CubeStretch.h" + +namespace Isis { + class CubeStretch; + /** + * @brief Blob to store stretch information to cube. + * + * @ingroup Utility + * + * @author 2020-07-28 Kristin Berry Stuart Sides + * + * @internal + * @history 2020-07-28 Kristin Berry Stuart Sides - Original Version + */ + class StretchBlob : public Isis::Blob { + public: + StretchBlob(); + StretchBlob(CubeStretch stretch); + StretchBlob(QString name); + ~StretchBlob(); + + CubeStretch getStretch(); + + protected: + void WriteInit(); + void ReadData(std::istream &is); + void WriteData(std::fstream &os); + + private: + CubeStretch *m_stretch; //! Stretch associated with the blob + }; +}; + +#endif + diff --git a/isis/src/base/objs/StretchBlob/StretchBlob.truth b/isis/src/base/objs/StretchBlob/StretchBlob.truth new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/isis/src/base/objs/StretchBlob/StretchBlob.truth @@ -0,0 +1 @@ + diff --git a/isis/src/base/objs/StretchBlob/unitTest.cpp b/isis/src/base/objs/StretchBlob/unitTest.cpp new file mode 100644 index 0000000000..82a131827f --- /dev/null +++ b/isis/src/base/objs/StretchBlob/unitTest.cpp @@ -0,0 +1,16 @@ +#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; +} From 98928e62011dac8e3ea3806017754b491e688fe5 Mon Sep 17 00:00:00 2001 From: Stuart Sides Date: Thu, 6 Aug 2020 14:52:27 -0700 Subject: [PATCH 08/19] Update Blob.cpp Commented the new parameter for Find --- isis/src/base/objs/Blob/Blob.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/isis/src/base/objs/Blob/Blob.cpp b/isis/src/base/objs/Blob/Blob.cpp index 23f8a71794..dca696325d 100644 --- a/isis/src/base/objs/Blob/Blob.cpp +++ b/isis/src/base/objs/Blob/Blob.cpp @@ -175,6 +175,10 @@ namespace Isis { * blob is stored and the pointer is removed from the blob pvl. * * @param pvl The Pvl to be searched + * @param keywords A list of keyword, value pairs to match inside the blob's + * PVL object. Only if all the keyword match is the blob processed. This is used + * 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) { bool found = false; @@ -190,7 +194,7 @@ namespace Isis { 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])) { + if (obj.hasKeyword(keywords[i].first) && (keywords[i].second != obj[keywords[i].first])) { std::cout << "FALSE: " << keywords[i].second << ", " << obj[keywords[i].first] << std::endl; found = false; } From d654177a5be2207e96cd1d12cb9bc2dafadebef5 Mon Sep 17 00:00:00 2001 From: Kristin Date: Thu, 6 Aug 2020 20:23:14 -0700 Subject: [PATCH 09/19] Update saved stretches for RGB from the advanced stretch tool --- .../objs/StretchTool/AdvancedStretch.cpp | 3 +- .../StretchTool/AdvancedStretchDialog.cpp | 54 +++++++------ .../objs/StretchTool/AdvancedStretchDialog.h | 9 ++- .../qisis/objs/StretchTool/StretchTool.cpp | 79 +++++++++++-------- .../qisis/objs/StretchTool/StretchType.cpp | 25 +++--- 5 files changed, 92 insertions(+), 78 deletions(-) diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp index d9594cf9ea..c279c5fe64 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp @@ -147,8 +147,7 @@ namespace Isis { index = 3; } - // Fail by defaulting to Linear. This is correct for non-Advanced Stretch - + // Fail by defaulting to Linear. This is correct for non-Advanced Stretches anyway. p_stretchTypeSelection->setCurrentIndex(index); } diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp index f6f8aba4d5..3b678dca16 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp @@ -143,7 +143,29 @@ namespace Isis { * @param stretch */ void AdvancedStretchDialog::restoreSavedStretch(CubeStretch stretch){ - p_grayStretch->restoreSavedStretch(stretch); + // if in gray mode + if (p_grayStretch) { + p_grayStretch->restoreSavedStretch(stretch); + } + +// if (isRgbMode()) { + // maybe just error, in this case + two different functions (need different args) +// } + } + + void AdvancedStretchDialog::restoreSavedRGB(CubeStretch red, CubeStretch green, CubeStretch blue) { + // error if not isRgbMode + if (p_redStretch) { + p_redStretch->restoreSavedStretch(red); + } + + if (p_grnStretch) { + p_grnStretch->restoreSavedStretch(green); + } + + if (p_bluStretch) { + p_bluStretch->restoreSavedStretch(blue); + } } @@ -282,23 +304,7 @@ namespace Isis { * * @return Stretch */ - Stretch AdvancedStretchDialog::getGrayStretch() { - if(p_grayStretch) { - return p_grayStretch->getStretch(); - } - else { - QString msg = "Gray mode not enabled, cannot get gray stretch"; - throw IException(IException::Programmer, msg, _FILEINFO_); - } - } - - - /** - * This returns the advanced stretch's stretch for gray. - * - * @return Stretch - */ - CubeStretch AdvancedStretchDialog::getGrayCubeStretch() { + CubeStretch AdvancedStretchDialog::getGrayStretch() { if(p_grayStretch) { return p_grayStretch->getCubeStretch(); } @@ -314,9 +320,9 @@ namespace Isis { * * @return Stretch */ - Stretch AdvancedStretchDialog::getRedStretch() { + CubeStretch AdvancedStretchDialog::getRedStretch() { if(p_redStretch) { - return p_redStretch->getStretch(); + return p_redStretch->getCubeStretch(); } else { QString msg = "RGB mode not enabled, cannot get red stretch"; @@ -330,9 +336,9 @@ namespace Isis { * * @return Stretch */ - Stretch AdvancedStretchDialog::getGrnStretch() { + CubeStretch AdvancedStretchDialog::getGrnStretch() { if(p_grnStretch) { - return p_grnStretch->getStretch(); + return p_grnStretch->getCubeStretch(); } else { QString msg = "RGB mode not enabled, cannot get green stretch"; @@ -346,9 +352,9 @@ namespace Isis { * * @return Stretch */ - Stretch AdvancedStretchDialog::getBluStretch() { + CubeStretch AdvancedStretchDialog::getBluStretch() { if(p_bluStretch) { - return p_bluStretch->getStretch(); + return p_bluStretch->getCubeStretch(); } else { QString msg = "RGB mode not enabled, cannot get blue stretch"; diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h index 5d92b52a47..c7cbfc9989 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h @@ -50,11 +50,12 @@ namespace Isis { void updateHistogram(const Histogram &grayHist); bool isRgbMode() const; void restoreSavedStretch(CubeStretch stretch); + void restoreSavedRGB(CubeStretch red, CubeStretch green, CubeStretch blue); - Stretch getGrayStretch(); - Stretch getRedStretch(); - Stretch getGrnStretch(); - Stretch getBluStretch(); + CubeStretch getGrayStretch(); + CubeStretch getRedStretch(); + CubeStretch getGrnStretch(); + CubeStretch getBluStretch(); CubeStretch getGrayCubeStretch(); /** diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index 2bd6e86cda..3b65d5af96 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -432,7 +432,8 @@ namespace Isis { int greenBandNumber = cvp->greenBand(); int blueBandNumber = cvp->blueBand(); - QList> tempNameList; +// QList> tempNameList; + QMap> tempNameMap; PvlObject::PvlObjectIterator objIter; for (objIter=lab->beginObject(); objIterendObject(); objIter++) { if (objIter->name() == "Stretch") { @@ -441,18 +442,26 @@ namespace Isis { if (bandNumber == redBandNumber || bandNumber == greenBandNumber || bandNumber == blueBandNumber) { QString tempName = tempKeyword[0]; - QPair tempElt = {tempName, bandNumber}; - tempNameList.append(tempElt); - namelist.append(tempName); + if (tempNameMap.contains(tempName)) { + tempNameMap[tempName].append(bandNumber); + } + else + { + tempNameMap[tempName] = {bandNumber}; + } } } - // STILL need to do this - // how do we deal with multiple of the same name? - // 2 passes through list? - // with band #s visible restriction (and need all 3 to load... -// namelist = tempNameList; + } + QMap>::const_iterator i = tempNameMap.constBegin(); + while (i != tempNameMap.constEnd()) { + qDebug() << i.key() << ": " << i.value(); + if (i.value().contains(redBandNumber) && i.value().contains(greenBandNumber) && + i.value().contains(blueBandNumber) ){ + namelist.append(i.key()); } + ++i; } + } bool ok; QString stretchName = QInputDialog::getItem((QWidget*)parent(), tr("Load Stretch"), @@ -478,32 +487,30 @@ namespace Isis { QList> keywordValueList; keywordValueList.append(keywordValue); - icube->read(redStretchBlob, keywordValueList); - - QPair keywordValue2 = {"BandNumber", QString::number(cvp->greenBand())}; - QList> keywordValueList2; - keywordValueList2.append(keywordValue2); + QPair keywordValueGreen = {"BandNumber", QString::number(cvp->greenBand())}; + QList> keywordValueListGreen; + keywordValueListGreen.append(keywordValueGreen); - QPair keywordValue3 = {"BandNumber", QString::number(cvp->blueBand())}; - QList> keywordValueList3; - keywordValueList3.append(keywordValue3); + QPair keywordValueBlue = {"BandNumber", QString::number(cvp->blueBand())}; + QList> keywordValueListBlue; + keywordValueListBlue.append(keywordValueBlue); - icube->read(greenStretchBlob, keywordValueList2); - icube->read(blueStretchBlob, keywordValueList3); + icube->read(redStretchBlob, keywordValueList); + icube->read(greenStretchBlob, keywordValueListGreen); + icube->read(blueStretchBlob, keywordValueListBlue); CubeStretch redStretch = redStretchBlob.getStretch(); CubeStretch greenStretch = greenStretchBlob.getStretch(); CubeStretch blueStretch = blueStretchBlob.getStretch(); - qDebug() << "LOADED stretches: "; qDebug() << redStretch.Text(); qDebug() << greenStretch.Text(); qDebug() << blueStretch.Text(); - // future work -// if (m_advancedStretch->isVisible()) { -// m_advancedStretch->restoreSavedStretch(cubeStretch); -// } + // works for RGB? + if (m_advancedStretch->isVisible()) { + m_advancedStretch->restoreSavedRGB(redStretch, greenStretch, blueStretch); + } cvp->stretchRed(redStretch); cvp->stretchGreen(greenStretch); @@ -626,8 +633,7 @@ namespace Isis { } if (icube->isReadOnly()) { - // ReOpen cube as read/write - // If cube readonly print error + // reOpen cube as read/write try { cvp->cube()->reopen("rw"); } @@ -638,11 +644,11 @@ namespace Isis { } } - // If grey, only one stretch to save + // If gray, only one stretch to save if (cvp->isGray()) { CubeStretch stretch; if (m_advancedStretch->isVisible()) { - stretch = m_advancedStretch->getGrayCubeStretch(); + stretch = m_advancedStretch->getGrayStretch(); } else { stretch = cvp->grayStretch(); @@ -653,16 +659,21 @@ namespace Isis { stretch.setBandNumber(cvp->grayBand()); StretchBlob stretchBlob(stretch); - // need to set overwrite to false so that multiple stretches with the same name can be added + //set overwrite to false so that multiple stretches with the same name can be added icube->write(stretchBlob, false); } else { - // NEED TO ADD SUPPORT FOR ADVANCED STRETCH TOOL CubeStretch redStretch, greenStretch, blueStretch; - redStretch = cvp->redStretch(); - greenStretch = cvp->greenStretch(); - blueStretch = cvp->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(); + } redStretch.setName(text); redStretch.setBandNumber(cvp->redBand()); StretchBlob redStretchBlob(redStretch); diff --git a/isis/src/qisis/objs/StretchTool/StretchType.cpp b/isis/src/qisis/objs/StretchTool/StretchType.cpp index fd6689365a..004080654a 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchType.cpp @@ -60,20 +60,17 @@ namespace Isis { connect(saveAsButton, SIGNAL(clicked(bool)), this, SLOT(savePairs())); p_mainLayout->addWidget(saveAsButton, 3, 0); - // Save/Restore strech only supported for Grayscale images. Hide buttons if in RGB. - if (name.compare("Gray") == 0) { - QPushButton *saveToCubeButton = new QPushButton("Save Stretch Pairs to Cube..."); - connect(saveToCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(saveToCube())); - p_mainLayout->addWidget(saveToCubeButton, 4, 0); - - QPushButton *deleteFromCubeButton = new QPushButton("Delete Stretch Pairs from Cube..."); - connect(deleteFromCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(deleteFromCube())); - p_mainLayout->addWidget(deleteFromCubeButton, 5, 0); - - QPushButton *loadStretchButton = new QPushButton("Load Saved Stretch from Cube..."); - connect(loadStretchButton, SIGNAL(clicked(bool)), this, SIGNAL(loadStretch())); - p_mainLayout->addWidget(loadStretchButton, 6, 0); - } + QPushButton *saveToCubeButton = new QPushButton("Save Stretch Pairs to Cube..."); + connect(saveToCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(saveToCube())); + p_mainLayout->addWidget(saveToCubeButton, 4, 0); + + QPushButton *deleteFromCubeButton = new QPushButton("Delete Stretch Pairs from Cube..."); + connect(deleteFromCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(deleteFromCube())); + p_mainLayout->addWidget(deleteFromCubeButton, 5, 0); + + QPushButton *loadStretchButton = new QPushButton("Load Saved Stretch from Cube..."); + connect(loadStretchButton, SIGNAL(clicked(bool)), this, SIGNAL(loadStretch())); + p_mainLayout->addWidget(loadStretchButton, 6, 0); QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); sizePolicy.setHeightForWidth(true); From e2a9e300b64e3ebb72cde3da0f504fde01e4bd7c Mon Sep 17 00:00:00 2001 From: Kristin Date: Fri, 7 Aug 2020 12:06:35 -0700 Subject: [PATCH 10/19] Remove couts and cleanup merge --- .../src/base/objs/StretchBlob/StretchBlob.cpp | 2 -- .../qisis/objs/StretchTool/StretchTool.cpp | 29 ------------------- 2 files changed, 31 deletions(-) diff --git a/isis/src/base/objs/StretchBlob/StretchBlob.cpp b/isis/src/base/objs/StretchBlob/StretchBlob.cpp index fc6211c622..e3e0be29a2 100644 --- a/isis/src/base/objs/StretchBlob/StretchBlob.cpp +++ b/isis/src/base/objs/StretchBlob/StretchBlob.cpp @@ -99,7 +99,6 @@ namespace Isis { * Initializes for writing stretch to cube blob */ void StretchBlob::WriteInit() { - std::cout << "In blob: " << p_blobPvl["BandNumber"][0] << ", " << m_stretch->Text() << std::endl; p_nbytes = m_stretch->Text().toStdString().size(); } @@ -113,7 +112,6 @@ namespace Isis { * @param os output stream to write the stretch data to. */ void StretchBlob::WriteData(std::fstream &os) { - std::cout << "In blob write: " << p_blobPvl["BandNumber"][0] << ", " << m_stretch->Text() << std::endl; os.write(m_stretch->Text().toStdString().c_str(), p_nbytes); } diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index d4cb5bdf84..8556a690e1 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -432,7 +432,6 @@ namespace Isis { int greenBandNumber = cvp->greenBand(); int blueBandNumber = cvp->blueBand(); -// QList> tempNameList; QMap> tempNameMap; PvlObject::PvlObjectIterator objIter; for (objIter=lab->beginObject(); objIterendObject(); objIter++) { @@ -454,7 +453,6 @@ namespace Isis { } QMap>::const_iterator i = tempNameMap.constBegin(); while (i != tempNameMap.constEnd()) { - qDebug() << i.key() << ": " << i.value(); if (i.value().contains(redBandNumber) && i.value().contains(greenBandNumber) && i.value().contains(blueBandNumber) ){ namelist.append(i.key()); @@ -462,32 +460,6 @@ namespace Isis { ++i; } } - else { - int redBandNumber = cvp->redBand(); - int greenBandNumber = cvp->greenBand(); - int blueBandNumber = cvp->blueBand(); - - QList> tempNameList; - PvlObject::PvlObjectIterator objIter; - for (objIter=lab->beginObject(); objIterendObject(); objIter++) { - if (objIter->name() == "Stretch") { - PvlKeyword tempKeyword = objIter->findKeyword("Name"); - int bandNumber = int(objIter->findKeyword("BandNumber")); - if (bandNumber == redBandNumber || bandNumber == greenBandNumber - || bandNumber == blueBandNumber) { - QString tempName = tempKeyword[0]; - QPair tempElt = {tempName, bandNumber}; - tempNameList.append(tempElt); - namelist.append(tempName); - } - } - // STILL need to do this - // how do we deal with multiple of the same name? - // 2 passes through list? - // with band #s visible restriction (and need all 3 to load... -// namelist = tempNameList; - } - } bool ok; QString stretchName = QInputDialog::getItem((QWidget*)parent(), tr("Load Stretch"), @@ -529,7 +501,6 @@ namespace Isis { CubeStretch greenStretch = greenStretchBlob.getStretch(); CubeStretch blueStretch = blueStretchBlob.getStretch(); - // works for RGB? if (m_advancedStretch->isVisible()) { m_advancedStretch->restoreSavedRGB(redStretch, greenStretch, blueStretch); } From a94df04e340d54f15c65196a771fea4d62ca5669 Mon Sep 17 00:00:00 2001 From: Kristin Date: Fri, 7 Aug 2020 12:26:56 -0700 Subject: [PATCH 11/19] Re-remove save/load/restore buttons from RGB StretchType panels --- .../StretchTool/AdvancedStretchDialog.cpp | 33 ++++++++++------- .../objs/StretchTool/AdvancedStretchDialog.h | 1 - .../qisis/objs/StretchTool/StretchTool.cpp | 6 ++- .../qisis/objs/StretchTool/StretchType.cpp | 37 +++++++++++-------- 4 files changed, 44 insertions(+), 33 deletions(-) diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp index 3b678dca16..7fa95a7a5f 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp @@ -147,24 +147,29 @@ namespace Isis { if (p_grayStretch) { p_grayStretch->restoreSavedStretch(stretch); } - -// if (isRgbMode()) { - // maybe just error, in this case + two different functions (need different args) -// } + else { + QString msg = "Gray mode not enabled, cannot restore gray stretch"; + throw IException(IException::Programmer, msg, _FILEINFO_); + } } void AdvancedStretchDialog::restoreSavedRGB(CubeStretch red, CubeStretch green, CubeStretch blue) { - // error if not isRgbMode - if (p_redStretch) { - p_redStretch->restoreSavedStretch(red); + if (isRgbMode()) { + if (p_redStretch) { + p_redStretch->restoreSavedStretch(red); + } + + if (p_grnStretch) { + p_grnStretch->restoreSavedStretch(green); + } + + if (p_bluStretch) { + p_bluStretch->restoreSavedStretch(blue); + } } - - if (p_grnStretch) { - p_grnStretch->restoreSavedStretch(green); - } - - if (p_bluStretch) { - p_bluStretch->restoreSavedStretch(blue); + else { + QString msg = "RGB mode not enabled, cannot restore RGB stretch"; + throw IException(IException::Programmer, msg, _FILEINFO_); } } diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h index c7cbfc9989..2c3eb6823d 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h @@ -56,7 +56,6 @@ namespace Isis { CubeStretch getRedStretch(); CubeStretch getGrnStretch(); CubeStretch getBluStretch(); - CubeStretch getGrayCubeStretch(); /** * Returns true if the advanced stretch is enabled diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index 8556a690e1..153188a821 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -651,8 +651,9 @@ namespace Isis { stretch.setBandNumber(cvp->grayBand()); StretchBlob stretchBlob(stretch); - //set overwrite to false so that multiple stretches with the same name can be added - icube->write(stretchBlob, false); + // Overwrite an existing stretch with the same name if it exists. The user was warned + // and decided to overwrite. + icube->write(stretchBlob); } else { CubeStretch redStretch, greenStretch, blueStretch; @@ -666,6 +667,7 @@ namespace Isis { greenStretch = cvp->greenStretch(); blueStretch = cvp->blueStretch(); } + redStretch.setName(text); redStretch.setBandNumber(cvp->redBand()); StretchBlob redStretchBlob(redStretch); diff --git a/isis/src/qisis/objs/StretchTool/StretchType.cpp b/isis/src/qisis/objs/StretchTool/StretchType.cpp index 004080654a..3112a22d5e 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchType.cpp @@ -41,7 +41,7 @@ namespace Isis { p_stretch = new Stretch(); - p_graph = new HistogramWidget(QString("Visible ") + name + QString(" Hist"), + p_graph = new HistogramWidget(QString("Visible ") + name , color.lighter(110), color.darker(110)); p_graph->setHistogram(*p_cubeHist); p_graph->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, @@ -60,21 +60,26 @@ namespace Isis { connect(saveAsButton, SIGNAL(clicked(bool)), this, SLOT(savePairs())); p_mainLayout->addWidget(saveAsButton, 3, 0); - QPushButton *saveToCubeButton = new QPushButton("Save Stretch Pairs to Cube..."); - connect(saveToCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(saveToCube())); - p_mainLayout->addWidget(saveToCubeButton, 4, 0); - - QPushButton *deleteFromCubeButton = new QPushButton("Delete Stretch Pairs from Cube..."); - connect(deleteFromCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(deleteFromCube())); - p_mainLayout->addWidget(deleteFromCubeButton, 5, 0); - - QPushButton *loadStretchButton = new QPushButton("Load Saved Stretch from Cube..."); - connect(loadStretchButton, SIGNAL(clicked(bool)), this, SIGNAL(loadStretch())); - p_mainLayout->addWidget(loadStretchButton, 6, 0); - - QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - sizePolicy.setHeightForWidth(true); - p_graph->setSizePolicy(sizePolicy); + // Only display Save/Delete/Restore here for Gray Stretches. For RGB stretches, + // this panel is displayed 3 times, but the Save/Delete/Restore should only be displayed + // once. + if (name.compare("Gray") == 0) { + QPushButton *saveToCubeButton = new QPushButton("Save Stretch Pairs to Cube..."); + connect(saveToCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(saveToCube())); + p_mainLayout->addWidget(saveToCubeButton, 4, 0); + + QPushButton *deleteFromCubeButton = new QPushButton("Delete Stretch Pairs from Cube..."); + connect(deleteFromCubeButton, SIGNAL(clicked(bool)), this, SIGNAL(deleteFromCube())); + p_mainLayout->addWidget(deleteFromCubeButton, 5, 0); + + QPushButton *loadStretchButton = new QPushButton("Restore Saved Stretch from Cube..."); + connect(loadStretchButton, SIGNAL(clicked(bool)), this, SIGNAL(loadStretch())); + p_mainLayout->addWidget(loadStretchButton, 6, 0); + + QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + sizePolicy.setHeightForWidth(true); + p_graph->setSizePolicy(sizePolicy); + } } From f9ede33eca6dd8350fe808bc8fedf9b338efc10d Mon Sep 17 00:00:00 2001 From: Kristin Date: Fri, 7 Aug 2020 12:32:00 -0700 Subject: [PATCH 12/19] Update button name from Load to Restore --- isis/src/qisis/objs/StretchTool/StretchTool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index 153188a821..c26f1ad106 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -298,7 +298,7 @@ namespace Isis { QPushButton *deleteFromCubeButton = new QPushButton("Delete"); connect(deleteFromCubeButton, SIGNAL(clicked(bool)), this, SLOT(deleteFromCube())); - QPushButton *loadStretchButton = new QPushButton("Load"); + QPushButton *loadStretchButton = new QPushButton("Restore"); connect(loadStretchButton, SIGNAL(clicked(bool)), this, SLOT(loadStretchFromCube())); QHBoxLayout *layout = new QHBoxLayout(hbox); From bb82d62c07abe9292d59f36e9d922b7b97711572 Mon Sep 17 00:00:00 2001 From: Kristin Date: Fri, 7 Aug 2020 13:13:41 -0700 Subject: [PATCH 13/19] Remove unused color/grayscale type from StretchBlob output, clean up redundant functions, improve method names --- .../src/base/objs/CubeStretch/CubeStretch.cpp | 4 ++-- .../src/base/objs/StretchBlob/StretchBlob.cpp | 1 - .../objs/StretchTool/AdvancedStretch.cpp | 7 +----- .../qisis/objs/StretchTool/AdvancedStretch.h | 3 +-- .../StretchTool/AdvancedStretchDialog.cpp | 23 ++++++++++++------- .../objs/StretchTool/AdvancedStretchDialog.h | 4 ++-- .../qisis/objs/StretchTool/StretchTool.cpp | 4 ++-- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/isis/src/base/objs/CubeStretch/CubeStretch.cpp b/isis/src/base/objs/CubeStretch/CubeStretch.cpp index da1dd53c34..31c189abd1 100644 --- a/isis/src/base/objs/CubeStretch/CubeStretch.cpp +++ b/isis/src/base/objs/CubeStretch/CubeStretch.cpp @@ -47,7 +47,7 @@ namespace Isis { // semi-copy constructor CubeStretch::CubeStretch(Stretch const& stretch): Stretch(stretch) { - m_name = "Default"; + m_name = "Unknown"; m_bandNumber = 1; m_type = "Default"; } @@ -56,7 +56,7 @@ namespace Isis { // semi-copy constructor CubeStretch::CubeStretch(Stretch const& stretch, QString stretchType): Stretch(stretch), m_type(stretchType) { - m_name = "unknown"; + m_name = "Unknown"; m_bandNumber = 1; } diff --git a/isis/src/base/objs/StretchBlob/StretchBlob.cpp b/isis/src/base/objs/StretchBlob/StretchBlob.cpp index e3e0be29a2..d6c14b91b0 100644 --- a/isis/src/base/objs/StretchBlob/StretchBlob.cpp +++ b/isis/src/base/objs/StretchBlob/StretchBlob.cpp @@ -27,7 +27,6 @@ namespace Isis { Label()["Name"] = m_stretch->getName(); Label() += PvlKeyword("StretchType", m_stretch->getType()); Label() += PvlKeyword("BandNumber", QString::number(m_stretch->getBandNumber())); - Label() += PvlKeyword("Color", "Greyscale"); } diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp index c279c5fe64..1d06c4028e 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretch.cpp @@ -99,16 +99,11 @@ namespace Isis { * * @return Stretch */ - Stretch AdvancedStretch::getStretch() { + CubeStretch AdvancedStretch::getStretch() { return ((StretchType *)p_stretchTypeStack->currentWidget())->getStretch(); } - CubeStretch AdvancedStretch::getCubeStretch() { - return ((StretchType *)p_stretchTypeStack->currentWidget())->getCubeStretch(); - } - - /** * This is called when the user creates a stretch outside of the * advanced stretch. For example, they do a global stretch. The diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretch.h b/isis/src/qisis/objs/StretchTool/AdvancedStretch.h index 66878dd274..fc578bbbb4 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretch.h +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretch.h @@ -36,8 +36,7 @@ namespace Isis { AdvancedStretch(Histogram &, const Stretch &, const QString &, const QColor &); ~AdvancedStretch(); - Stretch getStretch(); - CubeStretch getCubeStretch(); + CubeStretch getStretch(); void setStretch(Stretch newStretch); void restoreSavedStretch(CubeStretch newStretch); void setHistogram(const Histogram &newHist); diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp index 7fa95a7a5f..5aa14a3a15 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.cpp @@ -138,12 +138,11 @@ namespace Isis { /** - * Restores a saved stretch from the cube + * Restores a saved grayscale stretch from the cube * * @param stretch */ - void AdvancedStretchDialog::restoreSavedStretch(CubeStretch stretch){ - // if in gray mode + void AdvancedStretchDialog::restoreGrayStretch(CubeStretch stretch){ if (p_grayStretch) { p_grayStretch->restoreSavedStretch(stretch); } @@ -153,7 +152,15 @@ namespace Isis { } } - void AdvancedStretchDialog::restoreSavedRGB(CubeStretch red, CubeStretch green, CubeStretch blue) { + + /** + * Restores a saved RGB stretch from the cube + * + * @param red + * @param green + * @param blue + */ + void AdvancedStretchDialog::restoreRgbStretch(CubeStretch red, CubeStretch green, CubeStretch blue) { if (isRgbMode()) { if (p_redStretch) { p_redStretch->restoreSavedStretch(red); @@ -311,7 +318,7 @@ namespace Isis { */ CubeStretch AdvancedStretchDialog::getGrayStretch() { if(p_grayStretch) { - return p_grayStretch->getCubeStretch(); + return p_grayStretch->getStretch(); } else { QString msg = "Gray mode not enabled, cannot get gray stretch"; @@ -327,7 +334,7 @@ namespace Isis { */ CubeStretch AdvancedStretchDialog::getRedStretch() { if(p_redStretch) { - return p_redStretch->getCubeStretch(); + return p_redStretch->getStretch(); } else { QString msg = "RGB mode not enabled, cannot get red stretch"; @@ -343,7 +350,7 @@ namespace Isis { */ CubeStretch AdvancedStretchDialog::getGrnStretch() { if(p_grnStretch) { - return p_grnStretch->getCubeStretch(); + return p_grnStretch->getStretch(); } else { QString msg = "RGB mode not enabled, cannot get green stretch"; @@ -359,7 +366,7 @@ namespace Isis { */ CubeStretch AdvancedStretchDialog::getBluStretch() { if(p_bluStretch) { - return p_bluStretch->getCubeStretch(); + return p_bluStretch->getStretch(); } else { QString msg = "RGB mode not enabled, cannot get blue stretch"; diff --git a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h index 2c3eb6823d..9eff15a4f6 100644 --- a/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h +++ b/isis/src/qisis/objs/StretchTool/AdvancedStretchDialog.h @@ -49,8 +49,8 @@ namespace Isis { Histogram &grayHist); void updateHistogram(const Histogram &grayHist); bool isRgbMode() const; - void restoreSavedStretch(CubeStretch stretch); - void restoreSavedRGB(CubeStretch red, CubeStretch green, CubeStretch blue); + void restoreGrayStretch(CubeStretch stretch); + void restoreRgbStretch(CubeStretch red, CubeStretch green, CubeStretch blue); CubeStretch getGrayStretch(); CubeStretch getRedStretch(); diff --git a/isis/src/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index c26f1ad106..ecbc96b981 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -472,7 +472,7 @@ namespace Isis { icube->read(stretchBlob); CubeStretch cubeStretch = stretchBlob.getStretch(); if (m_advancedStretch->isVisible()) { - m_advancedStretch->restoreSavedStretch(cubeStretch); + m_advancedStretch->restoreGrayStretch(cubeStretch); } cvp->stretchGray(cubeStretch); } @@ -502,7 +502,7 @@ namespace Isis { CubeStretch blueStretch = blueStretchBlob.getStretch(); if (m_advancedStretch->isVisible()) { - m_advancedStretch->restoreSavedRGB(redStretch, greenStretch, blueStretch); + m_advancedStretch->restoreRgbStretch(redStretch, greenStretch, blueStretch); } cvp->stretchRed(redStretch); cvp->stretchGreen(greenStretch); From 928c588dfadd6121ea979d4e371321e6145b38aa Mon Sep 17 00:00:00 2001 From: Kristin Date: Mon, 10 Aug 2020 10:35:21 -0700 Subject: [PATCH 14/19] Update button location for AdvancedStretchTool --- .../StretchTool/AdvancedStretchDialog.cpp | 39 +++++++++++++++++-- .../objs/StretchTool/BinaryStretchType.cpp | 7 +++- .../objs/StretchTool/BinaryStretchType.h | 2 +- .../objs/StretchTool/LinearStretchType.cpp | 11 +++--- .../objs/StretchTool/LinearStretchType.h | 3 +- .../objs/StretchTool/ManualStretchType.cpp | 8 +++- .../objs/StretchTool/ManualStretchType.h | 2 +- .../objs/StretchTool/SawtoothStretchType.cpp | 8 +++- .../objs/StretchTool/SawtoothStretchType.h | 2 +- .../qisis/objs/StretchTool/StretchTool.cpp | 2 +- .../qisis/objs/StretchTool/StretchType.cpp | 16 +++----- isis/src/qisis/objs/StretchTool/StretchType.h | 3 +- 12 files changed, 73 insertions(+), 30 deletions(-) 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..4597a8e0a8 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() && diff --git a/isis/src/qisis/objs/StretchTool/StretchType.cpp b/isis/src/qisis/objs/StretchTool/StretchType.cpp index 3112a22d5e..66bd6dcb3f 100644 --- a/isis/src/qisis/objs/StretchTool/StretchType.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchType.cpp @@ -75,11 +75,11 @@ namespace Isis { QPushButton *loadStretchButton = new QPushButton("Restore Saved Stretch from Cube..."); connect(loadStretchButton, SIGNAL(clicked(bool)), this, SIGNAL(loadStretch())); p_mainLayout->addWidget(loadStretchButton, 6, 0); - - QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - sizePolicy.setHeightForWidth(true); - p_graph->setSizePolicy(sizePolicy); } + + QSizePolicy sizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + sizePolicy.setHeightForWidth(true); + p_graph->setSizePolicy(sizePolicy); } @@ -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 From ba738bde0f5a0e80763e789d10eb14f73ebc8405 Mon Sep 17 00:00:00 2001 From: Kristin Date: Mon, 10 Aug 2020 14:50:49 -0700 Subject: [PATCH 15/19] Switch Blob and Cube Reader filter list from QList to QMap --- isis/src/base/objs/Blob/Blob.cpp | 15 +++++++------ isis/src/base/objs/Blob/Blob.h | 10 ++++----- isis/src/base/objs/Cube/Cube.cpp | 4 +--- isis/src/base/objs/Cube/Cube.h | 4 ++-- .../qisis/objs/StretchTool/StretchTool.cpp | 21 ++++++++----------- 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/isis/src/base/objs/Blob/Blob.cpp b/isis/src/base/objs/Blob/Blob.cpp index ba1d0e9124..d031a252aa 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/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index 4597a8e0a8..02a725c08a 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -481,21 +481,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(); From 4e855b85bb0a1b21e1eae568819e26f4de340dc6 Mon Sep 17 00:00:00 2001 From: Kristin Date: Tue, 11 Aug 2020 09:50:02 -0700 Subject: [PATCH 16/19] 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. --- .../src/base/objs/CubeStretch/CubeStretch.cpp | 85 ++++++++++++++++--- isis/src/base/objs/CubeStretch/CubeStretch.h | 30 ++++++- .../src/base/objs/StretchBlob/StretchBlob.cpp | 22 ++++- isis/src/base/objs/StretchBlob/StretchBlob.h | 25 +++++- .../qisis/objs/StretchTool/StretchTool.cpp | 64 ++++++++++++-- 5 files changed, 198 insertions(+), 28 deletions(-) diff --git a/isis/src/base/objs/CubeStretch/CubeStretch.cpp b/isis/src/base/objs/CubeStretch/CubeStretch.cpp index 31c189abd1..9087cda79d 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,16 +38,16 @@ 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 @@ -45,23 +63,37 @@ 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 = "DefaultName"; 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; } + + 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 +102,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/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/qisis/objs/StretchTool/StretchTool.cpp b/isis/src/qisis/objs/StretchTool/StretchTool.cpp index 02a725c08a..a15c5ebc2c 100644 --- a/isis/src/qisis/objs/StretchTool/StretchTool.cpp +++ b/isis/src/qisis/objs/StretchTool/StretchTool.cpp @@ -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()) { @@ -533,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 { @@ -589,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, From 00b9b343324538c2ed549e68f5dbd138b16c0b87 Mon Sep 17 00:00:00 2001 From: Kristin Date: Tue, 11 Aug 2020 10:16:53 -0700 Subject: [PATCH 17/19] Add gtests and delete old-style tests --- .../src/base/objs/CubeStretch/CubeStretch.cpp | 13 +++- .../base/objs/CubeStretch/CubeStretch.truth | 64 ------------------- isis/src/base/objs/CubeStretch/unitTest.cpp | 13 ---- .../base/objs/StretchBlob/StretchBlob.truth | 1 - isis/src/base/objs/StretchBlob/unitTest.cpp | 16 ----- isis/tests/CubeStretchTest.cpp | 59 +++++++++++++++++ 6 files changed, 69 insertions(+), 97 deletions(-) delete mode 100644 isis/src/base/objs/CubeStretch/CubeStretch.truth delete mode 100644 isis/src/base/objs/CubeStretch/unitTest.cpp delete mode 100644 isis/src/base/objs/StretchBlob/StretchBlob.truth delete mode 100644 isis/src/base/objs/StretchBlob/unitTest.cpp create mode 100644 isis/tests/CubeStretchTest.cpp diff --git a/isis/src/base/objs/CubeStretch/CubeStretch.cpp b/isis/src/base/objs/CubeStretch/CubeStretch.cpp index 9087cda79d..a57b0b30ec 100644 --- a/isis/src/base/objs/CubeStretch/CubeStretch.cpp +++ b/isis/src/base/objs/CubeStretch/CubeStretch.cpp @@ -53,8 +53,8 @@ namespace Isis { * @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) { } @@ -69,7 +69,7 @@ namespace Isis { * @param Stretch Stretch to construct the CubeStretch from. */ CubeStretch::CubeStretch(Stretch const& stretch): Stretch(stretch) { - m_name = "DefaultName"; + m_name = "DefaultStretch"; m_bandNumber = 1; m_type = "Default"; } @@ -86,6 +86,13 @@ namespace Isis { } + /** + * 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()) && 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.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/tests/CubeStretchTest.cpp b/isis/tests/CubeStretchTest.cpp new file mode 100644 index 0000000000..d8bbfa20c1 --- /dev/null +++ b/isis/tests/CubeStretchTest.cpp @@ -0,0 +1,59 @@ +#include "Stretch.h" +#include "CubeStretch.h" +#include "IException.h" + +#include +#include + +#include + +TEST(CubeStretch, DefaultConstructor) { + Isis::CubeStretch cubeStretch; + EXPECT_STREQ(cubeStretch.getName(), "DefaultStretch"); + EXPECT_STREQ(cubeStretch.getType(), "Default"); + EXPECT_STREQ(cubeStretch.getBandNumber(), 1); +} + + +TEST(CubeStretch, ConstructorWithName) { + Isis::CubeStretch cubeStretch("name"); + EXPECT_STREQ(cubeStretch.getName(), "name"); + EXPECT_STREQ(cubeStretch.getType(), "Default"); + EXPECT_STREQ(cubeStretch.getBandNumber(), 1); +} + + +TEST(CubeStretch, ConstructorAllArge) { + Isis::CubeStretch cubeStretch("name", "type", 99); + EXPECT_STREQ(cubeStretch.getName(), "name"); + EXPECT_STREQ(cubeStretch.getType(), "type"); + EXPECT_STREQ(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 == cubeStrechOtherName) +} + +TEST(CubeStretch, GetSetType) { + Isis::CubeStretch cubeStretch("name", "type", 99); + cubeStretch.setType("NewType"); + EXPECT_STREQ(cubeStretch9.getType(), "NewType"); +} + +TEST(CubeStretch, GetSetName) { + Isis::CubeStretch cubeStretch("name", "type", 99); + cubeStretch.setName("NewName"); + EXPECT_STREQ(cubeStretch9.getName(), "NewName"); +} + +TEST(CubeStretch, GetSetBandNumber) { + Isis::CubeStretch cubeStretch("name", "type", 99); + cubeStretch.setBandNumber(50); + EXPECT_EQ(cubeStretch9.getBandNumber(), 50); +} + From 6afe27874cdd41260515c623e80ac3928c776bff Mon Sep 17 00:00:00 2001 From: Kristin Date: Tue, 11 Aug 2020 14:04:56 -0700 Subject: [PATCH 18/19] Add missing StretchBlob test --- isis/tests/CubeStretchTest.cpp | 29 +++++++++-------- isis/tests/StretchBlobTest.cpp | 57 ++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 15 deletions(-) create mode 100644 isis/tests/StretchBlobTest.cpp diff --git a/isis/tests/CubeStretchTest.cpp b/isis/tests/CubeStretchTest.cpp index d8bbfa20c1..0e22333fa9 100644 --- a/isis/tests/CubeStretchTest.cpp +++ b/isis/tests/CubeStretchTest.cpp @@ -9,51 +9,50 @@ TEST(CubeStretch, DefaultConstructor) { Isis::CubeStretch cubeStretch; - EXPECT_STREQ(cubeStretch.getName(), "DefaultStretch"); - EXPECT_STREQ(cubeStretch.getType(), "Default"); - EXPECT_STREQ(cubeStretch.getBandNumber(), 1); + 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(), "name"); - EXPECT_STREQ(cubeStretch.getType(), "Default"); - EXPECT_STREQ(cubeStretch.getBandNumber(), 1); + 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(), "name"); - EXPECT_STREQ(cubeStretch.getType(), "type"); - EXPECT_STREQ(cubeStretch.getBandNumber(), 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) + Isis::CubeStretch cubeStretchOtherName("othername", "type", 9); EXPECT_FALSE(cubeStretch99 == cubeStretch9); - EXPECT_FALSE(cubeStretch9 == cubeStrechOtherName) + EXPECT_FALSE(cubeStretch9 == cubeStretchOtherName); } TEST(CubeStretch, GetSetType) { Isis::CubeStretch cubeStretch("name", "type", 99); cubeStretch.setType("NewType"); - EXPECT_STREQ(cubeStretch9.getType(), "NewType"); + EXPECT_STREQ(cubeStretch.getType().toLatin1().data(), "NewType"); } TEST(CubeStretch, GetSetName) { Isis::CubeStretch cubeStretch("name", "type", 99); cubeStretch.setName("NewName"); - EXPECT_STREQ(cubeStretch9.getName(), "NewName"); + EXPECT_STREQ(cubeStretch.getName().toLatin1().data(), "NewName"); } TEST(CubeStretch, GetSetBandNumber) { Isis::CubeStretch cubeStretch("name", "type", 99); cubeStretch.setBandNumber(50); - EXPECT_EQ(cubeStretch9.getBandNumber(), 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); +}; From c3045fd6b0068a809f685b01affe4358eaeccbd0 Mon Sep 17 00:00:00 2001 From: Stuart Sides Date: Tue, 11 Aug 2020 15:02:44 -0700 Subject: [PATCH 19/19] Update Blob.cpp --- isis/src/base/objs/Blob/Blob.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/isis/src/base/objs/Blob/Blob.cpp b/isis/src/base/objs/Blob/Blob.cpp index d031a252aa..44b40f6847 100644 --- a/isis/src/base/objs/Blob/Blob.cpp +++ b/isis/src/base/objs/Blob/Blob.cpp @@ -196,7 +196,7 @@ namespace Isis { found = true; QMap::const_iterator i = keywords.constBegin(); while (i != keywords.constEnd()) { - if(obj.hasKeyword(i.key()) && (i.value() != obj[i.key()])) { + if (obj.hasKeyword(i.key()) && (i.value() != obj[i.key()])) { found = false; } ++i;