7 #include "Preference.h"
9 #include "Application.h"
10 #include "IException.h"
13 #include "ProcessMosaic.h"
15 #include "SerialNumber.h"
16 #include "SpecialPixel.h"
18 #include "TrackingTable.h"
26 const char *ProcessMosaic::TRACKING_TABLE_NAME =
"InputImages";
33 ProcessMosaic::ProcessMosaic() {
35 SetBandBinMatch(
true);
38 m_trackingEnabled =
false;
39 m_trackingCube = NULL;
40 m_createOutputMosaic =
false;
41 m_bandPriorityBandNumber = 0;
42 m_bandPriorityKeyName =
"";
43 m_bandPriorityKeyValue =
"";
44 m_bandPriorityUseMaxValue =
false;
47 m_placeHighSatPixels =
false;
48 m_placeLowSatPixels =
false;
49 m_placeNullPixels =
false;
52 m_imageOverlay = PlaceImagesOnTop;
54 m_enforceMatchDEM =
false;
71 ProcessMosaic::~ProcessMosaic() {
73 m_trackingCube->close();
74 delete m_trackingCube;
75 m_trackingCube = NULL;
106 void ProcessMosaic::StartProcess(
const int &os,
const int &ol,
const int &ob) {
108 if ((OutputCubes.size() != 1) || (InputCubes.size() != 1)) {
109 QString m =
"You must specify exactly one input and one output cube";
110 throw IException(IException::Programmer, m, _FILEINFO_);
113 bool bTrackExists =
false;
114 if (!m_createOutputMosaic) {
115 bTrackExists = GetTrackStatus();
116 if (m_trackingEnabled &&
117 !(OutputCubes[0]->hasGroup(
"Tracking") || OutputCubes[0]->hasTable(
"InputImages"))) {
118 QString m =
"Cannot enable tracking while adding to a mosaic without tracking ";
119 m +=
"information. Confirm that your mosaic was originally created with tracking enabled.";
120 throw IException(IException::User, m, _FILEINFO_);
132 ins = (int)InputCubes[0]->sampleCount();
135 inl = (int)InputCubes[0]->lineCount();
138 inb = (int)InputCubes[0]->bandCount();
147 iss = iss - m_oss + 1;
148 ins = ins + m_oss - 1;
153 isl = isl - m_osl + 1;
154 inl = inl + m_osl - 1;
158 if ((m_oss + ins - 1) > OutputCubes[0]->sampleCount()) {
159 ins = OutputCubes[0]->sampleCount() - m_oss + 1;
162 if ((m_osl + inl - 1) > OutputCubes[0]->lineCount()) {
163 inl = OutputCubes[0]->lineCount() - m_osl + 1;
166 PvlGroup imgPosition(
"ImageLocation");
167 imgPosition +=
PvlKeyword(
"File", InputCubes[0]->fileName());
170 m_imagePositions += imgPosition;
173 if ((ins < 1) || (inl < 1)) {
174 QString m =
"The input cube does not overlap the mosaic";
175 throw IException(IException::User, m, _FILEINFO_);
180 isb = isb - m_osb + 1;
181 inb = inb + m_osb - 1;
185 p_progress->SetMaximumSteps(
186 (
int)InputCubes[0]->lineCount() * (
int)InputCubes[0]->bandCount());
187 p_progress->CheckStatus();
196 if (m_trackingEnabled) {
197 if (!(m_imageOverlay == UseBandPlacementCriteria ||
198 ((m_imageOverlay == PlaceImagesOnTop || m_imageOverlay == PlaceImagesBeneath) &&
200 (OutputCubes[0]->bandCount()) == 1) ||
201 (m_imageOverlay == PlaceImagesOnTop && m_placeHighSatPixels && m_placeLowSatPixels &&
202 m_placeNullPixels)) ){
203 QString m =
"Tracking cannot be True for multi-band Mosaic with ontop or beneath priority";
204 throw IException(IException::Programmer, m, _FILEINFO_);
210 Pvl *inLab = InputCubes[0]->label();
212 if (m_enforceMatchDEM){
213 MatchDEMShapeModel();
217 if (m_enforceBandBinMatch) {
218 Pvl *outLab = OutputCubes[0]->label();
220 if (inLab->
findObject(
"IsisCube").hasGroup(
"BandBin")) {
223 if (!m_createOutputMosaic && outLab->
findObject(
"IsisCube").hasGroup(
"BandBin")) {
224 MatchBandBinGroup(isb, inb);
228 AddBandBinGroup(isb);
233 QString m =
"Match BandBin cannot be True when the Image does not have the BandBin group";
234 throw IException(IException::Programmer, m, _FILEINFO_);
239 if (m_createOutputMosaic) {
240 if (inLab->
findObject(
"IsisCube").hasGroup(
"BandBin")) {
241 AddBandBinGroup(isb);
244 AddDefaultBandBinGroup();
252 m_trackingEnabled =
true;
256 int bandPriorityInputBandNumber = -1;
257 int bandPriorityOutputBandNumber = -1;
258 if (m_imageOverlay == UseBandPlacementCriteria ) {
259 bandPriorityInputBandNumber = GetBandIndex(
true);
260 bandPriorityOutputBandNumber = GetBandIndex(
false);
264 int iIndex = VALID_MINUI4;
266 if (OutputCubes[0]->hasGroup(
"Tracking") && !m_createOutputMosaic) {
267 m_trackingEnabled =
true;
272 if (m_trackingEnabled) {
275 if (!m_trackingCube) {
276 m_trackingCube =
new Cube;
279 if (m_createOutputMosaic) {
282 m_trackingCube->
setPixelType(PixelType::UnsignedInteger);
285 m_trackingCube->setDimensions(OutputCubes[0]->sampleCount(),
286 OutputCubes[0]->lineCount(),
291 m_trackingCube->create(
FileName(OutputCubes[0]->fileName()).path()
292 +
"/" + trackingBase +
"_tracking.cub");
295 Pvl *mosaicLabel = OutputCubes[0]->label();
296 PvlGroup trackingFileGroup(
"Tracking");
298 trackingFileName.
setValue(trackingBase +
"_tracking.cub");
299 trackingFileGroup.
addKeyword(trackingFileName);
300 mosaicLabel->
findObject(
"IsisCube").addGroup(trackingFileGroup);
303 Pvl *trackingLabel = m_trackingCube->label();
306 trackBand +=
"TRACKING";
308 trackingLabel->
findObject(
"IsisCube").addGroup(bandBin);
317 if ( OutputCubes[0]->hasGroup(
"Tracking") ) {
318 QString trackingPath =
FileName(OutputCubes[0]->fileName()).
path();
319 QString trackingFile = OutputCubes[0]->group(
"Tracking").findKeyword(
"FileName")[0];
320 m_trackingCube->open(trackingPath +
"/" + trackingFile,
"rw");
325 table =
new Table(TRACKING_TABLE_NAME, m_trackingCube->fileName());
329 QString msg =
"Unable to find Tracking Table in " + m_trackingCube->fileName() +
".";
330 throw IException(IException::User, msg, _FILEINFO_);
336 QString msg =
"Tracking cannot be enabled when adding to an existing mosaic "
337 "that does not already have a tracking cube. Mosaics with a tracking band must "
338 "have the tracking band extracted into an external tracking cube.";
339 throw IException(IException::User, msg, _FILEINFO_);
345 SerialNumber::Compose(*(InputCubes[0])));
348 m_trackingCube->deleteBlob(Isis::trackingTableName,
"Table");
350 m_trackingCube->write(table);
354 else if (m_imageOverlay == AverageImageWithMosaic && m_createOutputMosaic) {
358 m_onb = OutputCubes[0]->bandCount();
360 if (m_trackingEnabled) {
363 if (m_imageOverlay == UseBandPlacementCriteria && !m_createOutputMosaic) {
364 BandComparison(iss, isl, ins, inl,
365 bandPriorityInputBandNumber, bandPriorityOutputBandNumber, iIndex);
368 else if (m_imageOverlay == AverageImageWithMosaic) {
371 QString msg =
"The mosaic cube needs a count band.";
372 throw IException(IException::Unknown, msg, _FILEINFO_);
377 if (m_imageOverlay == UseBandPlacementCriteria && !m_trackingEnabled ) {
378 BandPriorityWithNoTracking(iss, isl, isb, ins, inl, inb, bandPriorityInputBandNumber,
379 bandPriorityOutputBandNumber);
383 Portal iPortal(ins, 1, InputCubes[0]->pixelType());
384 Portal oPortal(ins, 1, OutputCubes[0]->pixelType());
385 Portal countPortal(ins, 1, OutputCubes[0]->pixelType());
386 Portal trackingPortal(ins, 1, PixelType::UnsignedInteger);
388 for (
int ib = isb, ob = m_osb; ib < (isb + inb) && ob <= m_onb; ib++, ob++) {
389 for (
int il = isl, ol = m_osl; il < isl + inl; il++, ol++) {
392 InputCubes[0]->read(iPortal);
395 OutputCubes[0]->read(oPortal);
397 if (m_trackingEnabled) {
399 m_trackingCube->read(trackingPortal);
401 else if (m_imageOverlay == AverageImageWithMosaic) {
403 OutputCubes[0]->read(countPortal);
406 bool bChanged =
false;
408 for (
int pixel = 0; pixel < oPortal.
size(); pixel++) {
411 if (m_createOutputMosaic) {
412 oPortal[pixel] = iPortal[pixel];
413 if (m_trackingEnabled) {
414 trackingPortal[pixel] = iIndex;
417 else if (m_imageOverlay == AverageImageWithMosaic) {
419 countPortal[pixel]=1;
425 else if (m_trackingEnabled && m_imageOverlay == UseBandPlacementCriteria) {
426 int iPixelOrigin = qRound(trackingPortal[pixel]);
428 Portal iComparePortal( ins, 1, InputCubes[0]->pixelType() );
429 Portal oComparePortal( ins, 1, OutputCubes[0]->pixelType() );
430 iComparePortal.
SetPosition(iss, il, bandPriorityInputBandNumber);
431 InputCubes[0]->read(iComparePortal);
432 oComparePortal.
SetPosition(m_oss, ol, bandPriorityOutputBandNumber);
433 OutputCubes[0]->read(oComparePortal);
435 if (iPixelOrigin == iIndex) {
438 ( (!m_bandPriorityUseMaxValue &&
439 iComparePortal[pixel] < oComparePortal[pixel]) ||
440 (m_bandPriorityUseMaxValue &&
441 iComparePortal[pixel] > oComparePortal[pixel]) ) ) {
444 ( m_placeHighSatPixels &&
IsHighPixel(iPortal[pixel]) ) ||
445 ( m_placeLowSatPixels &&
IsLowPixel (iPortal[pixel]) ) ||
446 ( m_placeNullPixels &&
IsNullPixel(iPortal[pixel]) ) ){
447 oPortal[pixel] = iPortal[pixel];
453 ( m_placeHighSatPixels &&
IsHighPixel(iPortal[pixel]) ) ||
454 ( m_placeLowSatPixels &&
IsLowPixel (iPortal[pixel]) ) ||
455 ( m_placeNullPixels &&
IsNullPixel(iPortal[pixel]) ) ) {
456 oPortal[pixel] = iPortal[pixel];
463 else if (m_imageOverlay == PlaceImagesOnTop) {
466 (m_placeHighSatPixels &&
IsHighPixel(iPortal[pixel])) ||
467 (m_placeLowSatPixels &&
IsLowPixel(iPortal[pixel])) ||
468 (m_placeNullPixels &&
IsNullPixel(iPortal[pixel]))) {
469 oPortal[pixel] = iPortal[pixel];
470 if (m_trackingEnabled) {
471 trackingPortal[pixel] = iIndex;
477 else if (m_imageOverlay == AverageImageWithMosaic) {
478 bChanged |= ProcessAveragePriority(pixel, iPortal, oPortal, countPortal);
481 else if (m_imageOverlay == PlaceImagesBeneath) {
483 oPortal[pixel] = iPortal[pixel];
486 if (m_trackingEnabled) {
487 trackingPortal[pixel] = iIndex;
494 if (m_trackingEnabled) {
495 m_trackingCube->write(trackingPortal);
497 if (m_imageOverlay == AverageImageWithMosaic) {
498 OutputCubes[0]->write(countPortal);
501 OutputCubes[0]->write(oPortal);
502 p_progress->CheckStatus();
506 if (m_trackingCube) {
507 m_trackingCube->close();
508 delete m_trackingCube;
509 m_trackingCube = NULL;
517 void ProcessMosaic::EndProcess() {
518 if (m_trackingCube) {
519 m_trackingCube->close();
520 delete m_trackingCube;
521 m_trackingCube = NULL;
523 Process::EndProcess();
533 return m_imagePositions;
574 Cube *ProcessMosaic::SetInputCube(
const QString ¶meter,
575 const int ss,
const int sl,
const int sb,
576 const int ns,
const int nl,
const int nb) {
579 if (InputCubes.size() > 0) {
580 QString m =
"You must specify exactly one input cube";
581 throw IException(IException::Programmer, m, _FILEINFO_);
591 Cube *cInCube = Process::SetInputCube(parameter);
594 Pvl *cInPvl = InputCubes[0]->label();
595 if (cInPvl->
findGroup(
"Dimensions", Pvl::Traverse).hasKeyword(
"Bands")) {
596 PvlKeyword &cBandKey = cInPvl->
findGroup(
"Dimensions", Pvl::Traverse).findKeyword(
"Bands");
597 QString sStr(cBandKey[0]);
598 if (
toInt(sStr) < nb) {
599 QString m =
"The parameter number of input bands exceeds the actual number of bands in the "
601 throw IException(IException::Programmer, m, _FILEINFO_);
644 Cube *ProcessMosaic::SetInputCube(
const QString &fname,
646 const int ss,
const int sl,
const int sb,
647 const int ns,
const int nl,
const int nb) {
650 if (InputCubes.size() > 0) {
651 QString m =
"You must specify exactly one input cube";
652 throw IException(IException::Programmer, m, _FILEINFO_);
662 Cube *cInCube = Process::SetInputCube(fname, att);
665 Pvl *cInPvl = InputCubes[0]->label();
666 if (cInPvl->
findGroup(
"Dimensions", Pvl::Traverse).hasKeyword(
"Bands")) {
667 PvlKeyword &cBandKey = cInPvl->
findGroup(
"Dimensions", Pvl::Traverse).findKeyword(
"Bands");
668 QString sStr(cBandKey[0]);
669 if (
toInt(sStr) < nb) {
670 QString m =
"The parameter number of input bands exceeds the actual number of bands in the input cube";
671 throw IException(IException::Programmer, m, _FILEINFO_);
692 Cube *ProcessMosaic::SetOutputCube(
const QString &psParameter) {
693 return SetOutputCube(psParameter, Application::GetUserInterface());
696 Cube *ProcessMosaic::SetOutputCube(
const QString &psParameter,
UserInterface &ui) {
700 if (OutputCubes.size() > 0) {
701 QString m =
"You must specify exactly one output cube";
702 throw IException(IException::Programmer, m, _FILEINFO_);
707 Cube *cube =
new Cube;
709 cube->open(fname,
"rw");
711 catch (IException &) {
716 if (m_createOutputMosaic) {
717 Pvl *outLab = cube->label();
718 if (outLab->findObject(
"IsisCube").hasGroup(
"BandBin")) {
719 outLab->findObject(
"IsisCube").deleteGroup(
"BandBin");
732 void ProcessMosaic::SetBandBinMatch(
bool enforceBandBinMatch) {
733 m_enforceBandBinMatch = enforceBandBinMatch;
740 void ProcessMosaic::SetBandKeyword(QString bandPriorityKeyName, QString bandPriorityKeyValue) {
741 m_bandPriorityKeyName = bandPriorityKeyName;
742 m_bandPriorityKeyValue = bandPriorityKeyValue;
749 void ProcessMosaic::SetBandNumber(
int bandPriorityBandNumber) {
750 m_bandPriorityBandNumber = bandPriorityBandNumber;
758 void ProcessMosaic::SetBandUseMaxValue(
bool useMax) {
759 m_bandPriorityUseMaxValue = useMax;
771 void ProcessMosaic::SetCreateFlag(
bool createOutputMosaic) {
772 m_createOutputMosaic = createOutputMosaic;
780 void ProcessMosaic::SetHighSaturationFlag(
bool placeHighSatPixels) {
781 m_placeHighSatPixels = placeHighSatPixels;
785 void ProcessMosaic::SetImageOverlay(ImageOverlay placement) {
786 m_imageOverlay = placement;
794 void ProcessMosaic::SetLowSaturationFlag(
bool placeLowSatPixels) {
795 m_placeLowSatPixels = placeLowSatPixels;
802 void ProcessMosaic::SetMatchDEM(
bool matchDEM) {
803 m_enforceMatchDEM = matchDEM;
811 void ProcessMosaic::SetNullFlag(
bool placeNullPixels) {
812 m_placeNullPixels = placeNullPixels;
816 void ProcessMosaic::SetTrackFlag(
bool trackingEnabled) {
817 m_trackingEnabled = trackingEnabled;
824 bool ProcessMosaic::GetHighSaturationFlag()
const {
825 return m_placeHighSatPixels;
833 return m_imageOverlay;
840 bool ProcessMosaic::GetLowSaturationFlag()
const {
841 return m_placeLowSatPixels;
848 bool ProcessMosaic::GetNullFlag()
const {
849 return m_placeNullPixels;
856 bool ProcessMosaic::GetTrackFlag()
const {
857 return m_trackingEnabled;
864 int ProcessMosaic::GetInputStartLineInMosaic()
const {
872 int ProcessMosaic::GetInputStartSampleInMosaic()
const {
880 int ProcessMosaic::GetInputStartBandInMosaic()
const {
892 switch (imageOverlay) {
893 case PlaceImagesOnTop:
897 case PlaceImagesBeneath:
901 case UseBandPlacementCriteria:
905 case AverageImageWithMosaic:
909 case NumImageOverlayOptions:
915 "Cannot convert overlay [" +
toString((
int)imageOverlay) +
"] to a string",
928 QString imageOverlayStringUpper = imageOverlayString.toUpper();
929 for (
int i = 0; i < NumImageOverlayOptions; i++) {
930 if (OverlayToString((
ImageOverlay)i).toUpper() == imageOverlayStringUpper)
935 "The text [" + imageOverlayString +
"] does not correspond to any known "
936 "image overlay modes (mosaic priorities)",
948 void ProcessMosaic::MatchDEMShapeModel() {
949 Pvl* inLabel = InputCubes[0]->label();
950 Pvl* outLabel = OutputCubes[0]->label();
952 if (outLabel->
findObject(
"IsisCube").hasGroup(
"Mosaic")) {
955 if (inLabel->
findObject(
"IsisCube").hasGroup(
"Kernels")) {
959 QString sShapeModel = inMosaicGrp.
findKeyword(
"ShapeModel")[0];
960 int found = sShapeModel.lastIndexOf(
"/");
962 sShapeModel.remove(0, found + 1);
964 if (sShapeModel == outShapeModelKey[0]) {
969 QString sErrMsg =
"Input and Mosaic DEM Shape Model do not match";
970 throw IException(IException::User, sErrMsg, _FILEINFO_);
974 if (m_createOutputMosaic) {
975 if (inLabel->
findObject(
"IsisCube").hasGroup(
"Kernels")) {
976 QString sShapeModel =
977 inLabel->
findObject(
"IsisCube").findGroup(
"Kernels").findKeyword(
"ShapeModel")[0];
978 int found = sShapeModel.lastIndexOf(
"/");
980 sShapeModel.remove(0, found+1);
985 shapeModelKey += sShapeModel;
986 mosaicGrp += shapeModelKey;
987 outIsisCubeObj += mosaicGrp;
999 void ProcessMosaic::ResetCountBands()
1001 int iBand = OutputCubes[0]->bandCount();
1002 int iLines = OutputCubes[0]->lineCount();
1003 int iSample = OutputCubes[0]->sampleCount();
1005 Portal countPortal(iSample, 1, OutputCubes[0]->pixelType());
1006 int iStartCountBand = iBand/2 + 1;
1008 for (
int band=iStartCountBand; band<=iBand; band++) {
1009 for (
int i = 1; i <= iLines; i++) {
1011 OutputCubes[0]->read(countPortal);
1012 for (
int iPixel = 0; iPixel < countPortal.
size(); iPixel++) {
1013 countPortal[iPixel] = 0;
1015 OutputCubes[0]->write(countPortal);
1034 bool ProcessMosaic::ProcessAveragePriority(
int piPixel,
Portal& piPortal,
Portal& poPortal,
1037 bool bChanged=
false;
1039 int iCount = (int)countPortal[piPixel];
1040 double dNewDN = (poPortal[piPixel] * iCount + piPortal[piPixel]) / (iCount + 1);
1041 poPortal[piPixel] = dNewDN;
1042 countPortal[piPixel] =iCount +1;
1047 poPortal[piPixel] = piPortal[piPixel];
1048 countPortal[piPixel] = 1;
1052 else if (
IsSpecial(piPortal[piPixel])) {
1053 if ((m_placeHighSatPixels &&
IsHighPixel(piPortal[piPixel])) ||
1054 (m_placeLowSatPixels &&
IsLowPixel (piPortal[piPixel])) ||
1055 (m_placeNullPixels &&
IsNullPixel(piPortal[piPixel]))) {
1056 poPortal[piPixel] = piPortal[piPixel];
1057 countPortal[piPixel] = 0;
1076 void ProcessMosaic::MatchBandBinGroup(
int origIsb,
int &inb) {
1077 Pvl *inLab = InputCubes[0]->label();
1078 Pvl *outLab = OutputCubes[0]->label();
1083 QString msg =
"Pvl Group [BandBin] does not match between the input and output cubes";
1084 throw IException(IException::User, msg, _FILEINFO_);
1088 int isb = (origIsb - 1);
1089 int osb = (m_osb - 1);
1090 int iOutBandsHalf = OutputCubes[0]->bandCount()/2;
1092 for (
int i = 0; i < outBin.
keywords(); i++) {
1094 QString sOutName = outKey.
name();
1097 for (
int j = osb, k = isb; j < outKey.
size() && k < inKey.
size(); j++, k++) {
1098 if (outKey[j] ==
"NA") {
1099 outKey[j] = inKey[k];
1100 if (m_imageOverlay == AverageImageWithMosaic) {
1101 if (sOutName.contains(
"Filter") ||
1102 sOutName.contains(
"Name")) {
1103 outKey[j+iOutBandsHalf] = inKey[k] +
"_Count";
1106 outKey[j+iOutBandsHalf] =
"Avg_Count";
1110 else if (outKey[j] != inKey[k]) {
1111 QString msg =
"The input cube [" + inLab->
fileName() +
"] and the base mosaic values "
1112 "of the Pvl Group [BandBin] for Keyword [" + outKey.
name() +
"] do not "
1113 "match. Base mosaic value at index [" + QString::number(j) +
"] = " +
1114 outKey[j] +
". Input cube value at index [" + QString::number(k) +
"] = "
1115 + inKey[k] +
". **Note: use mapmos/automos MatchBandBin = false to "
1116 "override this check**";
1119 throw IException(IException::User, msg, _FILEINFO_);
1124 QString msg =
"Pvl Group [BandBin] In Keyword[" + inBin[i].
name() +
"] and Out Keyword[" +
1125 outBin[i].
name() +
"] does not match";
1126 throw IException(IException::User, msg, _FILEINFO_);
1130 int inputRange = InputCubes[0]->bandCount() - isb;
1131 int outputRange = OutputCubes[0]->bandCount() - osb;
1132 inb = min(inputRange, outputRange);
1147 void ProcessMosaic::AddBandBinGroup(
int origIsb) {
1148 Pvl *inLab = InputCubes[0]->label();
1149 Pvl *outLab = OutputCubes[0]->label();
1151 int iOutBands = OutputCubes[0]->bandCount();
1154 if (m_imageOverlay == AverageImageWithMosaic) {
1158 int isb = origIsb - 1;
1159 int osb = m_osb - 1;
1164 for (
int i = 0; i < cInBin.
keywords(); i++) {
1166 int iInKeySize = cInKey.
size();
1169 for (
int b = 0; b < osb; b++) {
1172 for (
int b = osb; b < iOutBands; b++) {
1173 if (isb < iInKeySize) {
1174 cOutKey += cInKey[isb++];
1182 if (m_imageOverlay == AverageImageWithMosaic) {
1184 int iTotalOutBands = OutputCubes[0]->bandCount();
1186 int iOutStartBand = iOutBands + osb;
1187 QString sKeyName = cInKey.
name();
1188 bool bFilterKey =
false;
1189 if (sKeyName.contains(
"Filter") ||
1190 sKeyName.contains(
"Original") ||
1191 sKeyName.contains(
"Name")) {
1194 for (
int ob=iOutBands; ob<iTotalOutBands; ob++) {
1195 if (isb < iInKeySize && ob >= iOutStartBand) {
1197 cOutKey += cInKey[isb++] +
"_Count";
1212 if (cOutKey.
unit() != cInKey.
unit()) {
1219 outLab->
findObject(
"IsisCube").addGroup(cOutBin);
1232 void ProcessMosaic::AddDefaultBandBinGroup() {
1233 Pvl *outLab = OutputCubes[0]->label();
1237 int iOutBands = OutputCubes[0]->bandCount();
1238 int iOutBandsTotal = iOutBands;
1240 if (m_trackingEnabled) {
1243 else if (m_imageOverlay == AverageImageWithMosaic) {
1249 for (
int i=0; i<iOutBands; i++) {
1253 if (m_imageOverlay == AverageImageWithMosaic) {
1254 for (
int i=iOutBands; i<iOutBandsTotal; i++) {
1255 cOutKey +=
"NA_Count";
1259 if (m_trackingEnabled) {
1260 cOutKey +=
"TRACKING";
1265 outLab->
findObject(
"IsisCube").addGroup(cOutBin);
1272 int ProcessMosaic::GetBandIndex(
bool inputFile) {
1273 bool bFound =
false;
1279 cPvlLabel = *(InputCubes[0]->label());
1280 if (m_bandPriorityBandNumber <= InputCubes[0]->bandCount() &&
1281 m_bandPriorityBandNumber > 0) {
1282 iBandIndex = m_bandPriorityBandNumber;
1287 cPvlLabel = *(OutputCubes[0]->label());
1288 if (m_bandPriorityBandNumber <= OutputCubes[0]->bandCount() &&
1289 m_bandPriorityBandNumber > 0) {
1290 iBandIndex = m_bandPriorityBandNumber;
1296 if (!m_bandPriorityBandNumber) {
1298 if (cPvlLabel.
findGroup(
"BandBin", Pvl::Traverse).hasKeyword(m_bandPriorityKeyName)) {
1299 cKeyName = cPvlLabel.
findGroup(
"BandBin", Pvl::Traverse).findKeyword(m_bandPriorityKeyName);
1301 int iSize = cKeyName.
size();
1302 for (
int i = 0; i < iSize; i++) {
1303 if (m_bandPriorityKeyValue.toUpper() == cKeyName[i].toUpper()) {
1311 QString msg =
"Invalid Band / Key Name, Value ";
1312 throw IException(IException::User, msg, _FILEINFO_);
1335 void ProcessMosaic::BandComparison(
int iss,
int isl,
int ins,
int inl,
1336 int bandPriorityInputBandNumber,
int bandPriorityOutputBandNumber,
int index) {
1339 Portal cIportal(ins, 1, InputCubes[0]->pixelType());
1340 Portal cOportal(ins, 1, OutputCubes[0]->pixelType());
1341 Portal trackingPortal(ins, 1, PixelType::UnsignedInteger);
1343 for (
int iIL = isl, iOL = m_osl; iIL < isl + inl; iIL++, iOL++) {
1345 cIportal.
SetPosition(iss, iIL, bandPriorityInputBandNumber);
1346 InputCubes[0]->read(cIportal);
1348 cOportal.
SetPosition(m_oss, iOL, bandPriorityOutputBandNumber);
1349 OutputCubes[0]->read(cOportal);
1352 m_trackingCube->read(trackingPortal);
1355 for (
int iPixel = 0; iPixel < cOportal.
size(); iPixel++) {
1356 if ((m_placeHighSatPixels &&
IsHighPixel(cIportal[iPixel])) ||
1357 (m_placeLowSatPixels &&
IsLowPixel(cIportal[iPixel])) ||
1358 (m_placeNullPixels &&
IsNullPixel(cIportal[iPixel]))) {
1359 trackingPortal[iPixel] = index;
1364 (m_bandPriorityUseMaxValue ==
false && cIportal[iPixel] < cOportal[iPixel]) ||
1365 (m_bandPriorityUseMaxValue ==
true && cIportal[iPixel] > cOportal[iPixel])) {
1366 trackingPortal[iPixel] = index;
1371 m_trackingCube->write(trackingPortal);
1381 void ProcessMosaic::BandPriorityWithNoTracking(
int iss,
int isl,
int isb,
int ins,
int inl,
1382 int inb,
int bandPriorityInputBandNumber,
1383 int bandPriorityOutputBandNumber) {
1388 Portal iComparePortal( ins, 1, InputCubes[0]->pixelType() );
1389 Portal oComparePortal( ins, 1, OutputCubes[0]->pixelType() );
1390 Portal resultsPortal ( ins, 1, OutputCubes[0]->pixelType() );
1393 Portal iPortal( ins, 1, InputCubes[0]->pixelType() );
1394 Portal oPortal( ins, 1, OutputCubes[0]->pixelType() );
1396 for (
int inLine = isl, outLine = m_osl; inLine < isl + inl; inLine++, outLine++) {
1398 iComparePortal.
SetPosition(iss, inLine, bandPriorityInputBandNumber);
1399 InputCubes[0]->read(iComparePortal);
1401 oComparePortal.
SetPosition(m_oss, outLine, bandPriorityOutputBandNumber);
1402 OutputCubes[0]->read(oComparePortal);
1404 Portal iPortal( ins, 1, InputCubes[0]->pixelType() );
1405 Portal oPortal( ins, 1, OutputCubes[0]->pixelType() );
1407 bool inCopy =
false;
1409 for (
int iPixel = 0; iPixel < ins; iPixel++) {
1410 resultsPortal[iPixel] =
false;
1411 if (m_createOutputMosaic) {
1412 resultsPortal[iPixel] =
true;
1416 if ( (m_bandPriorityUseMaxValue ==
false &&
1417 iComparePortal[iPixel] < oComparePortal[iPixel]) ||
1418 (m_bandPriorityUseMaxValue ==
true &&
1419 iComparePortal[iPixel] > oComparePortal[iPixel]) ) {
1420 resultsPortal[iPixel] =
true;
1425 resultsPortal[iPixel] =
true;
1430 for (
int ib = isb, ob = m_osb; ib < (isb + inb) && ob <= m_onb; ib++, ob++) {
1433 InputCubes[0]->read(iPortal);
1436 OutputCubes[0]->read(oPortal);
1438 for (
int iPixel = 0; iPixel < ins; iPixel++) {
1439 if (resultsPortal[iPixel]) {
1440 if (m_createOutputMosaic) {
1441 oPortal[iPixel] = iPortal[iPixel];
1444 (m_placeHighSatPixels &&
IsHighPixel(iPortal[iPixel]) ) ||
1445 (m_placeLowSatPixels &&
IsLowPixel (iPortal[iPixel]) ) ||
1446 (m_placeNullPixels &&
IsNullPixel(iPortal[iPixel]) ) ) {
1447 oPortal[iPixel] = iPortal[iPixel];
1451 oPortal[iPixel] = iPortal[iPixel];
1454 OutputCubes[0]->write(oPortal);
1473 int ProcessMosaic::GetOriginDefaultByPixelType() {
1476 switch (
SizeOf(OutputCubes[0]->pixelType())) {
1490 QString msg =
"ProcessMosaic::GetOriginDefaultByPixelType - Invalid Pixel Type";
1491 throw IException(IException::Programmer, msg, _FILEINFO_);
1507 bool ProcessMosaic::GetTrackStatus() {
1509 Pvl *cPvlOut = OutputCubes[0]->label();
1511 bool bGroupExists =
false;
1515 if (cPvlOut->
hasGroup(
"Tracking")) {
1516 bGroupExists =
true;
1519 return bGroupExists;