diff --git a/isis/src/base/objs/GroundGrid/GroundGrid.cpp b/isis/src/base/objs/GroundGrid/GroundGrid.cpp index 4088741c82..f28546e9e0 100644 --- a/isis/src/base/objs/GroundGrid/GroundGrid.cpp +++ b/isis/src/base/objs/GroundGrid/GroundGrid.cpp @@ -83,7 +83,7 @@ namespace Isis { p_mapping = new PvlGroup; - if (p_groundMap->Camera()) { + if (p_groundMap->currentPriority() == 0) { Pvl tmp; p_groundMap->Camera()->BasicMapping(tmp); *p_mapping = tmp.findGroup("Mapping"); @@ -146,7 +146,7 @@ namespace Isis { // p_defaultResolution is in degrees/pixel - if (p_groundMap->HasCamera()) { + if (p_groundMap->currentPriority() == 0) { p_defaultResolution = (p_groundMap->Camera()->HighestImageResolution() / largerRadius.meters()) * 10; diff --git a/isis/src/base/objs/UniversalGroundMap/UniversalGroundMap.cpp b/isis/src/base/objs/UniversalGroundMap/UniversalGroundMap.cpp index bae21e107d..db3f3215bb 100644 --- a/isis/src/base/objs/UniversalGroundMap/UniversalGroundMap.cpp +++ b/isis/src/base/objs/UniversalGroundMap/UniversalGroundMap.cpp @@ -33,33 +33,33 @@ namespace Isis { UniversalGroundMap::UniversalGroundMap(Cube &cube, CameraPriority priority) { p_camera = NULL; p_projection = NULL; + p_priority = priority; Pvl &pvl = *cube.label(); try { - if(priority == CameraFirst) - p_camera = CameraFactory::Create(cube); - else - p_projection = Isis::ProjectionFactory::CreateFromCube(pvl); + p_camera = CameraFactory::Create(cube); } - catch (IException &firstError) { + catch (IException &e) { + if (p_priority == CameraFirst) { + p_priority = ProjectionFirst; + } p_camera = NULL; - p_projection = NULL; + } - try { - if(priority == CameraFirst) - p_projection = Isis::ProjectionFactory::CreateFromCube(pvl); - else - p_camera = CameraFactory::Create(cube); - } - catch (IException &secondError) { - p_projection = NULL; - QString msg = "Could not create camera or projection for [" + - cube.fileName() + "]"; - IException realError(IException::Unknown, msg, _FILEINFO_); - realError.append(firstError); - realError.append(secondError); - throw realError; + try { + p_projection = Isis::ProjectionFactory::CreateFromCube(pvl); + } + catch (IException &e) { + if (p_priority == ProjectionFirst) { + p_priority = CameraFirst; } + p_projection = NULL; + } + + if (p_camera == NULL && p_projection == NULL) { + QString msg = "Could not create camera or projection for [" + + cube.fileName() + "]"; + IException realError(IException::Unknown, msg, _FILEINFO_); } } @@ -100,7 +100,7 @@ namespace Isis { * false if it was not */ bool UniversalGroundMap::SetUniversalGround(double lat, double lon) { - if (p_camera != NULL) { + if (p_priority == CameraFirst) { if (p_camera->SetUniversalGround(lat, lon)) { // This should work for rings (radius,azimuth) return p_camera->InCube(); } @@ -125,7 +125,7 @@ namespace Isis { * false if it was not */ bool UniversalGroundMap::SetGround(Latitude lat, Longitude lon) { - if(p_camera != NULL) { + if(p_priority == CameraFirst) { if(p_camera->SetGround(lat, lon)) { // This should work for rings (radius,azimuth) return p_camera->InCube(); } @@ -152,7 +152,7 @@ namespace Isis { * false if it was not */ bool UniversalGroundMap::SetUnboundGround(Latitude lat, Longitude lon) { - if(p_camera != NULL) { + if(p_priority == CameraFirst) { if(p_camera->SetGround(lat, lon)) { // This should work for rings (radius,azimuth) return p_camera->InCube(); } @@ -178,7 +178,7 @@ namespace Isis { * otherwise */ bool UniversalGroundMap::SetGround(const SurfacePoint &sp) { - if (p_camera != NULL) { + if (p_priority == CameraFirst) { if (p_camera->SetGround(sp)) { return p_camera->InCube(); } @@ -198,7 +198,7 @@ namespace Isis { * @return Sample value */ double UniversalGroundMap::Sample() const { - if (p_camera != NULL) { + if (p_priority == CameraFirst) { return p_camera->Sample(); } else { @@ -212,7 +212,7 @@ namespace Isis { * @return Line value */ double UniversalGroundMap::Line() const { - if (p_camera != NULL) { + if (p_priority == CameraFirst) { return p_camera->Line(); } else { @@ -231,7 +231,7 @@ namespace Isis { * false if it was not */ bool UniversalGroundMap::SetImage(double sample, double line) { - if (p_camera != NULL) { + if (p_priority == CameraFirst) { return p_camera->SetImage(sample, line); } else { @@ -245,7 +245,7 @@ namespace Isis { * @return Universal Latitude */ double UniversalGroundMap::UniversalLatitude() const { - if (p_camera != NULL) { + if (p_priority == CameraFirst) { return p_camera->UniversalLatitude(); } else { @@ -268,7 +268,7 @@ namespace Isis { * @return Universal Longitude */ double UniversalGroundMap::UniversalLongitude() const { - if (p_camera != NULL) { + if (p_priority == CameraFirst) { return p_camera->UniversalLongitude(); } else { @@ -286,13 +286,27 @@ namespace Isis { } } + /** + * Returns the radius of the camera model or projection + * + * @return Radius + */ + double UniversalGroundMap::LocalRadius() const { + if (p_priority == CameraFirst) { + return p_camera->LocalRadius().meters(); + } + else { + return p_projection->LocalRadius(); + } + } + /** * Returns the resolution of the camera model or projection * * @return Resolution */ double UniversalGroundMap::Resolution() const { - if (p_camera != NULL) { + if (p_priority == CameraFirst) { return p_camera->PixelResolution(); } else { @@ -374,7 +388,7 @@ namespace Isis { if (!minLat.isValid() || !maxLat.isValid() || !minLon.isValid() || !maxLon.isValid()) { - if (HasCamera()) { + if (p_priority == CameraFirst) { // Footprint failed, ask the camera PvlGroup mappingGrp("Mapping"); mappingGrp += PvlKeyword("LatitudeType", "Planetocentric"); @@ -395,7 +409,7 @@ namespace Isis { minLon = Longitude(minLonDouble, Angle::Degrees); maxLon = Longitude(maxLonDouble, Angle::Degrees); } - else if (HasProjection()) { + else if (p_priority == ProjectionFirst) { // Footprint failed, look in the mapping group PvlGroup mappingGrp = p_projection->Mapping(); if (mappingGrp.hasKeyword("MinimumLatitude") && @@ -538,4 +552,13 @@ namespace Isis { minLon.isValid() && maxLon.isValid() && minLat < maxLat && minLon < maxLon); } + + void UniversalGroundMap::setPriority(int priority) { + if (priority == UniversalGroundMap::CameraFirst && HasCamera()) { + p_priority = (CameraPriority) priority; + } + else if (priority == UniversalGroundMap::ProjectionFirst && HasProjection()) { + p_priority = (CameraPriority) priority; + } + } } diff --git a/isis/src/base/objs/UniversalGroundMap/UniversalGroundMap.h b/isis/src/base/objs/UniversalGroundMap/UniversalGroundMap.h index d7d465e587..ff62bee393 100644 --- a/isis/src/base/objs/UniversalGroundMap/UniversalGroundMap.h +++ b/isis/src/base/objs/UniversalGroundMap/UniversalGroundMap.h @@ -99,6 +99,7 @@ namespace Isis { bool SetImage(double sample, double line); double UniversalLatitude() const; double UniversalLongitude() const; + double LocalRadius() const; double Resolution() const; bool GroundRange(Cube *cube, @@ -127,6 +128,12 @@ namespace Isis { return p_camera != 0; }; + int currentPriority() { + return p_priority; + }; + + void setPriority(int priority); + //! Return the projection associated with the ground map (NULL implies none) Isis::Projection *Projection() const { return p_projection; @@ -141,6 +148,7 @@ namespace Isis { private: Isis::Camera *p_camera; //!LocalRadius()))) { + Distance(ugm.LocalRadius(), Distance::Units::Meters)))) { cout << "Sample = " << ugm.Sample() << endl; cout << "Line = " << ugm.Line() << endl << endl; } @@ -91,7 +91,7 @@ int main(int argc, char *argv[]) { cout << " Testing Projection..." << endl; Cube c2("$base/dems/molaMarsPlanetaryRadius0001.cub", "r"); UniversalGroundMap ugm2(c2); - cout << "Is Projection? = " << ugm2.HasProjection() << endl << endl; + cout << "Has Projection? = " << ugm2.HasProjection() << endl << endl; // Test all four corners to make sure the conversions are right cerr << "For (2.0, 5.0) ..." << endl; diff --git a/isis/src/qisis/objs/CubeViewport/CubeViewport.cpp b/isis/src/qisis/objs/CubeViewport/CubeViewport.cpp index 6d58895dde..40b9019ef9 100644 --- a/isis/src/qisis/objs/CubeViewport/CubeViewport.cpp +++ b/isis/src/qisis/objs/CubeViewport/CubeViewport.cpp @@ -147,7 +147,7 @@ namespace Isis { // Setup a universal ground map try { - p_groundMap = new UniversalGroundMap(*p_cube, UniversalGroundMap::ProjectionFirst); + p_groundMap = new UniversalGroundMap(*p_cube); } catch(IException &) { } diff --git a/isis/src/qisis/objs/FindTool/FindTool.cpp b/isis/src/qisis/objs/FindTool/FindTool.cpp index e7ae47f10c..703c8ee181 100644 --- a/isis/src/qisis/objs/FindTool/FindTool.cpp +++ b/isis/src/qisis/objs/FindTool/FindTool.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -260,9 +261,23 @@ namespace Isis { Hint: If the cube is 'None' the find tool \ will not be active

"); + p_groundEngine = new QComboBox(); + p_groundEngine->setEditable(true); + p_groundEngine->setToolTip("Ground Engine Priority"); + p_groundEngine->setWhatsThis("Function: Set priority use of the projection \ + or the camera to determine ground coordinates. If both are available, \ + the selected option takes priority. If only one is available, it will \ + be used by default."); + p_groundEngine->insertItem(0, "Camera"); + p_groundEngine->insertItem(1, "Projection"); + p_groundEngine->setCurrentIndex(0); + connect( p_groundEngine, SIGNAL( currentIndexChanged(int) ), + this, SLOT( setProjectionEngine(int) ) ); + QHBoxLayout *layout = new QHBoxLayout(hbox); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(p_statusEdit); + layout->addWidget(p_groundEngine); layout->addWidget(p_showDialogButton); layout->addWidget(p_linkViewportsButton); layout->addWidget(p_togglePointVisibleButton); @@ -548,6 +563,19 @@ namespace Isis { } + //! toggles visibility of the red circle + void FindTool::setProjectionEngine(int index) { + for (int i = 0; i < cubeViewportList()->size(); i++) { + MdiCubeViewport *viewport = ( *( cubeViewportList() ) )[i]; + UniversalGroundMap *groundMap = viewport->universalGroundMap(); + + if (groundMap) { + groundMap->setPriority(index); + } + } + } + + //! Links all cubes that have camera models or are map projections void FindTool::handleLinkClicked() { MdiCubeViewport *d; @@ -634,9 +662,11 @@ namespace Isis { // UniversalGroundMaps default to camera priority, so create a new one so that we can use projection if it exists. UniversalGroundMap *groundMap = viewport->universalGroundMap(); Distance viewportResolution; - if (groundMap->Camera() != NULL){ - if (groundMap->Camera()->target()->isSky()) { - return Distance(groundMap->Camera()->RaDecResolution(), Distance::Units::Meters); + if (groundMap) { + if (groundMap->Camera() != NULL) { + if (groundMap->Camera()->target()->isSky()) { + return Distance(groundMap->Camera()->RaDecResolution(), Distance::Units::Meters); + } } } @@ -652,22 +682,20 @@ namespace Isis { if ( groundMap->SetImage(samp - 0.5, line - 0.5) ) { double lat1 = groundMap->UniversalLatitude(); double lon1 = groundMap->UniversalLongitude(); + double radius1 = groundMap->LocalRadius(); if ( groundMap->SetImage(samp + 0.5, line + 0.5) ) { double lat2 = groundMap->UniversalLatitude(); double lon2 = groundMap->UniversalLongitude(); - - double radius = groundMap->HasProjection()? - groundMap->Projection()->LocalRadius() : - groundMap->Camera()->LocalRadius().meters(); + double radius2 = groundMap->LocalRadius(); SurfacePoint point1( Latitude(lat1, Angle::Degrees), Longitude(lon1, Angle::Degrees), - Distance(radius, Distance::Meters) ); + Distance(radius1, Distance::Meters) ); SurfacePoint point2( Latitude(lat2, Angle::Degrees), Longitude(lon2, Angle::Degrees), - Distance(radius, Distance::Meters) ); + Distance(radius2, Distance::Meters) ); viewportResolution = point1.GetDistanceToPoint(point2); } diff --git a/isis/src/qisis/objs/FindTool/FindTool.h b/isis/src/qisis/objs/FindTool/FindTool.h index 4da090b88a..5654a395b8 100644 --- a/isis/src/qisis/objs/FindTool/FindTool.h +++ b/isis/src/qisis/objs/FindTool/FindTool.h @@ -15,6 +15,7 @@ find files of those names at the top level of this repository. **/ class QAction; class QCheckBox; +class QComboBox; class QLineEdit; class QTabWidget; class QToolButton; @@ -148,6 +149,7 @@ namespace Isis { void handleLinkClicked(); void handleRecordClicked(); void togglePointVisible(); + void setProjectionEngine(int index); private: // methods void centerLinkedViewports(); @@ -163,6 +165,7 @@ namespace Isis { QToolButton *p_togglePointVisibleButton; QCheckBox *p_syncScale; QLineEdit *p_statusEdit; + QComboBox *p_groundEngine; QTabWidget *p_tabWidget; GroundTab *p_groundTab; ImageTab *p_imageTab; diff --git a/isis/src/qisis/objs/SpatialPlotTool/SpatialPlotTool.cpp b/isis/src/qisis/objs/SpatialPlotTool/SpatialPlotTool.cpp index 27c7758f3f..d5a059b042 100644 --- a/isis/src/qisis/objs/SpatialPlotTool/SpatialPlotTool.cpp +++ b/isis/src/qisis/objs/SpatialPlotTool/SpatialPlotTool.cpp @@ -290,13 +290,7 @@ namespace Isis { SurfacePoint result; if (groundMap) { - Distance radius; - - if (groundMap->Camera()) - radius = groundMap->Camera()->LocalRadius(); - else if (groundMap->Projection()) - radius = Distance(groundMap->Projection()->LocalRadius(), Distance::Meters); - + Distance radius(groundMap->LocalRadius(), Distance::Units::Meters); result = SurfacePoint(Latitude(groundMap->UniversalLatitude(), Angle::Degrees), Longitude(groundMap->UniversalLongitude(), Angle::Degrees), radius); }