File failed to load: https://isis.astrogeology.usgs.gov/9.0.0/Object/assets/jax/output/NativeMML/config.js
Isis 3 Programmer Reference
PushFrameCameraGroundMap.cpp
1
5
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "PushFrameCameraGroundMap.h"
8
9#include <QDebug>
10
11#include "CameraDistortionMap.h"
12#include "CameraFocalPlaneMap.h"
13#include "Distance.h"
14#include "Latitude.h"
15#include "Longitude.h"
16#include "PushFrameCameraDetectorMap.h"
17#include "SurfacePoint.h"
18
19namespace Isis {
29 const Longitude &lon) {
30 PushFrameCameraDetectorMap *detectorMap = (PushFrameCameraDetectorMap *) p_camera->DetectorMap();
31
32 SurfacePoint surfacePoint(lat, lon, p_camera->LocalRadius(lat, lon));
33
34 // Get ending bounding framelets and distances for iterative loop to minimize the spacecraft distance
35 int startFramelet = 1;
36 double startDist = FindSpacecraftDistance(1, surfacePoint);
37
38 int endFramelet = detectorMap->TotalFramelets();
39 double endDist = FindSpacecraftDistance(endFramelet, surfacePoint);
40
41 bool minimizedSpacecraftDist = false;
42
43 for (int j = 0; j < 30 && !minimizedSpacecraftDist;j++) {
44 int deltaX = abs(startFramelet - endFramelet) / 2;
45
46 // start + deltaX = middle framelet.
47 // We're able to optimize this modified binary search
48 // because the 'V' shape -- it's mostly parallel. Meaning,
49 // if the left side is higher than the right, then the
50 // solution is closer to the right. The bias factor will
51 // determine how much closer, and then back off a little so
52 // we dont overshoot it.
53 double biasFactor = startDist / endDist;
54
55 if (biasFactor < 1.0) {
56 biasFactor = -1.0 / biasFactor;
57 biasFactor = -(biasFactor + 1) / biasFactor;
58
59 // The bias is about 50% unsure... sometimes our V is a U
60 biasFactor = std::min(biasFactor + 0.50, 0.0);
61 }
62 else {
63 biasFactor = (biasFactor - 1) / biasFactor;
64
65 // The bias is about 50% unsure... sometimes our V is a U
66 biasFactor = std::max(biasFactor - 0.50, 0.0);
67 }
68
69 int middleFramelet = startFramelet + (int)(deltaX + biasFactor * deltaX);
70 double middleDist = FindSpacecraftDistance(middleFramelet, surfacePoint);
71
72 if (startDist > endDist) {
73 // This makes sure we don't get stuck halfway between framelets
74 if (startFramelet == middleFramelet) middleFramelet++;
75 startFramelet = middleFramelet;
76 startDist = middleDist;
77 }
78 else {
79 endFramelet = middleFramelet;
80 endDist = middleDist;
81 }
82
83 if (startFramelet == endFramelet) {
84 minimizedSpacecraftDist = true;
85 }
86 }
87
88 if (!minimizedSpacecraftDist) {
89 return false;
90 }
91
92 int realFramelet = startFramelet;
93 bool frameletEven = (realFramelet % 2 == 0);
94 bool timeAscendingFramelets = detectorMap->timeAscendingFramelets();
95
96 // Do we need to find a neighboring framelet? Get the closest (minimize distance)
97 if ((timeAscendingFramelets && frameletEven != p_evenFramelets) ||
98 (!timeAscendingFramelets && frameletEven == p_evenFramelets)) {
99 realFramelet++; // this direction doesnt really matter... it's simply a guess
100 }
101
102 int direction = 2;
103
104 double realDist = FindDistance(realFramelet, surfacePoint);
105 int guessFramelet = realFramelet + direction;
106 double guessDist = FindDistance(guessFramelet, surfacePoint);
107
108 if (guessDist > realDist) {
109 direction = -1 * direction; // reverse the search direction
110 guessFramelet = realFramelet + direction;
111 guessDist = FindDistance(guessFramelet, surfacePoint);
112 }
113
114 for (int j = 0; (realDist >= guessDist) && (j < 30);j++) {
115 realFramelet = guessFramelet;
116 realDist = guessDist;
117
118 guessFramelet = realFramelet + direction;
119 guessDist = FindDistance(guessFramelet, surfacePoint);
120
121 if (realFramelet <= 0 || realFramelet > detectorMap->TotalFramelets()) {
122 return false;
123 }
124 }
125
126 detectorMap->SetFramelet(realFramelet);
127
128 return CameraGroundMap::SetGround(surfacePoint);
129 }
130
131
133 return SetGround(surfacePt.GetLatitude(), surfacePt.GetLongitude());
134 }
135
136
148 const SurfacePoint &surfacePoint) {
149 PushFrameCameraDetectorMap *detectorMap = (PushFrameCameraDetectorMap *) p_camera->DetectorMap();
150 CameraDistortionMap *distortionMap = (CameraDistortionMap *) p_camera->DistortionMap();
151
152 detectorMap->SetFramelet(framelet);
153 if(!p_camera->Sensor::SetGround(surfacePoint, false)) return DBL_MAX;
154
155 double lookC[3];
156 p_camera->Sensor::LookDirection(lookC);
157 double ux = p_camera->FocalLength() * lookC[0] / lookC[2];
158 double uy = p_camera->FocalLength() * lookC[1] / lookC[2];
159
160 if(!distortionMap->SetUndistortedFocalPlane(ux, uy)) return DBL_MAX;
161
162 double dx = distortionMap->FocalPlaneX();
163 double dy = distortionMap->FocalPlaneY();
164
165 CameraFocalPlaneMap *focalMap = p_camera->FocalPlaneMap();
166 if(!focalMap->SetFocalPlane(dx, dy)) return DBL_MAX;
167
168 detectorMap->SetDetector(focalMap->DetectorSample(), focalMap->DetectorLine());
169
170 double actualFrameletHeight = detectorMap->frameletHeight() / detectorMap->LineScaleFactor();
171 double frameletDeltaY = detectorMap->frameletLine() - (actualFrameletHeight / 2.0);
172
173 return frameletDeltaY * frameletDeltaY;
174 }
175
187 const SurfacePoint &surfacePoint) {
188 PushFrameCameraDetectorMap *detectorMap = (PushFrameCameraDetectorMap *) p_camera->DetectorMap();
189
190 detectorMap->SetFramelet(framelet);
191 if(!p_camera->Sensor::SetGround(surfacePoint, false)) return DBL_MAX;
192
193 return p_camera->SlantDistance();
194 }
195}
virtual double LineScaleFactor() const
Return scaling factor for computing line resolution.
Distort/undistort focal plane coordinates.
virtual bool SetUndistortedFocalPlane(double ux, double uy)
Compute distorted focal plane x/y.
double FocalPlaneX() const
Gets the x-value in the focal plane coordinate system.
double FocalPlaneY() const
Gets the y-value in the focal plane coordinate system.
Convert between distorted focal plane and detector coordinates.
virtual bool SetFocalPlane(const double dx, const double dy)
Compute detector position (sample,line) from focal plane coordinates.
virtual bool SetGround(const Latitude &lat, const Longitude &lon)
Compute undistorted focal plane coordinate from ground position.
Camera * p_camera
Camera.
This class is designed to encapsulate the concept of a Latitude.
Definition Latitude.h:51
This class is designed to encapsulate the concept of a Longitude.
Definition Longitude.h:40
Convert between parent image coordinates and detector coordinates.
int TotalFramelets() const
Return the total number of framelets including padding.
double frameletLine() const
This returns the calculated framelet line.
bool timeAscendingFramelets()
Returns if the framelets are reversed from top-to-bottom.
int frameletHeight() const
This returns how many lines are considered a single framelet.
virtual bool SetDetector(const double sample, const double line)
Compute parent position from a detector coordinate.
void SetFramelet(int framelet, const double deltaT=0)
This method changes the current framelet.
virtual bool SetGround(const Latitude &lat, const Longitude &lon)
Compute undistorted focal plane coordinate from ground position.
bool p_evenFramelets
True if the file contains even framelets.
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.
This class defines a body-fixed surface point.
Latitude GetLatitude() const
Return the body-fixed latitude for the surface point.
Longitude GetLongitude() const
Return the body-fixed longitude for the surface point.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16