20 using namespace ossim;
22 #define CINFO ossimNotify(ossimNotifyLevel_INFO) 23 #define CWARN ossimNotify(ossimNotifyLevel_WARN) 24 #define CFATAL ossimNotify(ossimNotifyLevel_FATAL) 27 "Provides DEM generation functionality. This tool uses JSON format to " 28 "communicate requests and results.";
33 m_algorithm (ALGO_UNASSIGNED),
34 m_method (METHOD_UNASSIGNED),
36 m_postSpacingUnits (UNITS_UNASSIGNED)
39 Json::Value configJson;
42 preferencesKWL().findKey( std::string(
"ossim_share_directory" ) );
44 if (!shareDir.
isDir())
45 throw ossimException(
"Nonexistent share drive provided for config files.");
47 configFilename.
setPath(shareDir);
49 if (configJsonStream.fail())
52 << configFilename <<
">. Ignoring." << endl;
56 configJsonStream >> configJson;
73 usageString +=
" dem [options] \n\n";
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";
81 "List available DEM generation algorithms");
83 "Reads request JSON from the input file specified instead of stdin.");
85 "Outputs response JSON to the output file instead of stdout.");
87 "List all algorithm parameters with default values.");
89 "Verbose. All non-response (debug) output to stdout is enabled.");
106 if ( ap.
read(
"--algorithms"))
109 if ( ap.
read(
"--parameters"))
112 if ( ap.
read(
"-i", sp1))
117 CFATAL<<__FILE__<<
" Could not open input file <"<<ts1<<
">";
122 Json::Value queryJson;
133 if ( ap.
read(
"-o", sp1))
139 CFATAL<<__FILE__<<
" Could not open output file <"<<ts1<<
">";
153 xmsg<<
"ossimDemTool::loadJSON() ";
157 string method = queryRoot[
"method"].asString();
158 if (method ==
"getAlgorithms")
160 else if (method ==
"getParameters")
173 string algorithm = queryRoot[
"algorithm"].asString();
174 if (algorithm.empty())
178 if (algorithm ==
"asp")
180 else if (algorithm ==
"omg")
185 if (queryRoot.isMember(
"postSpacing"))
203 if (queryRoot.isMember(
"photoblock"))
233 m_responseJSON[
"report"] =
"Unsupported algorthm requested for DEM generation.";
237 xmsg <<
"Fatal: No method selected prior to execute being called. I don't know what to do!";
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";
290 static const char* MODULE =
"ossimDemTool::doASP() ";
296 xmsg <<
"No photoblock has been declared or it has less than two images. Cannot perform ATP.";
302 string cmdPath (getenv(
"NGTASP_BIN_DIR"));
303 cmd<<cmdPath<<
"/stereo";
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;
310 for (
int i=0; i<numImages; i++)
313 shared_ptr<Image> image = imageList[i];
316 rpcFilename.setExtension(
"RPB");
317 if (!rpcFilename.isReadable())
320 if (!rpcSolver.
solve(imageFilename))
322 xmsg <<
"Error encountered in solving for RPC coefficients..";
327 ofstream rpbFile (rpcFilename.string());
328 if (rpbFile.fail() || !rpcModel->
toRPB(rpbFile))
330 xmsg <<
"Error encountered writing RPC to file <"<<rpcFilename<<
">.";
334 cout<<
"Generated RPC for "<<imageFilename<<endl;
335 rpcFilenameList.emplace_back(rpcFilename);
336 cmd <<
" " <<imageFilename;
340 for (
const auto &rpcFilename : rpcFilenameList)
341 cmd <<
" " <<rpcFilename;
344 cout <<
"\nSpawning command: "<<cmd.str()<<endl;
345 if (system(cmd.str().c_str()))
347 xmsg <<
"Error encountered running DEM generation command.";
354 static const char* MODULE =
"ossimDemTool::doOMG() ";
360 xmsg <<
"No photoblock has been declared or it has less than two images. Cannot perform ATP.";
368 xmsg <<
"OMG algorithm requires the ATP plugin but plugin not found in registry.";
374 atpJson[
"algorithm"] =
"crosscorr";
375 atpJson[
"method"] =
"generate";
378 CINFO<<atpJson<<endl;
388 int num_tiepoints =
m_photoBlock->getTiePointList().size();
394 xmsg <<
"OMG algorithm requires the MSP plugin but plugin not found in registry.";
399 omgJson[
"service"] =
"mensuration";
400 omgJson[
"method"] =
"pointExtraction";
401 omgJson[
"outputCoordinateSystem"] =
"ecf";
408 const Json::Value& observations = mspJson[
"mensurationReport"];
409 vector<ossimEcefPoint> pointCloud;
410 for (
const auto &observation : observations)
413 observation[
"y"].asDouble(),
414 observation[
"z"].asDouble());
415 pointCloud.emplace_back(ecfPt);
434 xmsg <<
"Error encountered creating writer object given filename <"<<
m_outputDemFile<<
">.";
440 xmsg <<
"Error encountered writing DEM file.";
std::string getApplicationName() const
return the application name, as specified by argv[0]
void addCommandLineOption(const ossimString &option, const ossimString &explanation)
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
ossimFilename & appendTimestamp()
Convenience method to append a generic timestamp to the base-name portion of the filename.
Represents serializable keyword/value map.
std::basic_ifstream< char > ifstream
Class for char input file streams.
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...
This code was derived from https://gist.github.com/mshockwave.
Base class for maintaining parameters affecting the runtime configuration of OSSIM executables...
ossimFilename & setPath(const ossimString &p)
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.
Class for representing MSP PhotoBlock.
void setCommandLineUsage(const ossimString &explanation)
ossimApplicationUsage * getApplicationUsage()
const ossimRefPtr< ossimRpcModel > getRpcModel() const
Fetches the solved-for RPC model.
virtual void saveJSON(Json::Value ¶ms_json_node) const
Reads the params controlling the process from the JSON node named "parameters".
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...
virtual const char * what() const
Returns the error message.
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
static ossimPreferences * instance()
This currently only support Rational poilynomial B format.
ossimImageFileWriter * createWriter(const ossimFilename &filename) const
std::basic_ofstream< char > ofstream
Class for char output file streams.
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
virtual bool execute()
Calls: writeFile() writeMetaDataFiles()
bool toRPB(std::ostream &out) const
Serialize to WorldView-style .RPB file to the stream provided.
const std::string & string() const