Unverified Commit aba85d99 authored by Christine Kim's avatar Christine Kim Committed by GitHub
Browse files

Segfault fix and tests (#5262)

parent 537d1236
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ release.
### Fixed
- Updated History constructor to check for invalid BLOB before copying History BLOB to output cube [#4966](https://github.com/DOI-USGS/ISIS3/issues/4966)
- Updated photomet MinnaertEmpirical model to support photemplate-style PVL format [#3621](https://github.com/DOI-USGS/ISIS3/issues/3621)
- Fixed gaussstretch segmentation fault error and refactored gaussstretch files/tests to use gtest [#5240](https://github.com/DOI-USGS/ISIS3/issues/5240)

## [8.0.0] - 2023-04-19

+55 −0
Original line number Diff line number Diff line
#include "ProcessByLine.h"
#include "Statistics.h"
#include "GaussianStretch.h"
#include "gaussstretch.h"

using namespace std;
using namespace Isis;

namespace Isis {

  void gaussstretch(UserInterface &ui) {
    Cube icube;
    CubeAttributeInput inAtt = ui.GetInputAttribute("FROM");
    if (inAtt.bands().size() != 0) {
      icube.setVirtualBands(inAtt.bands());
    }
    icube.open(ui.GetCubeName("FROM"));
    gaussstretch(&icube, ui);
  }

  void gaussstretch(Cube *icube, UserInterface &ui) {
    ProcessByLine p;
    p.SetInputCube(icube);
    QString outputFileName = ui.GetCubeName("TO");
    CubeAttributeOutput outputAttributes= ui.GetOutputAttribute("TO");
    p.SetOutputCube(outputFileName, outputAttributes, 
                    icube->sampleCount(), icube->lineCount(), icube->bandCount());
    double gsigma = ui.GetDouble("GSIGMA");

    vector<GaussianStretch *> stretch;
    for(int i = 0; i < icube->bandCount(); i++) {
      Histogram *hist = icube->histogram(i + 1);
      double mean = (hist->Maximum() + hist->Minimum()) / 2.0;
      double stdev = (hist->Maximum() - hist->Minimum()) / (2.0 * gsigma);
      stretch.push_back(new GaussianStretch(*hist, mean, stdev));
    }

    // Processing routine for the pca with one input cube
    auto gaussProcess = [&](Buffer &in, Buffer &out)->void {
      for(int i = 0; i < in.size(); i++) {
        if(IsSpecial(in[i])) out[i] = in[i];
        out[i] = stretch[in.Band(i)-1]->Map(in[i]);
      }
    };

    p.StartProcess(gaussProcess);
    for(int i = icube->bandCount()-1; i >= 0 ; i--) {
      delete stretch[i];
      stretch.pop_back();
    }
    p.EndProcess();

    stretch.clear();
  }
}
+12 −0
Original line number Diff line number Diff line
#ifndef gaussstretch_h
#define gaussstretch_h

#include "Cube.h"
#include "UserInterface.h"

namespace Isis {
    extern void gaussstretch(Cube *icube, UserInterface &ui);
    extern void gaussstretch(UserInterface &ui);
}

#endif
+5 −37
Original line number Diff line number Diff line
#include "Isis.h"
#include "ProcessByLine.h"
#include "Statistics.h"
#include "GaussianStretch.h"

#include "gaussstretch.h"
#include "Application.h"

using namespace std;
using namespace Isis;

void gauss(Buffer &in, Buffer &out);

vector<GaussianStretch *> stretch;

void IsisMain() {
  ProcessByLine p;
  Cube *icube = p.SetInputCube("FROM");
  p.SetOutputCube("TO");
  double gsigma = Isis::Application::GetUserInterface().GetDouble("GSIGMA");

  for(int i = 0; i < icube->bandCount(); i++) {
    Histogram *hist = icube->histogram(i + 1);
    double mean = (hist->Maximum() + hist->Minimum()) / 2.0;
    double stdev = (hist->Maximum() - hist->Minimum()) / (2.0 * gsigma);
    stretch.push_back(new GaussianStretch(*hist, mean, stdev));
  }

  p.StartProcess(gauss);
  for(int i = 0; i < icube->bandCount(); i++) delete stretch[i];
  p.EndProcess();

  while(!stretch.empty()) {
      delete stretch.back();
      stretch.pop_back();
  }

  stretch.clear();
}

// Processing routine for the pca with one input cube
void gauss(Buffer &in, Buffer &out) {
  for(int i = 0; i < in.size(); i++) {
    if(IsSpecial(in[i])) out[i] = in[i];
    out[i] = stretch[in.Band(i)-1]->Map(in[i]);
  }
  UserInterface &ui = Application::GetUserInterface();
  gaussstretch(ui);
}
+0 −4
Original line number Diff line number Diff line
BLANKS = "%-6s"    
LENGTH = "%-40s"

include $(ISISROOT)/make/isismake.tststree
Loading