7#include "ReseauDistortionMap.h" 
    8#include "LeastSquares.h" 
    9#include "BasisFunction.h" 
   10#include "CameraFocalPlaneMap.h" 
   12#include "Statistics.h" 
   32    PvlGroup dim = mast.findGroup(
"Dimensions");
 
   33    p_distortedLines = dim.findKeyword(
"DistortedLines");
 
   35    p_undistortedLines = dim.findKeyword(
"UndistortedLines");
 
   37    PvlGroup mastRes = mast.findGroup(
"MasterReseaus");
 
   38    PvlKeyword mline = mastRes.findKeyword(
"Line");
 
   39    PvlKeyword msamp = mastRes.findKeyword(
"Sample");
 
   41    if(mline.size() != msamp.size()) {
 
   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]));
 
   54    PvlKeyword rsamp = refRes.findKeyword(
"Sample");
 
   55    if(rline.size() != rsamp.size()) {
 
   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";
 
 
   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]];
 
  119    lstats.AddData(line, 5);
 
  120    sstats.AddData(samp, 5);
 
  123    if(lstats.StandardDeviation() < 10.0 || sstats.StandardDeviation() < 10.0) {
 
  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]];
 
  231    lstats.AddData(line, 5);
 
  232    sstats.AddData(samp, 5);
 
  234    if(lstats.StandardDeviation() < 10.0 || sstats.StandardDeviation() < 10.0) {
 
  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.
 
Distort/undistort focal plane coordinates.
 
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 DetectorSampleOrigin() const
 
double DetectorLineOrigin() const
 
double PixelPitch() const
Returns the pixel pitch.
 
CameraFocalPlaneMap * FocalPlaneMap()
Returns a pointer to the CameraFocalPlaneMap object.
 
@ 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.
 
Contains multiple PvlContainers.
 
Container for cube-like labels.
 
A single keyword-value pair.
 
@ Traverse
Search child objects.
 
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.
 
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.