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 
16 namespace 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 
40 
41  }
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 
121  std::pair<double, double> RollingShutterCameraDetectorMap::applyJitter(const double sample,
122  const double line) {
123  std::pair<double, double> jittered = removeJitter(sample, line);
124  double currentSample = sample;
125  double currentLine = line;
126 
127  int iterations = 0;
128  int maxIterations = 50;
129 
130  p_detectorSample = sample;
131  p_detectorLine = line;
134 
135  while((qFabs(sample - currentSample) < 1e-7) &&
136  (qFabs(line - currentLine) < 1e-7)) {
137 
138  currentSample = (currentSample - jittered.first);
139  currentLine = (currentLine - jittered.second);
140 
141  jittered = removeJitter(currentSample, currentLine);
142 
143  iterations++;
144  if (iterations > maxIterations) {
145  QString message = "Max Iterations reached.";
146  throw IException(IException::Unknown, message, _FILEINFO_);
147  }
148 
149  }
150 
151  return std::pair<double, double>(sample + currentSample, line + currentLine);
152  }
153 
165  std::pair<double, double> RollingShutterCameraDetectorMap::removeJitter(const double sample,
166  const double line) {
167  // De-jitter equation in form:
168  // c1(t^n) + c2(t^(n-2)) + ... + cn(t)
169  double sampleDejitter = 0.0;
170  double lineDejitter = 0.0;
171  // Note that # sample coeffs == # line coeffs
172  for (unsigned int n = 1; n <= m_lineCoeffs.size(); n++) {
173  double sampleCoeff = m_sampleCoeffs[n - 1];
174  double lineCoeff = m_lineCoeffs[n - 1];
175  // Round to nearest line
176  int timeEntry = 0;
177  // Any lines that round past last time entry will use last time entry as index
178  if (line > m_times.size()) {
179  timeEntry = m_times.size();
180  }
181  else {
182  timeEntry = (int)round(line);
183  }
184  double time = m_times[timeEntry - 1];
185  int exponent = m_lineCoeffs.size() - (n - 1);
186  time = pow(time, exponent);
187  sampleDejitter += (sampleCoeff * time);
188  lineDejitter += (lineCoeff * time);
189  }
190  return std::pair<double, double>(sample - sampleDejitter, line - lineDejitter);
191  }
192 }
Isis::Spice::time
iTime time() const
Returns the ephemeris time in seconds which was used to obtain the spacecraft and sun positions.
Definition: Spice.cpp:884
Isis::RollingShutterCameraDetectorMap::SetParent
virtual bool SetParent(const double sample, const double line)
Compute detector position from a parent image coordinate.
Definition: RollingShutterCameraDetectorMap.cpp:55
Isis::CameraDetectorMap::p_parentLine
double p_parentLine
The parent line calculated from the detector.
Definition: CameraDetectorMap.h:141
Isis::CameraDetectorMap
Convert between parent image coordinates and detector coordinates.
Definition: CameraDetectorMap.h:47
Isis::IException::Unknown
@ Unknown
A type of error that cannot be classified as any of the other error types.
Definition: IException.h:118
Isis::CameraDetectorMap::p_parentSample
double p_parentSample
The parent sample calculated from the detector.
Definition: CameraDetectorMap.h:140
Isis::Camera
Definition: Camera.h:236
Isis::CameraDetectorMap::p_detectorLineSumming
double p_detectorLineSumming
The scaling factor for computing line resolution.
Definition: CameraDetectorMap.h:146
Isis::RollingShutterCameraDetectorMap::~RollingShutterCameraDetectorMap
virtual ~RollingShutterCameraDetectorMap()
Destructor.
Definition: RollingShutterCameraDetectorMap.cpp:39
Isis::CameraDetectorMap::p_detectorLine
double p_detectorLine
Detector coordinate line value.
Definition: CameraDetectorMap.h:142
Isis::RollingShutterCameraDetectorMap::m_lineCoeffs
std::vector< double > m_lineCoeffs
List of coefficients for the n-order polynomial characterizing the jitter in the line direction.
Definition: RollingShutterCameraDetectorMap.h:67
Isis::Sensor::setTime
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:97
Isis::iTime::Et
double Et() const
Returns the ephemeris time (TDB) representation of the time as a double.
Definition: iTime.h:126
Isis::RollingShutterCameraDetectorMap::m_sampleCoeffs
std::vector< double > m_sampleCoeffs
List of coefficients for the n-order polynomial characterizing the jitter in the sample direction.
Definition: RollingShutterCameraDetectorMap.h:62
Isis::CameraDetectorMap::p_detectorSampleSumming
double p_detectorSampleSumming
The scaling factor for computing sample resolution.
Definition: CameraDetectorMap.h:145
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::CameraDetectorMap::p_sl
double p_sl
Start line.
Definition: CameraDetectorMap.h:151
Isis::CameraDetectorMap::p_camera
Camera * p_camera
Pointer to the camera.
Definition: CameraDetectorMap.h:138
Isis::RollingShutterCameraDetectorMap::SetDetector
virtual bool SetDetector(const double sample, const double line)
Compute parent position from a detector coordinate.
Definition: RollingShutterCameraDetectorMap.cpp:101
Isis::CameraDetectorMap::p_detectorSample
double p_detectorSample
Detector coordinate sample value.
Definition: CameraDetectorMap.h:143
Isis::RollingShutterCameraDetectorMap::applyJitter
std::pair< double, double > applyJitter(const double sample, const double line)
Iteratively finds a solution to "apply" jitter to an image coordinate.
Definition: RollingShutterCameraDetectorMap.cpp:121
Isis::Spice::isTimeSet
bool isTimeSet()
Returns true if time has been initialized.
Definition: Spice.cpp:1577
Isis::CameraDetectorMap::p_ss
double p_ss
Start sample.
Definition: CameraDetectorMap.h:150
Isis::RollingShutterCameraDetectorMap::removeJitter
std::pair< double, double > removeJitter(const double sample, const double line)
Remove the distortion from the image (parent) coordinates.
Definition: RollingShutterCameraDetectorMap.cpp:165
Isis::RollingShutterCameraDetectorMap::m_times
std::vector< double > m_times
List of normalized [-1, 1] readout times for all the lines in the input image.
Definition: RollingShutterCameraDetectorMap.h:57
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::RollingShutterCameraDetectorMap::RollingShutterCameraDetectorMap
RollingShutterCameraDetectorMap(Camera *parent, std::vector< double > times, std::vector< double > sampleCoeffs, std::vector< double > lineCoeffs)
Constructs a RollingShutterCameraDetectorMap.
Definition: RollingShutterCameraDetectorMap.cpp:25