Skip to content

Commit

Permalink
Update eisstitch to place DNs into an output cube
Browse files Browse the repository at this point in the history
  • Loading branch information
acpaquette committed Sep 11, 2024
1 parent 9fbf4e1 commit 3bfe391
Showing 1 changed file with 82 additions and 15 deletions.
97 changes: 82 additions & 15 deletions isis/src/clipper/apps/eisstitch/eisstitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -24,6 +27,7 @@ find files of those names at the top level of this repository. **/
#include <iostream>
#include <fstream>
#include <istream>
#include <cmath>

#include "eisstitch.h"
#include <QDebug>
Expand Down Expand Up @@ -72,14 +76,14 @@ namespace Isis {
throw IException(IException::User, msg, _FILEINFO_);
}

std::vector<struct eisTiming> eisTime = {};
std::vector<struct eisTiming> 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() + "]";
Expand All @@ -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() + "]";
Expand All @@ -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_);
Expand All @@ -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<double>::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();
}
}

0 comments on commit 3bfe391

Please sign in to comment.