Skip to content

Commit

Permalink
Update stretch branch based on PR review (#4253)
Browse files Browse the repository at this point in the history
* Update to use CubeStretches were appropriate and other updates based on PR review

* Further updates based on review and added tests based on minor problems uncovered and fixed

* Removed commented-out code

* Stretch tool updates based on error message popping up inappropriately

* Updated setting of member variable

* Fix but in which special pixel values selected by the Special Pixel tool or defaults were not applied to restored stretches
  • Loading branch information
krlberry authored Jan 15, 2021
1 parent 11150fb commit 1fc9a55
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 193 deletions.
32 changes: 19 additions & 13 deletions isis/src/base/objs/Blob/Blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ namespace Isis {
* when there are multiple blobs with the same name, but different keywords that
* define the exact blob (see Stretch with a band number)
*/
void Blob::Find(const Pvl &pvl, const QMap<QString, QString> keywords) {
void Blob::Find(const Pvl &pvl, const std::vector<PvlKeyword> keywords) {
bool found = false;
try {
// Search for the blob name
Expand All @@ -191,17 +191,23 @@ namespace Isis {
QString curName = obj["Name"];
curName = curName.toUpper();
if (blobName == curName) {

if (keywords.size() >= 1) {
found = true;
QMap<QString, QString>::const_iterator i = keywords.constBegin();
while (i != keywords.constEnd()) {
if (obj.hasKeyword(i.key()) && (i.value() != obj[i.key()])) {
found = false;
// If there are keywords supplied, check that those match, too!
if (!keywords.empty()){
bool keywordFound = true;
for (PvlKeyword keyword : keywords) {
if (obj.hasKeyword(keyword.name())) {
PvlKeyword blobKeyword = obj.findKeyword(keyword.name());
if (blobKeyword == keyword && !blobKeyword.isEquivalent(keyword[0])) {
keywordFound = false;
break;
}
}
else {
keywordFound = false;
break;
}
++i;
}
if (found) {
if (keywordFound) {
p_blobPvl = obj;
found = true;
break;
Expand Down Expand Up @@ -262,7 +268,7 @@ namespace Isis {
* @throws iException::Io - Unable to open file
* @throws iException::Pvl - Invalid label format
*/
void Blob::Read(const QString &file, const QMap<QString,QString> keywords) {
void Blob::Read(const QString &file, const std::vector<PvlKeyword> keywords) {
// Expand the filename
QString temp(FileName(file).expanded());

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

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

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

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 QMap<QString,QString> keywords = QMap<QString,QString>());
void Find(const Pvl &pvl, const std::vector<PvlKeyword> keywords = std::vector<PvlKeyword>());
virtual void ReadInit();
virtual void ReadData(std::istream &is);
virtual void WriteInit();
Expand Down
2 changes: 1 addition & 1 deletion isis/src/base/objs/Cube/Cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ namespace Isis {
*
* @return (type)return description
*/
void Cube::read(Blob &blob, const QMap<QString,QString> keywords) const {
void Cube::read(Blob &blob, const std::vector<PvlKeyword> keywords) const {
if (!isOpen()) {
string msg = "The cube is not opened so you can't read a blob from it";
throw IException(IException::Programmer, msg, _FILEINFO_);
Expand Down
3 changes: 2 additions & 1 deletion isis/src/base/objs/Cube/Cube.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "Endian.h"
#include "PixelType.h"
#include "PvlKeyword.h"

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

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

namespace Isis {

/**
* Default constructor
*/
CubeStretch::CubeStretch() {
m_name = "DefaultStretch";
m_type = "Default";
m_bandNumber = 1;
}
/** This is free and unencumbered software released into the public domain.
The authors of ISIS do not claim copyright on the contents of this file.
For more details about the LICENSE terms and the AUTHORS, you will
find files of those names at the top level of this repository. **/

/* SPDX-License-Identifier: CC0-1.0 */

/**
* Constructs a Stretch object with default mapping of special pixel values to
* themselves and a provided name.
*
* @param name Name to use for CubeStretch
*/
CubeStretch::CubeStretch(QString name) : m_name(name) {
m_type = "Default";
m_bandNumber = 1;
}
#include "CubeStretch.h"

namespace Isis {

/**
* Constructs a CubeStretch object with default mapping of special pixel values to
Expand Down
35 changes: 8 additions & 27 deletions isis/src/base/objs/CubeStretch/CubeStretch.h
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
#ifndef CubeStretch_h
#define CubeStretch_h
/**
* @file
* $Revision: 1.17 $
* $Date: 2010/03/22 19:44:53 $
*
* Unless noted otherwise, the portions of Isis written by the USGS are
* public domain. See individual third-party library and package descriptions
* for intellectual property information, user agreements, and related
* information.
*
* Although Isis has been used by the USGS, no warranty, expressed or
* implied, is made by the USGS as to the accuracy and functioning of such
* software and related material nor shall the fact of distribution
* constitute any such warranty, and no responsibility is assumed by the
* USGS in connection therewith.
*
* For additional information, launch
* $ISISROOT/doc//documents/Disclaimers/Disclaimers.html
* in a browser or see the Privacy &amp; Disclaimers page on the Isis website,
* http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on
* http://www.usgs.gov/privacy.html.
*/

/** This is free and unencumbered software released into the public domain.
The authors of ISIS do not claim copyright on the contents of this file.
For more details about the LICENSE terms and the AUTHORS, you will
find files of those names at the top level of this repository. **/

/* SPDX-License-Identifier: CC0-1.0 */

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

namespace Isis {
/**
Expand All @@ -41,14 +25,11 @@ namespace Isis {
*/
class CubeStretch : public Stretch {
public:
CubeStretch();
CubeStretch(QString name);
CubeStretch(QString name, QString stretchType, int bandNumber=1);
CubeStretch(QString name="DefaultStretch", QString stretchType="Default", 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);

bool operator==(CubeStretch& stretch2);

Expand Down
62 changes: 21 additions & 41 deletions isis/src/base/objs/StretchBlob/StretchBlob.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
/**
* @file
* $Revision: 1.19 $
* $Date: 2010/03/22 19:44:53 $
*
* Unless noted otherwise, the portions of Isis written by the USGS are
* public domain. See individual third-party library and package descriptions
* for intellectual property information, user agreements, and related
* information.
*
* Although Isis has been used by the USGS, no warranty, expressed or
* implied, is made by the USGS as to the accuracy and functioning of such
* software and related material nor shall the fact of distribution
* constitute any such warranty, and no responsibility is assumed by the
* USGS in connection therewith.
*
* For additional information, launch
* $ISISROOT/doc//documents/Disclaimers/Disclaimers.html
* in a browser or see the Privacy &amp; Disclaimers page on the Isis website,
* http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on
* http://www.usgs.gov/privacy.html.
*/
/** This is free and unencumbered software released into the public domain.
The authors of ISIS do not claim copyright on the contents of this file.
For more details about the LICENSE terms and the AUTHORS, you will
find files of those names at the top level of this repository. **/

/* SPDX-License-Identifier: CC0-1.0 */

#include <iostream>
#include <fstream>

Expand All @@ -32,19 +17,17 @@ namespace Isis {
/**
* Default constructor
*/
StretchBlob::StretchBlob() : Blob("CubeStretch", "Stretch") {
m_stretch = new CubeStretch();
StretchBlob::StretchBlob() : Blob("CubeStretch", "Stretch"), m_stretch() {
}


/**
* Default constructor
* Construct a StretchBlob from a CubeStretch.
*/
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()));
StretchBlob::StretchBlob(CubeStretch stretch) : Blob("CubeStretch", "Stretch"), m_stretch(stretch){
p_blobPvl["Name"] = m_stretch.getName();
p_blobPvl += PvlKeyword("StretchType", m_stretch.getType());
p_blobPvl += PvlKeyword("BandNumber", QString::number(m_stretch.getBandNumber()));
}


Expand All @@ -53,22 +36,19 @@ namespace Isis {
*
* @param name Name to use for Stretch
*/
StretchBlob::StretchBlob(QString name) : Blob(name, "Stretch") {
m_stretch = new CubeStretch(name);
StretchBlob::StretchBlob(QString name) : Blob(name, "Stretch"), m_stretch(name) {
}


/**
* Default Destructor
*/
StretchBlob::~StretchBlob() {
m_stretch = NULL;
delete m_stretch;
}


CubeStretch StretchBlob::getStretch() {
return *m_stretch;
return m_stretch;
}

/**
Expand All @@ -81,14 +61,14 @@ namespace Isis {
*/
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());
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() +
QString msg = "Error preparing to read data from " + m_stretch.getType() +
" [" + p_blobName + "]";
throw IException(IException::Io, msg, _FILEINFO_);
}
Expand All @@ -100,7 +80,7 @@ namespace Isis {

// Read buffer data into a QString so we can call Parse()
std::string stringFromBuffer(buf);
m_stretch->Parse(QString::fromStdString(stringFromBuffer));
m_stretch.Parse(QString::fromStdString(stringFromBuffer));

delete [] buf;

Expand All @@ -116,7 +96,7 @@ namespace Isis {
* Initializes for writing stretch to cube blob
*/
void StretchBlob::WriteInit() {
p_nbytes = m_stretch->Text().toStdString().size();
p_nbytes = m_stretch.Text().toStdString().size();
}


Expand All @@ -129,7 +109,7 @@ namespace Isis {
* @param os output stream to write the stretch data to.
*/
void StretchBlob::WriteData(std::fstream &os) {
os.write(m_stretch->Text().toStdString().c_str(), p_nbytes);
os.write(m_stretch.Text().toStdString().c_str(), p_nbytes);
}

} // end namespace isis
Expand Down
Loading

0 comments on commit 1fc9a55

Please sign in to comment.