OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
ossimDemTool Class Reference

#include <ossimDemTool.h>

Inheritance diagram for ossimDemTool:
ossimTool ossimObject ossim::JsonInterface ossimReferenced

Public Types

enum  Algorithm { ALGO_UNASSIGNED =0, ASP, OMG }
 
enum  Method { METHOD_UNASSIGNED =0, GET_ALGO_LIST, GET_PARAMS, GENERATE }
 
enum  Units { UNITS_UNASSIGNED =0, METERS, DEGREES }
 

Public Member Functions

 ossimDemTool ()
 
 ~ossimDemTool () override
 
void setUsage (ossimArgumentParser &ap) override
 Initializes the aurgument parser with expected parameters and options. More...
 
bool initialize (ossimArgumentParser &ap) override
 Initializes from command line arguments. More...
 
bool execute () override
 Writes product to output file if applicable. More...
 
ossimString getClassName () const override
 
void getKwlTemplate (ossimKeywordlist &kwl) override
 Assigns a template keywordlist to string for initializing derived classes. More...
 
void loadJSON (const Json::Value &json) override
 Reads processing params from JSON object provided. More...
 
void saveJSON (Json::Value &json) const override
 Fetch product as JSON object when applicable Always returns true since using exception on error. More...
 
- Public Member Functions inherited from ossimTool
 ossimTool ()
 
virtual ~ossimTool ()
 
virtual void initialize (const ossimKeywordlist &kwl)
 Reads processing params from KWL and prepares for execute. More...
 
virtual const std::string & getResponse () const
 Fetch product as string (typically JSON) when applicable, otherwise passes back empty string. More...
 
virtual void clear ()
 Disconnects and clears the DEM and image layers. More...
 
virtual void abort ()
 Kills current (asynchronous) process. More...
 
void getAPI (std::string &out) const
 Outputs a JSON representation of the Utility's API. More...
 
std::string getAPI () const
 
void getBuildDate (std::string &s) const
 Gets build date. More...
 
void getRevision (std::string &s) const
 Gets revision. More...
 
void getVersion (std::string &s) const
 Gets version. More...
 
virtual bool isChipProcessor () const
 Overrides base class implementation to indicate this class supports getChip() calls. More...
 
void setOutputStream (std::ostream *os)
 Redirects any console output to the supplied stream for logging or JNI application. More...
 
bool helpRequested () const
 Returns true when the initialization detects a "--help" option, so caller can avoid subsequent execute() call. More...
 
- Public Member Functions inherited from ossimObject
 ossimObject ()
 
virtual ~ossimObject ()
 
virtual ossimObjectdup () const
 
virtual ossimString getShortName () const
 
virtual ossimString getLongName () const
 
virtual ossimString getDescription () const
 
virtual RTTItypeid getType () const
 
virtual bool canCastTo (ossimObject *obj) const
 
virtual bool canCastTo (const RTTItypeid &id) const
 
virtual bool canCastTo (const ossimString &parentClassName) const
 
virtual bool saveState (ossimKeywordlist &kwl, const char *prefix=0) const
 
virtual bool loadState (const ossimKeywordlist &kwl, const char *prefix=0)
 
virtual std::ostream & print (std::ostream &out) const
 Generic print method. More...
 
virtual bool isEqualTo (const ossimObject &obj, ossimCompareType compareType=OSSIM_COMPARE_FULL) const
 
virtual void accept (ossimVisitor &visitor)
 
- Public Member Functions inherited from ossimReferenced
 ossimReferenced ()
 
 ossimReferenced (const ossimReferenced &)
 
ossimReferencedoperator= (const ossimReferenced &)
 
void ref () const
 increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void unref () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unref_nodelete () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
int referenceCount () const
 
- Public Member Functions inherited from ossim::JsonInterface
 JsonInterface ()
 
virtual ~JsonInterface ()
 

Static Public Attributes

static const char * DESCRIPTION
 

Private Member Functions

void getAlgorithms ()
 
void getParameters ()
 
void doASP ()
 
void doOMG ()
 

Private Attributes

