Isis 3.0 Programmer Reference
Back | Home
CameraFactory.cpp
Go to the documentation of this file.
1 
23 #include "CameraFactory.h"
24 
25 #include "Camera.h"
26 #include "Plugin.h"
27 #include "IException.h"
28 #include "FileName.h"
29 
30 using namespace std;
31 
32 namespace Isis {
33  Plugin CameraFactory::m_cameraPlugin;
34 
44  Camera *CameraFactory::Create(Cube &cube) {
45  // Try to load a plugin file in the current working directory and then
46  // load the system file
47  initPlugin();
48 
49  try {
50  // First get the spacecraft and instrument and combine them
51  Pvl &lab = *cube.label();
52  PvlGroup &inst = lab.findGroup("Instrument", Isis::Pvl::Traverse);
53  QString spacecraft = (QString) inst["SpacecraftName"];
54  QString name = (QString) inst["InstrumentId"];
55  spacecraft = spacecraft.toUpper();
56  name = name.toUpper();
57  QString group = spacecraft + "/" + name;
58  group = group.remove(" ");
59 
60  PvlGroup &kerns = lab.findGroup("Kernels", Isis::Pvl::Traverse);
61  // Default version 1 for backwards compatibility (spiceinit'd cubes before camera model versioning)
62  if (!kerns.hasKeyword("CameraVersion")) {
63  kerns.addKeyword(PvlKeyword("CameraVersion", "1"));
64  }
65 
66  int cameraOriginalVersion = (int)kerns["CameraVersion"];
67  int cameraNewestVersion = CameraVersion(cube);
68 
69  if (cameraOriginalVersion != cameraNewestVersion) {
70  string msg = "The camera model used to create a camera for this cube is out of date, " \
71  "please re-run spiceinit on the file or process with an old Isis version " \
72  "that has the correct camera model.";
73  throw IException(IException::Unknown, msg, _FILEINFO_);
74  }
75 
76  // See if we have a camera model plugin
77  QFunctionPointer ptr;
78  try {
79  ptr = m_cameraPlugin.GetPlugin(group);
80  }
81  catch(IException &e) {
82  QString msg = "Unsupported camera model, unable to find plugin for ";
83  msg += "SpacecraftName [" + spacecraft + "] with InstrumentId [";
84  msg += name + "]";
85  throw IException(e, IException::Unknown, msg, _FILEINFO_);
86  }
87 
88  // Now cast that pointer in the proper way
89  Camera * (*plugin)(Isis::Cube &cube);
90  plugin = (Camera * ( *)(Isis::Cube &cube)) ptr;
91 
92  // Create the projection as requested
93  return (*plugin)(cube);
94  }
95  catch(IException &e) {
96  string message = "Unable to initialize camera model from group [Instrument]";
97  throw IException(e, IException::Unknown, message, _FILEINFO_);
98  }
99  }
100 
101 
102  void CameraFactory::initPlugin() {
103  if (m_cameraPlugin.fileName() == "") {
104  FileName localFile("Camera.plugin");
105  if (localFile.fileExists())
106  m_cameraPlugin.read(localFile.expanded());
107 
108  FileName systemFile("$ISISROOT/lib/Camera.plugin");
109  if (systemFile.fileExists())
110  m_cameraPlugin.read(systemFile.expanded());
111  }
112  }
113 
114 
122  int CameraFactory::CameraVersion(Cube &cube) {
123  return CameraVersion(*cube.label());
124  }
125 
126 
127  int CameraFactory::CameraVersion(Pvl &lab) {
128  // Try to load a plugin file in the current working directory and then
129  // load the system file
130  initPlugin();
131 
132  try {
133  // First get the spacecraft and instrument and combine them
134  PvlGroup &inst = lab.findGroup("Instrument", Isis::Pvl::Traverse);
135  QString spacecraft = (QString) inst["SpacecraftName"];
136  QString name = (QString) inst["InstrumentId"];
137  spacecraft = spacecraft.toUpper();
138  name = name.toUpper();
139  QString group = spacecraft + "/" + name;
140  group = group.remove(" ");
141 
142  PvlGroup plugin;
143  try {
144  plugin = m_cameraPlugin.findGroup(group);
145  }
146  catch(IException &e) {
147  QString msg = "Unsupported camera model, unable to find plugin for ";
148  msg += "SpacecraftName [" + spacecraft + "] with InstrumentId [";
149  msg += name + "]";
150  throw IException(e, IException::Unknown, msg, _FILEINFO_);
151  }
152 
153  if (!plugin.hasKeyword("Version")) {
154  QString msg = "Camera model identified by [" + group + "] does not have a version number";
155  throw IException(IException::Programmer, msg, _FILEINFO_);
156  }
157 
158  return (int)plugin["Version"];
159  }
160  catch(IException &e) {
161  string msg = "Unable to locate latest camera model version number from group [Instrument]";
162  throw IException(e, IException::Unknown, msg, _FILEINFO_);
163  }
164  }
165 } // end namespace isis
PvlGroupIterator findGroup(const QString &name, PvlGroupIterator beg, PvlGroupIterator end)
Find a group with the specified name, within these indexes.
Definition: PvlObject.h:141
File name manipulation and expansion.
Definition: FileName.h:111
Pvl * label() const
Returns a pointer to the IsisLabel object associated with the cube.
Definition: Cube.cpp:1298
Search child objects.
Definition: PvlObject.h:170
void addKeyword(const PvlKeyword &keyword, const InsertMode mode=Append)
Add a keyword to the container.
Contains multiple PvlContainers.
Definition: PvlGroup.h:57
#define _FILEINFO_
Macro for the filename and line number.
Definition: IException.h:38
A single keyword-value pair.
Definition: PvlKeyword.h:98
Container for cube-like labels.
Definition: Pvl.h:135
Isis exception class.
Definition: IException.h:99
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
IO Handler for Isis Cubes.
Definition: Cube.h:158

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:15:32