diff --git a/isis/src/base/apps/demprep/demprep.cpp b/isis/src/base/apps/demprep/demprep.cpp new file mode 100644 index 0000000000..c0df1aa2f1 --- /dev/null +++ b/isis/src/base/apps/demprep/demprep.cpp @@ -0,0 +1,416 @@ +#include + +#include "Distance.h" +#include "ProcessByLine.h" +#include "TProjection.h" +#include "SpecialPixel.h" +#include "LineManager.h" +#include "OriginalLabel.h" +#include "History.h" +#include "Table.h" +#include "Pvl.h" +#include "UserInterface.h" + +using namespace std; + +namespace Isis{ + + void DoWrap(Buffer &in); + void GetStats(Buffer &in, Buffer &out); + + Cube *ocube; + + int leftPad; + int rightPad; + int topPad; + int bottomPad; + int inl; + Statistics inCubeStats; + Statistics outCubeStats; + + void demprep(UserInterface &ui, Pvl *log) { + // We will be using a mosaic technique so get the size of the input file + ProcessByLine p; + + CubeAttributeInput &inputAtt = ui.GetInputAttribute("FROM"); + Cube *icube = p.SetInputCube(ui.GetFileName("FROM"), inputAtt); + int ins = icube->sampleCount(); + inl = icube->lineCount(); + int inb = icube->bandCount(); + outCubeStats.Reset(); + + PvlGroup mapgrp = icube->label()->findGroup("Mapping", Pvl::Traverse); + bool hasExtents = false; + bool isGlobal = false; + double minLat,maxLat,minLon,maxLon; + if (mapgrp.hasKeyword("MinimumLatitude") && mapgrp.hasKeyword("MaximumLatitude") && + mapgrp.hasKeyword("MinimumLongitude") && mapgrp.hasKeyword("MaximumLongitude")) { + hasExtents = true; + minLat = mapgrp["MinimumLatitude"]; + maxLat = mapgrp["MaximumLatitude"]; + minLon = mapgrp["MinimumLongitude"]; + maxLon = mapgrp["MaximumLongitude"]; + if ((maxLat - minLat) >= 180.0 && (maxLon - minLon) >= 360.0) isGlobal = true; + } + + TProjection *proj = (TProjection *) icube->projection(); + if(proj == NULL) { + IString message = "The input cube must be a DEM file, which means it must be projected. "; + message += "This file is not map projected."; + throw IException(IException::User, message, _FILEINFO_); + } + + if(!proj->IsEquatorialCylindrical()) { + CubeAttributeOutput &att = ui.GetOutputAttribute("TO"); + ocube = p.SetOutputCube(ui.GetFileName("TO"), att); + p.StartProcess(GetStats); + + PvlGroup demRange("Results"); + demRange += PvlKeyword("MinimumRadius", toString(inCubeStats.Minimum()), "meters"); + demRange += PvlKeyword("MaximumRadius", toString(inCubeStats.Maximum()), "meters"); + if (log){ + log->addGroup(demRange); + } + + // Store min/max radii values in new ShapeModelStatistics table + QString shp_name = "ShapeModelStatistics"; + TableField fmin("MinimumRadius",Isis::TableField::Double); + TableField fmax("MaximumRadius",Isis::TableField::Double); + + TableRecord record; + record += fmin; + record += fmax; + + Table table(shp_name,record); + + record[0] = Distance(inCubeStats.Minimum(), + Distance::Meters).kilometers(); + record[1] = Distance(inCubeStats.Maximum(), + Distance::Meters).kilometers(); + table += record; + + ocube->write(table); + p.EndProcess(); + return; + } + + if (proj->LatitudeTypeString() != "Planetocentric") { + IString message = "The input cube must have Planetocentric latitude type."; + throw IException(IException::User, message, _FILEINFO_); + } + + // Determine if the file is global + bool isPadded = false; + int insideImage = 0; + if (!hasExtents) { + if (proj->LongitudeDomainString() == "360") { + proj->SetGround(90.0,0.0); + if (proj->IsGood()) { + if (proj->WorldX() > 0.0 && proj->WorldX() < ins+1 && + proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { + insideImage = insideImage + 1; + } + proj->SetGround(90.0,360.0); + } + if (proj->IsGood()) { + if (proj->WorldX() > 0.0 && proj->WorldX() < ins+1 && + proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { + insideImage = insideImage + 1; + } + proj->SetGround(-90.0,0.0); + } + if (proj->IsGood()) { + if (proj->WorldX() > 0.0 && proj->WorldX() < ins+1 && + proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { + insideImage = insideImage + 1; + } + proj->SetGround(-90.0,360.0); + } + if (proj->IsGood()) { + if (proj->WorldX() > 0.0 && proj->WorldX() < ins+1 && + proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { + insideImage = insideImage + 1; + } + } + if (proj->IsGood() && insideImage == 4) isGlobal = true; + } else { + proj->SetGround(90.0,-180.0); + if (proj->IsGood()) { + if (proj->WorldX() > 0.0 && proj->WorldX() < ins+1 && + proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { + insideImage = insideImage + 1; + } + proj->SetGround(90.0,180.0); + } + if (proj->IsGood()) { + if (proj->WorldX() > 0.0 && proj->WorldX() < ins+1 && + proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { + insideImage = insideImage + 1; + } + proj->SetGround(-90.0,-180.0); + } + if (proj->IsGood()) { + if (proj->WorldX() > 0.0 && proj->WorldX() < ins+1 && + proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { + insideImage = insideImage + 1; + } + proj->SetGround(-90.0,180.0); + } + if (proj->IsGood()) { + if (proj->WorldX() > 0.0 && proj->WorldX() < ins+1 && + proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { + insideImage = insideImage + 1; + } + } + if (proj->IsGood() && insideImage == 4) isGlobal = true; + } + } + + if (isGlobal) { + if (proj->LongitudeDomainString() == "360") { + if (proj->LongitudeDirectionString() == "PositiveEast") { + proj->SetGround(90.0,0.0); + } else { + proj->SetGround(90.0,360.0); + } + if (proj->WorldX() >= 1.0 && proj->WorldY() >= 1.0) isPadded = true; + } else { + if (proj->LongitudeDirectionString() == "PositiveEast") { + proj->SetGround(90.0,-180.0); + } else { + proj->SetGround(90.0,180.0); + } + if (proj->WorldX() >= 1.0 && proj->WorldY() >= 1.0) isPadded = true; + } + } + + // If the file isn't global, then determine if it contains either + // the south or north pole + bool hasSPole = false; + bool hasNPole = false; + if (!isGlobal) { + proj->SetGround(90.0,0.0); + if (proj->IsGood()) { + if (proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { + hasNPole = true; + if (proj->WorldY() >= 1.0) isPadded = true; + } + } + proj->SetGround(-90.0,0.0); + if (proj->IsGood()) { + if (proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { + hasSPole = true; + if (proj->WorldY() <= inl) isPadded = true; + } + } + } + + // Set the padding parameters + leftPad = 0; + rightPad = 0; + topPad = 0; + bottomPad = 0; + + if (isGlobal && !isPadded) { + leftPad = 1; + rightPad = 1; + topPad = 1; + bottomPad = 1; + } + if (!isGlobal && !isPadded) { + leftPad = 0; + rightPad = 0; + if (hasNPole) { + topPad = 1; + } else { + topPad = 0; + } + if (hasSPole) { + bottomPad = 1; + } else { + bottomPad = 0; + } + } + + // Compute the output size + int ns = ins + leftPad + rightPad; + int nl = inl + topPad + bottomPad; + int nb = inb; + + double upperLeftCorner = mapgrp["UpperLeftCornerX"]; + upperLeftCorner -= leftPad * proj->Resolution(); + mapgrp.addKeyword(PvlKeyword("UpperLeftCornerX", toString(upperLeftCorner), "meters"), + Pvl::Replace); + + upperLeftCorner = mapgrp["UpperLeftCornerY"]; + upperLeftCorner += topPad * proj->Resolution(); + mapgrp.addKeyword(PvlKeyword("UpperLeftCornerY", toString(upperLeftCorner), "meters"), + Pvl::Replace); + + + CubeAttributeOutput &att = ui.GetOutputAttribute("TO"); + ocube = p.SetOutputCube(ui.GetFileName("TO"), att, ns, nl, nb); + // Make sure everything is propagated and closed + p.EndProcess(); + + // Now we'll really be processing our input cube + p.SetInputCube(ui.GetFileName("FROM"), inputAtt); + + // We need to create the output file + ocube = new Cube(); + ocube->open(FileName(ui.GetFileName("TO")).expanded(), "rw"); + + p.StartProcess(DoWrap); + + // Update mapping grp + ocube->putGroup(mapgrp); + + PvlGroup demRange("Results"); + demRange += PvlKeyword("MinimumRadius", toString(outCubeStats.Minimum()), "meters"); + demRange += PvlKeyword("MaximumRadius", toString(outCubeStats.Maximum()), "meters"); + if (log){ + log->addGroup(demRange); + } + + // Store min/max radii values in new ShapeModelStatistics table + QString shp_name = "ShapeModelStatistics"; + TableField fmin("MinimumRadius",Isis::TableField::Double); + TableField fmax("MaximumRadius",Isis::TableField::Double); + + TableRecord record; + record += fmin; + record += fmax; + + Table table(shp_name,record); + + record[0] = Distance(outCubeStats.Minimum(), + Distance::Meters).kilometers(); + record[1] = Distance(outCubeStats.Maximum(), + Distance::Meters).kilometers(); + table += record; + + ocube->write(table); + + p.EndProcess(); + ocube->close(); + delete ocube; + } + + void GetStats(Buffer &in, Buffer &out) { + inCubeStats.AddData(&in[0], in.size()); + for (int i=0; iwrite(outMan); + outMan.SetLine(2); + } + + // Copy most data + for(int outputIndex = 0; outputIndex < outputSize; outputIndex++) { + int inputIndex = outputIndex - leftPad; + if(inputIndex < 0) { + outMan[outputIndex] = in[inputIndex + inputSize]; + } + else if(inputIndex < inputSize) { + outMan[outputIndex] = in[inputIndex]; + } + else { + outMan[outputIndex] = in[inputIndex - inputSize]; + } + } + + outCubeStats.AddData(&outMan[0], outMan.size()); + ocube->write(outMan); + + // Write bottom pad? + if (bottomPad == 1 && in.Line() == inl) { + double average = inputLineStats.Average(); //may be Isis::NULL8 + for (int outputIndex = 0; outputIndex < outputSize; outputIndex++) { + int inputIndex = outputIndex - leftPad; + if (average == Isis::NULL8) { + if(inputIndex < 0) { + outMan[outputIndex] = in[inputIndex + inputSize]; + } + else if(inputIndex < inputSize) { + outMan[outputIndex] = in[inputIndex]; + } + else { + outMan[outputIndex] = in[inputIndex - inputSize]; + } + } + else { + if(inputIndex < 0) { + outMan[outputIndex] = 2.0 * average - in[inputIndex + inputSize]; + } + else if(inputIndex < inputSize) { + outMan[outputIndex] = 2.0 * average - in[inputIndex]; + } + else { + outMan[outputIndex] = 2.0 * average - in[inputIndex - inputSize]; + } + } + } + outMan.SetLine(inl + topPad + bottomPad); + outCubeStats.AddData(&outMan[0], outMan.size()); + ocube->write(outMan); + } + } +} diff --git a/isis/src/base/apps/demprep/demprep.h b/isis/src/base/apps/demprep/demprep.h new file mode 100644 index 0000000000..29af3c4e92 --- /dev/null +++ b/isis/src/base/apps/demprep/demprep.h @@ -0,0 +1,11 @@ +#ifndef demprep_h // Change this to your app name in all lower case suffixed with _h (e.g. campt_h, cam2map_h etc.) +#define demprep_h + +#include "Cube.h" +#include "UserInterface.h" + +namespace Isis{ + extern void demprep(UserInterface &ui, Pvl *log); +} + +#endif diff --git a/isis/src/base/apps/demprep/main.cpp b/isis/src/base/apps/demprep/main.cpp index ff87ea920e..95cb0e9271 100644 --- a/isis/src/base/apps/demprep/main.cpp +++ b/isis/src/base/apps/demprep/main.cpp @@ -1,407 +1,25 @@ #include "Isis.h" -#include +#include "Application.h" +#include "Pvl.h" +#include "demprep.h" -#include "Distance.h" -#include "ProcessByLine.h" -#include "TProjection.h" -#include "SpecialPixel.h" -#include "LineManager.h" -#include "OriginalLabel.h" -#include "History.h" -#include "Table.h" - -using namespace std; using namespace Isis; -void DoWrap(Buffer &in); -void GetStats(Buffer &in, Buffer &out); - -Cube *ocube; - -int leftPad; -int rightPad; -int topPad; -int bottomPad; -int inl; -Statistics inCubeStats; -Statistics outCubeStats; - void IsisMain() { - // We will be using a mosaic technique so get the size of the input file - ProcessByLine p; UserInterface &ui = Application::GetUserInterface(); - Cube *icube = p.SetInputCube("FROM"); - int ins = icube->sampleCount(); - inl = icube->lineCount(); - int inb = icube->bandCount(); - outCubeStats.Reset(); - - PvlGroup mapgrp = icube->label()->findGroup("Mapping", Pvl::Traverse); - bool hasExtents = false; - bool isGlobal = false; - double minLat,maxLat,minLon,maxLon; - if (mapgrp.hasKeyword("MinimumLatitude") && mapgrp.hasKeyword("MaximumLatitude") && - mapgrp.hasKeyword("MinimumLongitude") && mapgrp.hasKeyword("MaximumLongitude")) { - hasExtents = true; - minLat = mapgrp["MinimumLatitude"]; - maxLat = mapgrp["MaximumLatitude"]; - minLon = mapgrp["MinimumLongitude"]; - maxLon = mapgrp["MaximumLongitude"]; - if ((maxLat - minLat) >= 180.0 && (maxLon - minLon) >= 360.0) isGlobal = true; - } - - TProjection *proj = (TProjection *) icube->projection(); - if(proj == NULL) { - IString message = "The input cube must be a DEM file, which means it must be projected. "; - message += "This file is not map projected."; - throw IException(IException::User, message, _FILEINFO_); - } - - if(!proj->IsEquatorialCylindrical()) { - ocube = p.SetOutputCube("TO"); - p.StartProcess(GetStats); - - PvlGroup demRange("Results"); - demRange += PvlKeyword("MinimumRadius", toString(inCubeStats.Minimum()), "meters"); - demRange += PvlKeyword("MaximumRadius", toString(inCubeStats.Maximum()), "meters"); - Application::Log(demRange); - - // Store min/max radii values in new ShapeModelStatistics table - QString shp_name = "ShapeModelStatistics"; - TableField fmin("MinimumRadius",Isis::TableField::Double); - TableField fmax("MaximumRadius",Isis::TableField::Double); - - TableRecord record; - record += fmin; - record += fmax; - - Table table(shp_name,record); - - record[0] = Distance(inCubeStats.Minimum(), - Distance::Meters).kilometers(); - record[1] = Distance(inCubeStats.Maximum(), - Distance::Meters).kilometers(); - table += record; - - ocube->write(table); - p.EndProcess(); - return; - } - - if (proj->LatitudeTypeString() != "Planetocentric") { - IString message = "The input cube must have Planetocentric latitude type."; - throw IException(IException::User, message, _FILEINFO_); - } - - // Determine if the file is global - bool isPadded = false; - int insideImage = 0; - if (!hasExtents) { - if (proj->LongitudeDomainString() == "360") { - proj->SetGround(90.0,0.0); - if (proj->IsGood()) { - if (proj->WorldX() > 0.0 && proj->WorldX() < ins+1 && - proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { - insideImage = insideImage + 1; - } - proj->SetGround(90.0,360.0); - } - if (proj->IsGood()) { - if (proj->WorldX() > 0.0 && proj->WorldX() < ins+1 && - proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { - insideImage = insideImage + 1; - } - proj->SetGround(-90.0,0.0); - } - if (proj->IsGood()) { - if (proj->WorldX() > 0.0 && proj->WorldX() < ins+1 && - proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { - insideImage = insideImage + 1; - } - proj->SetGround(-90.0,360.0); - } - if (proj->IsGood()) { - if (proj->WorldX() > 0.0 && proj->WorldX() < ins+1 && - proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { - insideImage = insideImage + 1; - } - } - if (proj->IsGood() && insideImage == 4) isGlobal = true; - } else { - proj->SetGround(90.0,-180.0); - if (proj->IsGood()) { - if (proj->WorldX() > 0.0 && proj->WorldX() < ins+1 && - proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { - insideImage = insideImage + 1; - } - proj->SetGround(90.0,180.0); - } - if (proj->IsGood()) { - if (proj->WorldX() > 0.0 && proj->WorldX() < ins+1 && - proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { - insideImage = insideImage + 1; - } - proj->SetGround(-90.0,-180.0); - } - if (proj->IsGood()) { - if (proj->WorldX() > 0.0 && proj->WorldX() < ins+1 && - proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { - insideImage = insideImage + 1; - } - proj->SetGround(-90.0,180.0); - } - if (proj->IsGood()) { - if (proj->WorldX() > 0.0 && proj->WorldX() < ins+1 && - proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { - insideImage = insideImage + 1; - } - } - if (proj->IsGood() && insideImage == 4) isGlobal = true; - } - } - - if (isGlobal) { - if (proj->LongitudeDomainString() == "360") { - if (proj->LongitudeDirectionString() == "PositiveEast") { - proj->SetGround(90.0,0.0); - } else { - proj->SetGround(90.0,360.0); - } - if (proj->WorldX() >= 1.0 && proj->WorldY() >= 1.0) isPadded = true; - } else { - if (proj->LongitudeDirectionString() == "PositiveEast") { - proj->SetGround(90.0,-180.0); - } else { - proj->SetGround(90.0,180.0); - } - if (proj->WorldX() >= 1.0 && proj->WorldY() >= 1.0) isPadded = true; - } - } - - // If the file isn't global, then determine if it contains either - // the south or north pole - bool hasSPole = false; - bool hasNPole = false; - if (!isGlobal) { - proj->SetGround(90.0,0.0); - if (proj->IsGood()) { - if (proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { - hasNPole = true; - if (proj->WorldY() >= 1.0) isPadded = true; - } - } - proj->SetGround(-90.0,0.0); - if (proj->IsGood()) { - if (proj->WorldY() > 0.0 && proj->WorldY() < inl+1) { - hasSPole = true; - if (proj->WorldY() <= inl) isPadded = true; - } - } - } - - // Set the padding parameters - leftPad = 0; - rightPad = 0; - topPad = 0; - bottomPad = 0; - - if (isGlobal && !isPadded) { - leftPad = 1; - rightPad = 1; - topPad = 1; - bottomPad = 1; - } - if (!isGlobal && !isPadded) { - leftPad = 0; - rightPad = 0; - if (hasNPole) { - topPad = 1; - } else { - topPad = 0; - } - if (hasSPole) { - bottomPad = 1; - } else { - bottomPad = 0; - } - } - - // Compute the output size - int ns = ins + leftPad + rightPad; - int nl = inl + topPad + bottomPad; - int nb = inb; - - double upperLeftCorner = mapgrp["UpperLeftCornerX"]; - upperLeftCorner -= leftPad * proj->Resolution(); - mapgrp.addKeyword(PvlKeyword("UpperLeftCornerX", toString(upperLeftCorner), "meters"), - Pvl::Replace); - - upperLeftCorner = mapgrp["UpperLeftCornerY"]; - upperLeftCorner += topPad * proj->Resolution(); - mapgrp.addKeyword(PvlKeyword("UpperLeftCornerY", toString(upperLeftCorner), "meters"), - Pvl::Replace); - - - p.SetOutputCube("TO", ns, nl, nb); - // Make sure everything is propagated and closed - p.EndProcess(); - - // Now we'll really be processing our input cube - p.SetInputCube("FROM"); - - // We need to create the output file - ocube = new Cube(); - ocube->open(FileName(ui.GetFileName("TO")).expanded(), "rw"); - - p.StartProcess(DoWrap); - - // Update mapping grp - ocube->putGroup(mapgrp); - - PvlGroup demRange("Results"); - demRange += PvlKeyword("MinimumRadius", toString(outCubeStats.Minimum()), "meters"); - demRange += PvlKeyword("MaximumRadius", toString(outCubeStats.Maximum()), "meters"); - Application::Log(demRange); - - // Store min/max radii values in new ShapeModelStatistics table - QString shp_name = "ShapeModelStatistics"; - TableField fmin("MinimumRadius",Isis::TableField::Double); - TableField fmax("MaximumRadius",Isis::TableField::Double); - - TableRecord record; - record += fmin; - record += fmax; - - Table table(shp_name,record); - - record[0] = Distance(outCubeStats.Minimum(), - Distance::Meters).kilometers(); - record[1] = Distance(outCubeStats.Maximum(), - Distance::Meters).kilometers(); - table += record; - - ocube->write(table); - - p.EndProcess(); - ocube->close(); - delete ocube; -} - -void GetStats(Buffer &in, Buffer &out) { - inCubeStats.AddData(&in[0], in.size()); - for (int i=0; iwrite(outMan); - outMan.SetLine(2); - } - - // Copy most data - for(int outputIndex = 0; outputIndex < outputSize; outputIndex++) { - int inputIndex = outputIndex - leftPad; - if(inputIndex < 0) { - outMan[outputIndex] = in[inputIndex + inputSize]; - } - else if(inputIndex < inputSize) { - outMan[outputIndex] = in[inputIndex]; - } - else { - outMan[outputIndex] = in[inputIndex - inputSize]; - } - } - - outCubeStats.AddData(&outMan[0], outMan.size()); - ocube->write(outMan); - - // Write bottom pad? - if (bottomPad == 1 && in.Line() == inl) { - double average = inputLineStats.Average(); //may be Isis::NULL8 - for (int outputIndex = 0; outputIndex < outputSize; outputIndex++) { - int inputIndex = outputIndex - leftPad; - if (average == Isis::NULL8) { - if(inputIndex < 0) { - outMan[outputIndex] = in[inputIndex + inputSize]; - } - else if(inputIndex < inputSize) { - outMan[outputIndex] = in[inputIndex]; - } - else { - outMan[outputIndex] = in[inputIndex - inputSize]; - } - } - else { - if(inputIndex < 0) { - outMan[outputIndex] = 2.0 * average - in[inputIndex + inputSize]; - } - else if(inputIndex < inputSize) { - outMan[outputIndex] = 2.0 * average - in[inputIndex]; - } - else { - outMan[outputIndex] = 2.0 * average - in[inputIndex - inputSize]; - } - } - } - outMan.SetLine(inl + topPad + bottomPad); - outCubeStats.AddData(&outMan[0], outMan.size()); - ocube->write(outMan); + for (auto grpIt = appLog.beginGroup(); grpIt!= appLog.endGroup(); grpIt++) { + Application::Log(*grpIt); } } diff --git a/isis/src/base/apps/demprep/tsts/Makefile b/isis/src/base/apps/demprep/tsts/Makefile deleted file mode 100644 index 46d84c74c2..0000000000 --- a/isis/src/base/apps/demprep/tsts/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -BLANKS = "%-6s" -LENGTH = "%-40s" - -include $(ISISROOT)/make/isismake.tststree diff --git a/isis/src/base/apps/demprep/tsts/prepglobal/Makefile b/isis/src/base/apps/demprep/tsts/prepglobal/Makefile deleted file mode 100644 index 67ec73d0e3..0000000000 --- a/isis/src/base/apps/demprep/tsts/prepglobal/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -APPNAME = demprep - -labels.txt.IGNORELINES = Bytes StartByte ByteOrder TileSamples TileLines - -include $(ISISROOT)/make/isismake.tsts - -commands: - $(APPNAME) from=$(INPUT)/ulcn2005_lpo.cub \ - to=$(OUTPUT)/ulcn2005_lpo_pad.cub > /dev/null; - catlab from=$(OUTPUT)/ulcn2005_lpo_pad.cub to=$(OUTPUT)/labels.txt > /dev/null; diff --git a/isis/src/base/apps/demprep/tsts/prepinside/Makefile b/isis/src/base/apps/demprep/tsts/prepinside/Makefile deleted file mode 100644 index 20c7a77d41..0000000000 --- a/isis/src/base/apps/demprep/tsts/prepinside/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -APPNAME = demprep - -labels.txt.IGNORELINES = Bytes StartByte ByteOrder TileSamples TileLines - -include $(ISISROOT)/make/isismake.tsts - -commands: - $(APPNAME) from=$(INPUT)/ulcn2005_lpo_inside.cub \ - to=$(OUTPUT)/ulcn2005_lpo_inside_pad.cub > /dev/null; - catlab from=$(OUTPUT)/ulcn2005_lpo_inside_pad.cub to=$(OUTPUT)/labels.txt > /dev/null; diff --git a/isis/src/base/apps/demprep/tsts/prepnpole/Makefile b/isis/src/base/apps/demprep/tsts/prepnpole/Makefile deleted file mode 100644 index bf45698152..0000000000 --- a/isis/src/base/apps/demprep/tsts/prepnpole/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -APPNAME = demprep - -labels.txt.IGNORELINES = Bytes StartByte ByteOrder TileSamples TileLines - -include $(ISISROOT)/make/isismake.tsts - -commands: - $(APPNAME) from=$(INPUT)/ulcn2005_lpo_npole.cub \ - to=$(OUTPUT)/ulcn2005_lpo_npole_pad.cub > /dev/null; - catlab from=$(OUTPUT)/ulcn2005_lpo_npole_pad.cub to=$(OUTPUT)/labels.txt > /dev/null; diff --git a/isis/src/base/apps/demprep/tsts/prepspole/Makefile b/isis/src/base/apps/demprep/tsts/prepspole/Makefile deleted file mode 100644 index a528150816..0000000000 --- a/isis/src/base/apps/demprep/tsts/prepspole/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -APPNAME = demprep - -labels.txt.IGNORELINES = Bytes StartByte ByteOrder TileSamples TileLines - -include $(ISISROOT)/make/isismake.tsts - -commands: - $(APPNAME) from=$(INPUT)/ulcn2005_lpo_spole.cub \ - to=$(OUTPUT)/ulcn2005_lpo_spole_pad.cub > /dev/null; - catlab from=$(OUTPUT)/ulcn2005_lpo_spole_pad.cub to=$(OUTPUT)/labels.txt > /dev/null; diff --git a/isis/src/base/apps/demprep/tsts/specialpixels/Makefile b/isis/src/base/apps/demprep/tsts/specialpixels/Makefile deleted file mode 100644 index 5e0b280be2..0000000000 --- a/isis/src/base/apps/demprep/tsts/specialpixels/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -APPNAME = demprep - -labels.txt.IGNORELINES = Bytes StartByte ByteOrder TileSamples TileLines - -include $(ISISROOT)/make/isismake.tsts - -commands: - $(APPNAME) from=$(INPUT)/vest64_dtm_specialpixels.cub \ - to=$(OUTPUT)/vest64_dtm_specialpixels.cub > /dev/null; - catlab from=$(OUTPUT)/vest64_dtm_specialpixels.cub \ - to=$(OUTPUT)/labels.txt > /dev/null; diff --git a/isis/tests/FunctionalTestsDemprep.cpp b/isis/tests/FunctionalTestsDemprep.cpp new file mode 100644 index 0000000000..90003dec3a --- /dev/null +++ b/isis/tests/FunctionalTestsDemprep.cpp @@ -0,0 +1,166 @@ +#include +#include +#include + +#include "demprep.h" + +#include "Cube.h" +#include "Pvl.h" +#include "TestUtilities.h" +#include "FileName.h" +#include "LineManager.h" +#include "Table.h" +#include "Histogram.h" + +#include "Fixtures.h" + +#include "gmock/gmock.h" + +using namespace Isis; + +static QString APP_XML = FileName("$ISISROOT/bin/xml/demprep.xml").expanded(); + +TEST(Demprep, DemprepDefault){ + Pvl appLog; + QTemporaryDir prefix; + QString cubeFileName = prefix.path() + "/padded.cub"; + QVector args = {"from=data/demprep/ulcn2005_lpo_downsampled.cub", "to=" + cubeFileName }; + + UserInterface options(APP_XML, args); + try { + demprep(options, &appLog); + } + catch (IException &e) { + FAIL() << "Unable to prep DEM: " << e.toString().toStdString().c_str() << std::endl; + } + + Cube cube(cubeFileName); + Pvl *isisLabel = cube.label(); + + ASSERT_EQ(cube.sampleCount(), 439); + ASSERT_EQ(cube.lineCount(), 221); + ASSERT_EQ(cube.bandCount(), 1); + + // Pixels Group + PvlGroup &pixels = isisLabel->findGroup("Pixels", Pvl::Traverse); + ASSERT_EQ(pixels["Type"][0].toStdString(), "SignedWord"); + ASSERT_EQ(pixels["ByteOrder"][0].toStdString(), "Lsb"); + ASSERT_EQ(double(pixels["Base"]), 1737400.0); + ASSERT_EQ(double(pixels["Multiplier"]), 1.0); + + // BandBin Group + // Check size, first, 2 middle, and last values? Enough? + PvlGroup &bandbin = isisLabel->findGroup("BandBin", Pvl::Traverse); + ASSERT_EQ(bandbin["Center"].size(), 1); + ASSERT_EQ(bandbin["OriginalBand"].size(), 1); + + // Mapping Group + PvlGroup &mapping = isisLabel->findGroup("Mapping", Pvl::Traverse); + ASSERT_EQ(mapping["ProjectionName"][0].toStdString(), "Equirectangular"); + ASSERT_DOUBLE_EQ(double(mapping["CenterLongitude"]), 180.0); + ASSERT_EQ(mapping["TargetName"][0].toStdString(), "Moon"); + ASSERT_DOUBLE_EQ(double(mapping["EquatorialRadius"]), 1737400.0); + ASSERT_DOUBLE_EQ(double(mapping["PolarRadius"]), 1737400.0); + ASSERT_EQ(mapping["LatitudeType"][0].toStdString(), "Planetocentric"); + ASSERT_EQ(mapping["LongitudeDirection"][0].toStdString(), "PositiveEast"); + ASSERT_EQ(int(mapping["LongitudeDomain"]), 180); + ASSERT_DOUBLE_EQ(double(mapping["MinimumLatitude"]), -90.0); + ASSERT_DOUBLE_EQ(double(mapping["MaximumLatitude"]), 90.0); + ASSERT_DOUBLE_EQ(double(mapping["MinimumLongitude"]), -180.0); + ASSERT_DOUBLE_EQ(double(mapping["MaximumLongitude"]), 180.0); + ASSERT_DOUBLE_EQ(double(mapping["UpperLeftCornerX"]), -10950000.0); + ASSERT_DOUBLE_EQ(double(mapping["UpperLeftCornerY"]), 2775000.0); + ASSERT_DOUBLE_EQ(double(mapping["PixelResolution"]), 25000.0); + ASSERT_NEAR(double(mapping["Scale"]), 1.21293, .00001); + ASSERT_DOUBLE_EQ(double(mapping["CenterLatitude"]), 0.0); + + Table shapeModel("ShapeModelStatistics"); + cube.read(shapeModel); + // Assertion for minimum radius + ASSERT_DOUBLE_EQ(double(shapeModel[0][0]), 1728.805); + // Assertion for maximum radius + ASSERT_DOUBLE_EQ(double(shapeModel[0][1]), 1745.313); + + + std::unique_ptr hist (cube.histogram()); + + ASSERT_NEAR(hist->Average(), 1736765.71744, .00001); + ASSERT_DOUBLE_EQ(hist->Sum(), 166974392841); + ASSERT_EQ(hist->ValidPixels(), 96141); + ASSERT_NEAR(hist->StandardDeviation(), 2055.78, .01); +} + + +TEST(Demprep, DemprepInside){ + + Pvl appLog; + QTemporaryDir prefix; + QString cubeFileName = prefix.path() + "/padded.cub"; + QVector args = {"from=data/demprep/ulcn2005_lpo_inside.cub", "to=" + cubeFileName }; + + UserInterface options(APP_XML, args); + try { + demprep(options, &appLog); + } + catch (IException &e) { + FAIL() << "Unable to prep DEM: " << e.toString().toStdString().c_str() << std::endl; + } + + Cube cube(cubeFileName); + Pvl *isisLabel = cube.label(); + ASSERT_EQ(cube.sampleCount(), 250); + ASSERT_EQ(cube.lineCount(), 250); + ASSERT_EQ(cube.bandCount(), 1); + + // Mapping Group + PvlGroup &mapping = isisLabel->findGroup("Mapping", Pvl::Traverse); + ASSERT_EQ(mapping["ProjectionName"][0].toStdString(), "SimpleCylindrical"); + ASSERT_NEAR(double(mapping["UpperLeftCornerX"]), -5801235.97802, .00001); + ASSERT_NEAR(double(mapping["UpperLeftCornerY"]), 77703.58546, .00001); + ASSERT_NEAR(double(mapping["PixelResolution"]), 1895.20940, .00001); + ASSERT_DOUBLE_EQ(double(mapping["Scale"]), 16.0); +} + + + +TEST(Demprep, DemprepSpecialPixels){ + Pvl appLog; + QTemporaryDir prefix; + QString cubeFileName = prefix.path() + "/padded.cub"; + QVector args = {"from=data/demprep/vest64_dtm_specialpixels_downsampled.cub", "to=" + cubeFileName }; + + UserInterface options(APP_XML, args); + try { + demprep(options, &appLog); + } + catch (IException &e) { + FAIL() << "Unable to prep DEM: " << e.toString().toStdString().c_str() << std::endl; + } + + Cube cube(cubeFileName); + Pvl *isisLabel = cube.label(); + ASSERT_EQ(cube.sampleCount(), 366); + ASSERT_EQ(cube.lineCount(), 184); + ASSERT_EQ(cube.bandCount(), 1); + + // Mapping Group + PvlGroup &mapping = isisLabel->findGroup("Mapping", Pvl::Traverse); + ASSERT_EQ(mapping["ProjectionName"][0].toStdString(), "Equirectangular"); + ASSERT_DOUBLE_EQ(double(mapping["UpperLeftCornerX"]), -915000.0); + ASSERT_DOUBLE_EQ(double(mapping["UpperLeftCornerY"]), 460000.0); + ASSERT_DOUBLE_EQ(double(mapping["PixelResolution"]), 5000); + ASSERT_NEAR(double(mapping["Scale"]), 1.00880, .00001); + + + std::unique_ptr hist (cube.histogram()); + + ASSERT_NEAR(double(hist->Average()), 254239.25400, .00001); + ASSERT_DOUBLE_EQ(hist->Sum(), 3869267206.65625); + ASSERT_EQ(hist->ValidPixels(), 15219); + ASSERT_EQ(hist->NullPixels(), 51665); + ASSERT_EQ(hist->LisPixels(), 460); + ASSERT_EQ(hist->LrsPixels(), 0); + ASSERT_EQ(hist->HisPixels(), 0); + ASSERT_EQ(hist->HrsPixels(), 0); + ASSERT_NEAR(hist->StandardDeviation(), 22217.85549, .00001); +} diff --git a/isis/tests/data/demprep/ulcn2005_lpo_downsampled.cub b/isis/tests/data/demprep/ulcn2005_lpo_downsampled.cub new file mode 100644 index 0000000000..47b5576b05 Binary files /dev/null and b/isis/tests/data/demprep/ulcn2005_lpo_downsampled.cub differ diff --git a/isis/tests/data/demprep/ulcn2005_lpo_inside.cub b/isis/tests/data/demprep/ulcn2005_lpo_inside.cub new file mode 100644 index 0000000000..d7046b61bb Binary files /dev/null and b/isis/tests/data/demprep/ulcn2005_lpo_inside.cub differ diff --git a/isis/tests/data/demprep/vest64_dtm_specialpixels_downsampled.cub b/isis/tests/data/demprep/vest64_dtm_specialpixels_downsampled.cub new file mode 100644 index 0000000000..d59798635b Binary files /dev/null and b/isis/tests/data/demprep/vest64_dtm_specialpixels_downsampled.cub differ