std::ostream * m_outputStream
 
bool m_verbose
 
Algorithm m_algorithm
 
Method m_method
 
Json::Value m_responseJSON
 
std::shared_ptr< ossim::PhotoBlockm_photoBlock
 
ossimFilename m_outputDemFile
 
double m_postSpacing
 
Units m_postSpacingUnits
 
Json::Value m_parameters
 
Json::Value m_atpParameters
 

Additional Inherited Members

- Protected Member Functions inherited from ossimReferenced
virtual ~ossimReferenced ()
 
- Protected Attributes inherited from ossimTool
ossimKeywordlist m_kwl
 
std::ostream * m_consoleStream
 
bool m_helpRequested
 
std::string m_response
 

Detailed Description

Definition at line 18 of file ossimDemTool.h.

Member Enumeration Documentation

◆ Algorithm

Enumerator
ALGO_UNASSIGNED 
ASP 
OMG 

Definition at line 21 of file ossimDemTool.h.

◆ Method

Enumerator
METHOD_UNASSIGNED 
GET_ALGO_LIST 
GET_PARAMS 
GENERATE 

Definition at line 22 of file ossimDemTool.h.

◆ Units

Enumerator
UNITS_UNASSIGNED 
METERS 
DEGREES 

Definition at line 23 of file ossimDemTool.h.

Constructor & Destructor Documentation

◆ ossimDemTool()

ossimDemTool::ossimDemTool ( )

Definition at line 30 of file ossimDemTool.cpp.

References ossimPreferences::instance(), ossimFilename::isDir(), loadJSON(), ossimNotify(), ossimNotifyLevel_WARN, ossimFilename::setPath(), and ossimString::string().

31 : m_outputStream (0),
32  m_verbose (false),
35  m_postSpacing (0),
37 {
38  // Read the default DEM extraction parameters:
39  Json::Value configJson;
40  ossimFilename configFilename ("omgConfig.json");
42  preferencesKWL().findKey( std::string( "ossim_share_directory" ) );
43  shareDir += "/atp"; // TODO: Consolidate tool configs
44  if (!shareDir.isDir())
45  throw ossimException("Nonexistent share drive provided for config files.");
46 
47  configFilename.setPath(shareDir);
48  ifstream configJsonStream (configFilename.string());
49  if (configJsonStream.fail())
50  {
51  ossimNotify(ossimNotifyLevel_WARN) << __FILE__ << " Bad file open or parse of config file <"
52  << configFilename << ">. Ignoring." << endl;
53  }
54  else
55  {
56  configJsonStream >> configJson;
57  loadJSON(configJson);
58  }
59 }
std::basic_ifstream< char > ifstream
Class for char input file streams.
Definition: ossimIosFwd.h:44
bool isDir() const
Units m_postSpacingUnits
Definition: ossimDemTool.h:60
double m_postSpacing
Definition: ossimDemTool.h:59
Method m_method
Definition: ossimDemTool.h:55
static ossimPreferences * instance()
Algorithm m_algorithm
Definition: ossimDemTool.h:54
std::ostream * m_outputStream
Definition: ossimDemTool.h:52
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
void loadJSON(const Json::Value &json) override
Reads processing params from JSON object provided.

◆ ~ossimDemTool()

ossimDemTool::~ossimDemTool ( )
override

Definition at line 61 of file ossimDemTool.cpp.

62 {
63 }

Member Function Documentation

◆ doASP()

void ossimDemTool::doASP ( )
private

Definition at line 288 of file ossimDemTool.cpp.

References ossimRpcSolver::getRpcModel(), m_outputDemFile, m_photoBlock, ossimRpcSolver::solve(), and ossimRpcModel::toRPB().

Referenced by execute().

