OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
AtpConfig.cpp
Go to the documentation of this file.
1 //**************************************************************************************************
2 //
3 // OSSIM Open Source Geospatial Data Processing Library
4 // See top level LICENSE.txt file for license information
5 //
6 //**************************************************************************************************
7 
8 #include "AtpConfig.h"
9 #include "AtpOpenCV.h"
12 #include "../AtpCommon.h"
13 
14 using namespace std;
15 using namespace ossim;
16 
17 namespace ATP
18 {
19 
20 AtpConfig& AtpConfig::instance()
21 {
22  static AtpConfig singleton;
23  return singleton;
24 }
25 
26 AtpConfig::AtpConfig()
27 {
28 
29  // Register the ISA-common parameters in the params map:
30  readConfig();
31 }
32 
33 AtpConfig::~AtpConfig()
34 {
35  m_paramsMap.clear();
36 }
37 
38 bool AtpConfig::readConfig(const string& cn)
39 {
40  // This method could eventually curl a spring config server for the param JSON. For now it
41  // is reading the installed share/ossim-isa system directory for config JSON files.
42 
43  // The previous parameters list is cleared first for a fresh start:
44  m_paramsMap.clear();
45 
46  ossimFilename configFilename;
47  Json::Value jsonRoot;
48  try
49  {
50  // First establish the directory location of the default config files:
52  preferencesKWL().findKey( std::string( "ossim_share_directory" ) );
53  shareDir += "/atp";
54  if (!shareDir.isDir())
55  throw ossimException("Nonexistent share drive provided for config files.");
56 
57  // Read the default common parameters first:
58  configFilename = "atpConfig.json";
59  configFilename.setPath(shareDir);
60  if (!open(configFilename))
61  throw ossimException("Bad file open or parse.");
62 
63  // Read the algorithm-specific default parameters if generic algo name specified as config:
64  ossimString configName (cn);
65  configFilename.clear();
66  if (configName == "crosscorr")
67  configFilename = "crossCorrConfig.json";
68  else if (configName == "descriptor")
69  configFilename = "descriptorConfig.json";
70  else if (configName == "nasa")
71  configFilename = "nasaConfig.json";
72  else if (!configName.empty())
73  {
74  // Custom configuration. TODO: the path here is still the install's share directory.
75  // Eventually want to provide a database access to the config JSON.
76  configFilename = configName + ".json";
77  }
78 
79  // Load the specified configuration. This will override the common defaults:
80  if (!configFilename.empty())
81  {
82  configFilename.setPath(shareDir);
83  if (!open(configFilename))
84  throw ossimException("Bad file open or parse.");
85  }
86  }
87  catch (ossimException& e)
88  {
89  CWARN<<"AtpConfig::readConfig(): Could not open/parse "
90  "config file at <"<< configFilename << ">. Error: "<<e.what()<<endl;
91  return false;
92  }
93  return true;
94 }
95 
96 }
void clear()
Erases the entire container.
Definition: ossimString.h:432
This code was derived from https://gist.github.com/mshockwave.
Definition: Barrier.h:8
ossimFilename & setPath(const ossimString &p)
bool isDir() const
virtual const char * what() const
Returns the error message.
THESE FUNCTIONS REQUIRE OPENCV.
static ossimPreferences * instance()
bool empty() const
Definition: ossimString.h:411
#define CWARN
Singleton class maintaining parameters affecting the automatic tie point generation.
Definition: AtpConfig.h:24