Isis 3.0 Programmer Reference
Back | Home
PushFrameCameraGroundMap.cpp
Go to the documentation of this file.
1 
24 
25 #include <QDebug>
26 
27 #include "CameraDistortionMap.h"
28 #include "CameraFocalPlaneMap.h"
29 #include "Distance.h"
30 #include "Latitude.h"
31 #include "Longitude.h"
33 #include "SurfacePoint.h"
34 
35 namespace Isis {
45  const Longitude &lon) {
47 
48  SurfacePoint surfacePoint(lat, lon, p_camera->LocalRadius(lat, lon));
49 
50  // Get ending bounding framelets and distances for iterative loop to minimize the spacecraft distance
51  int startFramelet = 1;
52  double startDist = FindSpacecraftDistance(1, surfacePoint);
53 
54  int endFramelet = detectorMap->TotalFramelets();
55  double endDist = FindSpacecraftDistance(endFramelet, surfacePoint);
56 
57  bool minimizedSpacecraftDist = false;
58 
59  for (int j = 0; j < 30 && !minimizedSpacecraftDist;j++) {
60  int deltaX = abs(startFramelet - endFramelet) / 2;
61 
62  // start + deltaX = middle framelet.
63  // We're able to optimize this modified binary search
64  // because the 'V' shape -- it's mostly parallel. Meaning,
65  // if the left side is higher than the right, then the
66  // solution is closer to the right. The bias factor will
67  // determine how much closer, and then back off a little so
68  // we dont overshoot it.
69  double biasFactor = startDist / endDist;
70 
71  if (biasFactor < 1.0) {
72  biasFactor = -1.0 / biasFactor;
73  biasFactor = -(biasFactor + 1) / biasFactor;
74 
75  // The bias is about 50% unsure... sometimes our V is a U
76  biasFactor = std::min(biasFactor + 0.50, 0.0);
77  }
78  else {
79  biasFactor = (biasFactor - 1) / biasFactor;
80 
81  // The bias is about 50% unsure... sometimes our V is a U
82  biasFactor = std::max(biasFactor - 0.50, 0.0);
83  }
84 
85  int middleFramelet = startFramelet + (int)(deltaX + biasFactor * deltaX);
86  double middleDist = FindSpacecraftDistance(middleFramelet, surfacePoint);
87 
88  if (startDist > endDist) {
89  // This makes sure we don't get stuck halfway between framelets
90  if (startFramelet == middleFramelet) middleFramelet++;
91  startFramelet = middleFramelet;
92  startDist = middleDist;
93  }
94  else {
95  endFramelet = middleFramelet;
96  endDist = middleDist;
97  }
98 
99  if (startFramelet == endFramelet) {
100  minimizedSpacecraftDist = true;
101  }
102  }
103 
104  if (!minimizedSpacecraftDist) {
105  return false;
106  }
107 
108  int realFramelet = startFramelet;
109  bool frameletEven = (realFramelet % 2 == 0);
110  bool timeAscendingFramelets = detectorMap->timeAscendingFramelets();
111 
112  // Do we need to find a neighboring framelet? Get the closest (minimize distance)
113  if ((timeAscendingFramelets && frameletEven != p_evenFramelets) ||
114  (!timeAscendingFramelets && frameletEven == p_evenFramelets)) {
115  realFramelet++; // this direction doesnt really matter... it's simply a guess
116  }
117 
118  int direction = 2;
119 
120  double realDist = FindDistance(realFramelet, surfacePoint);
121  int guessFramelet = realFramelet + direction;
122  double guessDist = FindDistance(guessFramelet, surfacePoint);
123 
124  if (guessDist > realDist) {
125  direction = -1 * direction; // reverse the search direction
126  guessFramelet = realFramelet + direction;
127  guessDist = FindDistance(guessFramelet, surfacePoint);
128  }
129 
130  for (int j = 0; (realDist >= guessDist) && (j < 30);j++) {
131  realFramelet = guessFramelet;
132  realDist = guessDist;
133 
134  guessFramelet = realFramelet + direction;
135  guessDist = FindDistance(guessFramelet, surfacePoint);
136 
137  if (realFramelet <= 0 || realFramelet > detectorMap->TotalFramelets()) {
138  return false;
139  }
140  }
141 
142  detectorMap->SetFramelet(realFramelet);
143 
144  return CameraGroundMap::SetGround(surfacePoint);
145  }
146 
147 
149  return SetGround(surfacePt.GetLatitude(), surfacePt.GetLongitude());
150  }
151 
152 
164  const SurfacePoint &surfacePoint) {
167 
168  detectorMap->SetFramelet(framelet);
169  if(!p_camera->Sensor::SetGround(surfacePoint, false)) return DBL_MAX;
170 
171  double lookC[3];
172  p_camera->Sensor::LookDirection(lookC);
173  double ux = p_camera->FocalLength() * lookC[0] / lookC[2];
174  double uy = p_camera->FocalLength() * lookC[1] / lookC[2];
175 
176  if(!distortionMap->SetUndistortedFocalPlane(ux, uy)) return DBL_MAX;
177 
178  double dx = distortionMap->FocalPlaneX();
179  double dy = distortionMap->FocalPlaneY();
180 
182  if(!focalMap->SetFocalPlane(dx, dy)) return DBL_MAX;
183 
184  detectorMap->SetDetector(focalMap->DetectorSample(), focalMap->DetectorLine());
185 
186  double actualFrameletHeight = detectorMap->frameletHeight() / detectorMap->LineScaleFactor();
187  double frameletDeltaY = detectorMap->frameletLine() - (actualFrameletHeight / 2.0);
188 
189  return frameletDeltaY * frameletDeltaY;
190  }
191 
203  const SurfacePoint &surfacePoint) {
205 
206  detectorMap->SetFramelet(framelet);
207  if(!p_camera->Sensor::SetGround(surfacePoint, false)) return DBL_MAX;
208 
209  return p_camera->SlantDistance();
210  }
211 }
This class defines a body-fixed surface point.
Definition: SurfacePoint.h:86
bool p_evenFramelets
True if the file contains even framelets.
double frameletLine() const
This returns the calculated framelet line.
CameraDetectorMap * DetectorMap()
Returns a pointer to the CameraDetectorMap object.
Definition: Camera.cpp:2906
Camera * p_camera
Camera.
CameraDistortionMap * DistortionMap()
Returns a pointer to the CameraDistortionMap object.
Definition: Camera.cpp:2886
double SlantDistance() const
Return the distance between the spacecraft and surface point in kmv.
Definition: Sensor.cpp:625
virtual bool SetFocalPlane(const double dx, const double dy)
Compute detector position (sample,line) from focal plane coordinates.
virtual double LineScaleFactor() const
Return scaling factor for computing line resolution.
void SetFramelet(int framelet, const double deltaT=0)
This method changes the current framelet.
This class is designed to encapsulate the concept of a Latitude.
Definition: Latitude.h:59
int frameletHeight() const
This returns how many lines are considered a single framelet.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
double FocalLength() const
Returns the focal length.
Definition: Camera.cpp:2794
virtual bool SetDetector(const double sample, const double line)
Compute parent position from a detector coordinate.
Longitude GetLongitude() const
Return the body-fixed longitude for the surface point.
double DetectorLine() const
Return detector line.
double DetectorSample() const
Return detector sample.
This class is designed to encapsulate the concept of a Longitude.
Definition: Longitude.h:52
virtual bool SetGround(const Latitude &lat, const Longitude &lon)
Compute undistorted focal plane coordinate from ground position.
double FindSpacecraftDistance(int framelet, const SurfacePoint &surfacePoint)
This method finds the distance from the point on the ground to the spacecraft at the time the specifi...
double FindDistance(int framelet, const SurfacePoint &surfacePoint)
This method finds the distance from the center of the framelet to the lat,lon.
Convert between distorted focal plane and detector coordinates.
Latitude GetLatitude() const
Return the body-fixed latitude for the surface point.
virtual bool SetUndistortedFocalPlane(double ux, double uy)
Compute distorted focal plane x/y.
Convert between parent image coordinates and detector coordinates.
int TotalFramelets() const
Return the total number of framelets including padding.
Distort/undistort focal plane coordinates.
virtual bool SetGround(const Latitude &lat, const Longitude &lon)
Compute undistorted focal plane coordinate from ground position.
CameraFocalPlaneMap * FocalPlaneMap()
Returns a pointer to the CameraFocalPlaneMap object.
Definition: Camera.cpp:2896
Unless noted otherwise, the portions of Isis written by the USGS are public domain.
Distance LocalRadius() const
Returns the local radius at the intersection point.
Definition: Sensor.cpp:282
double FocalPlaneY() const
Return distorted focal plane y.
bool timeAscendingFramelets()
Returns if the framelets are reversed from top-to-bottom.
double FocalPlaneX() const
Return distorted focal plane x.
Unless noted otherwise, the portions of Isis written by the USGS are public domain.

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:26:59