OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Image.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 <ossim/reg/Image.h>
10 #include <ossim/base/ossimString.h>
12 
13 using namespace std;
14 
15 namespace ossim
16 {
17 
18 Image::Image(const std::string& imageId,
19  const std::string& filename,
20  const std::string& modelName,
21  unsigned int entryIndex,
22  unsigned int band)
23 : m_imageId (imageId),
24  m_filename (filename),
25  m_entryIndex (entryIndex),
26  m_activeBand (band),
27  m_modelName (modelName)
28 {
29 
30 }
31 
32 Image::Image(const Json::Value& json_node)
33 : m_entryIndex (0),
34  m_activeBand (1)
35 {
36  loadJSON(json_node);
37 }
38 
40 {
41  //m_handler.reset();
42 }
43 
44 void Image::getAvailableModels(std::vector< pair<string, string> >& availableModels) const
45 {
47  createProjection(m_filename, m_entryIndex);
48  if (proj)
49  {
50  availableModels.push_back(pair<string, string>("OSSIM", proj->getLongName().string()));
51  delete proj;
52  }
53 }
54 
55 void Image::loadJSON(const Json::Value& json_node)
56 {
57  ostringstream xmsg;
58  xmsg<<__FILE__<<": loadJSON(JSON) -- ";
59 
60  // Parse JSON. Filename is required:
61  if (json_node.isMember("filename"))
62  {
63  ossimFilename imageFile = json_node["filename"].asString();
64  m_filename = imageFile.expand(); // allow embedded environment variables
65  }
66  else
67  {
68  xmsg<<"JSON node missing required field: \"filename\".";
69  throw ossimException(xmsg.str());
70  }
71 
72  // Entry index defaults to 0 if not present:
73  if (json_node["entryIndex"].isUInt())
74  m_entryIndex = json_node["entryIndex"].asUInt();
75 
76  // Band defaults to 1 if not present:
77  if (json_node["band"].isUInt())
78  m_activeBand = json_node["band"].asUInt();
79 
80  // Sensor model defaults to most accurate available if not provided (indicated by blank name):
81  if (json_node.isMember("sensorModel"))
82  m_modelName = json_node["sensorModel"].asString();
83 
84  // Sensor model defaults to most accurate available if not provided (indicated by blank name):
85  if (json_node.isMember("imageId"))
86  m_imageId = json_node["imageId"].asString();
87 
88  // Establish the sensor model. This also sets the official image ID, which will be overwritten
89  // if JSON field provided
90  string modelState = json_node["modelState"].asString();
91  ossimKeywordlist kwl;
92  kwl.parseString(modelState);
94  m_sensorModel = dynamic_cast<ossimSensorModel*>(proj);
95 }
96 
97 void Image::saveJSON(Json::Value& json_node) const
98 {
99  json_node.clear();
100  json_node["imageId"] = m_imageId;
101  json_node["filename"] = m_filename.string();
102  json_node["entryIndex"] = m_entryIndex;
103 
104  if (m_modelName.size())
105  json_node["sensorModel"] = m_modelName;
106 
107  if (m_sensorModel.valid())
108  {
109  ossimKeywordlist kwl;
110  m_sensorModel->saveState(kwl);
111  json_node["modelState"] = kwl.toString().string();
112  }
113 }
114 
115 
116 } // end namespace
ossimFilename m_filename
Definition: Image.h:73
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
virtual void loadJSON(const Json::Value &json)
Refer to 3DISA API document for JSON format used.
Definition: Image.cpp:55
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
ossimFilename expand() const
Method to do file name expansion.
virtual void saveJSON(Json::Value &json) const
Refer to 3DISA API document for JSON format used.
Definition: Image.cpp:97
This code was derived from https://gist.github.com/mshockwave.
Definition: Barrier.h:8
std::string m_imageId
Definition: Image.h:72
ossimRefPtr< ossimSensorModel > m_sensorModel
Definition: Image.h:78
unsigned int m_activeBand
Definition: Image.h:75
unsigned int m_entryIndex
Definition: Image.h:74
ossimProjection * createProjection(const ossimFilename &filename, ossim_uint32 entryIdx) const
virtual ossimString getLongName() const
Definition: ossimObject.cpp:53
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual bool parseString(const std::string &inString)
static ossimProjectionFactoryRegistry * instance()
virtual ossimString toString() const
std::string m_modelName
Definition: Image.h:76
Image(const std::string &imageId, const std::string &filename, const std::string &modelName="", unsigned int entryIndex=0, unsigned int band=1)
Definition: Image.cpp:18
virtual void getAvailableModels(std::vector< pair< std::string, std::string > > &availableModels) const
Returns all available sensor model plugins and model names for this image:
Definition: Image.cpp:44
const std::string & string() const
Definition: ossimString.h:414