Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marciflip gtest #4431

Merged
merged 4 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 3 additions & 56 deletions isis/src/mro/apps/marciflip/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,66 +7,13 @@ find files of those names at the top level of this repository. **/
/* SPDX-License-Identifier: CC0-1.0 */

#include "Isis.h"
#include "ProcessImportPds.h"
#include "FileName.h"
#include "Brick.h"
#include "ProcessByBrick.h"
#include "OriginalLabel.h"
#include "IException.h"
#include "UserInterface.h"
#include "marciflip.h"

using namespace std;
using namespace Isis;

Isis::Cube *outputCube = NULL;
int currentLine;
int filterHeight = 16;

void flipCube(Isis::Buffer &data);

void IsisMain() {
ProcessByBrick p;

Cube *icube = p.SetInputCube("FROM");

filterHeight = 16 / (int)icube->group("Instrument")["SummingMode"];
p.SetBrickSize(icube->sampleCount(), filterHeight, icube->bandCount());
currentLine = icube->lineCount();

UserInterface &ui = Application::GetUserInterface();
outputCube = new Isis::Cube();
outputCube->setDimensions(icube->sampleCount(), icube->lineCount(), icube->bandCount());
outputCube->create(ui.GetFileName("TO"));

if(icube->hasGroup("Instrument")) {
PvlGroup inst = icube->group("Instrument");

// change flipped keyword
inst["DataFlipped"] = toString(((int)inst["DataFlipped"] + 1) % 2);

outputCube->label()->findObject("IsisCube").addGroup(inst);
}

if(icube->hasGroup("BandBin")) {
outputCube->label()->findObject("IsisCube").addGroup(
icube->group("BandBin"));
}

if(icube->label()->hasObject("OriginalLabel")) {
OriginalLabel origLabel = icube->readOriginalLabel();
outputCube->write(origLabel);
}

p.StartProcess(flipCube);
p.EndProcess();

outputCube->close();
delete outputCube;
}

