File failed to load: https://isis.astrogeology.usgs.gov/6.0.0/Object/assets/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
ProcessMapMosaic.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 #include "ProcessMapMosaic.h"
8 
9 #include <QTime>
10 #include <QDebug>
11 
12 #include "Application.h"
13 #include "IException.h"
14 #include "ProcessByLine.h"
15 #include "Preference.h"
16 #include "Projection.h"
17 #include "ProjectionFactory.h"
18 #include "Pvl.h"
19 #include "RingPlaneProjection.h"
20 #include "SpecialPixel.h"
21 #include "TProjection.h"
22 #include "UniqueIOCachingAlgorithm.h"
23 
24 using namespace std;
25 
26 
27 namespace Isis {
29  ProcessMapMosaic::ProcessMapMosaic() {
30  p_createMosaic = true;
31  }
32 
33 
35  ProcessMapMosaic::~ProcessMapMosaic() { }
36 
37 
41  Isis::Cube *ProcessMapMosaic::SetInputCube() {
42  throw IException(IException::Programmer,
43  "ProcessMapMosaic does not support the SetInputCube method",
44  _FILEINFO_);
45  }
46 
47 
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_);
56  }
57 
58  if (OutputCubes.size() == 0) {
59  QString msg = "An output cube must be set before calling StartProcess";
60  throw IException(IException::Programmer, msg, _FILEINFO_);
61  }
62 
63  CubeAttributeInput inAtt(inputFile);
64  Cube *inCube = ProcessMosaic::SetInputCube(inputFile, inAtt);
65 
66  Cube *mosaicCube = OutputCubes[0];
67  Projection *iproj = inCube->projection();
68  Projection *oproj = mosaicCube->projection();
69  int nsMosaic = mosaicCube->sampleCount();
70  int nlMosaic = mosaicCube->lineCount();
71 
72  if (*iproj != *oproj) {
73  QString msg = "Mapping groups do not match between cube [" + inputFile + "] and mosaic";
74  throw IException(IException::User, msg, _FILEINFO_);
75  }
76 
77  int outSample, outSampleEnd, outLine, outLineEnd;
78 
79 
80  if (oproj->ToWorldX(iproj->ToProjectionX(1.0)) < 0) {
81  outSample = (int)(oproj->ToWorldX(iproj->ToProjectionX(1.0)) - 0.5);
82  }
83  else {
84  outSample = (int)(oproj->ToWorldX(iproj->ToProjectionX(1.0)) + 0.5);
85  }
86  if (oproj->ToWorldY(iproj->ToProjectionY(1.0)) < 0) {
87  outLine = (int)(oproj->ToWorldY(iproj->ToProjectionY(1.0)) - 0.5);
88  }
89  else {
90  outLine = (int)(oproj->ToWorldY(iproj->ToProjectionY(1.0)) + 0.5);
91  }
92 
93  int ins = InputCubes[0]->sampleCount();
94  int inl = InputCubes[0]->lineCount();
95  outSampleEnd = outSample + ins;
96  outLineEnd = outLine + inl;
97 
98  bool wrapPossible = iproj->IsEquatorialCylindrical();
99  int worldSize = 0;
100  if (wrapPossible) {
101  // Figure out how many samples 360 degrees is
102  wrapPossible = wrapPossible && oproj->SetUniversalGround(0, 0);
103  int worldStart = (int)(oproj->WorldX() + 0.5);
104  wrapPossible = wrapPossible && oproj->SetUniversalGround(0, 180);
105  int worldEnd = (int)(oproj->WorldX() + 0.5);
106 
107  worldSize = abs(worldEnd - worldStart) * 2;
108 
109  wrapPossible = wrapPossible && (worldSize > 0);
110 
111  // This is EquatorialCylindrical, so shift to the left all the way
112  if (wrapPossible) {
113  // While some data would still be put in the mosaic, move left
114  // >1 for end because 0 still means no data, whereas 1 means 1 line of data
115  while (outSampleEnd - worldSize > 1) {
116  outSample -= worldSize;
117  outSampleEnd -= worldSize;
118  }
119  // Now we have the sample range to the furthest left
120  }
121  }
122 
123  // Check overlaps of input image along the mosaic edges before
124  // calling ProcessMosaic::StartProcess
125  // Left edge
126  if (outSample < 1) {
127  ins = ins + outSample - 1;
128  }
129 
130  // Top edge
131  if (outLine < 1) {
132  inl = inl + outLine - 1;
133  }
134 
135  // Right edge
136  if ((outSample + ins - 1) > nsMosaic) {
137  ins = nsMosaic - outSample + 1;
138  }
139 
140  // Bottom edge
141  if ((outLine + inl - 1) > nlMosaic) {
142  inl = nlMosaic - outLine + 1;
143  }
144 
145  if (outSampleEnd < 1 || outLineEnd < 1 || outSample > nsMosaic || outLine > nlMosaic || ins < 1 || inl < 1) {
146  // Add a PvlKeyword naming which files are not included in output mosaic
147  ClearInputCubes();
148  return false;
149  }
150  else {
151  // Place the input in the mosaic
152  Progress()->SetText("Mosaicking " + FileName(inputFile).name());
153 
154  try {
155  do {
156  int outBand = 1;
157 
158  ProcessMosaic::StartProcess(outSample, outLine, outBand);
159  // Reset the creation flag to ensure that the data within the tracking cube written from
160  // this call of StartProcess isn't over-written in the next. This needs to occur since the
161  // tracking cube is created in ProcessMosaic if the m_createOutputMosaic flag is set to
162  // true and the cube would then be completely re-created (setting all pixels to Null).
163  ProcessMosaic::SetCreateFlag(false);
164 
165  // Increment for projections where occurrances may happen multiple times
166  outSample += worldSize;
167  outSampleEnd += worldSize;
168  }
169  while (wrapPossible && outSample < nsMosaic);
170  }
171  catch (IException &e) {
172  QString msg = "Unable to mosaic cube [" + FileName(inputFile).name() + "]";
173  throw IException(e, IException::User, msg, _FILEINFO_);
174  }
175  }
176 
177  WriteHistory(*mosaicCube);
178 
179  // Don't propagate any more histories now that we've done one
180  p_propagateHistory = false;
181 
182  ClearInputCubes();
183 
184  return true;
185  }
186 
187 
188  //*************************************************************************************************
193  Isis::Cube *ProcessMapMosaic::SetOutputCube(FileList &propagationCubes, CubeAttributeOutput &oAtt,
194  const QString &mosaicFile) {
195  int bands = 0;
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;
205 
206  TProjection *proj = NULL;
207 
208  if (propagationCubes.size() < 1) {
209  QString msg = "The list does not contain any data";
210  throw IException(IException::Programmer, msg, _FILEINFO_);
211  }
212 
213  for (int i = 0; i < propagationCubes.size(); i++) {
214  // Open the cube and get the maximum number of band in all cubes
215  Cube cube;
216  cube.open(propagationCubes[i].toString());
217  bands = max(bands, cube.bandCount());
218 
219  // See if the cube has a projection and make sure it matches
220  // previous input cubes
221  TProjection *projNew =
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_);
227  }
228 
229  // Figure out the x/y range as it may be needed later
230  double x = projNew->ToProjectionX(0.5);
231  double y = projNew->ToProjectionY(0.5);
232  if (x < xmin) xmin = x;
233  if (y < ymin) ymin = y;
234  if (x > xmax) xmax = x;
235  if (y > ymax) ymax = y;
236 
237  x = projNew->ToProjectionX(cube.sampleCount() + 0.5);
238  y = projNew->ToProjectionY(cube.lineCount() + 0.5);
239  if (x < xmin) xmin = x;
240  if (y < ymin) ymin = y;
241  if (x > xmax) xmax = x;
242  if (y > ymax) ymax = y;
243 
244  if (projNew->MinimumLatitude() == 0.0 && projNew->MaximumLatitude() == 0.0 &&
245  projNew->MinimumLongitude() == 0.0 && projNew->MaximumLongitude() == 0.0) {
246  latlonflag = false;
247  }
248 
249  slat = min(slat, projNew->MinimumLatitude());
250  elat = max(elat, projNew->MaximumLatitude());
251  slon = min(slon, projNew->MinimumLongitude());
252  elon = max(elon, projNew->MaximumLongitude());
253 
254  // Cleanup
255  cube.close();
256  if (proj) delete proj;
257  proj = projNew;
258  }
259 
260  if (proj) delete proj;
261 
262  return SetOutputCube(propagationCubes[0].toString(), xmin, xmax, ymin, ymax,
263  slat, elat, slon, elon, bands, oAtt, mosaicFile, latlonflag);
264  }
265 
266 
267  //*************************************************************************************************
272  Isis::Cube *ProcessMapMosaic::RingsSetOutputCube(FileList &propagationCubes, CubeAttributeOutput &oAtt,
273  const QString &mosaicFile) {
274  int bands = 0;
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; // starting ring radius
280  double erad = -DBL_MAX; // ending ring radius
281  double saz = DBL_MAX; // starting azimuth (ring longitude)
282  double eaz = -DBL_MAX; // ending azimuth (ring longitude)
283 
284  RingPlaneProjection *proj = NULL;
285 
286  if (propagationCubes.size() < 1) {
287  QString msg = "The list does not contain any data";
288  throw IException(IException::Programmer, msg, _FILEINFO_);
289  }
290 
291  for (int i = 0; i < propagationCubes.size(); i++) {
292  // Open the cube and get the maximum number of band in all cubes
293  Cube cube;
294  cube.open(propagationCubes[i].toString());
295  bands = max(bands, cube.bandCount());
296 
297  // See if the cube has a projection and make sure it matches
298  // previous input cubes
299  RingPlaneProjection *projNew =
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_);
305  }
306 
307  // Figure out the x/y range as it may be needed later
308  double x = projNew->ToProjectionX(0.5);
309  double y = projNew->ToProjectionY(0.5);
310  if (x < xmin) xmin = x;
311  if (y < ymin) ymin = y;
312  if (x > xmax) xmax = x;
313  if (y > ymax) ymax = y;
314 
315  x = projNew->ToProjectionX(cube.sampleCount() + 0.5);
316  y = projNew->ToProjectionY(cube.lineCount() + 0.5);
317  if (x < xmin) xmin = x;
318  if (y < ymin) ymin = y;
319  if (x > xmax) xmax = x;
320  if (y > ymax) ymax = y;
321 
322  srad = min(srad, projNew->MinimumRingRadius());
323  erad = max(erad, projNew->MaximumRingRadius());
324  saz = min(saz, projNew->MinimumRingLongitude());
325  eaz = max(eaz, projNew->MaximumRingLongitude());
326 
327  // Cleanup
328  cube.close();
329  if (proj) delete proj;
330  proj = projNew;
331  }
332 
333  if (proj) delete proj;
334 
335  return RingsSetOutputCube(propagationCubes[0].toString(), xmin, xmax, ymin, ymax,
336  srad, erad, saz, eaz, bands, oAtt, mosaicFile);
337  }
338 
339 
340  //*************************************************************************************************
345  Isis::Cube *ProcessMapMosaic::SetOutputCube(FileList &propagationCubes,
346  double slat, double elat, double slon, double elon,
347  CubeAttributeOutput &oAtt, const QString &mosaicFile) {
348  if (propagationCubes.size() < 1) {
349  QString msg = "The list does not contain any data";
350  throw IException(IException::Programmer, msg, _FILEINFO_);
351  }
352 
353  int samples, lines, bands = 0;
354  Pvl label;
355  label.read(propagationCubes[0].toString());
356  PvlGroup mGroup = label.findGroup("Mapping", Pvl::Traverse);
357 
358  // All mosaicking programs use only the upper left x and y to determine where to
359  // place an image into a mosaic. For clarity purposes, the mosaic programs do
360  // not use lat/lon ranges for anything except creating the mosaic. By specifying
361  // the lat/lon range of the mosaic, we compute the upper left x/y of the mosaic.
362  // All map projected cubes must have an upper left x/y and do not require a lat/lon
363  // range. If the current values for the latitude and longitude range are out of
364  // order or equal, then we don't write them to the labels.
365  if (slat < elat && slon < elon) {
366  mGroup.addKeyword(PvlKeyword("MinimumLatitude", toString(slat)), Pvl::Replace);
367  mGroup.addKeyword(PvlKeyword("MaximumLatitude", toString(elat)), Pvl::Replace);
368  mGroup.addKeyword(PvlKeyword("MinimumLongitude", toString(slon)), Pvl::Replace);
369  mGroup.addKeyword(PvlKeyword("MaximumLongitude", toString(elon)), Pvl::Replace);
370  }
371 
372  if (mGroup.hasKeyword("UpperLeftCornerX"))
373  mGroup.deleteKeyword("UpperLeftCornerX");
374 
375  if (mGroup.hasKeyword("UpperLeftCornerY"))
376  mGroup.deleteKeyword("UpperLeftCornerY");
377 
378  Pvl mapPvl;
379  mapPvl += mGroup;
380 
381  // Use CreateForCube because our range differs from any of the cubes (manually specified)
382  Projection *proj = Isis::ProjectionFactory::CreateForCube(mapPvl, samples, lines, false);
383 
384  double xmin, xmax, ymin, ymax;
385  proj->XYRange(xmin, xmax, ymin, ymax);
386 
387  // The xmin/ymax should be rounded for the labels
388  xmin = mapPvl.findGroup("Mapping")["UpperLeftCornerX"];
389  ymax = mapPvl.findGroup("Mapping")["UpperLeftCornerY"];
390 
391  for (int i = 0; i < propagationCubes.size(); i++) {
392  Cube cube;
393  cube.open(propagationCubes[i].toString());
394  bands = max(cube.bandCount(), bands);
395 
396  // See if the cube has a projection and make sure it matches
397  // previous input cubes
398  Projection *projNew =
400 
401  if (proj == NULL) {
402  }
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_);
407  }
408 
409  if (proj) delete proj;
410  proj = projNew;
411  }
412 
413  if (proj) delete proj;
414 
415  return SetOutputCube(propagationCubes[0].toString(), xmin, xmax, ymin, ymax,
416  slat, elat, slon, elon, bands, oAtt, mosaicFile);
417  }
418 
419 
420  //*************************************************************************************************
434  Isis::Cube *ProcessMapMosaic::RingsSetOutputCube(FileList &propagationCubes,
435  double srad, double erad, double saz, double eaz,
436  CubeAttributeOutput &oAtt, const QString &mosaicFile) {
437  if (propagationCubes.size() < 1) {
438  QString msg = "The list does not contain any data";
439  throw IException(IException::Programmer, msg, _FILEINFO_);
440  }
441 
442  int samples, lines, bands = 0;
443  Pvl label;
444  label.read(propagationCubes[0].toString());
445  PvlGroup mGroup = label.findGroup("Mapping", Pvl::Traverse);
446  mGroup.addKeyword(PvlKeyword("MinimumRingRadius", toString(srad)), Pvl::Replace);
447  mGroup.addKeyword(PvlKeyword("MaximumRingRadius", toString(erad)), Pvl::Replace);
448  mGroup.addKeyword(PvlKeyword("MinimumRingLongitude", toString(saz)), Pvl::Replace);
449  mGroup.addKeyword(PvlKeyword("MaximumRingLongitude", toString(eaz)), Pvl::Replace);
450 
451  if (mGroup.hasKeyword("UpperLeftCornerX"))
452  mGroup.deleteKeyword("UpperLeftCornerX");
453 
454  if (mGroup.hasKeyword("UpperLeftCornerY"))
455  mGroup.deleteKeyword("UpperLeftCornerY");
456 
457  Pvl mapPvl;
458  mapPvl += mGroup;
459 
460  // Use CreateForCube because our range differs from any of the cubes (manually specified)
461  Projection *proj = Isis::ProjectionFactory::RingsCreateForCube(mapPvl, samples, lines, false);
462 
463  double xmin, xmax, ymin, ymax;
464  proj->XYRange(xmin, xmax, ymin, ymax);
465 
466  // The xmin/ymax should be rounded for the labels
467  xmin = mapPvl.findGroup("Mapping")["UpperLeftCornerX"];
468  ymax = mapPvl.findGroup("Mapping")["UpperLeftCornerY"];
469 
470  for (int i = 0; i < propagationCubes.size(); i++) {
471  Cube cube;
472  cube.open(propagationCubes[i].toString());
473  bands = max(cube.bandCount(), bands);
474 
475  // See if the cube has a projection and make sure it matches
476  // previous input cubes
478 
479  if (proj == NULL) {
480  }
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_);
485  }
486 
487  if (proj) delete proj;
488  proj = projNew;
489  }
490 
491  if (proj) delete proj;
492 
493  return RingsSetOutputCube(propagationCubes[0].toString(), xmin, xmax, ymin, ymax,
494  srad, erad, saz, eaz, bands, oAtt, mosaicFile);
495  }
496 
497 
498  //NExt
499  //*************************************************************************************************
500 
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,
508  CubeAttributeOutput &oAtt, const QString &mosaicFile, bool latlonflag) {
509  Pvl fileLab(inputFile);
510  PvlGroup &mapping = fileLab.findGroup("Mapping", Pvl::Traverse);
511 
512  mapping["UpperLeftCornerX"] = toString(xmin);
513  mapping["UpperLeftCornerY"] = toString(ymax);
514 
515  // All mosaicking programs use only the upper left x and y to determine where to
516  // place an image into a mosaic. For clarity purposes, the mosaic programs do
517  // not use lat/lon ranges for anything except creating the mosaic. By specifying
518  // the lat/lon range of the mosaic, we compute the upper left x/y of the mosaic.
519  // All map projected cubes must have an upper left x/y and do not require a lat/lon
520  // range. If the current values for the latitude and longitude range are out of
521  // order or equal, then we don't write them to the labels.
522  if (latlonflag && slat < elat && slon < elon) {
523  mapping.addKeyword(PvlKeyword("MinimumLatitude", toString(slat)), Pvl::Replace);
524  mapping.addKeyword(PvlKeyword("MaximumLatitude", toString(elat)), Pvl::Replace);
525  mapping.addKeyword(PvlKeyword("MinimumLongitude", toString(slon)), Pvl::Replace);
526  mapping.addKeyword(PvlKeyword("MaximumLongitude", toString(elon)), Pvl::Replace);
527  }
528  else {
529  if (mapping.hasKeyword("MinimumLatitude")) {
530  mapping.deleteKeyword("MinimumLatitude");
531  }
532  if (mapping.hasKeyword("MaximumLatitude")) {
533  mapping.deleteKeyword("MaximumLatitude");
534  }
535  if (mapping.hasKeyword("MinimumLongitude")) {
536  mapping.deleteKeyword("MinimumLongitude");
537  }
538  if (mapping.hasKeyword("MaximumLongitude")) {
539  mapping.deleteKeyword("MaximumLongitude");
540  }
541  }
542 
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);
546  delete firstProj;
547 
548  if (p_createMosaic) {
549  Pvl newMap;
550  newMap.addGroup(mapping);
551 
552  // Initialize the mosaic
553  CubeAttributeInput inAtt;
554 
555  ProcessByLine p;
556  p.SetInputCube(inputFile, inAtt);
557  p.PropagateHistory(false);
558  p.PropagateLabels(false);
559  p.PropagateTables(false);
560  p.PropagatePolygons(false);
561  p.PropagateOriginalLabel(false);
562 
563  // For average priority, get the new band count
564  if (GetImageOverlay() == AverageImageWithMosaic) {
565  nbands *= 2;
566  }
567 
568  Cube *ocube = p.SetOutputCube(mosaicFile, oAtt, samps, lines, nbands);
569  p.Progress()->SetText("Initializing mosaic");
570  p.ClearInputCubes();
571  p.StartProcess(ProcessMapMosaic::FillNull);
572 
573  // CreateForCube created some keywords in the mapping group that needs to be added
574  ocube->putGroup(newMap.findGroup("Mapping", Pvl::Traverse));
575  p.EndProcess();
576  }
577 
578  Cube *mosaicCube = new Cube();
579  mosaicCube->open(mosaicFile, "rw");
580  mosaicCube->addCachingAlgorithm(new UniqueIOCachingAlgorithm(2));
581 
582  AddOutputCube(mosaicCube);
583  return mosaicCube;
584  }
585 
586 
587  //NExt
588  //*************************************************************************************************
589 
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,
610  CubeAttributeOutput &oAtt, const QString &mosaicFile) {
611  Pvl fileLab(inputFile);
612  PvlGroup &mapping = fileLab.findGroup("Mapping", Pvl::Traverse);
613 
614  mapping["UpperLeftCornerX"] = toString(xmin);
615  mapping["UpperLeftCornerY"] = toString(ymax);
616  mapping.addKeyword(PvlKeyword("MinimumRingRadius", toString(srad)), Pvl::Replace);
617  mapping.addKeyword(PvlKeyword("MaximumRingRadius", toString(erad)), Pvl::Replace);
618  mapping.addKeyword(PvlKeyword("MinimumRingLongitude", toString(saz)), Pvl::Replace);
619  mapping.addKeyword(PvlKeyword("MaximumRingLongitude", toString(eaz)), Pvl::Replace);
620 
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);
624  delete firstProj;
625 
626  if (p_createMosaic) {
627  Pvl newMap;
628  newMap.addGroup(mapping);
629 
630  // Initialize the mosaic
631  CubeAttributeInput inAtt;
632 
633  ProcessByLine p;
634  p.SetInputCube(inputFile, inAtt);
635  p.PropagateHistory(false);
636  p.PropagateLabels(false);
637  p.PropagateTables(false);
638  p.PropagatePolygons(false);
639  p.PropagateOriginalLabel(false);
640 
641  // For average priority, get the new band count
642  if (GetImageOverlay() == AverageImageWithMosaic) {
643  nbands *= 2;
644  }
645 
646  Cube *ocube = p.SetOutputCube(mosaicFile, oAtt, samps, lines, nbands);
647  p.Progress()->SetText("Initializing mosaic");
648  p.ClearInputCubes();
649  p.StartProcess(ProcessMapMosaic::FillNull);
650 
651  // CreateForCube created some keywords in the mapping group that needs to be added
652  ocube->putGroup(newMap.findGroup("Mapping", Pvl::Traverse));
653  p.EndProcess();
654  }
655 
656  Cube *mosaicCube = new Cube();
657  mosaicCube->open(mosaicFile, "rw");
658  mosaicCube->addCachingAlgorithm(new UniqueIOCachingAlgorithm(2));
659 
660  AddOutputCube(mosaicCube);
661  return mosaicCube;
662  }
663 
664 
665  //*************************************************************************************************
666 
671  Isis::Cube *ProcessMapMosaic::SetOutputCube(const QString &inputFile, PvlGroup mapping,
672  CubeAttributeOutput &oAtt, const QString &mosaicFile) {
673  if (OutputCubes.size() != 0) {
674  QString msg = "You can only specify one output cube and projection";
675  throw IException(IException::Programmer, msg, _FILEINFO_);
676  }
677 
678  if (mapping.hasKeyword("UpperLeftCornerX"))
679  mapping.deleteKeyword("UpperLeftCornerX");
680 
681  if (mapping.hasKeyword("UpperLeftCornerY"))
682  mapping.deleteKeyword("UpperLeftCornerY");
683 
684  if (p_createMosaic) {
685  Pvl newMap;
686  newMap.addGroup(mapping);
687  int samps, lines, bands;
688  delete ProjectionFactory::CreateForCube(newMap, samps, lines, false);
689 
690  // Initialize the mosaic
691  ProcessByLine p;
692  CubeAttributeInput inAtt(inputFile);
693  Cube *propCube = p.SetInputCube(inputFile, inAtt);
694  bands = propCube->bandCount();
695 
696  // For average priority, get the new band count
697  if (GetImageOverlay() == AverageImageWithMosaic) {
698  bands *= 2;
699  }
700 
701  p.PropagateHistory(false);
702  p.PropagateLabels(false);
703  Cube *ocube = p.SetOutputCube(mosaicFile, oAtt, samps, lines, bands);
704  p.Progress()->SetText("Initializing mosaic");
705  p.ClearInputCubes();
706 
707  p.StartProcess(ProcessMapMosaic::FillNull);
708 
709  // CreateForCube created some keywords in the mapping group that needs to be added
710  ocube->putGroup(newMap.findGroup("Mapping", Pvl::Traverse));
711  p.EndProcess();
712  }
713 
714  Cube *mosaicCube = new Cube();
715  AddOutputCube(mosaicCube);
716  mosaicCube->open(mosaicFile, "rw");
717  mosaicCube->addCachingAlgorithm(new UniqueIOCachingAlgorithm(2));
718 
719  return mosaicCube;
720  }
721 
722 
723  //*************************************************************************************************
724 
729  Isis::Cube *ProcessMapMosaic::RingsSetOutputCube(const QString &inputFile, PvlGroup mapping,
730  CubeAttributeOutput &oAtt, const QString &mosaicFile) {
731  if (OutputCubes.size() != 0) {
732  QString msg = "You can only specify one output cube and projection";
733  throw IException(IException::Programmer, msg, _FILEINFO_);
734  }
735 
736  if (mapping.hasKeyword("UpperLeftCornerX"))
737  mapping.deleteKeyword("UpperLeftCornerX");
738 
739  if (mapping.hasKeyword("UpperLeftCornerY"))
740  mapping.deleteKeyword("UpperLeftCornerY");
741 
742  if (p_createMosaic) {
743  Pvl newMap;
744  newMap.addGroup(mapping);
745  int samps, lines, bands;
746  delete ProjectionFactory::RingsCreateForCube(newMap, samps, lines, false);
747 
748  // Initialize the mosaic
749  ProcessByLine p;
750  CubeAttributeInput inAtt(inputFile);
751  Cube *propCube = p.SetInputCube(inputFile, inAtt);
752  bands = propCube->bandCount();
753 
754  // For average priority, get the new band count
755  if (GetImageOverlay() == AverageImageWithMosaic) {
756  bands *= 2;
757  }
758 
759  p.PropagateHistory(false);
760  p.PropagateLabels(false);
761  Cube *ocube = p.SetOutputCube(mosaicFile, oAtt, samps, lines, bands);
762  p.Progress()->SetText("Initializing mosaic");
763  p.ClearInputCubes();
764 
765  p.StartProcess(ProcessMapMosaic::FillNull);
766 
767  // CreateForCube created some keywords in the mapping group that needs to be added
768  ocube->putGroup(newMap.findGroup("Mapping", Pvl::Traverse));
769  p.EndProcess();
770  }
771 
772  Cube *mosaicCube = new Cube();
773  AddOutputCube(mosaicCube);
774  mosaicCube->open(mosaicFile, "rw");
775  mosaicCube->addCachingAlgorithm(new UniqueIOCachingAlgorithm(2));
776 
777  return mosaicCube;
778  }
779 
780 
781  //*************************************************************************************************
782 
786  Cube *ProcessMapMosaic::SetOutputCube(const QString &mosaicFile) {
787  p_createMosaic = false;
788  Cube mosaic;
789  mosaic.open(mosaicFile);
790 
791  PvlGroup &mapping = mosaic.label()->findGroup("Mapping", Pvl::Traverse);
792  CubeAttributeOutput oAtt;
793  // The other SetOutput will not use the attribute or filename
794  Cube *ocube = SetOutputCube("", mapping, oAtt, mosaicFile);
795  p_createMosaic = true;
796 
797  return ocube;
798  }
799 
800 
801  //*************************************************************************************************
802 
806  Cube *ProcessMapMosaic::RingsSetOutputCube(const QString &mosaicFile) {
807  p_createMosaic = false;
808  Cube mosaic;
809  mosaic.open(mosaicFile);
810 
811  PvlGroup &mapping = mosaic.label()->findGroup("Mapping", Pvl::Traverse);
812  CubeAttributeOutput oAtt;
813  // The other SetOutput will not use the attribute or filename
814  Cube *ocube = RingsSetOutputCube("", mapping, oAtt, mosaicFile);
815  p_createMosaic = true;
816 
817  return ocube;
818  }
819 
820 
821  //*************************************************************************************************
825  void ProcessMapMosaic::FillNull(Buffer &data) {
826  for (int i = 0; i < data.size(); i++) data[i] = Isis::Null;
827  }
828 } // end namespace isis
Isis::Process::PropagateTables
void PropagateTables(const bool prop)
This method allows the programmer to propagate input tables to the output cube (default is true)
Definition: Process.cpp:678
Isis::PvlObject::findGroup
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:129
Isis::RingPlaneProjection::MinimumRingRadius
double MinimumRingRadius() const
This returns the minimum radius of the area of interest.
Definition: RingPlaneProjection.cpp:405
Isis::PvlKeyword
A single keyword-value pair.
Definition: PvlKeyword.h:82
Isis::FileName::name
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
Definition: FileName.cpp:162
Isis::PvlContainer::addKeyword
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
Definition: PvlContainer.cpp:202
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::ProjectionFactory::CreateForCube
static Isis::Projection * CreateForCube(Isis::Pvl &label, int &ns, int &nl, bool sizeMatch=true)
This method creates a map projection for a cube given a label.
Definition: ProjectionFactory.cpp:188
Isis::TProjection::MinimumLongitude
virtual double MinimumLongitude() const
This returns the minimum longitude of the area of interest.
Definition: TProjection.cpp:732
Isis::Cube::putGroup
void putGroup(const PvlGroup &group)
Adds a group in a Label to the cube.
Definition: Cube.cpp:2056
Isis::Process::PropagatePolygons
void PropagatePolygons(const bool prop)
This method allows the programmer to propagate input blobs to the output cube (default is true)
Definition: Process.cpp:727
Isis::Projection::ToProjectionY
double ToProjectionY(const double worldY) const
This method converts a world y value to a projection y value.
Definition: Projection.cpp:650
Isis::ProcessByBrick::SetOutputCube
virtual Cube * SetOutputCube(const QString &fname, const CubeAttributeOutput &att)
Create the output file.
Definition: ProcessByBrick.cpp:364
Isis::Cube::close
void close(bool remove=false)
Closes the cube and updates the labels.
Definition: Cube.cpp:260
Isis::PvlContainer::hasKeyword
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Definition: PvlContainer.cpp:159
Isis::Pvl
Container for cube-like labels.
Definition: Pvl.h:119
Isis::CubeAttributeOutput
Manipulate and parse attributes of output cube filenames.
Definition: CubeAttribute.h:473
Isis::ProjectionFactory::RingsCreateFromCube
static Isis::Projection * RingsCreateFromCube(Isis::Cube &cube)
This method is a helper method.
Definition: ProjectionFactory.cpp:1081
Isis::Projection::SetUniversalGround
virtual bool SetUniversalGround(const double coord1, const double coord2)
This method is used to set the lat/lon or radius/azimuth (i.e.
Definition: Projection.cpp:417
Isis::TProjection::MaximumLatitude
virtual double MaximumLatitude() const
This returns the maximum latitude of the area of interest.
Definition: TProjection.cpp:721
Isis::toString
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition: IString.cpp:211
Isis::ProcessByLine
Process cubes by line.
Definition: ProcessByLine.h:97
Isis::RingPlaneProjection::MaximumRingRadius
double MaximumRingRadius() const
This returns the maximum radius of the area of interest.
Definition: RingPlaneProjection.cpp:416
Isis::Process::PropagateOriginalLabel
void PropagateOriginalLabel(const bool prop)
This method allows the programmer to propagate original labels to the output cube (default is true)
Definition: Process.cpp:748
Isis::Buffer
Buffer for reading and writing cube data.
Definition: Buffer.h:53
Isis::RingPlaneProjection
Base class for Map Projections of plane shapes.
Definition: RingPlaneProjection.h:147
Isis::Projection::IsEquatorialCylindrical
virtual bool IsEquatorialCylindrical()
This method returns true if the projection is equatorial cylindrical.
Definition: Projection.cpp:222
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Isis::Cube::lineCount
int lineCount() const
Definition: Cube.cpp:1734
Isis::Pvl::read
void read(const QString &file)
Loads PVL information from a stream.
Definition: Pvl.cpp:90
Isis::Process::ClearInputCubes
void ClearInputCubes()
Close owned input cubes from the list and clear the list.
Definition: Process.cpp:603
Isis::Process::PropagateHistory
void PropagateHistory(const bool prop)
This method allows the programmer to propagate history to the output cube (default is true)
Definition: Process.cpp:737
Isis::RingPlaneProjection::MaximumRingLongitude
double MaximumRingLongitude() const
This returns the maximum ring longitude of the area of interest.
Definition: RingPlaneProjection.cpp:438
Isis::TProjection
Base class for Map TProjections.
Definition: TProjection.h:166
Isis::RingPlaneProjection::MinimumRingLongitude
double MinimumRingLongitude() const
This returns the minimum ring longitude of the area of interest.
Definition: RingPlaneProjection.cpp:427
Isis::Progress::SetText
void SetText(const QString &text)
Changes the value of the text string reported just before 0% processed.
Definition: Progress.cpp:61
Isis::Cube::addCachingAlgorithm
void addCachingAlgorithm(CubeCachingAlgorithm *)
This will add the given caching algorithm to the list of attempted caching algorithms.
Definition: Cube.cpp:1922
Isis::Projection::ToWorldY
double ToWorldY(const double projectionY) const
This method converts a projection y value to a world y value.
Definition: Projection.cpp:594
Isis::Cube::sampleCount
int sampleCount() const
Definition: Cube.cpp:1807
Isis::Projection::WorldX
virtual double WorldX() const
This returns the world X coordinate provided SetGround, SetCoordinate, SetUniversalGround,...
Definition: Projection.cpp:524
Isis::Process::PropagateLabels
void PropagateLabels(const bool prop)
This method allows the programmer to turn on/off the propagation of labels from the 1st input cube to...
Definition: Process.cpp:639
Isis::Process::Progress
Isis::Progress * Progress()
This method returns a pointer to a Progress object.
Definition: Process.h:259
Isis::Cube
IO Handler for Isis Cubes.
Definition: Cube.h:167
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::Cube::bandCount
virtual int bandCount() const
Returns the number of virtual bands for the cube.
Definition: Cube.cpp:1410
Isis::Progress
Program progress reporter.
Definition: Progress.h:42
Isis::Null
const double Null
Value for an Isis Null pixel.
Definition: SpecialPixel.h:95
Isis::TProjection::MaximumLongitude
virtual double MaximumLongitude() const
This returns the maximum longitude of the area of interest.
Definition: TProjection.cpp:743
Isis::ProjectionFactory::CreateFromCube
static Isis::Projection * CreateFromCube(Isis::Cube &cube)
This method is a helper method.
Definition: ProjectionFactory.cpp:1069
Isis::PvlObject::addGroup
void addGroup(const Isis::PvlGroup &group)
Add a group to the object.
Definition: PvlObject.h:186
Isis::ProjectionFactory::RingsCreateForCube
static Isis::Projection * RingsCreateForCube(Isis::Pvl &label, int &samples, int &lines, bool sizeMatch)
This method creates a projection for a cube to a ring plane given a label.
Definition: ProjectionFactory.cpp:432
Isis::PvlContainer::deleteKeyword
void deleteKeyword(const QString &name)
Remove a specified keyword.
Definition: PvlContainer.cpp:97
std
Namespace for the standard library.
Isis::Projection::ToWorldX
double ToWorldX(const double projectionX) const
This method converts a projection x value to a world x value.
Definition: Projection.cpp:566
Isis::ProcessByLine::StartProcess
void StartProcess(void funct(Isis::Buffer &inout))
This method invokes the process by line operation over a single input or output cube.
Definition: ProcessByLine.cpp:130
Isis::Cube::label
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
Definition: Cube.cpp:1701
Isis::Projection::ToProjectionX
double ToProjectionX(const double worldX) const
This method converts a world x value to a projection x value.
Definition: Projection.cpp:622
Isis::CubeAttributeInput
Manipulate and parse attributes of input cube filenames.
Definition: CubeAttribute.h:381
Isis::UniqueIOCachingAlgorithm
This algorithm is designed for applications that jump around between a couple of spots in the cube wi...
Definition: UniqueIOCachingAlgorithm.h:30
Isis::Buffer::size
int size() const
Returns the total number of pixels in the shape buffer.
Definition: Buffer.h:97
Isis::TProjection::MinimumLatitude
virtual double MinimumLatitude() const
This returns the minimum latitude of the area of interest.
Definition: TProjection.cpp:710
Isis::Projection
Base class for Map Projections.
Definition: Projection.h:155
Isis::Cube::open
void open(const QString &cfile, QString access="r")
This method will open an isis cube for reading or reading/writing.
Definition: Cube.cpp:627
Isis::ProcessByBrick::EndProcess
void EndProcess()
End the processing sequence and cleans up by closing cubes, freeing memory, etc.
Definition: ProcessByBrick.cpp:669
Isis::FileList
Internalizes a list of files.
Definition: FileList.h:54
Isis::ProcessByLine::SetInputCube
Isis::Cube * SetInputCube(const QString &parameter, const int requirements=0)
Opens an input cube specified by the user and verifies requirements are met.
Definition: ProcessByLine.cpp:41
Isis::Cube::projection
Projection * projection()
Definition: Cube.cpp:1794
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/13/2023 15:17:04