OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimPointCloudTool.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: LGPL
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: Oscar Kramer
9 //
10 //*******************************************************************
11 // $Id$
12 
14 #include <ossim/init/ossimInit.h>
16 #include <ossim/base/ossimCommon.h>
24 
25 using namespace std;
26 
28 : m_operation (LOWEST_DEM),
29  m_gsd (0)
30 {
31 }
32 
34 {
35  m_pcHandler = 0;
36  m_prodGeom = 0;
37  m_pcuFilter = 0;
38 }
39 
41 {
42  // Set the general usage:
44  ossimString usageString = ap.getApplicationName();
45  usageString += " [options] <point-cloud-file> <output-image>";
46  au->setCommandLineUsage(usageString);
47 
48  // Set the command line options:
50  "--gsd <meters>",
51  "Specifies output GSD in meters. Defaults to the same "
52  "resolution as input DEM.");
54  "--dem <filename>",
55  "Specifies the input DEM filename. If none provided, the elevation database is "
56  "referenced as specified in prefs file");
58  "--lut <filename>",
59  "Specifies the optional lookup table filename for "
60  "mapping the single-band output image to an RGB. The LUT provided must be "
61  "in the ossimIndexToRgbLutFilter format and must handle the three output "
62  "viewshed values (see --values option).");
64  "--method",
65  "Specify the desired operation. Possible values are:\n"
66  " \"highest-dem\", \"lowest-dem\" (default), or \"highest-lowest\". \n"
67  "Alternatively can be specified in shorthand as \"h-d\", \"l-d\", or \"h-l\", "
68  "respectively.");
70  "--request-api",
71  "Causes applications API to be output as JSON to stdout."
72  " Accepts optional filename to store JSON output.");
74  "--threads <n>",
75  "Number of threads. Defaults to use all available cores. "
76  "For engineering/debug purposes ");
77 }
78 
80 {
81  // Add global usage options.
83 
84  // Add options.
85  addArguments(ap);
86 
87  // Write usage.
89 
91  <<"\nPerforms specified processing on point-cloud.\n\n"
92  << std::endl;
93 }
94 
96 {
97  if ( (ap.argc() == 1) || ap.read("-h") || ap.read("--help") )
98  {
99  usage(ap);
100  return false;
101  }
102 
103  ossimString ts1;
105 
106  if ( ap.read("--dem", sp1) )
107  m_demFile = ts1;
108 
109  if ( ap.read("--gsd", sp1) )
110  m_gsd = ossimString(ts1).toDouble();
111 
112  if ( ap.read("--lut", sp1) )
113  m_lutFile = ts1;
114 
115  if ( ap.read("--method", sp1) )
116  {
117  if (ts1.contains("highest-dem") || ts1.contains("h-d"))
119  else if (ts1.contains("highest-lowest") || ts1.contains("h-l"))
121  }
122 
123  if ( ap.read("--pc", sp1) )
124  m_demFile = ts1;
125 
126 /*
127  if ( ap.read("--request-api", sp1))
128  {
129  ofstream ofs ( ts1.c_str() );
130  printApiJson(ofs);
131  ofs.close();
132  return false;
133  }
134  if ( ap.read("--request-api"))
135  {
136  printApiJson(cout);
137  return false;
138  }
139 */
140  // There should only be the required command line args left:
141  if (ap.argc() < 3)
142  {
143  usage(ap);
144  return false;
145  }
146 
147  // Parse the required command line params:
148  m_pcFile = ap[1];
149  m_prodFile = ap[2];
150 
151  return initialize();
152 }
153 
154 void ossimPointCloudTool::loadJSON(const Json::Value &json_request)
155 {
156 
157 }
158 
160 {
161  if (loadPC())
162  {
164  << "ossimPointCloudTool::initialize ERR: Cannot open PC file at <"<<m_pcFile
165  <<">\n"<< endl;
166  return false;
167  }
168 
169  if (!m_demFile.empty() && !loadDem())
170  return false;
171 
173  return true;
174 }
175 
177 {
178  // DEM provided as file on command line, reset the elev manager to use only this:
180  if(!m_pcHandler.valid())
181  {
183  << "ossimPointCloudTool::initialize ERR: Cannot open PC file at <"<<m_pcFile
184  <<">\n" << std::endl;
185  return false;
186  }
187 
188  // Use "rasterized" PC to establish best output image geometry:
193  return false;
194 
195  if (m_gsd != 0)
197 
198  return true;
199 }
200 
202 {
203  // DEM provided as file on command line, reset the elev manager to use only this:
205  elevMgr->clear();
207  if(!ied->open(m_demFile))
208  {
210  << "ossimViewshedUtil::initialize ERR: Cannot open DEM file at <"<<m_demFile<<">\n"
211  << std::endl;
212  return false;
213  }
214 
215  elevMgr->addDatabase(ied.get());
216 
217  // When DEM file specified, need to turn off all defaulting to ellipsoid/geoid to make sure
218  // only the DEM file data is processed:
220  elevMgr->setUseGeoidIfNullFlag(false);
221 
222  return true;
223 }
224 
225 void ossimPointCloudTool::setGSD(const double& meters_per_pixel)
226 {
227  if (m_prodGeom->getAsMapProjection() && (meters_per_pixel > 0))
228  {
229  m_gsd = meters_per_pixel;
231  }
232 }
233 
235 {
236  // See if an LUT is requested:
237  ossimImageSource* last_source = m_pcuFilter.get();
239  if (!m_lutFile.empty())
240  {
241  ossimKeywordlist lut_kwl;
242  lut_kwl.addFile(m_lutFile);
243  lutSource = new ossimIndexToRgbLutFilter;
244  if (!lutSource->loadState(lut_kwl))
245  {
246  ossimNotify(ossimNotifyLevel_WARN) << "ossimPointCloudTool::writeFile() ERROR: The LUT "
247  "file <"<<m_lutFile<<"> could not be read. Ignoring remap request.\n"<< std::endl;
248  lutSource = 0;
249  }
250  else
251  {
252  lutSource->connectMyInputTo(last_source);
253  lutSource->initialize();
254  last_source = lutSource.get();
255  }
256  }
257 
258  // Set up the writer:
261  bool success = false;
262  if (writer.valid())
263  {
264  writer->connectMyInputTo(0, last_source);
265  success = writer->execute();
266  }
267 
268  return success;
269 }
270 
271 
272 void ossimPointCloudTool::saveJSON(Json::Value &json_request) const
273 {
274 
275 }
276 
void write(std::ostream &output, const UsageMap &um, unsigned int widthOfOutput=80)
std::string getApplicationName() const
return the application name, as specified by argv[0]
void addCommandLineOption(const ossimString &option, const ossimString &explanation)
enum ossimPointCloudTool::Operation m_operation
Represents serializable keyword/value map.
bool addFile(const char *file)
void usage(ossimArgumentParser &ap)
bool valid() const
Definition: ossimRefPtr.h:75
ossimRefPtr< ossimPointCloudImageHandler > m_pciHandler
void addOptions(ossimArgumentParser &parser)
Definition: ossimInit.cpp:100
void setUseGeoidIfNullFlag(bool flag)
const ossimMapProjection * getAsMapProjection() const
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...
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
bool contains(char aChar) const
Definition: ossimString.h:58
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.
static ossimElevManager * instance()
METHOD: instance() Implements singelton pattern.
void setCommandLineUsage(const ossimString &explanation)
ossimRefPtr< ossimImageGeometry > m_prodGeom
ossimRefPtr< ossimPointCloudHandler > m_pcHandler
ossimApplicationUsage * getApplicationUsage()
virtual void setMetersPerPixel(const ossimDpt &gsd)
virtual ossimPointCloudHandler * open(const ossimFilename &fileName) const
ossimRefPtr< ossimImageGeometry > getImageGeometry() override
Returns the image geometry object associated with this tile source or NULL if non defined...
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=NULL)
Method to the load (recreate) the state of an object from a keyword list.
double toDouble() const
friend class ossimPointCloudUtilityFilter
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
ossimRefPtr< ossimPointCloudUtilityFilter > m_pcuFilter
void loadJSON(const Json::Value &json_request) override
Reads processing params from JSON object provided.
static ossimPointCloudHandlerRegistry * instance()
void setGSD(const double &meters_per_pixel)
void setDefaultHeightAboveEllipsoid(double meters)
bool empty() const
Definition: ossimString.h:411
static ossimInit * instance()
Definition: ossimInit.cpp:89
ossimImageFileWriter * createWriter(const ossimFilename &filename) const
virtual bool open(const ossimString &connectionString)
Open a connection to a database.
void saveJSON(Json::Value &json) const override
Fetch product as JSON object when applicable Always returns true since using exception on error...
void addDatabase(ossimElevationDatabase *database, bool set_as_first=false)
Adds a new elevation database to the collection.
int & argc()
return the argument count.
void addArguments(ossimArgumentParser &ap)
virtual bool execute() override
Writes product to output file if applicable.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
virtual bool execute()
Calls: writeFile() writeMetaDataFiles()