USGS

Isis 3.0 Object Programmers' Reference

Home

LoCameraFiducialMap.cpp
1 #include "LoCameraFiducialMap.h"
2 
3 #include "Affine.h"
4 #include "CameraGroundMap.h"
5 #include "CameraSkyMap.h"
6 #include "IString.h"
7 
8 using namespace std;
9 
10 namespace Isis {
19  LoCameraFiducialMap::LoCameraFiducialMap(PvlGroup &inst, const int naifIkCode) {
20  // Get the Instrument label information needed to define the fiducial map for this frame
21  p_naifIkCode = naifIkCode;
22  ReadFiducials(inst);
23 
24  // Set the x-axis direction. The medium camera is reversed.
25  int xdir;
26  if(naifIkCode % 2 == 0) {
27  xdir = -1;
28  }
29  else {
30  xdir = 1;
31  }
32  CreateTrans(xdir);
33  }
34 
35 
45  void LoCameraFiducialMap::ReadFiducials(PvlGroup &inst) {
46 
47  // Try to read the fiducials from the labels
48  try {
49  // Fiducial mapping to define the Focal Plane map
50  PvlKeyword &fSamps = inst["FiducialSamples"];
51  PvlKeyword &fLines = inst["FiducialLines"];
52  PvlKeyword &fXs = inst["FiducialXCoordinates"];
53  PvlKeyword &fYs = inst["FiducialYCoordinates"];
54 
55  for(int i = 0; i < fSamps.size(); i++) {
56  p_fidSamples.push_back(toDouble(fSamps[i]));
57  p_fidLines.push_back(toDouble(fLines[i]));
58  p_fidXCoords.push_back(toDouble(fXs[i]));
59  p_fidYCoords.push_back(toDouble(fYs[i]));
60  }
61  }
62  catch(IException &e) {
63  string msg = "Unable to read fiducial mapping from cube labels - ";
64  msg += "Input cube must be processed in Isis 2 through lofixlabel ";
65  msg += "and converted to Isis 3 with pds2isis";
66  throw IException(e, IException::User, msg, _FILEINFO_);
67  }
68  }
69 
70 
78  void LoCameraFiducialMap::CreateTrans(int xdir) {
79  // Setup focal plane map
80  Affine *fptrans = new Affine();
81 
82  try {
83  fptrans->Solve(&p_fidSamples[0], (double *) &p_fidLines[0],
84  (double *) &p_fidXCoords[0], (double *) &p_fidYCoords[0],
85  p_fidSamples.size());
86 
87  }
88  catch(IException &e) {
89  string msg = "Unable to create fiducial map.";
90  throw IException(IException::User, msg, _FILEINFO_);
91  }
92 
93  // Get the coefficients
94  vector<double> transx;
95  vector<double> transy;
96  transx = fptrans->Coefficients(1);
97  transy = fptrans->Coefficients(2);
98 
99  // Medium camera has a reversed x-axis
100  for(int icoef = 0; icoef < 3; icoef++) {
101  transx[icoef] *= xdir;
102  };
103 
104  // Correct the Affine order - move the constant to the front
105  transx.insert(transx.begin(), transx[2]);
106  transx.pop_back();
107  transy.insert(transy.begin(), transy[2]);
108  transy.pop_back();
109 
110  string icode = "INS" + IString(p_naifIkCode);
111  string icodex = icode + "_TRANSX";
112  string icodey = icode + "_TRANSY";
113  pdpool_c(icodex.c_str(), 3, (double( *)) &transx[0]);
114  pdpool_c(icodey.c_str(), 3, (double( *)) &transy[0]);
115 
116  vector<double> transs;
117  vector<double> transl;
118  transs = fptrans->InverseCoefficients(1);
119  transl = fptrans->InverseCoefficients(2);
120 
121  // Correct the Affine order - move the constant to the front
122  transs.insert(transs.begin(), transs[2]);
123  transs.pop_back();
124  transl.insert(transl.begin(), transl[2]);
125  transl.pop_back();
126 
127  // Medium camera has a reversed x-axis
128  transs[1] *= xdir;
129  transl[1] *= xdir;
130 
131  string icodes = icode + "_ITRANSS";
132  string icodel = icode + "_ITRANSL";
133  pdpool_c(icodes.c_str(), 3, (double( *)) &transs[0]);
134  pdpool_c(icodel.c_str(), 3, (double( *)) &transl[0]);
135  }
136 }