USGS

Isis 3.0 Application Source Code Reference

Home

automos.cpp

Go to the documentation of this file.
00001 #define GUIHELPERS
00002 
00003 #include "Isis.h"
00004 #include "ProcessMapMosaic.h"
00005 #include "ProcessByLine.h"
00006 #include "FileList.h"
00007 #include "iException.h"
00008 #include "SpecialPixel.h"
00009 #include "ProjectionFactory.h"
00010 
00011 using namespace std; 
00012 using namespace Isis;
00013 
00014 void calcRange(double &minLat, double &maxLat,
00015                double &minLon, double &maxLon);
00016 void helperButtonCalcRange ();
00017 
00018 map <string,void*> GuiHelpers(){
00019   map <string,void*> helper;
00020   helper ["helperButtonCalcRange"] = (void*) helperButtonCalcRange;
00021   return helper;
00022 }
00023 void IsisMain() {
00024   // Get the list of cubes to mosaic
00025   Process p;
00026   FileList list;
00027   UserInterface &ui = Application::GetUserInterface();
00028   list.Read(ui.GetFilename("FROMLIST"));
00029   if (list.size() < 1) {
00030     string msg = "The list file [" + ui.GetFilename("FROMLIST") +
00031                  "does not contain any data";
00032     throw iException::Message(iException::User,msg,_FILEINFO_);
00033   }
00034 
00035   ProcessMapMosaic m;
00036   CubeAttributeOutput &oAtt = ui.GetOutputAttribute("MOSAIC");
00037   if (ui.GetString("GRANGE") == "USER") {
00038     m.SetOutputCube(list, 
00039                     ui.GetDouble("MINLAT"), ui.GetDouble("MAXLAT"),
00040                     ui.GetDouble("MINLON"), ui.GetDouble("MAXLON"),
00041                     oAtt, ui.GetFilename("MOSAIC"));
00042   }
00043   else {
00044     m.SetOutputCube(list, oAtt, ui.GetFilename("MOSAIC"));
00045   }
00046 
00047   // Set up the mosaic priority, either the input cubes will be
00048   // placed ontop of each other in the mosaic or beneath each other
00049   ui = Application::GetUserInterface();
00050   MosaicPriority priority;
00051   if (ui.GetString("PRIORITY") == "BENEATH") {
00052     priority = mosaic;
00053   }
00054   else {
00055     priority = input;
00056   }
00057 
00058   // Loop for each input file and place it in the output mosaic
00059   PvlGroup outsiders("Outside");
00060   m.SetBandBinMatch(ui.GetBoolean("MATCHBANDBIN"));
00061 
00062   CubeAttributeInput inAtt;
00063 
00064   for (unsigned int i=0; i<list.size(); i++) {
00065     if(!m.StartProcess(list[i], priority)) {
00066       outsiders += PvlKeyword("File", list[i]); 
00067     }
00068   }
00069 
00070   m.EndProcess();
00071   Application::Log(outsiders); 
00072 }
00073 
00074 // Function to calculate the ground range from multiple inputs (list of images)
00075 void calcRange(double &minLat, double &maxLat, 
00076                double &minLon, double &maxLon) {
00077   UserInterface &ui = Application::GetUserInterface();
00078   FileList list(ui.GetFilename("FROMLIST"));
00079   minLat = DBL_MAX;
00080   maxLat = -DBL_MAX;
00081   minLon = DBL_MAX;
00082   maxLon = -DBL_MAX;
00083   // We will loop through each input cube and do some 
00084   // computations needed for mosaicking
00085   int nbands = 0;
00086   Projection *firstProj = NULL;
00087 
00088   for (unsigned int i=0; i<list.size(); i++) {
00089     // Open the cube and get the maximum number of band in all cubes
00090     Cube cube;
00091     cube.Open(list[i]);
00092     if (cube.Bands() > nbands) nbands = cube.Bands();
00093 
00094     // See if the cube has a projection and make sure it matches
00095     // previous input cubes
00096     Projection *proj = Isis::ProjectionFactory::CreateFromCube(*(cube.Label()));
00097     if (firstProj == NULL) {
00098       firstProj = proj;
00099     }
00100     else if (*proj != *firstProj) {
00101       string msg = "Mapping groups do not match between cubes [" + 
00102                    list[0] + "] and [" + list[i] + "]";
00103       throw iException::Message(iException::User,msg,_FILEINFO_);
00104     }
00105 
00106     if (proj->HasGroundRange()) {
00107       if (proj->MinimumLatitude() < minLat) minLat = proj->MinimumLatitude();
00108       if (proj->MaximumLatitude() > maxLat) maxLat = proj->MaximumLatitude();
00109       if (proj->MinimumLongitude() < minLon) minLon = proj->MinimumLongitude();
00110       if (proj->MaximumLongitude() > maxLon) maxLon = proj->MaximumLongitude();
00111     }
00112 
00113     // Cleanup
00114     cube.Close();
00115     if (proj != firstProj) delete proj;
00116   }
00117 }
00118 
00119 //Helper function to run calcRange function.
00120 void helperButtonCalcRange () {
00121   UserInterface &ui = Application::GetUserInterface();
00122   double minLat;
00123   double maxLat;
00124   double minLon;
00125   double maxLon;
00126 
00127   // Run the function calcRange of calculate range info
00128   calcRange(minLat,maxLat,minLon,maxLon);
00129 
00130   // Write ranges to the GUI
00131   string use = "USER";
00132   ui.Clear("GRANGE");
00133   ui.PutAsString("GRANGE",use);
00134   ui.Clear("MINLAT");
00135   ui.PutDouble("MINLAT",minLat);
00136   ui.Clear("MAXLAT");
00137   ui.PutDouble("MAXLAT",maxLat);
00138   ui.Clear("MINLON");
00139   ui.PutDouble("MINLON",minLon);
00140   ui.Clear("MAXLON");
00141   ui.PutDouble("MAXLON",maxLon);
00142 }