Isis 3 Programmer Reference
IdealCamera.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 
8 #include "IdealCamera.h"
9 
10 #include <iomanip>
11 #include <string>
12 
13 #include <QDebug>
14 #include <QString>
15 
16 #include "CameraDistortionMap.h"
17 #include "CameraFocalPlaneMap.h"
18 #include "IException.h"
19 #include "IString.h"
20 #include "iTime.h"
21 #include "LineScanCameraDetectorMap.h"
22 #include "LineScanCameraGroundMap.h"
23 #include "LineScanCameraSkyMap.h"
24 #include "NaifStatus.h"
25 #include "Pvl.h"
26 
27 using namespace std;
28 namespace Isis {
61  IdealCamera::IdealCamera(Cube &cube) : Camera(cube) {
63 
64  // Since this is an ideal camera, we'll call it Ideal Spacecraft
65  m_spacecraftNameLong = "Ideal Spacecraft";
66  m_spacecraftNameShort = "Ideal";
67  m_instrumentNameLong = "Ideal Camera";
68  m_instrumentNameShort = "Ideal";
69 
70  // Get required keywords from instrument group
71  PvlGroup &inst = cube.label()->findGroup("Instrument", Pvl::Traverse);
72 
73  // Setup camera characteristics from instrument
74 
75  if (inst.hasKeyword("FocalLength")) {
76  SetFocalLength(inst["FocalLength"]);
77  }
78  else {
79  SetFocalLength(readValue("IDEAL_FOCAL_LENGTH", SpiceDoubleType).toDouble());
80  }
81 
82  if (inst.hasKeyword("PixelPitch")) {
83  SetPixelPitch(inst["PixelPitch"]);
84  }
85  else {
86  SetPixelPitch(readValue("IDEAL_PIXEL_PITCH", SpiceDoubleType).toDouble());
87  }
88 
89  double et = inst["EphemerisTime"];
90 
91  double exposureDuration = 0.0;
92  if (inst.hasKeyword("ExposureDuration")) {
93  exposureDuration = ((double) inst["ExposureDuration"]) / 1000.0;
94  }
95 
96  double sampleDetectors = inst["SampleDetectors"];
97  double lineDetectors = inst["LineDetectors"];
98 
99  // These variables are used for maintaining compatibility with older versions of the
100  // ideal camera (noproj before it modified the naif keywords group) and for cubes without the
101  // naif keywords group at all.
102  int xDependency = inst["FocalPlaneXDependency"];
103  int yDependency = CameraFocalPlaneMap::Line;
104  // Pixel direction
105  double xdir = 1.0;
106  double ydir = 1.0;
107  double sdir = xdir;
108  double ldir = ydir;
109 
110  if (inst.hasKeyword("TransX")) xdir = inst["TransX"];
111  if (inst.hasKeyword("TransY")) ydir = inst["TransY"];
112 
113  if (xDependency == CameraFocalPlaneMap::Line) {
114  yDependency = CameraFocalPlaneMap::Sample;
115  sdir = ydir;
116  ldir = xdir;
117  }
118 
119  // Put the translation coefficients into the Naif kernel pool so the
120  // CameraFocalPlaneClass can find them
121  try {
122  readValue("IDEAL_TRANSX", SpiceDoubleType);
123  }
124  catch (IException &) {
125  double keyval[3];
126  keyval[0] = 0.;
127  if (inst.hasKeyword("TransX0")) {
128  keyval[0] = inst["TransX0"];
129  }
130 
131  keyval[xDependency] = PixelPitch() * xdir;
132  keyval[yDependency] = 0.;
133 
134  storeValue("IDEAL_TRANSX", 0, SpiceDoubleType, keyval[0]);
135  storeValue("IDEAL_TRANSX", 1, SpiceDoubleType, keyval[1]);
136  storeValue("IDEAL_TRANSX", 2, SpiceDoubleType, keyval[2]);
137  pdpool_c("IDEAL_TRANSX", 3, keyval);
138  }
139 
140  try {
141  readValue("IDEAL_TRANSY", SpiceDoubleType);
142  }
143  catch (IException &) {
144  double keyval[3];
145  keyval[0] = 0.;
146  if (inst.hasKeyword("TransY0")) {
147  keyval[0] = inst["TransY0"];
148  }
149 
150  keyval[yDependency] = PixelPitch() * ydir;
151  keyval[xDependency] = 0.;
152 
153  storeValue("IDEAL_TRANSY", 0, SpiceDoubleType, keyval[0]);
154  storeValue("IDEAL_TRANSY", 1, SpiceDoubleType, keyval[1]);
155  storeValue("IDEAL_TRANSY", 2, SpiceDoubleType, keyval[2]);
156  pdpool_c("IDEAL_TRANSY", 3, keyval);
157  }
158 
159  try {
160  readValue("IDEAL_TRANSS", SpiceDoubleType);
161  }
162  catch (IException &) {
163  double keyval[3];
164  keyval[0] = 0.;
165  if (inst.hasKeyword("TransS0")) {
166  keyval[0] = inst["TransS0"];
167  }
168 
169  keyval[xDependency] = 1 / PixelPitch() * sdir;
170  keyval[yDependency] = 0.;
171 
172  storeValue("IDEAL_TRANSS", 0, SpiceDoubleType, keyval[0]);
173  storeValue("IDEAL_TRANSS", 1, SpiceDoubleType, keyval[1]);
174  storeValue("IDEAL_TRANSS", 2, SpiceDoubleType, keyval[2]);
175  pdpool_c("IDEAL_TRANSS", 3, keyval);
176  }
177 
178  try {
179  readValue("IDEAL_TRANSL", SpiceDoubleType);
180  }
181  catch (IException &) {
182  double keyval[3];
183  keyval[0] = 0.;
184  if (inst.hasKeyword("TransL0")) {
185  keyval[0] = inst["TransL0"];
186  }
187 
188  keyval[yDependency] = 1 / PixelPitch() * ldir;
189  keyval[xDependency] = 0.0;
190 
191  storeValue("IDEAL_TRANSL", 0, SpiceDoubleType, keyval[0]);
192  storeValue("IDEAL_TRANSL", 1, SpiceDoubleType, keyval[1]);
193  storeValue("IDEAL_TRANSL", 2, SpiceDoubleType, keyval[2]);
194  pdpool_c("IDEAL_TRANSL", 3, keyval);
195  }
196 
197  // Create correct camera type
198  QString type = (QString) inst["InstrumentType"];
199  if (type.toUpper() == "FRAMING") {
200  p_framing = true;
201  new CameraDetectorMap(this);
202  CameraFocalPlaneMap *fmap = new CameraFocalPlaneMap(this, 0);
203  fmap->SetDetectorOrigin(sampleDetectors / 2.0 + 0.5,
204  lineDetectors / 2.0 + 0.5);
205  new CameraDistortionMap(this);
206  new CameraGroundMap(this);
207  new CameraSkyMap(this);
208 
209  setTime(et);
210  LoadCache();
211  }
212  else if (type.toUpper() == "LINESCAN") {
213  p_framing = false;
215  CameraFocalPlaneMap *fmap = new CameraFocalPlaneMap(this, 0);
216  fmap->SetDetectorOrigin(sampleDetectors / 2.0 + 0.5,
217  0.0);
218  new CameraDistortionMap(this);
219  new LineScanCameraGroundMap(this);
220  new LineScanCameraSkyMap(this);
221 
222  LoadCache();
224  }
225  else {
226  QString msg = "Unknown InstrumentType [" +
227  (QString) inst["InstrumentType"] + "]";
228  throw IException(IException::User, msg, _FILEINFO_);
229  }
230  }
231 
232 
235 
236 
244  string msg = "No CK Frame ID for Ideal Camera class";
245  throw IException(IException::User, msg, _FILEINFO_);
246  }
247 
248 
256  string msg = "No CK Reference ID for Ideal Camera class";
257  throw IException(IException::User, msg, _FILEINFO_);
258  }
259 
260 
268  string msg = "No SPK Target ID for Ideal Camera class";
269  throw IException(IException::User, msg, _FILEINFO_);
270  }
271 
272 
280  string msg = "No SPK Center ID for Ideal Camera class";
281  throw IException(IException::User, msg, _FILEINFO_);
282  }
283 
284 
292  string msg = "No SPK Reference ID for Ideal Camera class";
293  throw IException(IException::User, msg, _FILEINFO_);
294  }
295 
296 
303  return m_instrumentNameLong;
304  }
305 
306 
313  return m_instrumentNameShort;
314  }
315 
316 
323  return m_spacecraftNameLong;
324  }
325 
326 
333  return m_spacecraftNameShort;
334  }
335 }
336 
337 
347 extern "C" Isis::Camera *IdealCameraPlugin(Isis::Cube &cube) {
348  return new Isis::IdealCamera(cube);
349 }
Isis::IdealCamera::instrumentNameShort
virtual QString instrumentNameShort() const
This method returns the shortened instrument name.
Definition: IdealCamera.cpp:312
Isis::LineScanCameraSkyMap
Convert between undistorted focal plane and ra/dec coordinates.
Definition: LineScanCameraSkyMap.h:34
Isis::CameraFocalPlaneMap::SetDetectorOrigin
void SetDetectorOrigin(const double sample, const double line)
Set the detector origin.
Definition: CameraFocalPlaneMap.cpp:293
Isis::Camera::exposureDuration
virtual double exposureDuration() const
Return the exposure duration for the pixel that the camera is set to.
Definition: Camera.cpp:3063
Isis::PvlObject::findGroup
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:129
Isis::IdealCamera::spacecraftNameShort
virtual QString spacecraftNameShort() const
This method returns the shortened spacecraft name.
Definition: IdealCamera.cpp:332
Isis::CameraDetectorMap
Convert between parent image coordinates and detector coordinates.
Definition: CameraDetectorMap.h:47
Isis::IdealCamera::m_instrumentNameShort
QString m_instrumentNameShort
Shortened instrument name.
Definition: IdealCamera.h:89
Isis::IdealCamera::spacecraftNameLong
virtual QString spacecraftNameLong() const
This method returns the full spacecraft name.
Definition: IdealCamera.cpp:322
Isis::IdealCamera::SpkReferenceId
virtual int SpkReferenceId() const
SPK Reference ID.
Definition: IdealCamera.cpp:291
Isis::PvlContainer::hasKeyword
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Definition: PvlContainer.cpp:159
Isis::NaifStatus::CheckErrors
static void CheckErrors(bool resetNaif=true)
This method looks for any naif errors that might have occurred.
Definition: NaifStatus.cpp:28
Isis::Camera
Definition: Camera.h:236
Isis::Spice::SpiceDoubleType
@ SpiceDoubleType
SpiceDouble type.
Definition: Spice.h:349
Isis::IdealCamera
Ideal Camera Model.
Definition: IdealCamera.h:58
Isis::CameraGroundMap
Convert between undistorted focal plane and ground coordinates.
Definition: CameraGroundMap.h:73
Isis::PvlObject::Traverse
@ Traverse
Search child objects.
Definition: PvlObject.h:158
Isis::IdealCamera::m_instrumentNameLong
QString m_instrumentNameLong
Full instrument name.
Definition: IdealCamera.h:88
Isis::IdealCamera::CkReferenceId
virtual int CkReferenceId() const
CK Reference ID.
Definition: IdealCamera.cpp:255
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::Camera::SetPixelPitch
void SetPixelPitch()
Reads the Pixel Pitch from the instrument kernel.
Definition: Camera.cpp:1418
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Isis::IdealCamera::m_spacecraftNameLong
QString m_spacecraftNameLong
Full spacecraft name.
Definition: IdealCamera.h:90
Isis::CameraFocalPlaneMap::Line
@ Line
The x value of the focal plane maps to a line.
Definition: CameraFocalPlaneMap.h:125
Isis::LineScanCameraGroundMap
Convert between undistorted focal plane and ground coordinates.
Definition: LineScanCameraGroundMap.h:49
Isis::IdealCamera::instrumentNameLong
virtual QString instrumentNameLong() const
This method returns the full instrument name.
Definition: IdealCamera.cpp:302
Isis::CameraDistortionMap
Distort/undistort focal plane coordinates.
Definition: CameraDistortionMap.h:41
Isis::Cube
IO Handler for Isis Cubes.
Definition: Cube.h:167
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::IdealCamera::CkFrameId
virtual int CkFrameId() const
CK frame ID.
Definition: IdealCamera.cpp:243
Isis::IdealCamera::SpkCenterId
virtual int SpkCenterId() const
SPK Center ID.
Definition: IdealCamera.cpp:279
Isis::CameraFocalPlaneMap::Sample
@ Sample
The x value of the focal plane maps to a sample.
Definition: CameraFocalPlaneMap.h:124
Isis::toDouble
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition: IString.cpp:149
std
Namespace for the standard library.
Isis::Camera::LoadCache
void LoadCache()
This loads the spice cache big enough for this image.
Definition: Camera.cpp:2420
Isis::IdealCamera::~IdealCamera
~IdealCamera()
Destroys the IdealCamera object.
Definition: IdealCamera.cpp:234
Isis::CameraFocalPlaneMap
Convert between distorted focal plane and detector coordinates.
Definition: CameraFocalPlaneMap.h:85
Isis::Camera::PixelPitch
double PixelPitch() const
Returns the pixel pitch.
Definition: Camera.cpp:2742
Isis::Cube::label
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
Definition: Cube.cpp:1701
Isis::CameraSkyMap
Convert between undistorted focal plane and ra/dec coordinates.
Definition: CameraSkyMap.h:31
Isis::IdealCamera::p_framing
bool p_framing
true if framing camera
Definition: IdealCamera.h:87
Isis::IdealCamera::SpkTargetId
virtual int SpkTargetId() const
SPK Target ID.
Definition: IdealCamera.cpp:267
Isis::Spice::readValue
QVariant readValue(QString key, SpiceValueType type, int index=0)
This should be used for reading ALL text naif kernel values.
Definition: Spice.cpp:1093
Isis::Camera::SetFocalLength
void SetFocalLength()
Reads the focal length from the instrument kernel.
Definition: Camera.cpp:1411
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::LineScanCameraDetectorMap
Convert between parent image coordinates and detector coordinates.
Definition: LineScanCameraDetectorMap.h:37
Isis::IException::User
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition: IException.h:126
Isis::IdealCamera::m_spacecraftNameShort
QString m_spacecraftNameShort
Shortened spacecraft name.
Definition: IdealCamera.h:91