7#include "ReseauDistortionMap.h"
8#include "LeastSquares.h"
9#include "BasisFunction.h"
10#include "CameraFocalPlaneMap.h"
12#include "Statistics.h"
33 p_distortedLines = dim.
findKeyword(
"DistortedLines");
35 p_undistortedLines = dim.
findKeyword(
"UndistortedLines");
42 string msg =
"The number of lines and samples for the master reseaus are";
43 msg +=
"not equal, the data file may be bad";
47 p_mlines.push_back(
toDouble(mline[i]));
56 string msg =
"The number of lines and samples for the refined reseaus are";
57 msg +=
"not equal, the data file may be bad";
61 p_rlines.push_back(
toDouble(rline[i]));
64 if(p_mlines.size() != p_rlines.size()) {
65 string msg =
"The number of master reseaus and refined reseaus";
66 msg +=
"do not appear to be equal";
87 p_camera->FocalPlaneMap()->DetectorSampleOrigin();
89 p_camera->FocalPlaneMap()->DetectorLineOrigin();
94 double ldiffsq, sdiffsq;
97 ldiffsq = (focalLine - p_rlines[i]) * (focalLine - p_rlines[i]);
98 distances[i] = ldiffsq + sdiffsq;
102 for(
int ifpt = 0; ifpt < 5; ifpt++) {
105 if(distances[i] < distances[imin]) imin = i;
107 closepts[ifpt] = imin;
108 wt[ifpt] = distances[imin];
109 distances[imin] = DBL_MAX;
114 double line[5], samp[5];
115 for(
int k = 0; k < 5; k++) {
116 line[k] = p_rlines[closepts[k]];
129 double scale = wt[0];
130 double rfitlines[5], rfitsamps[5], mfitlines[5], mfitsamps[5];
131 for(
int ifpt = 0; ifpt < 5; ifpt++) {
132 int index = closepts[ifpt];
133 rfitlines[ifpt] = p_rlines[index];
135 mfitlines[ifpt] = p_mlines[index];
137 wt[ifpt] = scale / wt[ifpt];
144 vector<double> known;
146 for(
int i = 0; i < 5; i++) {
148 known[1] = rfitsamps[i];
149 known[2] = rfitlines[i];
150 lsqX.
AddKnown(known, mfitsamps[i], wt[i]);
151 lsqY.
AddKnown(known, mfitlines[i], wt[i]);
156 known[1] = focalSamp;
157 known[2] = focalLine;
160 double undistortedFocalSamp = lsqX.
Evaluate(known);
161 double undistortedFocalLine = lsqY.
Evaluate(known);
162 if(undistortedFocalSamp < 0.5)
return false;
163 if(undistortedFocalLine < 0.5)
return false;
165 if(undistortedFocalLine > p_undistortedLines + 0.5)
return false;
174 int index = closepts[0];
199 double undistortedFocalLine = uy /
p_pixelPitch + p_undistortedLines / 2.0;
204 double ldiffsq, sdiffsq;
206 sdiffsq = (undistortedFocalSamp -
p_msamps[i]) *
207 (undistortedFocalSamp -
p_msamps[i]);
208 ldiffsq = (undistortedFocalLine - p_mlines[i]) *
209 (undistortedFocalLine - p_mlines[i]);
210 distances[i] = ldiffsq + sdiffsq;
214 for(
int ifpt = 0; ifpt < 5; ifpt++) {
217 if(distances[i] < distances[imin]) imin = i;
219 closepts[ifpt] = imin;
220 wt[ifpt] = distances[imin];
221 distances[imin] = DBL_MAX;
226 double line[5], samp[5];
227 for(
int k = 0; k < 5; k++) {
228 line[k] = p_rlines[closepts[k]];
240 double scale = wt[0];
241 double rfitlines[5], rfitsamps[5], mfitlines[5], mfitsamps[5];
242 for(
int ifpt = 0; ifpt < 5; ifpt++) {
243 int index = closepts[ifpt];
244 mfitlines[ifpt] = p_mlines[index];
246 rfitlines[ifpt] = p_rlines[index];
248 wt[ifpt] = scale / wt[ifpt];
255 vector<double> known;
257 for(
int i = 0; i < 5; i++) {
259 known[1] = mfitsamps[i];
260 known[2] = mfitlines[i];
261 lsqX.
AddKnown(known, rfitsamps[i], wt[i]);
262 lsqY.
AddKnown(known, rfitlines[i], wt[i]);
267 known[1] = undistortedFocalSamp;
268 known[2] = undistortedFocalLine;
271 double distortedFocalSamp = lsqX.
Evaluate(known);
272 double distortedFocalLine = lsqY.
Evaluate(known);
273 if(distortedFocalSamp < 0.5)
return false;
274 if(distortedFocalLine < 0.5)
return false;
276 if(distortedFocalLine > p_undistortedLines + 0.5)
return false;
286 int index = closepts[0];
Generic linear equation class.
CameraDistortionMap(Camera *parent, double zDirection=1.0)
Camera distortion map constructor.
double p_focalPlaneX
Distorted focal plane x.
double p_undistortedFocalPlaneX
Undistorted focal plane x.
double p_undistortedFocalPlaneY
Undistorted focal plane y.
Camera * p_camera
The camera to distort/undistort.
double p_focalPlaneY
Distorted focal plane y.
double PixelPitch() const
Returns the pixel pitch.
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Generic least square fitting class.
double Evaluate(const std::vector< double > &input)
Invokes the BasisFunction Evaluate method.
int Solve(Isis::LeastSquares::SolveMethod method=SVD)
After all the data has been registered through AddKnown, invoke this method to solve the system of eq...
void AddKnown(const std::vector< double > &input, double expected, double weight=1.0)
Invoke this method for each set of knowns.
PvlKeyword & findKeyword(const QString &name)
Find a keyword with a specified name.
Contains multiple PvlContainers.
Container for cube-like labels.
A single keyword-value pair.
int size() const
Returns the number of values stored in this keyword.
@ Traverse
Search child objects.
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
std::vector< double > p_msamps
Master Reseau Locations.
std::vector< double > p_rsamps
Refined Reseau Locations.
double p_undistortedSamps
Dimensions of undistorted cube.
virtual bool SetFocalPlane(const double dx, const double dy)
Finds the undistorted x/y position of the given distorted point.
double p_pixelPitch
Pixel Pitch of parent Camera.
int p_numRes
Number of Reseaus.
ReseauDistortionMap(Camera *parent, Pvl &labels, const QString &fname)
Creates a ReseauDistortionMap object.
virtual bool SetUndistortedFocalPlane(const double ux, const double uy)
Finds the distorted x/y position of the given undistorted point.
double p_distortedSamps
Dimensions of distorted cube.
This class is used to accumulate statistics on double arrays.
void AddData(const double *data, const unsigned int count)
Add an array of doubles to the accumulators and counters.
double StandardDeviation() const
Computes and returns the standard deviation.
This is free and unencumbered software released into the public domain.
double toDouble(const QString &string)
Global function to convert from a string to a double.
Namespace for the standard library.