289 {
290  static const char* MODULE = "ossimDemTool::doASP() ";
291  ostringstream xmsg;
292  xmsg<<MODULE;
293 
294  if (!m_photoBlock || (m_photoBlock->getImageList().size() < 2))
295  {
296  xmsg << "No photoblock has been declared or it has less than two images. Cannot perform ATP.";
297  throw ossimException(xmsg.str());
298  }
299 
300  // Start the ASP command ine:
301  ostringstream cmd;
302  string cmdPath (getenv("NGTASP_BIN_DIR"));
303  cmd<<cmdPath<<"/stereo";
304 
305  // First obtain list of images from photoblock:
306  std::vector<shared_ptr<Image> >& imageList = m_photoBlock->getImageList();
307  std::vector<ossimFilename> rpcFilenameList;
308  int numImages = (int) imageList.size();
309  int numPairs = (numImages * (numImages-1))/2; // triangular number assumes all overlap
310  for (int i=0; i<numImages; i++)
311  {
312  // Establish existence of RPB, and create it if not available:
313  shared_ptr<Image> image = imageList[i];
314  ossimFilename imageFilename (image->getFilename());
315  ossimFilename rpcFilename(imageFilename);
316  rpcFilename.setExtension("RPB");
317  if (!rpcFilename.isReadable())
318  {
319  ossimRpcSolver rpcSolver;
320  if (!rpcSolver.solve(imageFilename))
321  {
322  xmsg << "Error encountered in solving for RPC coefficients..";
323  throw ossimException(xmsg.str());
324  }
325 
326  ossimRefPtr<ossimRpcModel> rpcModel = rpcSolver.getRpcModel();
327  ofstream rpbFile (rpcFilename.string());
328  if (rpbFile.fail() || !rpcModel->toRPB(rpbFile))
329  {
330  xmsg << "Error encountered writing RPC to file <"<<rpcFilename<<">.";
331  throw ossimException(xmsg.str());
332  }
333  }
334  cout<<"Generated RPC for "<<imageFilename<<endl;
335  rpcFilenameList.emplace_back(rpcFilename);
336  cmd << " " <<imageFilename;
337  }
338 
339  // Loop to add model filenames to the command line:
340  for (const auto &rpcFilename : rpcFilenameList)
341  cmd << " " <<rpcFilename;
342 
343  cmd<<" "<<m_outputDemFile<<ends;
344  cout << "\nSpawning command: "<<cmd.str()<<endl;
345  if (system(cmd.str().c_str()))
346  {
347  xmsg << "Error encountered running DEM generation command.";
348  throw ossimException(xmsg.str());
349  }
350 }
ossimFilename m_outputDemFile
Definition: ossimDemTool.h:58
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
const ossimRefPtr< ossimRpcModel > getRpcModel() const
Fetches the solved-for RPC model.
bool solve(const ossimDrect &aoiBounds, ossimImageGeometry *geom, const double &pixel_tolerance=0.5)
Similar to the other solve methods except that the final grid size is established iteratively so that...
This currently only support Rational poilynomial B format.
std::basic_ofstream< char > ofstream
Class for char output file streams.
Definition: ossimIosFwd.h:47
std::shared_ptr< ossim::PhotoBlock > m_photoBlock
Definition: ossimDemTool.h:57
bool toRPB(std::ostream &out) const
Serialize to WorldView-style .RPB file to the stream provided.

◆ doOMG()

void ossimDemTool::doOMG ( )
private

Definition at line 352 of file ossimDemTool.cpp.

References CINFO, ossimConnectableObject::connectMyInputTo(), ossimToolRegistry::createTool(), ossimImageWriterFactoryRegistry::createWriter(), ossimTool::execute(), ossimImageFileWriter::execute(), ossimRefPtr< T >::get(), ossimImageWriterFactoryRegistry::instance(), ossimToolRegistry::instance(), ossimTool::loadJSON(), m_atpParameters, m_outputDemFile, m_photoBlock, m_responseJSON, ossimTool::saveJSON(), ossimPointCloudImageHandler::setPointCloudHandler(), and ossimString::string().

Referenced by execute().

