Skip to content
4 changes: 2 additions & 2 deletions isis/src/base/objs/GroundGrid/GroundGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
87 changes: 55 additions & 32 deletions isis/src/base/objs/UniversalGroundMap/UniversalGroundMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}
}

Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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");
Expand All @@ -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") &&
Expand Down Expand Up @@ -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;
}
}
}
8 changes: 8 additions & 0 deletions isis/src/base/objs/UniversalGroundMap/UniversalGroundMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -141,6 +148,7 @@ namespace Isis {
private:
Isis::Camera *p_camera; //!<The camera (if the image has a camera)
Isis::Projection *p_projection; //!<The projection (if the image is projected)
CameraPriority p_priority;
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Sample = 1203.99978
Line = 1056.0001

Testing Projection...
Is Projection? = 1
Has Projection? = 1

For (2.0, 5.0) ...
Universal Latitude = 89.9727
Expand All @@ -57,7 +57,7 @@ Sample = 23040
Line = 11520

Testing Camera Model and Projection...
Is Projection? = 0
Is Projection? = 1

For (1.0, 5.0) ...
Universal Latitude = -86.9422124
Expand Down
4 changes: 2 additions & 2 deletions isis/src/base/objs/UniversalGroundMap/unitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int main(int argc, char *argv[]) {
if (ugm.SetGround(
SurfacePoint(Latitude(ugm.UniversalLatitude(), Angle::Degrees),
Longitude(ugm.UniversalLongitude(), Angle::Degrees),
ugm.Camera()->LocalRadius()))) {
Distance(ugm.LocalRadius(), Distance::Units::Meters)))) {
cout << "Sample = " << ugm.Sample() << endl;
cout << "Line = " << ugm.Line() << endl << endl;
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion isis/src/qisis/objs/CubeViewport/CubeViewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &) {
}
Expand Down
46 changes: 37 additions & 9 deletions isis/src/qisis/objs/FindTool/FindTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QApplication>
#include <QCheckBox>
#include <QComboBox>
#include <QDialog>
#include <QHBoxLayout>
#include <QLabel>
Expand Down Expand Up @@ -260,9 +261,23 @@ namespace Isis {
<b>Hint: </b> If the cube is 'None' the find tool \
will not be active</p>");

p_groundEngine = new QComboBox();
p_groundEngine->setEditable(true);
p_groundEngine->setToolTip("Ground Engine Priority");
p_groundEngine->setWhatsThis("<b>Function: </b> 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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}

Expand All @@ -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);
}
Expand Down
Loading
Loading