Isis 3 Programmer Reference
NormModelFactory.cpp
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 
8 #include "NormModelFactory.h"
9 #include "NormModel.h"
10 #include "Plugin.h"
11 #include "IException.h"
12 #include "FileName.h"
13 
14 namespace Isis {
37  // Get the algorithm name to create
38  PvlGroup &algo = pvl.findObject("NormalizationModel")
39  .findGroup("Algorithm", Pvl::Traverse);
40  QString algorithm = "";
41  if (algo.hasKeyword("NormName")) {
42  algorithm = QString(algo["NormName"]);
43  }
44  else if (algo.hasKeyword("Name")) {
45  algorithm = QString(algo["Name"]);
46  }
47  else {
48  QString msg = "Keyword [Name] or keyword [NormName] must ";
49  msg += "exist in [Group = Algorithm]";
50  throw IException(IException::User, msg, _FILEINFO_);
51  }
52 
53  // Open the factory plugin file
54  Plugin *p = new Plugin;
55  FileName f("NormModel.plugin");
56  if(f.fileExists()) {
57  p->read("NormModel.plugin");
58  }
59  else {
60  p->read("$ISISROOT/lib/NormModel.plugin");
61  }
62 
63  // Get the algorithm specific plugin and return it
64  NormModel * (*plugin)(Pvl & pvl, PhotoModel & pmodel);
65  plugin = (NormModel * ( *)(Pvl & pvl, PhotoModel & pmodel))
66  p->GetPlugin(algorithm);
67  return (*plugin)(pvl, pmodel);
68  }
69 
92  AtmosModel &amodel) {
93  // Get the algorithm name to create
94  PvlGroup &algo = pvl.findObject("NormalizationModel")
95  .findGroup("Algorithm", Pvl::Traverse);
96  QString algorithm = "";
97  if (algo.hasKeyword("NormName")) {
98  algorithm = QString(algo["NormName"]);
99  }
100  else if (algo.hasKeyword("Name")) {
101  algorithm = QString(algo["Name"]);
102  }
103  else {
104  IString msg = "Keyword [Name] or keyword [NormName] must ";
105  msg += "exist in [Group = Algorithm]";
106  throw IException(IException::User, msg, _FILEINFO_);
107  }
108 
109  // Open the factory plugin file
110  Plugin *p = new Plugin;
111  FileName f("NormModel.plugin");
112  if(f.fileExists()) {
113  p->read("NormModel.plugin");
114  }
115  else {
116  p->read("$ISISROOT/lib/NormModel.plugin");
117  }
118 
119  // Get the algorithm specific plugin and return it
120  NormModel * (*plugin)(Pvl & pvl, PhotoModel & pmodel,
121  AtmosModel & amodel);
122  plugin = (NormModel * ( *)(Pvl & pvl, PhotoModel & pmodel,
123  AtmosModel & amodel))
124  p->GetPlugin(algorithm);
125  return (*plugin)(pvl, pmodel, amodel);
126  }
127 } // end namespace isis
Isis::PhotoModel
Definition: PhotoModel.h:41
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::FileName::fileExists
bool fileExists() const
Returns true if the file exists; false otherwise.
Definition: FileName.cpp:449
Isis::AtmosModel
Isotropic atmos scattering model.
Definition: AtmosModel.h:60
Isis::PvlContainer::hasKeyword
bool hasKeyword(const QString &name) const
Check to see if a keyword exists.
Definition: PvlContainer.cpp:159
Isis::Pvl
Container for cube-like labels.
Definition: Pvl.h:119
Isis::NormModelFactory::Create
static NormModel * Create(Pvl &pvl, PhotoModel &pmodel)
Create a NormModel object using a PVL specification.
Definition: NormModelFactory.cpp:36
Isis::PvlObject::Traverse
@ Traverse
Search child objects.
Definition: PvlObject.h:158
Isis::NormModel
Definition: NormModel.h:36
Isis::PvlGroup
Contains multiple PvlContainers.
Definition: PvlGroup.h:41
Isis::Pvl::read
void read(const QString &file)
Loads PVL information from a stream.
Definition: Pvl.cpp:90
Isis::PvlObject::findObject
PvlObjectIterator findObject(const QString &name, PvlObjectIterator beg, PvlObjectIterator end)
Find the index of object with a specified name, between two indexes.
Definition: PvlObject.h:274
Isis::Plugin::GetPlugin
QFunctionPointer GetPlugin(const QString &group)
This method returns a void pointer to a C function (i.e., the plugin) It does this by looking in itse...
Definition: Plugin.cpp:39
Isis::IException
Isis exception class.
Definition: IException.h:91
Isis::IString
Adds specific functionality to C++ strings.
Definition: IString.h:165
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::IException::User
@ User
A type of error that could only have occurred due to a mistake on the user's part (e....
Definition: IException.h:126
Isis::Plugin
Loads plugins from a shared library.
Definition: Plugin.h:55