353 {
354  static const char* MODULE = "ossimDemTool::doOMG() ";
355  ostringstream xmsg;
356  xmsg<<MODULE;
357 
358  if (!m_photoBlock || (m_photoBlock->getImageList().size() < 2))
359  {
360  xmsg << "No photoblock has been declared or it has less than two images. Cannot perform ATP.";
361  throw ossimException(xmsg.str());
362  }
363 
364  // OMG uses the ATP plugin:
365  ossimRefPtr<ossimTool> atpTool = ossimToolRegistry::instance()->createTool("ossimAtpTool") ;
366  if (!atpTool)
367  {
368  xmsg << "OMG algorithm requires the ATP plugin but plugin not found in registry.";
369  throw ossimException(xmsg.str());
370  }
371 
372  // Pass along any user parameter modifications to the ATP tool:
373  Json::Value atpJson;
374  atpJson["algorithm"] = "crosscorr";
375  atpJson["method"] = "generate";
376  m_photoBlock->saveJSON(atpJson["photoblock"]);
377  atpJson["parameters"] = m_atpParameters;
378  CINFO<<atpJson<<endl; //TODO REMOVE
379  atpTool->loadJSON(atpJson);
380 
381  // Generate dense tiepoint field:
382  atpTool->execute();
383  Json::Value omgJson;
384  atpTool->saveJSON(omgJson);
385 
386  // Use dense points to do intersections to generate point cloud
387  m_photoBlock->loadJSON(omgJson);
388  int num_tiepoints = m_photoBlock->getTiePointList().size();
389 
390  // Get instance of MSP tool for performing n-way intersection:
391  ossimRefPtr<ossimTool> mspTool = ossimToolRegistry::instance()->createTool("ossimMspTool") ;
392  if (!mspTool)
393  {
394  xmsg << "OMG algorithm requires the MSP plugin but plugin not found in registry.";
395  throw ossimException(xmsg.str());
396  }
397 
398  // Prepare the JSON used to communicate with the mensuration tool and kick off bulk mensuration:
399  omgJson["service"] = "mensuration";
400  omgJson["method"] = "pointExtraction";
401  omgJson["outputCoordinateSystem"] = "ecf";
402  mspTool->loadJSON(omgJson);
403  mspTool->execute();
404  Json::Value mspJson;
405  mspTool->saveJSON(mspJson);
406 
407  // Save resulting geo point to point cloud:
408  const Json::Value& observations = mspJson["mensurationReport"];
409  vector<ossimEcefPoint> pointCloud;
410  for (const auto &observation : observations)
411  {
412  ossimEcefPoint ecfPt(observation["x"].asDouble(),
413  observation["y"].asDouble(),
414  observation["z"].asDouble());
415  pointCloud.emplace_back(ecfPt);
416  }
417 
418  // Convert point cloud to DEM
421  pcih->setPointCloudHandler(pch.get());
422  ossimImageSource* lastSource = pcih.get();
423 
424  // TODO: Need to set up output projection to match desired GSD and units
425 
426  // TODO: Need smart interpolation resampling to fill in the nulls
427  // lastSource = resampler...
428 
429  // Set up the writer and output the DEM:
432  if (!writer)
433  {
434  xmsg << "Error encountered creating writer object given filename <"<<m_outputDemFile<<">.";
435  throw ossimException(xmsg.str());
436  }
437  writer->connectMyInputTo(0, lastSource);
438  if (!writer->execute())
439  {
440  xmsg << "Error encountered writing DEM file.";
441  throw ossimException(xmsg.str());
442  }
443 
444  // Need to populate response JSON with product filepath and statistics
446 }
ossimFilename m_outputDemFile
Definition: ossimDemTool.h:58
virtual void saveJSON(Json::Value &json) const
Fetch product as JSON object when applicable Always returns true since using exception on error...
Definition: ossimTool.h:59
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
virtual void loadJSON(const Json::Value &json_request)
Reads processing params from JSON object provided.
Definition: ossimTool.h:52
Class used for rendering point cloud data into a raster tile.
static ossimImageWriterFactoryRegistry * instance()
bool setPointCloudHandler(ossimPointCloudHandler *pch)
Permits backdoor for setting the input point cloud handler object.
Json::Value m_responseJSON
Definition: ossimDemTool.h:56
virtual ossimTool * createTool(const std::string &typeName) const
static ossimToolRegistry * instance()
virtual bool execute()=0
Writes product to output file if applicable.
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
Json::Value m_atpParameters
Definition: ossimDemTool.h:62
ossimImageFileWriter * createWriter(const ossimFilename &filename) const
#define CINFO
virtual bool execute()
Calls: writeFile() writeMetaDataFiles()
std::shared_ptr< ossim::PhotoBlock > m_photoBlock
Definition: ossimDemTool.h:57
const std::string & string() const
Definition: ossimString.h:414

