|
Isis 3.0 Application Source Code Reference |
Home |
00001 #include "Isis.h" 00002 #include "PvlObject.h" 00003 #include "PvlGroup.h" 00004 #include "UserInterface.h" 00005 #include "iException.h" 00006 00007 using namespace std; 00008 using namespace Isis; 00009 00010 void IsisMain() { 00011 // Get user interface 00012 UserInterface &ui = Application::GetUserInterface(); 00013 00014 Pvl algos("$ISISROOT/lib/AutoReg.plugin"); 00015 Pvl p; 00016 string algoName = ui.GetString("ALGORITHM"); 00017 00018 // Give the user a list of possible algorithms if the algoName="Unknown" 00019 if (algoName == "Unknown") { 00020 string msg = "Unknown Algorithm Name [" + algoName + "] " + 00021 "Possible Algorithms are: "; 00022 for (int i=0; i<algos.Groups(); i++) { 00023 msg += algos.Group(i).Name(); 00024 if (i<algos.Groups()-1) msg += ", "; 00025 } 00026 throw Isis::iException::Message(Isis::iException::User,msg,_FILEINFO_); 00027 } 00028 00029 // Everything seems to be okay, continue creating the mapping group 00030 else { 00031 PvlObject autoreg("AutoRegistration"); 00032 00033 // Make sure the entered algorithm name is valid 00034 if (!algos.HasGroup(algoName)) { 00035 string msg = "Invalid Algorithm Name [" + algoName + "]"; 00036 throw Isis::iException::Message(Isis::iException::User,msg,_FILEINFO_); 00037 } 00038 00039 // Make algorithm group 00040 PvlGroup algorithm("Algorithm"); 00041 algorithm += PvlKeyword("Name",algoName); 00042 00043 // Set the tolerance 00044 if (ui.WasEntered("TOLERANCE")) { 00045 double tol = ui.GetDouble("TOLERANCE"); 00046 algorithm += PvlKeyword("Tolerance",iString(tol)); 00047 } 00048 00049 // Set the sampling if the user entered it 00050 if (ui.WasEntered("SAMPLING")) { 00051 algorithm += PvlKeyword("Sampling",iString(ui.GetInteger("SAMPLING")), 00052 "percent"); 00053 } 00054 00055 if (ui.GetBoolean("SUBPIXELACCURACY")) algorithm += PvlKeyword("SubpixelAccuracy","True"); 00056 else algorithm += PvlKeyword("SubpixelAccuracy","False"); 00057 00058 00059 00060 // Add algorithm group to the autoreg object 00061 autoreg.AddGroup(algorithm); 00062 00063 // Get pattern and search chip size values for error testing 00064 int psamp = ui.GetInteger("PSAMP"); 00065 int pline = ui.GetInteger("PLINE"); 00066 int ssamp = ui.GetInteger("SSAMP"); 00067 int sline = ui.GetInteger("SLINE"); 00068 00069 // Make sure the pattern chip is not just one pixel 00070 if (psamp + pline < 3) { 00071 string msg = "The Pattern Chip must be larger than one pixel for the "; 00072 msg += "autoregistration to work properly"; 00073 throw Isis::iException::Message(Isis::iException::User,msg,_FILEINFO_); 00074 } 00075 // Make sure the pattern chip is smaller than the search chip 00076 if (ssamp < psamp || sline < pline) { 00077 string msg = "The Pattern Chip must be smaller than the Search Chip"; 00078 throw Isis::iException::Message(Isis::iException::User,msg,_FILEINFO_); 00079 } 00080 // Make sure the pattern chip spans at least a 3x3 window in the search chip 00081 if (psamp +2 > ssamp || pline + 2 > sline) { 00082 string msg = "The Pattern Chip must span at least a 3x3 window in the "; 00083 msg += "Search Chip"; 00084 throw Isis::iException::Message(Isis::iException::User,msg,_FILEINFO_); 00085 } 00086 00087 // Set up the pattern chip group 00088 PvlGroup patternChip("PatternChip"); 00089 patternChip += PvlKeyword("Samples",iString(psamp)); 00090 patternChip += PvlKeyword("Lines",iString(pline)); 00091 if (ui.WasEntered("PMIN")) { 00092 patternChip += PvlKeyword("ValidMinimum",iString(ui.GetInteger("PMIN"))); 00093 } 00094 if (ui.WasEntered("PMAX")) { 00095 patternChip += PvlKeyword("ValidMaximum",iString(ui.GetInteger("PMAX"))); 00096 } 00097 if (ui.WasEntered("PPERCENT")) { 00098 patternChip += PvlKeyword("ValidPercent",iString(ui.GetInteger("PPERCENT"))); 00099 } 00100 if (ui.WasEntered("MINIMUMPATTERNZSCORE")) { 00101 double minsd = ui.GetDouble("MINIMUMPATTERNZSCORE"); 00102 patternChip += PvlKeyword("MinimumZScore",iString(minsd)); 00103 } 00104 00105 // Set up the search chip group 00106 PvlGroup searchChip("SearchChip"); 00107 searchChip += PvlKeyword("Samples",iString(ssamp)); 00108 searchChip += PvlKeyword("Lines",iString(sline)); 00109 if (ui.WasEntered("SMIN")) { 00110 searchChip += PvlKeyword("ValidMinimum",iString(ui.GetInteger("SMIN"))); 00111 } 00112 if (ui.WasEntered("SMAX")) { 00113 searchChip += PvlKeyword("ValidMaximum",iString(ui.GetInteger("SMAX"))); 00114 } 00115 if (ui.WasEntered("SPERCENT")) { 00116 searchChip += PvlKeyword("ValidPercent",iString(ui.GetInteger("SPERCENT"))); 00117 } 00118 int sinc = ui.GetInteger("SINC"); 00119 int linc = ui.GetInteger("LINC"); 00120 if (sinc != 1 || linc !=1) { 00121 string den = "(" + iString(sinc) + "," + iString(linc) + ")"; 00122 searchChip += PvlKeyword("Density",den); 00123 } 00124 00125 // Add groups to the autoreg object 00126 autoreg.AddGroup(patternChip); 00127 autoreg.AddGroup(searchChip); 00128 00129 // Add autoreg group to Pvl 00130 p.AddObject(autoreg); 00131 } 00132 00133 // Write the autoreg group pvl to the output file 00134 string output = ui.GetFilename("TO"); 00135 p.Write(output); 00136 }