8 #include <csm/Plugin.h>
10 #include <QDirIterator>
14 #include "CameraFactory.h"
17 #include "CSMCamera.h"
19 #include "IException.h"
21 #include "Preference.h"
24 #include "csm/Model.h"
25 #include "csm/Plugin.h"
31 Plugin CameraFactory::m_cameraPlugin;
32 bool CameraFactory::m_initialized =
false;
53 if (cube.
hasBlob(
"CSMState",
"String")) {
59 QString msg =
"Unable to create CSM camera using CSMState Cube blob.";
60 throw IException(e, IException::Unknown, msg, _FILEINFO_);
67 QString spacecraft = (QString) inst[
"SpacecraftName"];
68 QString name = (QString) inst[
"InstrumentId"];
69 spacecraft = spacecraft.toUpper();
70 name = name.toUpper();
71 QString group = spacecraft +
"/" + name;
72 group = group.remove(
" ");
80 int cameraOriginalVersion = (int)kerns[
"CameraVersion"];
81 int cameraNewestVersion = CameraVersion(cube);
83 if (cameraOriginalVersion != cameraNewestVersion) {
84 string msg =
"The camera model used to create a camera for this cube is out of date, " \
85 "please re-run spiceinit on the file or process with an old Isis version " \
86 "that has the correct camera model.";
87 throw IException(IException::Unknown, msg, _FILEINFO_);
93 ptr = m_cameraPlugin.GetPlugin(group);
96 QString msg =
"Unsupported camera model, unable to find plugin for ";
97 msg +=
"SpacecraftName [" + spacecraft +
"] with InstrumentId [";
99 throw IException(e, IException::Unknown, msg, _FILEINFO_);
107 return (*plugin)(cube);
111 string message =
"Unable to initialize camera model in Camera Factory.";
112 throw IException(e, IException::Unknown, message, _FILEINFO_);
121 void CameraFactory::initPlugin() {
122 if (!m_initialized) {
124 if (m_cameraPlugin.fileName() ==
"") {
125 FileName localFile(
"Camera.plugin");
127 m_cameraPlugin.read(localFile.
expanded());
129 FileName systemFile(
"$ISISROOT/lib/Camera.plugin");
131 m_cameraPlugin.read(systemFile.
expanded());
139 for (
int i = 0; i<grp[
"CSMDirectory"].size(); i++) {
140 FileName csmDir = grp[
"CSMDirectory"][i];
142 QDirIterator csmLib(csmDir.
expanded(), {
"*.so",
"*.dylib"}, QDir::Files);
143 while (csmLib.hasNext()) {
144 QString csmLibName = csmLib.next();
145 QLibrary csmDynamicLib(csmLibName);
146 csmDynamicLib.load();
150 m_initialized =
true;
161 int CameraFactory::CameraVersion(
Cube &cube) {
162 return CameraVersion(*cube.
label());
173 int CameraFactory::CameraVersion(
Pvl &lab) {
181 QString spacecraft = (QString) inst[
"SpacecraftName"];
182 QString name = (QString) inst[
"InstrumentId"];
183 spacecraft = spacecraft.toUpper();
184 name = name.toUpper();
185 QString group = spacecraft +
"/" + name;
186 group = group.remove(
" ");
192 for (
int i = m_cameraPlugin.groups() - 1; i >= 0; i--) {
193 if (m_cameraPlugin.group(i) == group) {
194 plugin = m_cameraPlugin.group(i);
200 QString msg =
"Unable to find PVL group [" + group +
"].";
201 throw IException(IException::Unknown, msg, _FILEINFO_);
205 QString msg =
"Unsupported camera model, unable to find plugin for ";
206 msg +=
"SpacecraftName [" + spacecraft +
"] with InstrumentId [";
208 throw IException(e, IException::Unknown, msg, _FILEINFO_);
212 QString msg =
"Camera model identified by [" + group +
"] does not have a version number";
213 throw IException(IException::Programmer, msg, _FILEINFO_);
216 return (
int)plugin[
"Version"];
219 string msg =
"Unable to locate latest camera model version number from group [Instrument]";
220 throw IException(e, IException::Unknown, msg, _FILEINFO_);