◆ execute()

bool ossimDemTool::execute ( )
overridevirtual

Writes product to output file if applicable.

The product may also beAlways returns true since using exception on error.

Note
Throws ossimException on error.

Implements ossimTool.

Definition at line 210 of file ossimDemTool.cpp.

References ASP, CFATAL, doASP(), doOMG(), GENERATE, GET_ALGO_LIST, GET_PARAMS, getAlgorithms(), getParameters(), m_algorithm, m_method, m_outputStream, m_responseJSON, OMG, and ossimException::what().

Referenced by main().

211 {
212  ostringstream xmsg;
213 
214  try
215  {
216  switch (m_method)
217  {
218  case GET_ALGO_LIST:
219  getAlgorithms();
220  break;
221  case GET_PARAMS:
222  getParameters();
223  break;
224  case GENERATE:
225  // Establish server-side output filename:
226  if (m_algorithm == ASP)
227  doASP();
228  if (m_algorithm == OMG)
229  doOMG();
230  else
231  {
232  m_responseJSON["status"] = "failed";
233  m_responseJSON["report"] = "Unsupported algorthm requested for DEM generation.";
234  }
235  break;
236  default:
237  xmsg << "Fatal: No method selected prior to execute being called. I don't know what to do!";
238  throw ossimException(xmsg.str());
239  }
240 
241  // Serialize JSON object for return:
242  if (m_outputStream)
243  (*m_outputStream) << m_responseJSON;
244  }
245  catch(ossimException &e)
246  {
247  CFATAL<<"Exception: "<<e.what()<<endl;
248  if (m_outputStream)
249  *m_outputStream<<"{ \"ERROR\": \"" << e.what() << "\" }\n"<<endl;
250  }
251 
252  // close any open file streams:
253  ofstream* so = dynamic_cast<ofstream*>(m_outputStream);
254  if (so)
255  {
256  so->close();
257  delete so;
258  }
259 
260  return true;
261 }
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
Json::Value m_responseJSON
Definition: ossimDemTool.h:56
void getParameters()
virtual const char * what() const
Returns the error message.
Method m_method
Definition: ossimDemTool.h:55
Algorithm m_algorithm
Definition: ossimDemTool.h:54
#define CFATAL
std::basic_ofstream< char > ofstream
Class for char output file streams.
Definition: ossimIosFwd.h:47
std::ostream * m_outputStream
Definition: ossimDemTool.h:52
void getAlgorithms()

◆ getAlgorithms()

void ossimDemTool::getAlgorithms ( )
private

Definition at line 267 of file ossimDemTool.cpp.

References m_responseJSON.

Referenced by execute().

268 {
269  m_responseJSON.clear();
270 
271  Json::Value algoList;
272  algoList[0]["name"] = "asp";
273  algoList[0]["description"] = "NASA Ames Stereo Pipeline";
274  algoList[0]["name"] = "omg";
275  algoList[0]["description"] = "OSSIM/MSP Generator";
276 
277  m_responseJSON["algorithms"] = algoList;
278 }
Json::Value m_responseJSON
Definition: ossimDemTool.h:56

◆ getClassName()

ossimString ossimDemTool::getClassName ( ) const
inlineoverridevirtual

Reimplemented from ossimTool.

Definition at line 37 of file ossimDemTool.h.

37 { return "ossimDemTool"; }

◆ getKwlTemplate()

void ossimDemTool::getKwlTemplate ( ossimKeywordlist kwl)
overridevirtual

Assigns a template keywordlist to string for initializing derived classes.

Reimplemented from ossimTool.

