Isis 3 Programmer Reference
RollingShutterCameraDetectorMap.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include "RollingShutterCameraDetectorMap.h"
8
9#include "iTime.h"
10
11#include <QtMath>
12#include <utility>
13#include <vector>
14
15
16namespace Isis {
26 Camera *parent,
27 std::vector<double> times,
28 std::vector<double> sampleCoeffs,
29 std::vector<double> lineCoeffs) : CameraDetectorMap(parent) {
30 m_times = times;
31 m_sampleCoeffs = sampleCoeffs;
32 m_lineCoeffs = lineCoeffs;
33 }
34
35
42
43
56 const double line) {
57 return RollingShutterCameraDetectorMap::SetParent(sample, line, 0.0);
58 }
59
60
76 const double line,
77 const double deltaT) {
78 std::pair<double, double> jittered = removeJitter(sample, line);
79 p_parentSample = jittered.first;
80 p_parentLine = jittered.second;
83 if (p_camera->isTimeSet()) {
84 p_camera->setTime(p_camera->time().Et() + deltaT);
85 }
86 return true;
87 }
88
89
101 bool RollingShutterCameraDetectorMap::SetDetector(const double sample, const double line) {
102 p_detectorSample = sample;
103 p_detectorLine = line;
106 std::pair<double, double> jittered = applyJitter(p_parentSample, p_parentLine);
107 p_parentSample = jittered.first;
108 p_parentLine = jittered.second;
109 return true;
110 }
111
112
128 std::pair<double, double> RollingShutterCameraDetectorMap::applyJitter(const double sample,
129 const double line) {
130 std::pair<double, double> jittered = removeJitter(sample, line);
131 double currentSample = sample;
132 double currentLine = line;
133
134 int iterations = 0;
135 int maxIterations = 50;
136
137 while((qFabs(sample - jittered.first) > 1e-7) ||
138 (qFabs(line - jittered.second) > 1e-7)) {
139
140 currentSample = sample + (currentSample - jittered.first);
141 currentLine = line + (currentLine - jittered.second);
142
143 jittered = removeJitter(currentSample, currentLine);
144
145 iterations++;
146 if (iterations > maxIterations) {
147 QString message = "Max Iterations reached.";
148 throw IException(IException::Unknown, message, _FILEINFO_);
149 }
150
151 }
152
153 return std::pair<double, double>(currentSample, currentLine);
154 }
155
167 std::pair<double, double> RollingShutterCameraDetectorMap::removeJitter(const double sample,
168 const double line) {
169 // De-jitter equation in form:
170 // c1(t^n) + c2(t^(n-2)) + ... + cn(t)
171 double sampleDejitter = 0.0;
172 double lineDejitter = 0.0;
173 // Note that # sample coeffs == # line coeffs
174 for (unsigned int n = 1; n <= m_lineCoeffs.size(); n++) {
175 double sampleCoeff = m_sampleCoeffs[n - 1];
176 double lineCoeff = m_lineCoeffs[n - 1];
177 // Round to nearest line
178 int timeEntry = 0;
179 // Any lines that round past last time entry will use last time entry as index
180 if (line > m_times.size()) {
181 timeEntry = m_times.size();
182 }
183 else {
184 timeEntry = (int)round(line);
185 }
186 double time = m_times[timeEntry - 1];
187 int exponent = m_lineCoeffs.size() - (n - 1);
188 time = pow(time, exponent);
189 sampleDejitter += (sampleCoeff * time);
190 lineDejitter += (lineCoeff * time);
191 }
192 return std::pair<double, double>(sample - sampleDejitter, line - lineDejitter);
193 }
194}
Convert between parent image coordinates and detector coordinates.
double p_detectorLineSumming
The scaling factor for computing line resolution.
double p_parentLine
The parent line calculated from the detector.
double p_parentSample
The parent sample calculated from the detector.
double p_detectorSample
Detector coordinate sample value.
double p_detectorLine
Detector coordinate line value.
double p_ss
Start sample.
Camera * p_camera
Pointer to the camera.
double p_detectorSampleSumming
The scaling factor for computing sample resolution.
Isis exception class.
Definition IException.h:91
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition IException.h:118
RollingShutterCameraDetectorMap(Camera *parent, std::vector< double > times, std::vector< double > sampleCoeffs, std::vector< double > lineCoeffs)
Constructs a RollingShutterCameraDetectorMap.
std::vector< double > m_times
List of normalized [-1, 1] readout times for all the lines in the input image.
std::pair< double, double > applyJitter(const double sample, const double line)
Iteratively finds a solution to "apply" jitter to an image coordinate.
std::vector< double > m_sampleCoeffs
List of coefficients for the n-order polynomial characterizing the jitter in the sample direction.
std::vector< double > m_lineCoeffs
List of coefficients for the n-order polynomial characterizing the jitter in the line direction.
std::pair< double, double > removeJitter(const double sample, const double line)
Remove the distortion from the image (parent) coordinates.
virtual bool SetParent(const double sample, const double line)
Compute detector position from a parent image coordinate.
virtual bool SetDetector(const double sample, const double line)
Compute parent position from a detector coordinate.
void setTime(const iTime &time)
By setting the time you essential set the position of the spacecraft and body as indicated in the cla...
Definition Sensor.cpp:99
virtual iTime time() const
Returns the ephemeris time in seconds which was used to obtain the spacecraft and sun positions.
Definition Spice.cpp:891
bool isTimeSet()
Returns true if time has been initialized.
Definition Spice.cpp:1589
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16