7 #include "ProcessMapMosaic.h"
12 #include "Application.h"
13 #include "IException.h"
14 #include "ProcessByLine.h"
15 #include "Preference.h"
16 #include "Projection.h"
17 #include "ProjectionFactory.h"
19 #include "RingPlaneProjection.h"
20 #include "SpecialPixel.h"
21 #include "TProjection.h"
22 #include "UniqueIOCachingAlgorithm.h"
29 ProcessMapMosaic::ProcessMapMosaic() {
30 p_createMosaic =
true;
35 ProcessMapMosaic::~ProcessMapMosaic() { }
43 "ProcessMapMosaic does not support the SetInputCube method",
51 bool ProcessMapMosaic::StartProcess(QString inputFile) {
52 if (InputCubes.size() != 0) {
53 QString msg =
"Input cubes already exist; do not call SetInputCube when using ";
54 msg +=
"ProcessMosaic::StartProcess(QString)";
55 throw IException(IException::Programmer, msg, _FILEINFO_);
58 if (OutputCubes.size() == 0) {
59 QString msg =
"An output cube must be set before calling StartProcess";
60 throw IException(IException::Programmer, msg, _FILEINFO_);
64 Cube *inCube = ProcessMosaic::SetInputCube(inputFile, inAtt);
66 Cube *mosaicCube = OutputCubes[0];
72 if (*iproj != *oproj) {
73 QString msg =
"Mapping groups do not match between cube [" + inputFile +
"] and mosaic";
74 throw IException(IException::User, msg, _FILEINFO_);
77 int outSample, outSampleEnd, outLine, outLineEnd;
93 int ins = InputCubes[0]->sampleCount();
94 int inl = InputCubes[0]->lineCount();
95 outSampleEnd = outSample + ins;
96 outLineEnd = outLine + inl;
103 int worldStart = (int)(oproj->
WorldX() + 0.5);
105 int worldEnd = (int)(oproj->
WorldX() + 0.5);
107 worldSize = abs(worldEnd - worldStart) * 2;
109 wrapPossible = wrapPossible && (worldSize > 0);
115 while (outSampleEnd - worldSize > 1) {
116 outSample -= worldSize;
117 outSampleEnd -= worldSize;
127 ins = ins + outSample - 1;
132 inl = inl + outLine - 1;
136 if ((outSample + ins - 1) > nsMosaic) {
137 ins = nsMosaic - outSample + 1;
141 if ((outLine + inl - 1) > nlMosaic) {
142 inl = nlMosaic - outLine + 1;
145 if (outSampleEnd < 1 || outLineEnd < 1 || outSample > nsMosaic || outLine > nlMosaic || ins < 1 || inl < 1) {
158 ProcessMosaic::StartProcess(outSample, outLine, outBand);
163 ProcessMosaic::SetCreateFlag(
false);
166 outSample += worldSize;
167 outSampleEnd += worldSize;
169 while (wrapPossible && outSample < nsMosaic);
172 QString msg =
"Unable to mosaic cube [" +
FileName(inputFile).
name() +
"]";
173 throw IException(e, IException::User, msg, _FILEINFO_);
177 WriteHistory(*mosaicCube);
180 p_propagateHistory =
false;
194 const QString &mosaicFile) {
196 double xmin = DBL_MAX;
197 double xmax = -DBL_MAX;
198 double ymin = DBL_MAX;
199 double ymax = -DBL_MAX;
200 double slat = DBL_MAX;
201 double elat = -DBL_MAX;
202 double slon = DBL_MAX;
203 double elon = -DBL_MAX;
204 bool latlonflag =
true;
208 if (propagationCubes.size() < 1) {
209 QString msg =
"The list does not contain any data";
210 throw IException(IException::Programmer, msg, _FILEINFO_);
213 for (
int i = 0; i < propagationCubes.size(); i++) {
223 if ((proj != NULL) && (*proj != *projNew)) {
224 QString msg =
"Mapping groups do not match between cubes [" +
225 propagationCubes[0].toString() +
"] and [" + propagationCubes[i].toString() +
"]";
226 throw IException(IException::User, msg, _FILEINFO_);
232 if (x < xmin) xmin = x;
233 if (y < ymin) ymin = y;
234 if (x > xmax) xmax = x;
235 if (y > ymax) ymax = y;
239 if (x < xmin) xmin = x;
240 if (y < ymin) ymin = y;
241 if (x > xmax) xmax = x;
242 if (y > ymax) ymax = y;
256 if (proj)
delete proj;
260 if (proj)
delete proj;
262 return SetOutputCube(propagationCubes[0].
toString(), xmin, xmax, ymin, ymax,
263 slat, elat, slon, elon, bands, oAtt, mosaicFile, latlonflag);
273 const QString &mosaicFile) {
275 double xmin = DBL_MAX;
276 double xmax = -DBL_MAX;
277 double ymin = DBL_MAX;
278 double ymax = -DBL_MAX;
279 double srad = DBL_MAX;
280 double erad = -DBL_MAX;
281 double saz = DBL_MAX;
282 double eaz = -DBL_MAX;
286 if (propagationCubes.size() < 1) {
287 QString msg =
"The list does not contain any data";
288 throw IException(IException::Programmer, msg, _FILEINFO_);
291 for (
int i = 0; i < propagationCubes.size(); i++) {
301 if ((proj != NULL) && (*proj != *projNew)) {
302 QString msg =
"Mapping groups do not match between cubes [" +
303 propagationCubes[0].toString() +
"] and [" + propagationCubes[i].toString() +
"]";
304 throw IException(IException::User, msg, _FILEINFO_);
310 if (x < xmin) xmin = x;
311 if (y < ymin) ymin = y;
312 if (x > xmax) xmax = x;
313 if (y > ymax) ymax = y;
317 if (x < xmin) xmin = x;
318 if (y < ymin) ymin = y;
319 if (x > xmax) xmax = x;
320 if (y > ymax) ymax = y;
329 if (proj)
delete proj;
333 if (proj)
delete proj;
335 return RingsSetOutputCube(propagationCubes[0].
toString(), xmin, xmax, ymin, ymax,
336 srad, erad, saz, eaz, bands, oAtt, mosaicFile);
346 double slat,
double elat,
double slon,
double elon,
348 if (propagationCubes.size() < 1) {
349 QString msg =
"The list does not contain any data";
350 throw IException(IException::Programmer, msg, _FILEINFO_);
353 int samples, lines, bands = 0;
365 if (slat < elat && slon < elon) {
384 double xmin, xmax, ymin, ymax;
385 proj->XYRange(xmin, xmax, ymin, ymax);
388 xmin = mapPvl.
findGroup(
"Mapping")[
"UpperLeftCornerX"];
389 ymax = mapPvl.
findGroup(
"Mapping")[
"UpperLeftCornerY"];
391 for (
int i = 0; i < propagationCubes.size(); i++) {
403 else if (*proj != *projNew) {
404 QString msg =
"Mapping groups do not match between cube [" + propagationCubes[i].toString() +
405 "] and [" + propagationCubes[0].toString() +
"]";
406 throw IException(IException::User, msg, _FILEINFO_);
409 if (proj)
delete proj;
413 if (proj)
delete proj;
415 return SetOutputCube(propagationCubes[0].
toString(), xmin, xmax, ymin, ymax,
416 slat, elat, slon, elon, bands, oAtt, mosaicFile);
435 double srad,
double erad,
double saz,
double eaz,
437 if (propagationCubes.size() < 1) {
438 QString msg =
"The list does not contain any data";
439 throw IException(IException::Programmer, msg, _FILEINFO_);
442 int samples, lines, bands = 0;
463 double xmin, xmax, ymin, ymax;
464 proj->XYRange(xmin, xmax, ymin, ymax);
467 xmin = mapPvl.
findGroup(
"Mapping")[
"UpperLeftCornerX"];
468 ymax = mapPvl.
findGroup(
"Mapping")[
"UpperLeftCornerY"];
470 for (
int i = 0; i < propagationCubes.size(); i++) {
481 else if (*proj != *projNew) {
482 QString msg =
"Mapping groups do not match between cube [" + propagationCubes[i].toString() +
483 "] and [" + propagationCubes[0].toString() +
"]";
484 throw IException(IException::User, msg, _FILEINFO_);
487 if (proj)
delete proj;
491 if (proj)
delete proj;
493 return RingsSetOutputCube(propagationCubes[0].
toString(), xmin, xmax, ymin, ymax,
494 srad, erad, saz, eaz, bands, oAtt, mosaicFile);
505 Isis::Cube *ProcessMapMosaic::SetOutputCube(
const QString &inputFile,
506 double xmin,
double xmax,
double ymin,
double ymax,
507 double slat,
double elat,
double slon,
double elon,
int nbands,
509 Pvl fileLab(inputFile);
512 mapping[
"UpperLeftCornerX"] =
toString(xmin);
513 mapping[
"UpperLeftCornerY"] =
toString(ymax);
522 if (latlonflag && slat < elat && slon < elon) {
543 Projection *firstProj = ProjectionFactory::CreateFromCube(fileLab);
544 int samps = (int)(ceil(firstProj->
ToWorldX(xmax) - firstProj->
ToWorldX(xmin)) + 0.5);
545 int lines = (int)(ceil(firstProj->
ToWorldY(ymin) - firstProj->
ToWorldY(ymax)) + 0.5);
548 if (p_createMosaic) {
564 if (GetImageOverlay() == AverageImageWithMosaic) {
579 mosaicCube->
open(mosaicFile,
"rw");
582 AddOutputCube(mosaicCube);
607 Isis::Cube *ProcessMapMosaic::RingsSetOutputCube(
const QString &inputFile,
608 double xmin,
double xmax,
double ymin,
double ymax,
609 double srad,
double erad,
double saz,
double eaz,
int nbands,
611 Pvl fileLab(inputFile);
614 mapping[
"UpperLeftCornerX"] =
toString(xmin);
615 mapping[
"UpperLeftCornerY"] =
toString(ymax);
621 Projection *firstProj = ProjectionFactory::RingsCreateFromCube(fileLab);
622 int samps = (int)(ceil(firstProj->
ToWorldX(xmax) - firstProj->
ToWorldX(xmin)) + 0.5);
623 int lines = (int)(ceil(firstProj->
ToWorldY(ymin) - firstProj->
ToWorldY(ymax)) + 0.5);
626 if (p_createMosaic) {
642 if (GetImageOverlay() == AverageImageWithMosaic) {
657 mosaicCube->
open(mosaicFile,
"rw");
660 AddOutputCube(mosaicCube);
673 if (OutputCubes.size() != 0) {
674 QString msg =
"You can only specify one output cube and projection";
675 throw IException(IException::Programmer, msg, _FILEINFO_);
684 if (p_createMosaic) {
687 int samps, lines, bands;
688 delete ProjectionFactory::CreateForCube(newMap, samps, lines,
false);
697 if (GetImageOverlay() == AverageImageWithMosaic) {
715 AddOutputCube(mosaicCube);
716 mosaicCube->
open(mosaicFile,
"rw");
731 if (OutputCubes.size() != 0) {
732 QString msg =
"You can only specify one output cube and projection";
733 throw IException(IException::Programmer, msg, _FILEINFO_);
742 if (p_createMosaic) {
745 int samps, lines, bands;
746 delete ProjectionFactory::RingsCreateForCube(newMap, samps, lines,
false);
755 if (GetImageOverlay() == AverageImageWithMosaic) {
773 AddOutputCube(mosaicCube);
774 mosaicCube->
open(mosaicFile,
"rw");
786 Cube *ProcessMapMosaic::SetOutputCube(
const QString &mosaicFile) {
787 p_createMosaic =
false;
789 mosaic.
open(mosaicFile);
794 Cube *ocube = SetOutputCube(
"", mapping, oAtt, mosaicFile);
795 p_createMosaic =
true;
806 Cube *ProcessMapMosaic::RingsSetOutputCube(
const QString &mosaicFile) {
807 p_createMosaic =
false;
809 mosaic.
open(mosaicFile);
814 Cube *ocube = RingsSetOutputCube(
"", mapping, oAtt, mosaicFile);
815 p_createMosaic =
true;
825 void ProcessMapMosaic::FillNull(
Buffer &data) {