Definition at line 263 of file ossimDemTool.cpp.

264 {
265 }

◆ getParameters()

void ossimDemTool::getParameters ( )
private

Definition at line 280 of file ossimDemTool.cpp.

References ossimDemToolConfig::instance(), m_responseJSON, and ossim::JsonConfig::saveJSON().

Referenced by execute().

281 {
282  m_responseJSON.clear();
283  Json::Value params;
285  m_responseJSON["parameters"] = params;
286 }
Json::Value m_responseJSON
Definition: ossimDemTool.h:56
virtual void saveJSON(Json::Value &params_json_node) const
Reads the params controlling the process from the JSON node named "parameters".
Definition: JsonConfig.cpp:447
static ossimDemToolConfig & instance()
Singleton implementation.

◆ initialize()

bool ossimDemTool::initialize ( ossimArgumentParser ap)
overridevirtual

Initializes from command line arguments.

This base class has some common arguments to read. The derived class should call this implementation in addition to setting its own arguments.

Parameters
apRepresents command line.
Returns
FALSE if –help option requested or no params provided, so that derived classes can exit without error.
Note
Throws ossimException on error.

Reimplemented from ossimTool.

Definition at line 92 of file ossimDemTool.cpp.

References CFATAL, GENERATE, GET_ALGO_LIST, GET_PARAMS, ossimTool::initialize(), loadJSON(), ossimTool::m_helpRequested, m_method, m_outputStream, m_verbose, ossimNotify(), ossimNotifyLevel_FATAL, and ossimArgumentParser::read().

93 {
94  string ts1;
97 
98  if (!ossimTool::initialize(ap))
99  return false;
100  if (m_helpRequested)
101  return true;
102 
103  if ( ap.read("-v"))
104  m_verbose = true;
105 
106  if ( ap.read("--algorithms"))
108 
109  if ( ap.read("--parameters"))
111 
112  if ( ap.read("-i", sp1))
113  {
114  ifstream s (ts1);
115  if (s.fail())
116  {
117  CFATAL<<__FILE__<<" Could not open input file <"<<ts1<<">";
118  return false;
119  }
120  try
121  {
122  Json::Value queryJson;
123  s >> queryJson;
124  loadJSON(queryJson);
125  }
126  catch (exception& e)
127  {
128  ossimNotify(ossimNotifyLevel_FATAL)<<__FILE__<<" Could not parse input JSON <"<<ts1<<">";
129  return false;
130  }
131  }
132 
133  if ( ap.read("-o", sp1))
134  {
135 
136  ofstream* s = new ofstream (ts1);
137  if (s->fail())
138  {
139  CFATAL<<__FILE__<<" Could not open output file <"<<ts1<<">";
140  return false;
141  }
142  m_outputStream = s;
143  }
144  else
145  m_outputStream = &clog;
146 
147  return true;
148 }
bool m_helpRequested
Definition: ossimTool.h:150
std::basic_ifstream< char > ifstream
Class for char input file streams.
Definition: ossimIosFwd.h:44
bool read(const std::string &str)
search for an occurance of a string in the argument list, on sucess remove that occurance from the li...
virtual bool initialize(ossimArgumentParser &ap)
Initializes from command line arguments.
Definition: ossimTool.cpp:58
Method m_method
Definition: ossimDemTool.h:55
#define CFATAL
std::basic_ofstream< char > ofstream
Class for char output file streams.
Definition: ossimIosFwd.h:47
std::ostream * m_outputStream
Definition: ossimDemTool.h:52
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
void loadJSON(const Json::Value &json) override
Reads processing params from JSON object provided.

◆ loadJSON()

void ossimDemTool::loadJSON ( const Json::Value &  json_request)
overridevirtual

Reads processing params from JSON object provided.

If all good, the object is ready for subsequent call to execute().

Note
Throws ossimException on error.

Reimplemented from ossimTool.

Definition at line 150 of file ossimDemTool.cpp.

