Isis 3 Programmer Reference
MarciCamera.cpp
1
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include <iomanip>
10
11#include "MarciCamera.h"
12#include "MarciDistortionMap.h"
13
14#include <QString>
15
16#include "CameraFocalPlaneMap.h"
17#include "CameraSkyMap.h"
18#include "IException.h"
19#include "iTime.h"
20#include "NaifStatus.h"
21#include "PushFrameCameraDetectorMap.h"
22#include "PushFrameCameraGroundMap.h"
23
24using namespace std;
25namespace Isis {
26
38 m_instrumentNameLong = "Mars Color Imager";
39 m_instrumentNameShort = "MARCI";
40 m_spacecraftNameLong = "Mars Reconnaissance Orbiter";
42
44 Pvl &lab = *cube.label();
45 PvlGroup &inst = lab.findGroup("Instrument", Pvl::Traverse);
46 // make sure it is a marci image
47 if(inst["InstrumentId"][0] != "Marci") {
48 string msg = "The image does not appear to be a Marci Image";
49 throw IException(IException::User, msg, _FILEINFO_);
50 }
51
52 // Set up the camera characteristics
54
55 QString pixelPitchKey = "INS" + toString(naifIkCode()) + "_PIXEL_SIZE";
56 SetPixelPitch(getDouble(pixelPitchKey));
57
58 // Get necessary variables
59 p_exposureDur = inst["ExposureDuration"];
60 p_interframeDelay = inst["InterframeDelay"];
61 int sumMode = inst["SummingMode"];
62
63 // Get the start and end time
64 double et;
65 QString stime = inst["SpacecraftClockCount"];
66 et = getClockTime(stime).Et();
67 p_etStart = et - ((p_exposureDur / 1000.0) / 2.0);
68 p_nframelets = (int) (ParentLines() / sumMode);
69
70 // These numbers came from "MARCI_CTX_Cal_Report_v1.5.pdf" page 7 (Bandpasses & downlinked detector rows)
71 map<QString, int> filterToDetectorOffset;
72 filterToDetectorOffset.insert(pair<QString, int>("BLUE", 709));
73 filterToDetectorOffset.insert(pair<QString, int>("GREEN", 734));
74 filterToDetectorOffset.insert(pair<QString, int>("ORANGE", 760));
75 filterToDetectorOffset.insert(pair<QString, int>("RED", 786));
76 filterToDetectorOffset.insert(pair<QString, int>("NIR", 811));
77 filterToDetectorOffset.insert(pair<QString, int>("LONG_UV", 266));
78 filterToDetectorOffset.insert(pair<QString, int>("SHORT_UV", 293));
79
80 map<QString, int> filterToFilterNumbers;
81 filterToFilterNumbers.insert(pair<QString, int>("BLUE", 0));
82 filterToFilterNumbers.insert(pair<QString, int>("GREEN", 1));
83 filterToFilterNumbers.insert(pair<QString, int>("ORANGE", 2));
84 filterToFilterNumbers.insert(pair<QString, int>("RED", 3));
85 filterToFilterNumbers.insert(pair<QString, int>("NIR", 4));
86 filterToFilterNumbers.insert(pair<QString, int>("LONG_UV", 5));
87 filterToFilterNumbers.insert(pair<QString, int>("SHORT_UV", 6));
88
89 int frameletOffsetFactor = inst["ColorOffset"];
90
91 if((int)inst["DataFlipped"] != 0) frameletOffsetFactor *= -1;
92 map<QString, int> filterToFrameletOffset;
93 filterToFrameletOffset.insert(pair<QString, int>("NIR", 0 * frameletOffsetFactor));
94 filterToFrameletOffset.insert(pair<QString, int>("RED", 1 * frameletOffsetFactor));
95 filterToFrameletOffset.insert(pair<QString, int>("ORANGE", 2 * frameletOffsetFactor));
96 filterToFrameletOffset.insert(pair<QString, int>("GREEN", 3 * frameletOffsetFactor));
97 filterToFrameletOffset.insert(pair<QString, int>("BLUE", 4 * frameletOffsetFactor));
98 filterToFrameletOffset.insert(pair<QString, int>("LONG_UV", 5 * frameletOffsetFactor));
99 filterToFrameletOffset.insert(pair<QString, int>("SHORT_UV", 6 * frameletOffsetFactor));
100
101 // Get the keywords from labels
102 const PvlGroup &bandBin = lab.findGroup("BandBin", Pvl::Traverse);
103 const PvlKeyword &filtNames = bandBin["FilterName"];
104
105 for(int i = 0; i < filtNames.size(); i++) {
106 if(filterToDetectorOffset.find(filtNames[i]) == filterToDetectorOffset.end()) {
107 QString msg = "Unrecognized filter name [" + filtNames[i] + "]";
108 throw IException(IException::Programmer, msg, _FILEINFO_);
109 }
110
111 p_detectorStartLines.push_back(filterToDetectorOffset.find(filtNames[i])->second);
112 p_filterNumbers.push_back(filterToFilterNumbers.find(filtNames[i])->second);
113 p_frameletOffsets.push_back(filterToFrameletOffset.find(filtNames[i])->second);
114 }
115
116 // Setup detector map
117 double frameletRate = p_interframeDelay;
119 new PushFrameCameraDetectorMap(this, p_etStart, frameletRate, 16);
120 dmap->SetDetectorSampleSumming(sumMode);
121 dmap->SetDetectorLineSumming(sumMode);
122 dmap->SetFrameletsGeometricallyFlipped(false);
123
124 int numFramelets = ParentLines() / (16 / sumMode);
125 bool flippedFramelets = (int)inst["DataFlipped"] != 0;
126 dmap->SetFrameletOrderReversed(flippedFramelets, numFramelets);
127
128 // Setup focal plane map
129 new CameraFocalPlaneMap(this, -74400);
130
131 if ((int) naifIkCode() == -74410) {
132 // The line detector origin is in the middle of the orange framelet
133 FocalPlaneMap()->SetDetectorOrigin(512.5, 760.0 + 8.5);
134 }
135 else if ((int) naifIkCode() == -74420) {
136 FocalPlaneMap()->SetDetectorOrigin(512.5, 288.5);
137 }
138 else {
139 string msg = "Unrecognized NaifIkCode [" + IString((int) naifIkCode()) + "]";
140 throw IException(IException::Programmer, msg, _FILEINFO_);
141 }
142
143 // Setup distortion map
144 new MarciDistortionMap(this, naifIkCode());
145
146 // Setup the ground and sky map
147 bool evenFramelets = (inst["Framelets"][0] == "Even");
148 new PushFrameCameraGroundMap(this, evenFramelets);
149 new CameraSkyMap(this);
150 LoadCache();
152
153 if(sumMode == 1) {
155 }
156 else if(sumMode == 2) {
158 }
159 else if(sumMode == 4) {
161 }
162 else {
164 }
165 }
166
167
168
172
173
174
180 void MarciCamera::SetBand(const int vband) {
181 // Sanity check on requested band
182 int maxVirtualBands = min(p_detectorStartLines.size(), p_frameletOffsets.size());
183
184 if (((vband <= 0) || (vband > maxVirtualBands)) && (vband > Bands())) {
185 ostringstream mess;
186 mess << "Requested virtual band (" << vband
187 << ") outside valid (BandBin/Center) limits (1 - " << maxVirtualBands
188 << ")";
189 throw IException(IException::Programmer, mess.str(), _FILEINFO_);
190 }
191
192 Camera::SetBand(vband);
193
194 if ((vband > maxVirtualBands) && (vband <= Bands())) {
195 // probably switching to a band from phocube or similar
196 // instead of a different filter band, so just re-use the
197 // properties from the current band.
198 return;
199 }
200
202 dmap->SetBandFirstDetectorLine(p_detectorStartLines.at(vband-1));
203 dmap->SetFrameletOffset(p_frameletOffsets.at(vband-1));
204
206 distmap->SetFilter(p_filterNumbers.at(vband-1));
207
208 }
209
210
211
218 return false;
219 }
220
221
222
230 return (-74000);
231 }
232
233
234
242 return (-74900);
243 }
244
245
246
254 return (1);
255 }
256}
257
258
268extern "C" Isis::Camera *MarciCameraPlugin(Isis::Cube &cube) {
269 return new Isis::MarciCamera(cube);
270}
Convert between distorted focal plane and detector coordinates.
void SetDetectorOrigin(const double sample, const double line)
Set the detector origin.
QString m_spacecraftNameLong
Full spacecraft name.
Definition Camera.h:499
int ParentLines() const
Returns the number of lines in the parent alphacube.
Definition Camera.cpp:2836
void SetGeometricTilingHint(int startSize=128, int endSize=8)
This method sets the best geometric tiling size for projecting from this camera model.
Definition Camera.cpp:2584
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
QString m_instrumentNameShort
Shortened instrument name.
Definition Camera.h:498
CameraDistortionMap * DistortionMap()
Returns a pointer to the CameraDistortionMap object.
Definition Camera.cpp:2856
QString m_spacecraftNameShort
Shortened spacecraft name.
Definition Camera.h:500
CameraFocalPlaneMap * FocalPlaneMap()
Returns a pointer to the CameraFocalPlaneMap object.
Definition Camera.cpp:2866
virtual void SetBand(const int band)
Virtual method that sets the band number.
Definition Camera.cpp:2710
QString m_instrumentNameLong
Full instrument name.
Definition Camera.h:497
int Bands() const
Returns the number of bands in the image.
Definition Camera.cpp:2826
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
@ Programmer
This error is for when a programmer made an API call that was illegal.
Definition IException.h:146
Adds specific functionality to C++ strings.
Definition IString.h:165
Marci Camera Model.
Definition MarciCamera.h:51
virtual int CkFrameId() const
CK frame ID - - Instrument Code from spacit run on CK.
int p_nframelets
Number of framelets in whole image.
Definition MarciCamera.h:73
double p_interframeDelay
Interframe Delay value from labels.
Definition MarciCamera.h:72
double p_etStart
Ephemeris Start iTime.
Definition MarciCamera.h:69
void SetBand(const int band)
Sets the band in the camera model.
virtual int CkReferenceId() const
CK Reference ID - MRO_MME_OF_DATE.
virtual int SpkReferenceId() const
SPK Reference ID - J2000.
MarciCamera(Cube &cube)
Constructor for the Marci Camera Model.
~MarciCamera()
Destroys the Themis Vis Camera object.
bool IsBandIndependent()
The camera model is band dependent, so this method returns false.
double p_exposureDur
Exposure Duration value from labels.
Definition MarciCamera.h:71
Distort/undistort focal plane coordinates.
static void CheckErrors(bool resetNaif=true)
This method looks for any naif errors that might have occurred.
Convert between parent image coordinates and detector coordinates.
void SetBandFirstDetectorLine(int firstLine)
Change the starting line in the detector based on band.
Convert between undistorted focal plane and ground coordinates.
Generic class for Push Frame Cameras.
PushFrameCameraDetectorMap * DetectorMap()
Returns a pointer to the PushFrameCameraDetectorMap object.
Contains multiple PvlContainers.
Definition PvlGroup.h:41
Container for cube-like labels.
Definition Pvl.h:119
A single keyword-value pair.
Definition PvlKeyword.h:87
@ Traverse
Search child objects.
Definition PvlObject.h:158
virtual iTime getClockTime(QString clockValue, int sclkCode=-1, bool clockTicks=false)
This converts the spacecraft clock ticks value (clockValue) to an iTime.
Definition Spice.cpp:1060
SpiceInt naifIkCode() const
This returns the NAIF IK code to use when reading from instrument kernels.
Definition Spice.cpp:975
SpiceDouble getDouble(const QString &key, int index=0)
This returns a value from the NAIF text pool.
Definition Spice.cpp:1046
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
QString toString(bool boolToConvert)
Global function to convert a boolean to a string.
Definition IString.cpp:211
Namespace for the standard library.