USGS

Isis 3.0 Object Programmers' Reference

Home

IdealCamera.cpp
Go to the documentation of this file.
1 
23 #include "IdealCamera.h"
24 
25 #include <iomanip>
26 #include <string>
27 
28 #include <QDebug>
29 #include <QString>
30 
31 #include "CameraDistortionMap.h"
32 #include "CameraFocalPlaneMap.h"
33 #include "IException.h"
34 #include "IString.h"
35 #include "iTime.h"
38 #include "LineScanCameraSkyMap.h"
39 #include "NaifStatus.h"
40 #include "Pvl.h"
41 
42 using namespace std;
43 namespace Isis {
76  IdealCamera::IdealCamera(Cube &cube) : Camera(cube) {
78 
79  // Since this is an ideal camera, we'll call it Ideal Spacecraft
80  m_spacecraftNameLong = "Ideal Spacecraft";
81  m_spacecraftNameShort = "Ideal";
82  m_instrumentNameLong = "Ideal Camera";
83  m_instrumentNameShort = "Ideal";
84 
85  // Get required keywords from instrument group
86  PvlGroup &inst = cube.label()->findGroup("Instrument", Pvl::Traverse);
87 
88  // Setup camera characteristics from instrument
89 
90  if (inst.hasKeyword("FocalLength")) {
91  SetFocalLength(inst["FocalLength"]);
92  }
93  else {
94  SetFocalLength(readValue("IDEAL_FOCAL_LENGTH", SpiceDoubleType).toDouble());
95  }
96 
97  if (inst.hasKeyword("PixelPitch")) {
98  SetPixelPitch(inst["PixelPitch"]);
99  }
100  else {
101  SetPixelPitch(readValue("IDEAL_PIXEL_PITCH", SpiceDoubleType).toDouble());
102  }
103 
104  double et = inst["EphemerisTime"];
105 
106  double exposureDuration = 0.0;
107  if (inst.hasKeyword("ExposureDuration")) {
108  exposureDuration = ((double) inst["ExposureDuration"]) / 1000.0;
109  }
110 
111  double sampleDetectors = inst["SampleDetectors"];
112  double lineDetectors = inst["LineDetectors"];
113 
114  // These variables are used for maintaining compatibility with older versions of the
115  // ideal camera (noproj before it modified the naif keywords group) and for cubes without the
116  // naif keywords group at all.
117  int xDependency = inst["FocalPlaneXDependency"];
118  int yDependency = CameraFocalPlaneMap::Line;
119  // Pixel direction
120  double xdir = 1.0;
121  double ydir = 1.0;
122  double sdir = xdir;
123  double ldir = ydir;
124 
125  if (inst.hasKeyword("TransX")) xdir = inst["TransX"];
126  if (inst.hasKeyword("TransY")) ydir = inst["TransY"];
127 
128  if (xDependency == CameraFocalPlaneMap::Line) {
129  yDependency = CameraFocalPlaneMap::Sample;
130  sdir = ydir;
131  ldir = xdir;
132  }
133 
134  // Put the translation coefficients into the Naif kernel pool so the
135  // CameraFocalPlaneClass can find them
136  try {
137  readValue("IDEAL_TRANSX", SpiceDoubleType);
138  }
139  catch (IException &) {
140  double keyval[3];
141  keyval[0] = 0.;
142  if (inst.hasKeyword("TransX0")) {
143  keyval[0] = inst["TransX0"];
144  }
145 
146  keyval[xDependency] = PixelPitch() * xdir;
147  keyval[yDependency] = 0.;
148 
149  storeValue("IDEAL_TRANSX", 0, SpiceDoubleType, keyval[0]);
150  storeValue("IDEAL_TRANSX", 1, SpiceDoubleType, keyval[1]);
151  storeValue("IDEAL_TRANSX", 2, SpiceDoubleType, keyval[2]);
152  pdpool_c("IDEAL_TRANSX", 3, keyval);
153  }
154 
155  try {
156  readValue("IDEAL_TRANSY", SpiceDoubleType);
157  }
158  catch (IException &) {
159  double keyval[3];
160  keyval[0] = 0.;
161  if (inst.hasKeyword("TransY0")) {
162  keyval[0] = inst["TransY0"];
163  }
164 
165  keyval[yDependency] = PixelPitch() * ydir;
166  keyval[xDependency] = 0.;
167 
168  storeValue("IDEAL_TRANSY", 0, SpiceDoubleType, keyval[0]);
169  storeValue("IDEAL_TRANSY", 1, SpiceDoubleType, keyval[1]);
170  storeValue("IDEAL_TRANSY", 2, SpiceDoubleType, keyval[2]);
171  pdpool_c("IDEAL_TRANSY", 3, keyval);
172  }
173 
174  try {
175  readValue("IDEAL_TRANSS", SpiceDoubleType);
176  }
177  catch (IException &) {
178  double keyval[3];
179  keyval[0] = 0.;
180  if (inst.hasKeyword("TransS0")) {
181  keyval[0] = inst["TransS0"];
182  }
183 
184  keyval[xDependency] = 1 / PixelPitch() * sdir;
185  keyval[yDependency] = 0.;
186 
187  storeValue("IDEAL_TRANSS", 0, SpiceDoubleType, keyval[0]);
188  storeValue("IDEAL_TRANSS", 1, SpiceDoubleType, keyval[1]);
189  storeValue("IDEAL_TRANSS", 2, SpiceDoubleType, keyval[2]);
190  pdpool_c("IDEAL_TRANSS", 3, keyval);
191  }
192 
193  try {
194  readValue("IDEAL_TRANSL", SpiceDoubleType);
195  }
196  catch (IException &) {
197  double keyval[3];
198  keyval[0] = 0.;
199  if (inst.hasKeyword("TransL0")) {
200  keyval[0] = inst["TransL0"];
201  }
202 
203  keyval[yDependency] = 1 / PixelPitch() * ldir;
204  keyval[xDependency] = 0.0;
205 
206  storeValue("IDEAL_TRANSL", 0, SpiceDoubleType, keyval[0]);
207  storeValue("IDEAL_TRANSL", 1, SpiceDoubleType, keyval[1]);
208  storeValue("IDEAL_TRANSL", 2, SpiceDoubleType, keyval[2]);
209  pdpool_c("IDEAL_TRANSL", 3, keyval);
210  }
211 
212  // Create correct camera type
213  QString type = (QString) inst["InstrumentType"];
214  if (type.toUpper() == "FRAMING") {
215  p_framing = true;
216  new CameraDetectorMap(this);
217  CameraFocalPlaneMap *fmap = new CameraFocalPlaneMap(this, 0);
218  fmap->SetDetectorOrigin(sampleDetectors / 2.0 + 0.5,
219  lineDetectors / 2.0 + 0.5);
220  new CameraDistortionMap(this);
221  new CameraGroundMap(this);
222  new CameraSkyMap(this);
223 
224  setTime(et);
225  LoadCache();
226  }
227  else if (type.toUpper() == "LINESCAN") {
228  p_framing = false;
229  new LineScanCameraDetectorMap(this, et, exposureDuration);
230  CameraFocalPlaneMap *fmap = new CameraFocalPlaneMap(this, 0);
231  fmap->SetDetectorOrigin(sampleDetectors / 2.0 + 0.5,
232  0.0);
233  new CameraDistortionMap(this);
234  new LineScanCameraGroundMap(this);
235  new LineScanCameraSkyMap(this);
236 
237  LoadCache();
239  }
240  else {
241  QString msg = "Unknown InstrumentType [" +
242  (QString) inst["InstrumentType"] + "]";
244  }
245  }
246 
247 
250 
251 
259  string msg = "No CK Frame ID for Ideal Camera class";
261  }
262 
263 
271  string msg = "No CK Reference ID for Ideal Camera class";
273  }
274 
275 
283  string msg = "No SPK Target ID for Ideal Camera class";
285  }
286 
287 
295  string msg = "No SPK Center ID for Ideal Camera class";
297  }
298 
299 
307  string msg = "No SPK Reference ID for Ideal Camera class";
309  }
310 
311 
318  return m_instrumentNameLong;
319  }
320 
321 
328  return m_instrumentNameShort;
329  }
330 
331 
338  return m_spacecraftNameLong;
339  }
340 
341 
348  return m_spacecraftNameShort;
349  }
350 }
351 
352 
363  return new Isis::IdealCamera(cube);
364 }