References ALGO_UNASSIGNED, ossimFilename::appendTimestamp(), ASP, ossimString::empty(), GENERATE, GET_ALGO_LIST, GET_PARAMS, ossimDemToolConfig::instance(), m_algorithm, m_atpParameters, m_method, m_outputDemFile, m_parameters, m_photoBlock, m_postSpacing, OMG, and ossimFilename::setExtension().

Referenced by initialize(), main(), and ossimDemTool().

151 {
152  ostringstream xmsg;
153  xmsg<<"ossimDemTool::loadJSON() ";
154 
155  // Fetch the desired method from the JSON if provided, otherwise rely on command line options:
156  m_method = GENERATE;
157  string method = queryRoot["method"].asString();
158  if (method == "getAlgorithms")
160  else if (method == "getParameters")
162 
163  m_outputDemFile = queryRoot["filename"].asString();
164  if (m_outputDemFile.empty())
165  {
166  m_outputDemFile = "dem-result";
169  }
170 
171  // Fetch the desired algorithm or configuration:
173  string algorithm = queryRoot["algorithm"].asString();
174  if (algorithm.empty())
175  algorithm = "asp"; // default for now
176 
177  // Assign enum data member used throughout the service:
178  if (algorithm == "asp")
179  m_algorithm = ASP;
180  else if (algorithm == "omg")
181  m_algorithm = OMG;
182  else
184 
185  if (queryRoot.isMember("postSpacing"))
186  m_postSpacing = queryRoot["postSpacing"].asDouble();
187 
188 
189  // If parameters were provided in the JSON payload, have the config override the defaults:
190  m_parameters = queryRoot["parameters"];
191  m_atpParameters = queryRoot["atpParameters"];
192  //if (!m_parameters.isNull())
193  // config.loadJSON(m_parameters);
194 
195  //if (config.diagnosticLevel(2))
196  // clog<<"\nDEM configuration after loading:\n"<<config<<endl;
197 
198  if (m_method == GENERATE)
199  {
200  // Load the active photoblock from JSON.
201  // The root JSON object can optionally contain a photoblock with image list contained. If so,
202  // use that object to load images, otherwise use the root.
203  if (queryRoot.isMember("photoblock"))
204  m_photoBlock.reset(new PhotoBlock(queryRoot["photoblock"]));
205  else
206  m_photoBlock.reset(new PhotoBlock(queryRoot));
207  }
208 }
ossimFilename m_outputDemFile
Definition: ossimDemTool.h:58
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
ossimFilename & appendTimestamp()
Convenience method to append a generic timestamp to the base-name portion of the filename.
Base class for maintaining parameters affecting the runtime configuration of OSSIM executables...
Definition: JsonConfig.h:64
Class for representing MSP PhotoBlock.
Definition: PhotoBlock.h:25
double m_postSpacing
Definition: ossimDemTool.h:59
Json::Value m_parameters
Definition: ossimDemTool.h:61
Method m_method
Definition: ossimDemTool.h:55
static ossimDemToolConfig & instance()
Singleton implementation.
Algorithm m_algorithm
Definition: ossimDemTool.h:54
Json::Value m_atpParameters
Definition: ossimDemTool.h:62
bool empty() const
Definition: ossimString.h:411
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.
std::shared_ptr< ossim::PhotoBlock > m_photoBlock
Definition: ossimDemTool.h:57

◆ saveJSON()

void ossimDemTool::saveJSON ( Json::Value &  json) const
inlineoverridevirtual

Fetch product as JSON object when applicable Always returns true since using exception on error.

Parameters
jsonReturns non-empty object if valid response available.

Reimplemented from ossimTool.

Definition at line 43 of file ossimDemTool.h.

43 { json = m_responseJSON; }
Json::Value m_responseJSON
Definition: ossimDemTool.h:56

◆ setUsage()

void ossimDemTool::setUsage ( ossimArgumentParser ap)
overridevirtual

Initializes the aurgument parser with expected parameters and options.

It does not output anything. To see the usage, the caller will need to do something like:

ap.getApplicationUsage()->write(<ostream>);

This base class has some common arguments to add. The derived class should call this implementation in addition to setting its own arguments.

Reimplemented from ossimTool.

