diff --git a/isis/src/clipper/apps/eisstitch/eisstitch.cpp b/isis/src/clipper/apps/eisstitch/eisstitch.cpp index 2e46aa8a61..606e7396ee 100644 --- a/isis/src/clipper/apps/eisstitch/eisstitch.cpp +++ b/isis/src/clipper/apps/eisstitch/eisstitch.cpp @@ -14,6 +14,9 @@ find files of those names at the top level of this repository. **/ #include "IException.h" #include "iTime.h" +#include "CubeAttribute.h" +#include "EisStitchFunctor.h" +#include "ProcessByBrick.h" #include "Pvl.h" #include "PvlKeyword.h" #include "Table.h" @@ -24,6 +27,7 @@ find files of those names at the top level of this repository. **/ #include #include #include +#include #include "eisstitch.h" #include @@ -72,14 +76,14 @@ namespace Isis { throw IException(IException::User, msg, _FILEINFO_); } - std::vector eisTime = {}; + std::vector eisTimes = {}; for (auto file : fileList) { - Pvl cubeLabel(file.expanded()); + Pvl inputCubeLabel = Pvl(file.expanded()); PvlGroup instGroup; try { - instGroup = cubeLabel.findGroup("Instrument", PvlObject::FindOptions::Traverse); + instGroup = inputCubeLabel.findGroup("Instrument", PvlObject::FindOptions::Traverse); } catch(IException &e) { QString msg = "Unable to find instrument group in [" + file.name() + "]"; @@ -88,7 +92,7 @@ namespace Isis { PvlGroup dimGroup; try { - dimGroup = cubeLabel.findGroup("Dimensions", PvlObject::FindOptions::Traverse); + dimGroup = inputCubeLabel.findGroup("Dimensions", PvlObject::FindOptions::Traverse); } catch(IException &e) { QString msg = "Unable to find instrument group in [" + file.name() + "]"; @@ -99,14 +103,16 @@ namespace Isis { int lines = dimGroup.findKeyword("Lines"); double exposureDuration = instGroup.findKeyword("LineExposureDuration"); exposureDuration /= 1000; - eisTime.push_back(eisTiming(time.Et(), lines, exposureDuration)); + eisTimes.push_back(eisTiming(time.Et(), lines, exposureDuration)); } - sort(eisTime.begin(), eisTime.end(), compareByStartTime); + // Likely need to re-order the cubes in the fileList if the eisTimes + // are moved around + sort(eisTimes.begin(), eisTimes.end(), compareByStartTime); // Check for overlap - for (int i = 0; i < eisTime.size() - 1; i++) { - if (eisTime[i].stop > eisTime[i + 1].start) { + for (int i = 0; i < eisTimes.size() - 1; i++) { + if (eisTimes[i].stop > eisTimes[i + 1].start) { QString msg = "Image " + QString(i + 1) + " and " + QString(i + 2) + " in the image list have " + "overlapping times."; throw IException(IException::User, msg, _FILEINFO_); @@ -125,14 +131,75 @@ namespace Isis { Table timesTable("LineScanTimes", timesRecord); - int currentLine = 1; - for (auto time : eisTime) { - timesRecord[0] = time.start; - timesRecord[1] = time.exposureDuration; - timesRecord[2] = currentLine; - currentLine += time.lines; + int lineCount = 1; + for (int i = 0; i < eisTimes.size(); i++) { + timesRecord[0] = eisTimes[i].start; + timesRecord[1] = eisTimes[i].exposureDuration; + timesRecord[2] = lineCount; + lineCount += eisTimes[i].lines; timesTable += timesRecord; + + if (i < eisTimes.size() - 1) { + double imageTotalTime = eisTimes[i].start + (eisTimes[i].exposureDuration * eisTimes[i].lines); + if ( std::abs(imageTotalTime - eisTimes[i + 1].start) > std::numeric_limits::epsilon()) { + double remainingTime = eisTimes[i + 1].start - imageTotalTime; + int blankLines = int(remainingTime / eisTimes[i].exposureDuration); + lineCount += blankLines; + } + } + } + + Pvl firstCubeLabel(fileList[0].expanded()); + PvlGroup dimGroup; + try { + dimGroup = firstCubeLabel.findGroup("Dimensions", PvlObject::FindOptions::Traverse); + } + catch(IException &e) { + QString msg = "Unable to find instrument group in [" + fileList[0].name() + "]"; + throw IException(e, IException::User, msg, _FILEINFO_); } - cout << Table::toString(timesTable, ",") << endl; + int outLines = lineCount - 1; + int outSamples = dimGroup["Samples"]; + + ProcessByBrick process; + process.PropagateLabels(false); + process.PropagateTables(false); + process.PropagatePolygons(false); + process.PropagateOriginalLabel(false); + process.SetInputCube(fileList[0].expanded(), CubeAttributeInput()); + + QString outCubeFile = ui.GetCubeName("TO"); + Cube *outCube = process.SetOutputCube(outCubeFile, CubeAttributeOutput(outCubeFile), + outSamples, outLines, 1); + process.ClearInputCubes(); + Brick cubeBrick = Brick(outCube->sampleCount(), 1, 1, outCube->pixelType()); + + int writeLine = 1; + + for (int i = 0; i < fileList.size(); i++) { + + Cube *inputCube = process.SetInputCube(fileList[i].expanded(), CubeAttributeInput()); + + for (int line = 1; line < inputCube->lineCount() + 1; line++) { + cubeBrick.SetBasePosition(1, line, 1); + inputCube->read(cubeBrick); + cubeBrick.SetBasePosition(1, writeLine, 1); + outCube->write(cubeBrick); + writeLine++; + } + + if (i < fileList.size() - 1) { + int expectedLines = (int)timesTable[i + 1][2] - 1; + while(writeLine != expectedLines) { + writeLine++; + } + } + + process.ClearInputCubes(); + } + + // Still need to write the Time table and other label data + + process.EndProcess(); } } \ No newline at end of file