USGS

Isis 3.0 Object Programmers' Reference

Home

CameraPointInfo.cpp
Go to the documentation of this file.
00001 
00023 #include "CameraPointInfo.h"
00024 
00025 #include "Brick.h"
00026 #include "Camera.h"
00027 #include "CubeManager.h"
00028 #include "Distance.h"
00029 #include "IException.h"
00030 #include "iTime.h"
00031 #include "Longitude.h"
00032 #include "Projection.h"
00033 #include "PvlGroup.h"
00034 
00035 using namespace std;
00036 
00037 namespace Isis {
00038 
00039 
00045   CameraPointInfo::CameraPointInfo() {
00046     usedCubes = NULL;
00047     usedCubes = new CubeManager();
00048     usedCubes->SetNumOpenCubes(50);
00049     currentCube = NULL;
00050     camera = NULL;
00051   }
00052 
00057   CameraPointInfo::~CameraPointInfo() {
00058     if(usedCubes) {
00059       delete usedCubes;
00060       usedCubes = NULL;
00061     }
00062   }
00063 
00064 
00072   void CameraPointInfo::SetCube(const QString &cubeFileName) {
00073     currentCube = usedCubes->OpenCube(cubeFileName);
00074     camera = currentCube->camera();
00075   }
00076 
00077 
00088   PvlGroup *CameraPointInfo::SetImage(const double sample, const double line,
00089                                       const bool outside, const bool errors) {
00090     if(CheckCube()) {
00091       bool passed = camera->SetImage(sample, line);
00092       return GetPointInfo(passed, outside, errors);
00093     }
00094     // Should never get here, error will be thrown in CheckCube()
00095     return NULL;
00096   }
00097 
00104   PvlGroup *CameraPointInfo::SetCenter(const bool outside, const bool errors) {
00105     if(CheckCube()) {
00106       bool passed = camera->SetImage(currentCube->sampleCount() / 2.0, currentCube->lineCount() / 2.0);
00107       return GetPointInfo(passed, outside, errors);
00108     }
00109     // Should never get here, error will be thrown in CheckCube()
00110     return NULL;
00111   }
00112 
00113 
00121   PvlGroup *CameraPointInfo::SetSample(const double sample,
00122                                        const bool outside, const bool errors) {
00123     if(CheckCube()) {
00124       bool passed = camera->SetImage(sample, currentCube->lineCount() / 2.0);
00125       return GetPointInfo(passed, outside, errors);
00126     }
00127     // Should never get here, error will be thrown in CheckCube()
00128     return NULL;
00129   }
00130 
00131 
00139   PvlGroup *CameraPointInfo::SetLine(const double line,
00140                                      const bool outside, const bool errors) {
00141     if(CheckCube()) {
00142       bool passed = camera->SetImage(currentCube->sampleCount() / 2.0, line);
00143       return GetPointInfo(passed, outside, errors);
00144     }
00145     // Should never get here, error will be thrown in CheckCube()
00146     return NULL;
00147   }
00148 
00149 
00162   PvlGroup *CameraPointInfo::SetGround(const double latitude, const double longitude,
00163                                        const bool outside, const bool errors) {
00164     if(CheckCube()) {
00165       bool passed = camera->SetUniversalGround(latitude, longitude);
00166       return GetPointInfo(passed, outside, errors);
00167     }
00168     // Should never get here, error will be thrown in CheckCube()
00169     return NULL;
00170   }
00171 
00172 
00179   bool CameraPointInfo::CheckCube() {
00180     if(currentCube == NULL) {
00181       string msg = "Please set a cube before setting parameters";
00182       throw IException(IException::Programmer, msg, _FILEINFO_);
00183       return false;
00184     }
00185     return true;
00186   }
00187 
00195   PvlGroup *CameraPointInfo::GetPointInfo(bool passed, bool allowOutside, bool allowErrors) {
00196     PvlGroup *gp = new PvlGroup("GroundPoint");
00197     {
00198       gp->AddKeyword(PvlKeyword("Filename"));
00199       gp->AddKeyword(PvlKeyword("Sample"));
00200       gp->AddKeyword(PvlKeyword("Line"));
00201       gp->AddKeyword(PvlKeyword("PixelValue"));
00202       gp->AddKeyword(PvlKeyword("RightAscension"));
00203       gp->AddKeyword(PvlKeyword("Declination"));
00204       gp->AddKeyword(PvlKeyword("PlanetocentricLatitude"));
00205       gp->AddKeyword(PvlKeyword("PlanetographicLatitude"));
00206       gp->AddKeyword(PvlKeyword("PositiveEast360Longitude"));
00207       gp->AddKeyword(PvlKeyword("PositiveEast180Longitude"));
00208       gp->AddKeyword(PvlKeyword("PositiveWest360Longitude"));
00209       gp->AddKeyword(PvlKeyword("PositiveWest180Longitude"));
00210       gp->AddKeyword(PvlKeyword("BodyFixedCoordinate"));
00211       gp->AddKeyword(PvlKeyword("LocalRadius"));
00212       gp->AddKeyword(PvlKeyword("SampleResolution"));
00213       gp->AddKeyword(PvlKeyword("LineResolution"));
00214       gp->AddKeyword(PvlKeyword("SpacecraftPosition"));
00215       gp->AddKeyword(PvlKeyword("SpacecraftAzimuth"));
00216       gp->AddKeyword(PvlKeyword("SlantDistance"));
00217       gp->AddKeyword(PvlKeyword("TargetCenterDistance"));
00218       gp->AddKeyword(PvlKeyword("SubSpacecraftLatitude"));
00219       gp->AddKeyword(PvlKeyword("SubSpacecraftLongitude"));
00220       gp->AddKeyword(PvlKeyword("SpacecraftAltitude"));
00221       gp->AddKeyword(PvlKeyword("OffNadirAngle"));
00222       gp->AddKeyword(PvlKeyword("SubSpacecraftGroundAzimuth"));
00223       gp->AddKeyword(PvlKeyword("SunPosition"));
00224       gp->AddKeyword(PvlKeyword("SubSolarAzimuth"));
00225       gp->AddKeyword(PvlKeyword("SolarDistance"));
00226       gp->AddKeyword(PvlKeyword("SubSolarLatitude"));
00227       gp->AddKeyword(PvlKeyword("SubSolarLongitude"));
00228       gp->AddKeyword(PvlKeyword("SubSolarGroundAzimuth"));
00229       gp->AddKeyword(PvlKeyword("Phase"));
00230       gp->AddKeyword(PvlKeyword("Incidence"));
00231       gp->AddKeyword(PvlKeyword("Emission"));
00232       gp->AddKeyword(PvlKeyword("NorthAzimuth"));
00233       gp->AddKeyword(PvlKeyword("EphemerisTime"));
00234       gp->AddKeyword(PvlKeyword("UTC"));
00235       gp->AddKeyword(PvlKeyword("LocalSolarTime"));
00236       gp->AddKeyword(PvlKeyword("SolarLongitude"));
00237       if(allowErrors) gp->AddKeyword(PvlKeyword("Error"));
00238     }
00239 
00240     bool noErrors = passed;
00241     QString error = "";
00242     if(!camera->HasSurfaceIntersection()) {
00243       error = "Requested position does not project in camera model; no surface intersection";
00244       noErrors = false;
00245       if(!allowErrors) throw IException(IException::Unknown, error, _FILEINFO_);
00246     }
00247     if(!camera->InCube() && !allowOutside) {
00248       error = "Requested position does not project in camera model; not inside cube";
00249       noErrors = false;
00250       if(!allowErrors) throw IException(IException::Unknown, error, _FILEINFO_);
00251     }
00252 
00253     if(!noErrors) {
00254       for(int i = 0; i < gp->Keywords(); i++) {
00255         QString name = (*gp)[i].Name();
00256         // These three keywords have 3 values, so they must have 3 N/As
00257         if(name == "BodyFixedCoordinate" || name == "SpacecraftPosition" ||
00258             name == "SunPosition") {
00259           (*gp)[i].AddValue("N/A");
00260           (*gp)[i].AddValue("N/A");
00261           (*gp)[i].AddValue("N/A");
00262         }
00263         else {
00264           (*gp)[i].SetValue("N/A");
00265         }
00266       }
00267       // Set all keywords that still have valid information
00268       gp->FindKeyword("Error").SetValue(error);
00269       gp->FindKeyword("FileName").SetValue(currentCube->fileName());
00270       gp->FindKeyword("Sample").SetValue(toString(camera->Sample()));
00271       gp->FindKeyword("Line").SetValue(toString(camera->Line()));
00272       gp->FindKeyword("EphemerisTime").SetValue(toString(camera->time().Et()), "seconds");
00273       gp->FindKeyword("EphemerisTime").AddComment("Time");
00274       QString utc = camera->time().UTC();
00275       gp->FindKeyword("UTC").SetValue(utc);
00276       gp->FindKeyword("SpacecraftPosition").AddComment("Spacecraft Information");
00277       gp->FindKeyword("SunPosition").AddComment("Sun Information");
00278       gp->FindKeyword("Phase").AddComment("Illumination and Other");
00279     }
00280 
00281     else {
00282 
00283       Brick b(3, 3, 1, currentCube->pixelType());
00284 
00285       int intSamp = (int)(camera->Sample() + 0.5);
00286       int intLine = (int)(camera->Line() + 0.5);
00287       b.SetBasePosition(intSamp, intLine, 1);
00288       currentCube->read(b);
00289 
00290       double pB[3], spB[3], sB[3];
00291       QString utc;
00292       double ssplat, ssplon, sslat, sslon, pwlon, oglat;
00293 
00294       {
00295         gp->FindKeyword("FileName").SetValue(currentCube->fileName());
00296         gp->FindKeyword("Sample").SetValue(toString(camera->Sample()));
00297         gp->FindKeyword("Line").SetValue(toString(camera->Line()));
00298         gp->FindKeyword("PixelValue").SetValue(PixelToString(b[0]));
00299         gp->FindKeyword("RightAscension").SetValue(toString(camera->RightAscension()));
00300         gp->FindKeyword("Declination").SetValue(toString(camera->Declination()));
00301         gp->FindKeyword("PlanetocentricLatitude").SetValue(toString(camera->UniversalLatitude()));
00302 
00303         // Convert lat to planetographic
00304         Distance radii[3];
00305         camera->radii(radii);
00306         oglat = Isis::Projection::ToPlanetographic(camera->UniversalLatitude(),
00307                 radii[0].kilometers(), radii[2].kilometers());
00308         gp->FindKeyword("PlanetographicLatitude").SetValue(toString(oglat));
00309 
00310         gp->FindKeyword("PositiveEast360Longitude").SetValue(toString(
00311           camera->UniversalLongitude()));
00312 
00313         //Convert lon to -180 - 180 range
00314         gp->FindKeyword("PositiveEast180Longitude").SetValue(toString(
00315           Isis::Projection::To180Domain(
00316             camera->UniversalLongitude())));
00317 
00318         //Convert lon to positive west
00319         pwlon = Isis::Projection::ToPositiveWest(camera->UniversalLongitude(),
00320                 360);
00321         gp->FindKeyword("PositiveWest360Longitude").SetValue(toString(pwlon));
00322 
00323         //Convert pwlon to -180 - 180 range
00324         gp->FindKeyword("PositiveWest180Longitude").SetValue(toString(
00325           Isis::Projection::To180Domain(pwlon)));
00326 
00327         camera->Coordinate(pB);
00328         gp->FindKeyword("BodyFixedCoordinate").AddValue(toString(pB[0]), "km");
00329         gp->FindKeyword("BodyFixedCoordinate").AddValue(toString(pB[1]), "km");
00330         gp->FindKeyword("BodyFixedCoordinate").AddValue(toString(pB[2]), "km");
00331 
00332         gp->FindKeyword("LocalRadius").SetValue(toString(camera->LocalRadius().meters()), "meters");
00333         gp->FindKeyword("SampleResolution").SetValue(toString(camera->SampleResolution()), "meters/pixel");
00334         gp->FindKeyword("LineResolution").SetValue(toString(camera->LineResolution()), "meters/pixel");
00335 
00336         camera->instrumentPosition(spB);
00337         gp->FindKeyword("SpacecraftPosition").AddValue(toString(spB[0]), "km");
00338         gp->FindKeyword("SpacecraftPosition").AddValue(toString(spB[1]), "km");
00339         gp->FindKeyword("SpacecraftPosition").AddValue(toString(spB[2]), "km");
00340         gp->FindKeyword("SpacecraftPosition").AddComment("Spacecraft Information");
00341 
00342         gp->FindKeyword("SpacecraftAzimuth").SetValue(toString(camera->SpacecraftAzimuth()));
00343         gp->FindKeyword("SlantDistance").SetValue(toString(camera->SlantDistance()), "km");
00344         gp->FindKeyword("TargetCenterDistance").SetValue(toString(camera->targetCenterDistance()), "km");
00345         camera->subSpacecraftPoint(ssplat, ssplon);
00346         gp->FindKeyword("SubSpacecraftLatitude").SetValue(toString(ssplat));
00347         gp->FindKeyword("SubSpacecraftLongitude").SetValue(toString(ssplon));
00348         gp->FindKeyword("SpacecraftAltitude").SetValue(toString(camera->SpacecraftAltitude()), "km");
00349         gp->FindKeyword("OffNadirAngle").SetValue(toString(camera->OffNadirAngle()));
00350         double subspcgrdaz;
00351         subspcgrdaz = camera->GroundAzimuth(camera->UniversalLatitude(), camera->UniversalLongitude(),
00352                                             ssplat, ssplon);
00353         gp->FindKeyword("SubSpacecraftGroundAzimuth").SetValue(toString(subspcgrdaz));
00354 
00355         camera->sunPosition(sB);
00356         gp->FindKeyword("SunPosition").AddValue(toString(sB[0]), "km");
00357         gp->FindKeyword("SunPosition").AddValue(toString(sB[1]), "km");
00358         gp->FindKeyword("SunPosition").AddValue(toString(sB[2]), "km");
00359         gp->FindKeyword("SunPosition").AddComment("Sun Information");
00360 
00361         gp->FindKeyword("SubSolarAzimuth").SetValue(toString(camera->SunAzimuth()));
00362         gp->FindKeyword("SolarDistance").SetValue(toString(camera->SolarDistance()), "AU");
00363         camera->subSolarPoint(sslat, sslon);
00364         gp->FindKeyword("SubSolarLatitude").SetValue(toString(sslat));
00365         gp->FindKeyword("SubSolarLongitude").SetValue(toString(sslon));
00366         double subsolgrdaz;
00367         subsolgrdaz = camera->GroundAzimuth(camera->UniversalLatitude(), camera->UniversalLongitude(),
00368                                             sslat, sslon);
00369         gp->FindKeyword("SubSolarGroundAzimuth").SetValue(toString(subsolgrdaz));
00370 
00371         gp->FindKeyword("Phase").SetValue(toString(camera->PhaseAngle()));
00372         gp->FindKeyword("Phase").AddComment("Illumination and Other");
00373         gp->FindKeyword("Incidence").SetValue(toString(camera->IncidenceAngle()));
00374         gp->FindKeyword("Emission").SetValue(toString(camera->EmissionAngle()));
00375         gp->FindKeyword("NorthAzimuth").SetValue(toString(camera->NorthAzimuth()));
00376 
00377         gp->FindKeyword("EphemerisTime").SetValue(toString(camera->time().Et()), "seconds");
00378         gp->FindKeyword("EphemerisTime").AddComment("Time");
00379         utc = camera->time().UTC();
00380         gp->FindKeyword("UTC").SetValue(utc);
00381         gp->FindKeyword("LocalSolarTime").SetValue(toString(camera->LocalSolarTime()), "hour");
00382         gp->FindKeyword("SolarLongitude").SetValue(toString(camera->solarLongitude().degrees()));
00383         if(allowErrors) gp->FindKeyword("Error").SetValue("N/A");
00384       }
00385     }
00386     return gp;
00387   }
00388 }