OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
plugin-test.cpp
Go to the documentation of this file.
1 //**************************************************************************************************
2 //
3 // OSSIM (http://trac.osgeo.org/ossim/)
4 //
5 // License: LGPL -- See LICENSE.txt file in the top level directory for more details.
6 //
7 //**************************************************************************************************
8 // $Id: plugin-test.cpp 23401 2015-06-25 15:00:31Z okramer $
9 #include "../src/ossimPdalFileReader.h"
10 #include "../src/ossimRialtoReader.h"
11 #include <ossim/init/ossimInit.h>
14 #include <assert.h>
17 #include <pdal/pdal.hpp>
18 #include <pdal/util/Bounds.hpp>
19 #include <pdal/LasWriter.hpp>
20 #include <pdal/FauxReader.hpp>
21 
22 #define TEST_READER false
23 
24 using namespace pdal;
25 
26 int usage(char* app_name)
27 {
28  cout << "\nUsage: "<<app_name<<" <pdal|rialto|genlas> [filename]\n" << endl;
29  return 1;
30 }
31 
32 bool writeRaster(ossimPdalReader* reader, const char* test)
33 {
36  ih->setPointCloudHandler(reader);
37 
38  ossimDpt gsd;
39  ih->getGSD(gsd, 0);
40  ossimString gsdstr = ossimString::toString((gsd.x + gsd.y)/6.0);
43  ih->setProperty(gsd_prop);
44 
45  // Set up the writer:
47  tif_writer->setGeotiffFlag(true);
48 
49  ossimFilename outfile (test);
50  outfile += "-OUTPUT.tif";
51  tif_writer->setFilename(outfile);
52  if (tif_writer.valid())
53  {
54  tif_writer->connectMyInputTo(0, ih.get());
55  tif_writer->execute();
56  }
57 
58  cout << "Output written to <"<<outfile<<">"<<endl;
59  return true;
60 }
61 
62 
63 bool test_rialto(const ossimFilename& fname)
64 {
65  cout << "Testing rialto with <"<<fname<<">"<<endl;
66 
68  reader->open(fname);
69 
70  ossimGrect bounds;
71  reader->getBounds(bounds);
72  cout <<"bounds = "<<bounds<<endl;
73 
74  ossimPointBlock pointBlock;
75  reader->getBlock(bounds, pointBlock);
76 
77  writeRaster(reader.get(), "rialto");
78 
79  return true;
80 }
81 
82 
83 bool test_pdal(const ossimFilename& fname)
84 {
85  cout << "Testing pdal with <"<<fname<<">"<<endl;
86 
88  reader->open(fname);
89 
90  ossimGrect bounds;
91  reader->getBounds(bounds);
92  cout <<"bounds = "<<bounds<<endl;
93 
94  writeRaster(reader.get(), "pdal");
95 
96  return 0;
97 }
98 
99 bool genlas(const ossimFilename& fname)
100 {
101  cout << "Generating file <"<<fname<<">"<<endl;
102 
103  FauxReader reader;
104  Options roptions;
105  BOX3D bbox(-0.001, -0.001, -100.0, 0.001, 0.001, 100.0);
106  roptions.add("bounds", bbox);
107  roptions.add("num_points", 11);
108  roptions.add("mode", "ramp");
109  reader.setOptions(roptions);
110 
111  LasWriter writer;
112  Options woptions;
113  woptions.add("filename", fname.string());
114  woptions.add("a_srs", "EPSG:4326"); // causes core dump when ossimInit::initialize() called on startup
115  woptions.add("scale_x", 0.0000001);
116  woptions.add("scale_y", 0.0000001);
117  writer.setOptions(woptions);
118  writer.setInput(reader);
119 
120  PointTable wtable;
121  writer.prepare(wtable);
122  writer.execute(wtable);
123 
124  return true;
125 }
126 
127 int main(int argc, char** argv)
128 {
129  // TODO: Figure out why program core-dumps on exit when this line is included and genlas test is
130  // run. Determined problem to be in GDAL's OGRSpatialReference::SetFromUserInput() called from
131  // PDAL's SpatialReference::setFromUserInput() called when EPSG option is set:
132  //ossimInit::instance()->initialize(argc, argv);
133 
134  if (argc == 1)
135  return usage(argv[0]);
136 
137  ossimFilename fname;
138  if (argc > 2)
139  fname = argv[2];
140 
141  ossimString test_name (argv[1]);
142  bool passed = false;
143  if (test_name.downcase() == "rialto")
144  {
145  if (fname.empty())
146  fname = "autzen.gpkg";
147  passed = test_rialto(fname);
148  }
149  else if (test_name.downcase() == "pdal")
150  {
151  if (fname.empty())
152  fname = "autzen.las";
153  passed = test_pdal(fname);
154  }
155  else if (test_name.downcase() == "genlas")
156  {
157  if (fname.empty())
158  fname = "ramp.las";
159  passed = genlas(fname);
160  }
161  else
162  return usage(argv[0]);
163 
164  if (passed)
165  return 0;
166  return 1;
167 }
168 
169 
bool valid() const
Definition: ossimRefPtr.h:75
int usage(char *app_name)
Definition: plugin-test.cpp:26
double y
Definition: ossimDpt.h:165
Class used for rendering point cloud data into a raster tile.
static ossimString toString(bool aValue)
Numeric to string methods.
bool setPointCloudHandler(ossimPointCloudHandler *pch)
Permits backdoor for setting the input point cloud handler object.
virtual bool open(const ossimFilename &fname)
Accepts filename of Rialto database file.
virtual void getBounds(ossimGrect &bounds) const
void getGSD(ossimDpt &gsd, ossim_uint32 resLevel) const
Get the GSD for resLevel.
bool writeRaster(ossimPdalReader *reader, const char *test)
Definition: plugin-test.cpp:32
virtual bool open(const ossimFilename &fname)
Accepts the name of a point cloud file.
bool test_rialto(const ossimFilename &fname)
Definition: plugin-test.cpp:63
virtual void setGeotiffFlag(bool flag)
int main(int argc, char **argv)
unsigned int ossim_uint32
bool genlas(const ossimFilename &fname)
Definition: plugin-test.cpp:99
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
bool setCurrentEntry(ossim_uint32 entryIdx) override
void setProperty(ossimRefPtr< ossimProperty > property) override
The reader properties are: – the GSD ("meters_per_pixel") which overrides computed nominal GSD – th...
virtual void setFilename(const ossimFilename &file)
bool test_pdal(const ossimFilename &fname)
Definition: plugin-test.cpp:83
static const char * METERS_PER_PIXEL_KW
double x
Definition: ossimDpt.h:164
bool empty() const
Definition: ossimString.h:411
virtual void getBlock(const ossimGrect &bounds, ossimPointBlock &block) const
Fetches the block of points inside the block bounds.
virtual bool execute()
Calls: writeFile() writeMetaDataFiles()
const std::string & string() const
Definition: ossimString.h:414