void flipCube(Isis::Buffer &data) {
currentLine -= filterHeight;
Brick outBrick(data.SampleDimension(), data.LineDimension(), data.BandDimension(), data.PixelType());
outBrick.Copy(data);
outBrick.SetBasePosition(1, currentLine + 1, data.Band());
outputCube->write(outBrick);
marciflip(ui);
}
84 changes: 84 additions & 0 deletions isis/src/mro/apps/marciflip/marciflip.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/** 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 "ProcessImportPds.h"
#include "FileName.h"
#include "Brick.h"
#include "ProcessByBrick.h"
#include "OriginalLabel.h"
#include "IException.h"
#include "marciflip.h"

using namespace std;

Isis::Cube *outputCube = NULL;
int currentLine;
int filterHeight = 16;

void flipCube(Isis::Buffer &data);

namespace Isis {

void marciflip(UserInterface &ui) {

Isis::ProcessByBrick p;
QString cubeFn;
Isis::Cube *icube;
Isis::CubeAttributeInput inAtt;

cubeFn = ui.GetFileName("FROM");
icube = new Cube(cubeFn);
inAtt = ui.GetInputAttribute("FROM");

p.SetInputCube(cubeFn, inAtt);

filterHeight = 16 / (int)icube->group("Instrument")["SummingMode"];

p.SetBrickSize(icube->sampleCount(), filterHeight, icube->bandCount());

currentLine = icube->lineCount();

outputCube = new Cube();
outputCube->setDimensions(icube->sampleCount(), icube->lineCount(), icube->bandCount());

outputCube->create(ui.GetFileName("TO"));

if(icube->hasGroup("Instrument")) {
PvlGroup inst = icube->group("Instrument");

// change flipped keyword
inst["DataFlipped"] = toString(((int)inst["DataFlipped"] + 1) % 2);

outputCube->label()->findObject("IsisCube").addGroup(inst);
}

if(icube->hasGroup("BandBin")) {
outputCube->label()->findObject("IsisCube").addGroup(
icube->group("BandBin"));
}

if(icube->label()->hasObject("OriginalLabel")) {
OriginalLabel origLabel = icube->readOriginalLabel();
outputCube->write(origLabel);
}

p.StartProcess(flipCube);
p.EndProcess();

outputCube->close();
delete outputCube;
}
}

void flipCube(Isis::Buffer &data) {
currentLine -= filterHeight;
Isis::Brick outBrick(data.SampleDimension(), data.LineDimension(), data.BandDimension(), data.PixelType());
outBrick.Copy(data);
outBrick.SetBasePosition(1, currentLine + 1, data.Band());
outputCube->write(outBrick);
}
18 changes: 18 additions & 0 deletions isis/src/mro/apps/marciflip/marciflip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef marciflip_h
#define marciflip_h

/** 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 "UserInterface.h"

namespace Isis{
extern void marciflip(UserInterface &ui);
}

#endif
4 changes: 0 additions & 4 deletions isis/src/mro/apps/marciflip/tsts/Makefile

This file was deleted.

8 changes: 0 additions & 8 deletions isis/src/mro/apps/marciflip/tsts/default/Makefile

This file was deleted.

8 changes: 4 additions & 4 deletions isis/tests/FunctionalTestsMarcical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static QString APP_XML = FileName("$ISISROOT/bin/xml/marcical.xml").expanded();
TEST(Marcical, MarcicalTestDefault) {
QTemporaryDir prefix;
QString cubeFileName = prefix.path() + "/marcical_out.cub";
QVector<QString> args = {"from=data/marci2isis/P12_005901_3391_MA_00N096W_cropped.cub", "to=" + cubeFileName };
QVector<QString> args = {"from=data/marcical/P12_005901_3391_MA_00N096W_cropped.cub", "to=" + cubeFileName };
UserInterface options(APP_XML, args);
marcical(options);

Expand All @@ -44,7 +44,7 @@ TEST(Marcical, MarcicalTestDefault) {
TEST(Marcical, MarcicalTestDefaultNoIof) {
QTemporaryDir prefix;
QString cubeFileName = prefix.path() + "/marcical_out.cub";
QVector<QString> args = {"from=data/marci2isis/P12_005901_3391_MA_00N096W_cropped.cub", "to=" + cubeFileName, "iof=no" };
QVector<QString> args = {"from=data/marcical/P12_005901_3391_MA_00N096W_cropped.cub", "to=" + cubeFileName, "iof=no" };
UserInterface options(APP_XML, args);
marcical(options);

Expand All @@ -71,7 +71,7 @@ TEST(Marcical, MarcicalTestDefaultNoIof) {
TEST(Marcical, MarcicalTestSingleDuration) {
QTemporaryDir prefix;
QString cubeFileName = prefix.path() + "/marcical_out.cub";
QVector<QString> args = {"from=data/marci2isis/K14_059003_3475_MA_00N112W_cropped.cub", "to=" + cubeFileName };
QVector<QString> args = {"from=data/marcical/K14_059003_3475_MA_00N112W_cropped.cub", "to=" + cubeFileName };
UserInterface options(APP_XML, args);
marcical(options);

Expand All @@ -96,7 +96,7 @@ TEST(Marcical, MarcicalTestSingleDuration) {
TEST(Marcical, MarcicalTestSingleDurationNoIof) {
QTemporaryDir prefix;
QString cubeFileName = prefix.path() + "/marcical_out.cub";
QVector<QString> args = {"from=data/marci2isis/K14_059003_3475_MA_00N112W_cropped.cub", "to=" + cubeFileName, "iof=no" };
QVector<QString> args = {"from=data/marcical/K14_059003_3475_MA_00N112W_cropped.cub", "to=" + cubeFileName, "iof=no" };
UserInterface options(APP_XML, args);
marcical(options);

Expand Down
63 changes: 63 additions & 0 deletions isis/tests/FunctionalTestsMarciflip.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <QTemporaryDir>

#include "marciflip.h"
#include "Fixtures.h"
#include "Pvl.h"
#include "PvlGroup.h"
#include "TestUtilities.h"
#include "Histogram.h"
#include "Portal.h"

#include "gtest/gtest.h"
#include "gmock/gmock.h"

using namespace Isis;

static QString APP_XML = FileName("$ISISROOT/bin/xml/marciflip.xml").expanded();

TEST(Marciflip, MarciflipTestDefault) {
QTemporaryDir prefix;
QString outCubeFn = prefix.path() + "/marciflip_out.cub";
QString inCubeFn = "data/marciflip/T02_001002_1200_MC_00N284W_cropped.cub";
QVector<QString> args = {"from=" + inCubeFn, "to=" + outCubeFn };
UserInterface options(APP_XML, args);
marciflip(options);

Cube inCube(inCubeFn);
Cube outCube(outCubeFn);
Pvl *label = outCube.label();

PvlGroup &dims = label->findGroup("Dimensions", Pvl::Traverse);
EXPECT_EQ( (int)dims["Lines"], 48 );
EXPECT_EQ( (int)dims["Samples"], 2 );
EXPECT_EQ( (int)dims["Bands"], 3 );

PvlGroup &inst = label->findGroup("Instrument", Pvl::Traverse);
EXPECT_EQ( (int)inst.findKeyword("DataFlipped"), 0 );

// check that the cubes have equal histograms
// since pixels should only be moved, not changed
std::unique_ptr<Histogram> outHist (outCube.histogram());
std::unique_ptr<Histogram> inHist (inCube.histogram());
EXPECT_EQ( outHist->Average(), outHist->Average() );
EXPECT_EQ( outHist->Sum(), outHist->Sum() );
EXPECT_EQ( outHist->ValidPixels(), outHist->ValidPixels() );
EXPECT_EQ( outHist->StandardDeviation(), outHist->StandardDeviation() );


// check that first 8 lines of input cube
// are equal to last 8 lines of output cube
Portal iPortal( 2, 1, inCube.pixelType() );
Portal oPortal( 2, 1, outCube.pixelType() );

for( int lines = 0; lines < 8; lines++ ) {
iPortal.SetPosition(1, 1 + lines, 1);
inCube.read(iPortal);

oPortal.SetPosition(1, 41 + lines, 1);
outCube.read(oPortal);

EXPECT_DOUBLE_EQ(iPortal[0], oPortal[0]);
EXPECT_DOUBLE_EQ(iPortal[1], oPortal[1]);
}
}
Binary file not shown.