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
27using namespace std;
28namespace Isis {
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
304 }
305
306
314 }
315
316
324 }
325
326
334 }
335}
336
337
347extern "C" Isis::Camera *IdealCameraPlugin(Isis::Cube &cube) {
348 return new Isis::IdealCamera(cube);
349}
Convert between parent image coordinates and detector coordinates.
Distort/undistort focal plane coordinates.
Convert between distorted focal plane and detector coordinates.
@ Line
The x value of the focal plane maps to a line.
@ Sample
The x value of the focal plane maps to a sample.
Convert between undistorted focal plane and ground coordinates.
virtual double exposureDuration() const
Return the exposure duration for the pixel that the camera is set to.
Definition Camera.cpp:3093
double PixelPitch() const
Returns the pixel pitch.
Definition Camera.cpp:2772
void SetFocalLength()
Reads the focal length from the instrument kernel.
Definition Camera.cpp:1422
void SetPixelPitch()
Reads the Pixel Pitch from the instrument kernel.
Definition Camera.cpp:1429
void LoadCache()
This loads the spice cache big enough for this image.
Definition Camera.cpp:2450
Convert between undistorted focal plane and ra/dec coordinates.
IO Handler for Isis Cubes.
Definition Cube.h:168
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
Definition Cube.cpp:1707
Isis exception class.
Definition IException.h:91
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition IException.h:126
Ideal Camera Model.
Definition IdealCamera.h:58
virtual QString instrumentNameShort() const
This method returns the shortened instrument name.
virtual int CkFrameId() const
CK frame ID.
virtual int SpkReferenceId() const
SPK Reference ID.
virtual QString spacecraftNameLong() const
This method returns the full spacecraft name.
virtual int SpkTargetId() const
SPK Target ID.
virtual int CkReferenceId() const
CK Reference ID.
virtual int SpkCenterId() const
SPK Center ID.
QString m_instrumentNameShort
Shortened instrument name.
Definition IdealCamera.h:89
QString m_spacecraftNameLong
Full spacecraft name.
Definition IdealCamera.h:90
~IdealCamera()
Destroys the IdealCamera object.
QString m_spacecraftNameShort
Shortened spacecraft name.
Definition IdealCamera.h:91
IdealCamera(Cube &cube)
Creates a generic camera model.
virtual QString spacecraftNameShort() const
This method returns the shortened spacecraft name.
QString m_instrumentNameLong
Full instrument name.
Definition IdealCamera.h:88
virtual QString instrumentNameLong() const
This method returns the full instrument name.
bool p_framing
true if framing camera
Definition IdealCamera.h:87
Convert between parent image coordinates and detector coordinates.
Convert between undistorted focal plane and ground coordinates.
Convert between undistorted focal plane and ra/dec coordinates.
static void CheckErrors(bool resetNaif=true)
This method looks for any naif errors that might have occurred.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
@ Traverse
Search child objects.
Definition PvlObject.h:158
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition PvlObject.h:129
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:99
QVariant readValue(QString key, SpiceValueType type, int index=0)
This should be used for reading ALL text naif kernel values.
Definition Spice.cpp:1100
@ SpiceDoubleType
SpiceDouble type.
Definition Spice.h:349
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
double toDouble(const QString &string)
Global function to convert from a string to a double.
Definition IString.cpp:149
Namespace for the standard library.