// Populate cube label using filname and film code // Code decrypted as specified in film decoder document (July 23, 1971 Revision) // available at ASU Apollo Resources archive void TranslateApolloLabels (IString filename, Cube *opack) { //Instrument group PvlGroup inst("Instrument"); PvlGroup kern("Kernels"); PvlGroup codeGroup("Code"); inst += PvlKeyword("SpacecraftName", apollo->SpacecraftName()); inst += PvlKeyword("InstrumentId", apollo->InstrumentId()); inst += PvlKeyword("TargetName", apollo->TargetName()); if ( !IsValidCode() ){ PvlGroup error("ERROR"); error.addComment("The decrypted code is invalid."); for (int i=0; i<4; i++) { PvlKeyword keyword("Column"+toString(i+1)); for (int j=0; j<32; j++) { keyword += toString((int)code[i][j]); } error.addKeyword(keyword); codeGroup += keyword; } Application::Log(error); } else { codeGroup += PvlKeyword("StartTime", FrameTime()); codeGroup += PvlKeyword("SpacecraftAltitude", toString(Altitude()),"meters"); if (apollo->IsMetric()){ codeGroup += PvlKeyword("ExposureDuration", toString(ShutterInterval()), "milliseconds"); codeGroup += PvlKeyword("ForwardMotionCompensation", FMC()); } for (int i=0; i<4; i++) { PvlKeyword keyword("Column"+toString(i+1)); for (int j=0; j<32; j++) { keyword += toString((int)code[i][j]); } codeGroup += keyword; } } PvlGroup bandBin("BandBin"); // There are no filters on the camera, so the default is clear with id # of 1 // the BandBin group is only included to work with the spiceinit application bandBin += PvlKeyword("FilterName", "CLEAR"); bandBin += PvlKeyword("FilterId", "1"); kern += PvlKeyword("NaifFrameCode", apollo->NaifFrameCode()); // Set up the nominal reseaus group Isis::PvlGroup &dataDir = Isis::Preference::Preferences().findGroup("DataDirectory"); Process p; PvlTranslationTable tTable( (QString)p.MissionData("base", "translations/MissionName2DataDir.trn")); QString missionDir = dataDir[tTable.Translate("MissionName", apollo->SpacecraftName())][0]; Pvl resTemplate(missionDir + "/reseaus/" + apollo->InstrumentId() + "_NOMINAL.pvl"); PvlGroup *reseaus = &resTemplate.findGroup("Reseaus"); // Update reseau locations based on refined code location for (int i=0; i<(reseaus->findKeyword("Type")).size(); i++) { double x = toDouble(reseaus->findKeyword("Sample")[i]) + sampleTranslation + 2278, y = toDouble(reseaus->findKeyword("Line")[i]) + lineTranslation - 20231; if (apollo->IsApollo17()) { x += 50; y += 20; } reseaus->findKeyword("Sample")[i] = toString( cos(rotation)*(x-sampleTranslation) - sin(rotation)*(y-lineTranslation) + sampleTranslation); reseaus->findKeyword("Line")[i] = toString( sin(rotation)*(x-sampleTranslation) + cos(rotation)*(y-lineTranslation) + lineTranslation); } inst += PvlKeyword("StartTime", utcTime); opack->putGroup(inst); opack->putGroup(bandBin); opack->putGroup(kern); opack->putGroup(*reseaus); opack->putGroup(codeGroup); }
void IsisMain() { // Open the input cube Process p; UserInterface &ui = Application::GetUserInterface(); CubeAttributeInput cai; Cube *icube = p.SetInputCube(ui.GetFilename("FROM"), cai, ReadWrite); // Make sure at least one CK & SPK quality was selected if (!ui.GetBoolean("CKPREDICTED") && !ui.GetBoolean("CKRECON") && !ui.GetBoolean("CKSMITHED") && !ui.GetBoolean("CKNADIR")) { string msg = "At least one CK quality must be selected"; throw iException::Message(iException::User,msg,_FILEINFO_); } if (!ui.GetBoolean("SPKPREDICTED") && !ui.GetBoolean("SPKRECON") && !ui.GetBoolean("SPKSMITHED")) { string msg = "At least one SPK quality must be selected"; throw iException::Message(iException::User,msg,_FILEINFO_); } // Make sure it is not projected Projection *proj = NULL; try { proj = icube->Projection(); } catch (iException &e) { proj = NULL; e.Clear(); } if (proj != NULL) { string msg = "Can not initialize SPICE for a map projected cube"; throw iException::Message(iException::User,msg,_FILEINFO_); } Pvl lab = *icube->Label(); // if cube has existing polygon delete it if (icube->Label()->HasObject("Polygon")) { icube->Label()->DeleteObject("Polygon"); } // Set up for getting the mission name // Get the directory where the system missions translation table is. string transFile = p.MissionData("base", "translations/MissionName2DataDir.trn"); // Get the mission translation manager ready PvlTranslationManager missionXlater (lab, transFile); // Get the mission name so we can search the correct DB's for kernels string mission = missionXlater.Translate ("MissionName"); // Get system base kernels unsigned int allowed = 0; unsigned int allowedCK = 0; unsigned int allowedSPK = 0; if (ui.GetBoolean("CKPREDICTED")) allowedCK |= spiceInit::kernelTypeEnum("PREDICTED"); if (ui.GetBoolean("CKRECON")) allowedCK |= spiceInit::kernelTypeEnum("RECONSTRUCTED"); if (ui.GetBoolean("CKSMITHED")) allowedCK |= spiceInit::kernelTypeEnum("SMITHED"); if (ui.GetBoolean("CKNADIR")) allowedCK |= spiceInit::kernelTypeEnum("NADIR"); if (ui.GetBoolean("SPKPREDICTED")) allowedSPK |= spiceInit::kernelTypeEnum("PREDICTED"); if (ui.GetBoolean("SPKRECON")) allowedSPK |= spiceInit::kernelTypeEnum("RECONSTRUCTED"); if (ui.GetBoolean("SPKSMITHED")) allowedSPK |= spiceInit::kernelTypeEnum("SMITHED"); KernelDb baseKernels (allowed); KernelDb ckKernels (allowedCK); KernelDb spkKernels (allowedSPK); baseKernels.LoadSystemDb(mission); ckKernels.LoadSystemDb(mission); spkKernels.LoadSystemDb(mission); Kernel lk, pck, targetSpk, fk, ik, sclk, spk, iak, dem, exk; std::priority_queue< Kernel > ck; lk = baseKernels.LeapSecond(lab); pck = baseKernels.TargetAttitudeShape(lab); targetSpk = baseKernels.TargetPosition(lab); ik = baseKernels.Instrument(lab); sclk = baseKernels.SpacecraftClock(lab); iak = baseKernels.InstrumentAddendum(lab); fk = ckKernels.Frame(lab); ck = ckKernels.SpacecraftPointing(lab); spk = spkKernels.SpacecraftPosition(lab); if (ui.GetBoolean("CKNADIR")) { // Only add nadir if no spacecraft pointing found std::vector<std::string> kernels; kernels.push_back("Nadir"); ck.push(Kernel((spiceInit::kernelTypes)0, kernels)); } // Get user defined kernels and override ones already found GetUserEnteredKernel("LS", lk); GetUserEnteredKernel("PCK", pck); GetUserEnteredKernel("TSPK", targetSpk); GetUserEnteredKernel("FK", fk); GetUserEnteredKernel("IK", ik); GetUserEnteredKernel("SCLK", sclk); GetUserEnteredKernel("SPK", spk); GetUserEnteredKernel("IAK", iak); GetUserEnteredKernel("EXTRA", exk); // Get shape kernel if (ui.GetString ("SHAPE") == "USER") { GetUserEnteredKernel("MODEL", dem); } else if (ui.GetString("SHAPE") == "SYSTEM") { dem = baseKernels.Dem(lab); } bool kernelSuccess = false; if (ck.size() == 0 && !ui.WasEntered("CK")) { throw iException::Message(iException::Camera, "No Camera Kernel found for the image ["+ui.GetFilename("FROM") +"]", _FILEINFO_); } else if(ui.WasEntered("CK")) { // ck needs to be array size 1 and empty kernel objects while(ck.size()) ck.pop(); ck.push(Kernel()); } while(ck.size() != 0 && !kernelSuccess) { Kernel realCkKernel = ck.top(); ck.pop(); if (ui.WasEntered("CK")) { ui.GetAsString("CK", realCkKernel.kernels); } // Merge SpacecraftPointing and Frame into ck for (int i = 0; i < fk.size(); i++) { realCkKernel.push_back(fk[i]); } kernelSuccess = TryKernels(icube, p, lk, pck, targetSpk, realCkKernel, fk, ik, sclk, spk, iak, dem, exk); } if(!kernelSuccess) { throw iException::Message(iException::Camera, "Unable to initialize camera model", _FILEINFO_); } p.EndProcess(); }