56 if (cube.
hasBlob(
"CSMState",
"String")) {
61 catch (IException &e) {
62 QString msg =
"Unable to create CSM camera using CSMState Cube blob.";
63 throw IException(e, IException::Unknown, msg, _FILEINFO_);
68 Pvl &lab = *cube.
label();
69 PvlGroup &inst = lab.findGroup(
"Instrument", Isis::Pvl::Traverse);
70 QString spacecraft = (QString) inst[
"SpacecraftName"];
71 QString name = (QString) inst[
"InstrumentId"];
72 spacecraft = spacecraft.toUpper();
73 name = name.toUpper();
74 QString group = spacecraft +
"/" + name;
75 group = group.remove(
" ");
77 PvlGroup &kerns = lab.findGroup(
"Kernels", Isis::Pvl::Traverse);
79 if (!kerns.hasKeyword(
"CameraVersion")) {
80 kerns.addKeyword(PvlKeyword(
"CameraVersion",
"1"));
83 int cameraOriginalVersion = (int)kerns[
"CameraVersion"];
86 if (cameraOriginalVersion != cameraNewestVersion) {
87 string msg =
"The camera model used to create a camera for this cube is out of date, " \
88 "please re-run spiceinit on the file or process with an old Isis version " \
89 "that has the correct camera model.";
90 throw IException(IException::Unknown, msg, _FILEINFO_);
98 catch(IException &e) {
99 QString msg =
"Unsupported camera model, unable to find plugin for ";
100 msg +=
"SpacecraftName [" + spacecraft +
"] with InstrumentId [";
102 throw IException(e, IException::Unknown, msg, _FILEINFO_);
110 return (*plugin)(cube);
113 catch(IException &e) {
114 string message =
"Unable to initialize camera model in Camera Factory.";
115 throw IException(e, IException::Unknown, message, _FILEINFO_);
128 FileName localFile(
"Camera.plugin");
129 if (localFile.fileExists())
132 FileName systemFile(
"$ISISROOT/lib/Camera.plugin");
133 if (systemFile.fileExists())
140 Preference &p = Preference::Preferences();
141 PvlGroup &grp = p.findGroup(
"Plugins", Isis::Pvl::Traverse);
142 for (
int i = 0; i<grp[
"CSMDirectory"].size(); i++) {
143 FileName csmDir = grp[
"CSMDirectory"][i];
145 QDirIterator csmLib(csmDir.expanded(), {
"*.so",
"*.dylib"}, QDir::Files);
146 while (csmLib.hasNext()) {
147 QString csmLibName = csmLib.next();
148 QLibrary csmDynamicLib(csmLibName);
149 csmDynamicLib.load();
183 PvlGroup &inst = lab.findGroup(
"Instrument", Isis::Pvl::Traverse);
184 QString spacecraft = (QString) inst[
"SpacecraftName"];
185 QString name = (QString) inst[
"InstrumentId"];
186 spacecraft = spacecraft.toUpper();
187 name = name.toUpper();
188 QString group = spacecraft +
"/" + name;
189 group = group.remove(
" ");
203 QString msg =
"Unable to find PVL group [" + group +
"].";
204 throw IException(IException::Unknown, msg, _FILEINFO_);
207 catch(IException &e) {
208 QString msg =
"Unsupported camera model, unable to find plugin for ";
209 msg +=
"SpacecraftName [" + spacecraft +
"] with InstrumentId [";
211 throw IException(e, IException::Unknown, msg, _FILEINFO_);
214 if (!plugin.hasKeyword(
"Version")) {
215 QString msg =
"Camera model identified by [" + group +
"] does not have a version number";
216 throw IException(IException::Programmer, msg, _FILEINFO_);
219 return (
int)plugin[
"Version"];
221 catch(IException &e) {
222 string msg =
"Unable to locate latest camera model version number from group [Instrument]";
223 throw IException(e, IException::Unknown, msg, _FILEINFO_);
239 if (pluginName.isEmpty() || modelName.isEmpty() || isdFormat.isEmpty()) {
241 pluginName = modelSpec[0];
242 modelName = modelSpec[1];
243 isdFormat = modelSpec[2];
246 csm::Model *model =
nullptr;
248 const csm::Plugin *plugin = csm::Plugin::findPlugin(pluginName.toStdString());
249 if (plugin == NULL) {
250 QString message =
"Cannot find requested Plugin: [" + pluginName +
"].";
251 throw IException(IException::User, message, _FILEINFO_);
254 csm::Isd fileIsd(isdFilePath.toStdString());
255 csm::Nitf21Isd nitf21Isd(isdFilePath.toStdString());
256 if (isdFormat == QString::fromStdString(fileIsd.format())) {
257 model = plugin->constructModelFromISD(fileIsd, modelName.toStdString());
259 else if (isdFormat == QString::fromStdString(nitf21Isd.format())) {
260 model = plugin->constructModelFromISD(nitf21Isd, modelName.toStdString());
263 QString message =
"Invalid ISD format specifications [" + isdFormat +
"].";
264 throw IException(IException::Programmer, message, _FILEINFO_);
279 for (
const csm::Plugin * plugin : csm::Plugin::getList()) {
280 QString currentPluginName = QString::fromStdString(plugin->getPluginName());
282 if (!pluginName.isEmpty() && pluginName != pluginName) {
286 for (
size_t modelIndex = 0; modelIndex < plugin->getNumModels(); modelIndex++) {
287 QString currentModelName = QString::fromStdString(plugin->getModelName(modelIndex));
289 if (!modelName.isEmpty() && currentModelName != modelName) {
293 csm::Isd fileIsd(isdFilePath.toStdString());
294 if (plugin->canModelBeConstructedFromISD(fileIsd, currentModelName.toStdString())) {
298 QString::fromStdString(fileIsd.format())};
299 possibleModels.append(modelSpec);
303 csm::Nitf21Isd nitf21Isd(isdFilePath.toStdString());
304 if (plugin->canModelBeConstructedFromISD(nitf21Isd, currentModelName.toStdString())) {
308 QString::fromStdString(nitf21Isd.format())};
309 possibleModels.append(modelSpec);
315 if (possibleModels.size() > 1) {
316 QString message =
"Multiple models can be created from the ISD [" + isdFilePath +
"]. "
317 "Re-run with the PLUGINNAME and MODELNAME parameters. "
318 "Possible plugin & model names:\n";
319 for (
const QStringList &modelSpec : possibleModels) {
320 message +=
"Plugin [" + modelSpec[0] +
"], Model [" + modelSpec[1] +
"]\n";
322 throw IException(IException::User, message, _FILEINFO_);
325 if (possibleModels.empty()) {
326 QString message =
"No loaded model could be created from the ISD [" + isdFilePath +
"]."
327 "Loaded plugin & model names:\n";
328 for (
const csm::Plugin * plugin : csm::Plugin::getList()) {
329 QString currentPluginName = QString::fromStdString(plugin->getPluginName());
330 for (
size_t modelIndex = 0; modelIndex < plugin->getNumModels(); modelIndex++) {
331 QString modelName = QString::fromStdString(plugin->getModelName(modelIndex));
332 message +=
"Plugin [" + currentPluginName +
"], Model [" + modelName +
"]\n";
335 throw IException(IException::User, message, _FILEINFO_);
341 if (modelSpec.size() != 3) {
342 QString message =
"Model specification [" + modelSpec.join(
" ") +
"] has [" + QString::number(modelSpec.size()) +
"] elements "
343 "when it should have 3 elements.";
344 throw IException(IException::Programmer, message, _FILEINFO_);