Definition at line 65 of file ossimDemTool.cpp.

References ossimApplicationUsage::addCommandLineOption(), ossimArgumentParser::getApplicationName(), ossimArgumentParser::getApplicationUsage(), ossimApplicationUsage::setCommandLineUsage(), and ossimTool::setUsage().

66 {
67  // Add global usage options. Don't include ossimChipProcUtil options as not appropriate.
69 
70  // Set the general usage:
72  ossimString usageString = ap.getApplicationName();
73  usageString += " dem [options] \n\n";
74  usageString +=
75  "Accesses DEM generation functionality given JSON request on stdin (or input file if\n"
76  "-i specified). The response JSON is output to stdout unless -o option is specified.\n";
77  au->setCommandLineUsage(usageString);
78 
79  // Set the command line options:
80  au->addCommandLineOption("--algorithms",
81  "List available DEM generation algorithms");
82  au->addCommandLineOption("-i <filename>",
83  "Reads request JSON from the input file specified instead of stdin.");
84  au->addCommandLineOption("-o <filename>",
85  "Outputs response JSON to the output file instead of stdout.");
86  au->addCommandLineOption("--parameters",
87  "List all algorithm parameters with default values.");
88  au->addCommandLineOption("-v",
89  "Verbose. All non-response (debug) output to stdout is enabled.");
90 }
std::string getApplicationName() const
return the application name, as specified by argv[0]
void addCommandLineOption(const ossimString &option, const ossimString &explanation)
void setCommandLineUsage(const ossimString &explanation)
ossimApplicationUsage * getApplicationUsage()
virtual void setUsage(ossimArgumentParser &ap)
Initializes the aurgument parser with expected parameters and options.
Definition: ossimTool.cpp:41

Member Data Documentation

◆ DESCRIPTION

const char * ossimDemTool::DESCRIPTION
static
Initial value:
=
"Provides DEM generation functionality. This tool uses JSON format to "
"communicate requests and results."

Definition at line 25 of file ossimDemTool.h.

Referenced by ossimDemToolFactory::getCapabilities().

◆ m_algorithm

Algorithm ossimDemTool::m_algorithm
private

Definition at line 54 of file ossimDemTool.h.

Referenced by execute(), and loadJSON().

◆ m_atpParameters

Json::Value ossimDemTool::m_atpParameters
private

Definition at line 62 of file ossimDemTool.h.

Referenced by doOMG(), and loadJSON().

◆ m_method

Method ossimDemTool::m_method
private

Definition at line 55 of file ossimDemTool.h.

Referenced by execute(), initialize(), and loadJSON().

◆ m_outputDemFile

ossimFilename ossimDemTool::m_outputDemFile
private

Definition at line 58 of file ossimDemTool.h.

Referenced by doASP(), doOMG(), and loadJSON().

◆ m_outputStream

std::ostream* ossimDemTool::m_outputStream
private

Definition at line 52 of file ossimDemTool.h.

Referenced by execute(), and initialize().

◆ m_parameters

Json::Value ossimDemTool::m_parameters
private

Definition at line 61 of file ossimDemTool.h.

Referenced by loadJSON().

◆ m_photoBlock

std::shared_ptr<ossim::PhotoBlock> ossimDemTool::m_photoBlock
private

Definition at line 57 of file ossimDemTool.h.

Referenced by doASP(), doOMG(), and loadJSON().

◆ m_postSpacing

double ossimDemTool::m_postSpacing
private

Definition at line 59 of file ossimDemTool.h.

Referenced by loadJSON().

◆ m_postSpacingUnits

Units ossimDemTool::m_postSpacingUnits
private

Definition at line 60 of file ossimDemTool.h.

◆ m_responseJSON

Json::Value ossimDemTool::m_responseJSON
private

Definition at line 56 of file ossimDemTool.h.

Referenced by doOMG(), execute(), getAlgorithms(), and getParameters().

◆ m_verbose

bool ossimDemTool::m_verbose
private

Definition at line 53 of file ossimDemTool.h.

Referenced by initialize().


The documentation for this class was generated from the following files: