void IsisMain() { UserInterface &ui = Application::GetUserInterface(); Cube cube; cube.open(ui.GetFileName("FROM"), "rw"); // Make sure cube has been run through spiceinit try { cube.camera(); } catch(IException &e) { string msg = "Spiceinit must be run before initializing the polygon"; throw IException(e, IException::User, msg, _FILEINFO_); } Progress prog; prog.SetMaximumSteps(1); prog.CheckStatus(); QString sn = SerialNumber::Compose(cube); ImagePolygon poly; if(ui.WasEntered("MAXEMISSION")) { poly.Emission(ui.GetDouble("MAXEMISSION")); } if(ui.WasEntered("MAXINCIDENCE")) { poly.Incidence(ui.GetDouble("MAXINCIDENCE")); } if(ui.GetString("LIMBTEST") == "ELLIPSOID") { poly.EllipsoidLimb(true); } int sinc = 1; int linc = 1; IString incType = ui.GetString("INCTYPE"); if(incType.UpCase() == "VERTICES") { poly.initCube(cube); sinc = linc = (int)(0.5 + (((poly.validSampleDim() * 2) + (poly.validLineDim() * 2) - 3.0) / ui.GetInteger("NUMVERTICES"))); if (sinc < 1.0 || linc < 1.0) sinc = linc = 1.0; } else if (incType.UpCase() == "LINCSINC"){ sinc = ui.GetInteger("SINC"); linc = ui.GetInteger("LINC"); } else { string msg = "Invalid INCTYPE option[" + incType + "]"; throw IException(IException::Programmer, msg, _FILEINFO_); } bool precision = ui.GetBoolean("INCREASEPRECISION"); try { poly.Create(cube, sinc, linc, 1, 1, 0, 0, 1, precision); } catch (IException &e) { QString msg = "Cannot generate polygon for [" + ui.GetFileName("FROM") + "]"; throw IException(e, IException::User, msg, _FILEINFO_); } if(ui.GetBoolean("TESTXY")) { Pvl cubeLab(ui.GetFileName("FROM")); PvlGroup inst = cubeLab.findGroup("Instrument", Pvl::Traverse); QString target = inst["TargetName"]; PvlGroup radii = Projection::TargetRadii(target); Pvl map(ui.GetFileName("MAP")); PvlGroup &mapping = map.findGroup("MAPPING"); if(!mapping.hasKeyword("TargetName")) mapping += Isis::PvlKeyword("TargetName", target); if(!mapping.hasKeyword("EquatorialRadius")) mapping += Isis::PvlKeyword("EquatorialRadius", (QString)radii["EquatorialRadius"]); if(!mapping.hasKeyword("PolarRadius")) mapping += Isis::PvlKeyword("PolarRadius", (QString)radii["PolarRadius"]); if(!mapping.hasKeyword("LatitudeType")) mapping += Isis::PvlKeyword("LatitudeType", "Planetocentric"); if(!mapping.hasKeyword("LongitudeDirection")) mapping += Isis::PvlKeyword("LongitudeDirection", "PositiveEast"); if(!mapping.hasKeyword("LongitudeDomain")) mapping += Isis::PvlKeyword("LongitudeDomain", "360"); if(!mapping.hasKeyword("CenterLatitude")) mapping += Isis::PvlKeyword("CenterLatitude", "0"); if(!mapping.hasKeyword("CenterLongitude")) mapping += Isis::PvlKeyword("CenterLongitude", "0"); sinc = poly.getSinc(); linc = poly.getLinc(); bool polygonGenerated = false; while (!polygonGenerated) { Projection *proj = NULL; geos::geom::MultiPolygon *xyPoly = NULL; try { proj = ProjectionFactory::Create(map, true); xyPoly = PolygonTools::LatLonToXY(*poly.Polys(), proj); polygonGenerated = true; } catch (IException &e) { if (precision && sinc > 1 && linc > 1) { sinc = sinc * 2 / 3; linc = linc * 2 / 3; poly.Create(cube, sinc, linc); } else { delete proj; delete xyPoly; e.print(); // This should be a NAIF error QString msg = "Cannot calculate XY for ["; msg += ui.GetFileName("FROM") + "]"; throw IException(e, IException::User, msg, _FILEINFO_); } } delete proj; delete xyPoly; } } cube.deleteBlob("Polygon", sn); cube.write(poly); if(precision) { PvlGroup results("Results"); results.addKeyword(PvlKeyword("SINC", toString(sinc))); results.addKeyword(PvlKeyword("LINC", toString(linc))); Application::Log(results); } Process p; p.SetInputCube("FROM"); p.WriteHistory(cube); cube.close(); prog.CheckStatus(); }
int main () { Isis::Preference::Preferences(true); /** * @brief Test ImagePolygon object for accuracy and correct behavior. * * @author 2005-11-22 Tracie Sucharski * * @history 2007-01-19 Tracie Sucharski, Removed ToGround method (for now) * because of round off problems going back and forth between * lat/lon,line/samp. * @history 2007-01-31 Tracie Sucharski, Added WKT method to return polygon * in string as WKT. * @history 2007-11-09 Tracie Sucharski, Remove WKT method, geos now has * a method to return a WKT string. * @history 2007-11-20 Tracie Sucharski, Added test for sub-polys */ // simple MOC image string inFile = "/usgs/cpkgs/isis3/data/mgs/testData/ab102401.cub"; //string inFile = "/work1/tsucharski/poly/I17621017RDR_lev2.cub"; // same MOC image, but sinusoidal projection //string inFile = "/farm/prog1/tsucharski/isis3/ab102401.lev2.cub"; // same MOC image, but sinusoidal projection , doctored left edge //string inFile = "/farm/prog1/tsucharski/isis3/ab102401.lev2.leftTrim.cub"; // MOC north pole image //string inFile = "/work1/tsucharski/isis3/poly/e0202226.lev1.cub"; // MOC image with 0/360 boundary // orkin //string inFile = "/farm/prog1/tsucharski/isis3/cubes/m0101631.lev1.cub"; // blackflag //string inFile = "/work1/tsucharski/isis3/poly/m0101631.lev1.cub"; // galileo ssi image //string inFile = "/farm/prog1/tsucharski/isis3/6700r.cub"; // Open the cube Cube cube; Cube cube1; cube.Open(inFile,"r"); ImagePolygon poly; try { poly.Create(cube); } catch (iException &e) { std::string msg = "Cannot create polygon for [" + cube.Filename() + "]"; throw iException::Message(iException::Programmer,msg,_FILEINFO_); } // write poly as WKT std::cout<< poly.Polys()->toString()<<std::endl; // Test sub-poly option try { poly.Create(cube,12,1,384,640,385); } catch (iException &e) { std::string msg = "Cannot create sub-polygon for [" + cube.Filename() + "]"; throw iException::Message(iException::Programmer,msg,_FILEINFO_); } // write poly as WKT std::cout<< poly.Polys()->toString()<<std::endl; // Test lower quality option try { poly.Create(cube,10,12,1,384,640,385); } catch (iException &e) { std::string msg = "Cannot create lower quality polygon for [" + cube.Filename() + "]"; throw iException::Message(iException::Programmer,msg,_FILEINFO_); } // write poly as WKT std::cout<< poly.Polys()->toString()<<std::endl; cube.Close(); }