[Liblas-commits] hg: fix up ts2las. It was quite broken after the
point refactor...
liblas-commits at liblas.org
liblas-commits at liblas.org
Tue Jan 11 11:49:28 EST 2011
details: http://hg.liblas.orghg/rev/47ff872c9d5b
changeset: 2721:47ff872c9d5b
user: Howard Butler <hobu.inc at gmail.com>
date: Tue Jan 11 10:49:21 2011 -0600
description:
fix up ts2las. It was quite broken after the point refactoring and used some old idioms that we no longer use -- providing a bad example
diffstat:
apps/CMakeLists.txt | 2 +-
apps/ts2las.cpp | 467 ++++++++++++++++++++++++++++-----------------------
2 files changed, 260 insertions(+), 209 deletions(-)
diffs (truncated from 569 to 300 lines):
diff -r 3b90c0b0382e -r 47ff872c9d5b apps/CMakeLists.txt
--- a/apps/CMakeLists.txt Tue Jan 11 09:08:12 2011 -0600
+++ b/apps/CMakeLists.txt Tue Jan 11 10:49:21 2011 -0600
@@ -132,7 +132,7 @@
endif()
if(TS2LAS)
- add_executable(${TS2LAS} ts2las.cpp )
+ add_executable(${TS2LAS} ts2las.cpp laskernel.cpp)
target_link_libraries(${TS2LAS} ${APPS_CPP_DEPENDENCIES} )
endif()
diff -r 3b90c0b0382e -r 47ff872c9d5b apps/ts2las.cpp
--- a/apps/ts2las.cpp Tue Jan 11 09:08:12 2011 -0600
+++ b/apps/ts2las.cpp Tue Jan 11 10:49:21 2011 -0600
@@ -11,6 +11,21 @@
// http://www.opensource.org/licenses/bsd-license.php)
//
#include "ts2las.hpp"
+#include "laskernel.hpp"
+
+// boost
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable : 4512)
+#endif
+
+#include <boost/program_options.hpp>
+
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
+
+namespace po = boost::program_options;
#include <fstream>
#include <iostream>
@@ -18,55 +33,55 @@
using namespace liblas;
-std::istream* OpenInput(std::string filename)
-{
- std::ios::openmode const mode = std::ios::in | std::ios::binary;
- std::istream* istrm;
- if (compare_no_case(filename.c_str(),"STDIN",5) == 0)
- {
- istrm = &std::cin;
- }
- else
- {
- istrm = new std::ifstream(filename.c_str(), mode);
- }
-
- if (!istrm->good())
- {
- delete istrm;
- throw std::runtime_error("Reading stream was not able to be created");
- exit(1);
- }
- return istrm;
-}
+// std::istream* OpenInput(std::string filename)
+// {
+// std::ios::openmode const mode = std::ios::in | std::ios::binary;
+// std::istream* istrm;
+// if (compare_no_case(filename.c_str(),"STDIN",5) == 0)
+// {
+// istrm = &std::cin;
+// }
+// else
+// {
+// istrm = new std::ifstream(filename.c_str(), mode);
+// }
+//
+// if (!istrm->good())
+// {
+// delete istrm;
+// throw std::runtime_error("Reading stream was not able to be created");
+// exit(1);
+// }
+// return istrm;
+// }
+//
+// std::ostream* OpenOutput(std::string filename)
+// {
+// std::ostream* ostrm;
+// std::ios::openmode m;
+// m = std::ios::out | std::ios::binary | std::ios::ate;
+//
+// if (compare_no_case(filename.c_str(),"STOUT",5) == 0)
+// {
+// ostrm = &std::cout;
+// }
+// else
+// {
+// ostrm = new std::ofstream(filename.c_str(), m);
+// }
+//
+//
+// if (!ostrm->good())
+// {
+// delete ostrm;
+// throw std::runtime_error("Writing stream was not able to be created");
+// exit(1);
+// }
+//
+// return ostrm;
+// }
-std::ostream* OpenOutput(std::string filename)
-{
- std::ostream* ostrm;
- std::ios::openmode m;
- m = std::ios::out | std::ios::binary | std::ios::ate;
-
- if (compare_no_case(filename.c_str(),"STOUT",5) == 0)
- {
- ostrm = &std::cout;
- }
- else
- {
- ostrm = new std::ofstream(filename.c_str(), m);
- }
-
-
- if (!ostrm->good())
- {
- delete ostrm;
- throw std::runtime_error("Writing stream was not able to be created");
- exit(1);
- }
-
- return ostrm;
-}
-
-liblas::Header CreateHeader(ScanHdr* hdr)
+liblas::Header CreateHeader(ScanHdr* hdr, bool verbose)
{
liblas::Header header;
@@ -84,25 +99,42 @@
}
header.SetVersionMinor(2);
header.SetDataFormatId(format);
- // header.SetPointRecordsCount(hdr->PntCnt);
- std::cout << "units: " << hdr->Units << std::endl;
- std::cout << "format: " << format << std::endl;
+
double scale = 1.0/(double)hdr->Units;
- std::cout << "scale: " << scale << std::endl;
header.SetScale(scale, scale, scale);
header.SetOffset(hdr->OrgX*scale, hdr->OrgY*scale, hdr->OrgZ*scale);
- std::cout << "offset x: " << header.GetOffsetX()
- << " offset y: " << header.GetOffsetY()
- << " offset z: " <<header.GetOffsetZ() << std::endl;
+ header.SetPointRecordsCount(hdr->PntCnt);
+
+ if (verbose)
+ {
+ std::cout << "The file says there should be " << hdr->PntCnt << " points" << std::endl;
+ std::cout << "units: " << hdr->Units << std::endl;
+ std::cout << "format: " << format << std::endl;
+ std::cout << "scale: " << scale << std::endl;
+ std::cout << "x origin: " << hdr->OrgX << std::endl;
+ std::cout << "y origin: " << hdr->OrgY << std::endl;
+ std::cout << "z origin: " << hdr->OrgZ << std::endl;
+
+ boost::uint32_t precision = GetStreamPrecision(scale);
+
+ std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
+ std::cout.precision(precision);
+ std::cout << "offset x: " << header.GetOffsetX() << std::endl;
+ std::cout << "offset y: " << header.GetOffsetY() << std::endl;
+ std::cout << "offset z: " << header.GetOffsetZ() << std::endl;
+
+ }
+
+
return header;
}
-bool ReadHeader(ScanHdr* hdr, std::istream* istrm)
+bool ReadHeader(ScanHdr* hdr, std::istream& istrm)
{
try
{
- liblas::detail::read_n(*hdr, *istrm, sizeof(ScanHdr));
+ liblas::detail::read_n(*hdr, istrm, sizeof(ScanHdr));
if (hdr->Tunniste != 970401) return false;
if (memcmp(hdr->Magic,"CXYZ",4)) return false;
@@ -115,127 +147,145 @@
if (( version > 20020715) && (version < 20051231)) return true;
return false;
}
- catch (std::exception const)
+ catch (std::exception const&)
{
return false;
}
}
-bool WritePoints(liblas::Writer* writer, std::istream* strm, ScanHdr* hdr)
+bool WritePoints(liblas::Writer& writer, std::istream& strm, ScanHdr* hdr, bool verbose)
{
ScanPnt* point = new ScanPnt;
ScanRow* row = new ScanRow;
- while (true)
+ boost::uint32_t i = 0;
+
+ for (std::size_t t = 0; t < static_cast<std::size_t>(hdr->PntCnt); t++)
{
-///std::cout << "We have header version" << std::endl;
-
- try
+ if (hdr->HdrVersion == 20020715) {
+ try
{
- // std::cout << "stream position is: " << strm->tellg() << std::endl;
- if (hdr->HdrVersion == 20020715) {
- liblas::detail::read_n(*point, *strm, sizeof(ScanPnt));
- } else{
- liblas::detail::read_n(*row, *strm, sizeof(ScanRow));
- point->Pnt.x = row->x;
- point->Pnt.y = row->y;
- point->Pnt.z = row->z;
- point->Code = row->Code;
- point->Line = row->Line;
- point->Intensity = row->EchoInt & 0x3FFF;
- point->Echo = (row->EchoInt >> 14);
- }
- Point p;
-
- p.SetCoordinates( point->Pnt.x,
- point->Pnt.y,
- point->Pnt.z);
-
- // std::cout << "read x: " << point->Pnt.x << " y: "<< point->Pnt.y << " z: " <<point->Pnt.z<< std::endl;
- // std::cout << "wrote x: " << p.GetX() << " y: "<< p.GetY() << " z: " <<p.GetZ()<< std::endl;
- // std::cout << "Code: " << point->Code << " Intensity: "<< point->Intensity << std::endl;
- p.SetClassification(point->Code);
- p.SetIntensity(point->Intensity);
- if (hdr->Time) {
- boost::uint32_t t = 0xFFFFFFFF;
- liblas::detail::read_n(t, *strm, sizeof(t));
-
- // Time stamps are assumed to be GPS week seconds. The
- // storage format is a 32 bit unsigned integer where
- // each integer step is 0.0002 seconds.
-
- p.SetTime(t*0.0002);
- }
- if (hdr->Color) {
- boost::uint8_t r, g, b, a = 0;
- liblas::Color color;
- liblas::detail::read_n(r, *strm, sizeof(r));
- liblas::detail::read_n(b, *strm, sizeof(b));
- liblas::detail::read_n(g, *strm, sizeof(g));
-
- // TS .bin says to read 4 bytes here for some reason. Maybe
- // this is an alpha value or something
- liblas::detail::read_n(a, *strm, sizeof(a));
-
- color.SetGreen(g);
- color.SetBlue(b);
- color.SetRed(r);
- p.SetColor(color);
- }
-
- // Set return number
- /*
- TerraScan uses two bits for storing echo information. The possible values are:
- 0 Only echo
- 1 First of many echo
- 2 Intermediate echo
- 3 Last of many echo
- */
- if (point->Echo == 0) {
- p.SetNumberOfReturns(1);
- p.SetReturnNumber(1);
- } else if (point->Echo == 1) {
- p.SetReturnNumber(1);
- } else if (point->Echo == 3) {
- p.SetReturnNumber(2);
- p.SetNumberOfReturns(2);
- } else {
- // I don't know what the hell to do here without cumulating
- // through all of the points. Why wouldn't you store the return
- // number?!
- p.SetReturnNumber(2);
- p.SetNumberOfReturns(3);
- }
-
- try {
- writer->WritePoint(p);
- } catch (std::exception)
More information about the Liblas-commits
mailing list