[Liblas-commits] hg: 2 new changesets
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Jul 2 11:31:09 EDT 2010
changeset 9df20d59979d in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=9df20d59979d
summary: add argument handling to filtering example
changeset 93601d9ded83 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=93601d9ded83
summary: add LastReturnFilter example
diffstat:
doc/tutorial/cpp.txt | 64 +++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 59 insertions(+), 5 deletions(-)
diffs (102 lines):
diff -r dcdb9c0e2a81 -r 93601d9ded83 doc/tutorial/cpp.txt
--- a/doc/tutorial/cpp.txt Thu Jul 01 11:29:15 2010 -0500
+++ b/doc/tutorial/cpp.txt Fri Jul 02 10:31:02 2010 -0500
@@ -227,15 +227,64 @@
#include <liblas/laswriter.hpp>
#include <liblas/lasfilter.hpp>
#include <vector>
+ #include <iostream>
+
+
+ class LastReturnFilter: public liblas::FilterI
+ {
+ public:
+
+ LastReturnFilter();
+ bool filter(const liblas::Point& point);
+
+
+ private:
+
+ LastReturnFilter(LastReturnFilter const& other);
+ LastReturnFilter& operator=(LastReturnFilter const& rhs);
+ };
+
+
+ LastReturnFilter::LastReturnFilter( ) :
+ liblas::FilterI(eInclusion)
+ {
+ }
+
+
+
+ bool LastReturnFilter::filter(const liblas::Point& p)
+ {
+
+ // If the GetReturnNumber equals the GetNumberOfReturns,
+ // we're a last return
+ bool output = false;
+ if (p.GetReturnNumber() == p.GetNumberOfReturns()) {
+ output = true;
+ }
+
+ // If the type is switched to eExclusion, we'll throw out all last returns.
+ if (GetType() == eInclusion) {
+ output = true;
+ } else {
+ output = false;
+ }
+ return output;
+ }
int main(int argc, char* argv[])
{
std::ifstream ifs;
- std::string in_file("input.las");
- std::string out_file("output.las");
+
+ if (argc < 3) {
+ std::cout <<std::string("not all arguments specified. Usage: 'filter input.las output.las'") << std::endl;
+ exit(1);
+ }
+ std::string in_file(argv[1]);
+ std::string out_file(argv[2]);
if (!liblas::Open(ifs, in_file.c_str()))
{
- throw std::runtime_error(std::string("Can not open \'") + in_file + "\'");
+ std::cout <<std::string("Can not open \'") + in_file + "\'" << std::endl;;
+ exit(1);
}
std::vector<liblas::uint8_t> classes;
classes.push_back(2); // ground
@@ -249,6 +298,9 @@
// throw out those that matched
class_filter->SetType(liblas::FilterI::eInclusion);
filters.push_back(class_filter);
+
+ LastReturnFilter* return_filter = new LastReturnFilter();
+ filters.push_back(return_filter);
liblas::Reader reader(ifs);
reader.SetFilters(&filters);
@@ -256,7 +308,8 @@
std::ofstream ofs;
if (!liblas::Create(ofs, out_file.c_str()))
{
- throw std::runtime_error(std::string("Can not create \'") + in_file + "\'");
+ std::cout <<std::string("Can not create \'") + out_file + "\'" << std::endl;;
+ exit(1);
}
liblas::Writer writer(ofs, reader.GetHeader());
@@ -265,8 +318,9 @@
liblas::Point const& p = reader.GetPoint();
writer.WritePoint(p);
}
-
+
delete class_filter;
+ delete return_filter;
}
.. _`unit tests package`: http://liblas.org/browser/trunk/test/unit
More information about the Liblas-commits
mailing list