[Liblas-commits] hg: 3 new changesets
liblas-commits at liblas.org
liblas-commits at liblas.org
Fri Sep 24 11:08:36 EDT 2010
changeset c8b5e45fa3f7 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=c8b5e45fa3f7
summary: clean up writer to use shared_ptr of header and properly return as-written header to caller.
changeset 8b0808d02713 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=8b0808d02713
summary: lasindex shouldn't need access to writer internals
changeset f9607da58af0 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=f9607da58af0
summary: add min-offset option to allow the user to set the offsets for the file to the minimum of points (as filtered). This will require another pass through the file, and the user is reminded of this in the help note
diffstat:
apps/las2las2.cpp | 65 +++++++++++++++++++++++++++++---
apps/laskernel.cpp | 4 +-
include/liblas/detail/writer/header.hpp | 2 +-
include/liblas/detail/writer/point.hpp | 4 +-
include/liblas/detail/writer/writer.hpp | 2 +-
include/liblas/laswriter.hpp | 2 +-
include/liblas/liblas.hpp | 6 +-
python/tests/File.txt | 2 +-
src/detail/writer/point.cpp | 22 +++++++----
src/detail/writer/writer.cpp | 7 +---
src/lasindex.cpp | 9 ++--
src/laswriter.cpp | 14 ++++---
test/unit/laswriter_test.cpp | 3 +
13 files changed, 100 insertions(+), 42 deletions(-)
diffs (truncated from 402 to 300 lines):
diff -r 27172e34ddff -r f9607da58af0 apps/las2las2.cpp
--- a/apps/las2las2.cpp Thu Sep 23 15:49:11 2010 -0500
+++ b/apps/las2las2.cpp Fri Sep 24 10:08:25 2010 -0500
@@ -109,11 +109,11 @@
{
header.SetMin(tree.get<double>("minimum.x"),
tree.get<double>("minimum.y"),
- tree.get<double>("minimum.x"));
+ tree.get<double>("minimum.z"));
header.SetMax(tree.get<double>("maximum.x"),
tree.get<double>("maximum.y"),
- tree.get<double>("maximum.x"));
+ tree.get<double>("maximum.z"));
for (boost::uint32_t i = 0; i < 5; i++)
{
@@ -141,13 +141,26 @@
}
+void SetStreamPrecision(std::ostream& os, double scale)
+{
+ os.setf(std::ios_base::fixed, std::ios_base::floatfield);
+
+ double frac = 0;
+ double integer = 0;
+ frac = std::modf(scale, &integer);
+
+ boost::uint32_t prec = static_cast<boost::uint32_t>(std::fabs(std::floor(std::log10(frac))));
+ os.precision(prec);
+}
+
bool process( std::string const& input,
std::string const& output,
- liblas::Header const& header,
+ liblas::Header & header,
std::vector<liblas::FilterPtr>& filters,
std::vector<liblas::TransformPtr>& transforms,
boost::uint32_t split_size,
- bool verbose)
+ bool verbose,
+ bool min_offset)
{
@@ -164,6 +177,39 @@
reader.SetFilters(filters);
reader.SetTransforms(transforms);
+ if (min_offset)
+ {
+
+ liblas::property_tree::ptree tree = reader.Summarize();
+
+ try
+ {
+ header.SetOffset(tree.get<double>("minimum.x"),
+ tree.get<double>("minimum.y"),
+ tree.get<double>("minimum.z"));
+
+
+ } catch (liblas::property_tree::ptree_bad_path const& e)
+ {
+ std::cerr << "Unable to write minimum header info. Does the outputted file have any points?";
+ return false;
+ }
+ if (verbose)
+ {
+
+
+ std::cout << "Using minimum offsets ";
+ SetStreamPrecision(std::cout, header.GetScaleX());
+ std::cout << header.GetOffsetX() << " ";
+ SetStreamPrecision(std::cout, header.GetScaleY());
+ std::cout << header.GetOffsetY() << " ";
+ SetStreamPrecision(std::cout, header.GetScaleZ());
+ std::cout << header.GetOffsetZ() << " ";
+ std::cout << std::endl;
+ }
+ reader.Reset();
+ }
+
std::ofstream* ofs = new std::ofstream;
std::string out = output;
liblas::Writer* writer = 0;
@@ -261,6 +307,8 @@
std::string output;
bool verbose = false;
+ bool bMinOffset = false;
+
std::vector<liblas::FilterPtr> filters;
std::vector<liblas::TransformPtr> transforms;
@@ -316,7 +364,11 @@
OutputHelp(std::cout, options);
return 1;
}
-
+
+ if (vm.count("min-offset"))
+ {
+ bMinOffset = true;
+ }
filters = GetFilters(vm, verbose);
@@ -329,7 +381,8 @@
filters,
transforms,
split_size,
- verbose
+ verbose,
+ bMinOffset
);
if (!op) {
return (1);
diff -r 27172e34ddff -r f9607da58af0 apps/laskernel.cpp
--- a/apps/laskernel.cpp Thu Sep 23 15:49:11 2010 -0500
+++ b/apps/laskernel.cpp Fri Sep 24 10:08:25 2010 -0500
@@ -142,11 +142,11 @@
transform_options.add_options()
("a_srs", po::value< string >(), "Coordinate system to assign to input LAS file")
("t_srs", po::value< string >(), "Coordinate system to reproject output LAS file to. Use --a_srs or verify that your input LAS file has a coordinate system according to lasinfo")
- ("offset", po::value< string >(), "A comma-separated list of offsets to set on the output file: \n--offset 0,0,0 \n--offset min,min,min")
+ ("offset", po::value< string >(), "A comma-separated list of offsets to set on the output file: \n--offset 0,0,0")
("scale", po::value< string >(), "A comma-separated list of scales to set on the output file: \n--scale 0.1,0.1,0.00001")
("format,f", po::value< string >(), "Set the LAS format of the new file (only 1.0-1.2 supported at this time): \n--format 1.2\n-f 1.1")
("pad-header", po::value< string >(), "Add extra bytes to the existing header")
-
+ ("min-offset", po::value<bool>()->zero_tokens(), "Set the offset of the header to the minimums of all values in the file. Note that this requires multiple read passes through the file to achieve.")
;
return transform_options;
diff -r 27172e34ddff -r f9607da58af0 include/liblas/detail/writer/header.hpp
--- a/include/liblas/detail/writer/header.hpp Thu Sep 23 15:49:11 2010 -0500
+++ b/include/liblas/detail/writer/header.hpp Fri Sep 24 10:08:25 2010 -0500
@@ -61,7 +61,7 @@
Header(std::ostream& ofs, boost::uint32_t& count, liblas::Header const& header );
- const liblas::Header& GetHeader() const { return m_header; }
+ liblas::Header const& GetHeader() const { return m_header; }
void write();
private:
diff -r 27172e34ddff -r f9607da58af0 include/liblas/detail/writer/point.hpp
--- a/include/liblas/detail/writer/point.hpp Thu Sep 23 15:49:11 2010 -0500
+++ b/include/liblas/detail/writer/point.hpp Fri Sep 24 10:08:25 2010 -0500
@@ -63,7 +63,7 @@
typedef WriterBase Base;
- Point(std::ostream& ofs, boost::uint32_t& count, liblas::Header const& header);
+ Point(std::ostream& ofs, boost::uint32_t& count, HeaderPtr header);
virtual ~Point();
const liblas::Point& GetPoint() const { return m_point; }
@@ -81,7 +81,7 @@
Point& operator=(Point const& rhs);
std::ostream& m_ofs;
- const liblas::Header& m_header;
+ HeaderPtr m_header;
liblas::Point m_point;
PointRecord m_record;
diff -r 27172e34ddff -r f9607da58af0 include/liblas/detail/writer/writer.hpp
--- a/include/liblas/detail/writer/writer.hpp Thu Sep 23 15:49:11 2010 -0500
+++ b/include/liblas/detail/writer/writer.hpp Fri Sep 24 10:08:25 2010 -0500
@@ -64,7 +64,7 @@
LASVersion GetVersion() const;
liblas::Header const& WriteHeader(liblas::Header const& header);
void UpdateHeader(liblas::Header const& header);
- void WritePoint(liblas::Point const& record, const liblas::Header& header);
+ void WritePoint(liblas::Point const& record, HeaderPtr header);
std::ostream& GetStream() const;
diff -r 27172e34ddff -r f9607da58af0 include/liblas/laswriter.hpp
--- a/include/liblas/laswriter.hpp Thu Sep 23 15:49:11 2010 -0500
+++ b/include/liblas/laswriter.hpp Fri Sep 24 10:08:25 2010 -0500
@@ -116,7 +116,7 @@
const std::auto_ptr<WriterI> m_pimpl;
- Header m_header;
+ HeaderPtr m_header;
detail::PointRecord m_record;
std::vector<liblas::FilterI*>* m_filters;
diff -r 27172e34ddff -r f9607da58af0 include/liblas/liblas.hpp
--- a/include/liblas/liblas.hpp Thu Sep 23 15:49:11 2010 -0500
+++ b/include/liblas/liblas.hpp Fri Sep 24 10:08:25 2010 -0500
@@ -137,9 +137,9 @@
{
public:
- virtual Header const& WriteHeader(const Header& header) = 0;
- virtual void UpdateHeader(const Header& header) = 0;
- virtual void WritePoint(const Point& point, const Header& header) = 0;
+ virtual Header const& WriteHeader(Header const& header) = 0;
+ virtual void UpdateHeader(Header const& header) = 0;
+ virtual void WritePoint(const Point& point, HeaderPtr header) = 0;
virtual std::ostream& GetStream() const = 0;
diff -r 27172e34ddff -r f9607da58af0 python/tests/File.txt
--- a/python/tests/File.txt Thu Sep 23 15:49:11 2010 -0500
+++ b/python/tests/File.txt Fri Sep 24 10:08:25 2010 -0500
@@ -266,7 +266,7 @@
>>> f4 = file.File('junk4.las',mode='w',header=h2)
>>> f4.header.data_offset
- 227L
+ 229L
>>> for i in points:
... f4.write(i)
diff -r 27172e34ddff -r f9607da58af0 src/detail/writer/point.cpp
--- a/src/detail/writer/point.cpp Thu Sep 23 15:49:11 2010 -0500
+++ b/src/detail/writer/point.cpp Fri Sep 24 10:08:25 2010 -0500
@@ -55,14 +55,14 @@
namespace liblas { namespace detail { namespace writer {
-Point::Point(std::ostream& ofs, uint32_t& count, const liblas::Header& header)
+Point::Point(std::ostream& ofs, uint32_t& count, HeaderPtr header)
: Base(ofs, count)
, m_ofs(ofs)
, m_header(header)
, m_point(liblas::Point())
- , m_format(header.GetSchema())
- , bTime(header.GetSchema().HasTime())
- , bColor(header.GetSchema().HasColor())
+ , m_format(header->GetSchema())
+ , bTime(header->GetSchema().HasTime())
+ , bColor(header->GetSchema().HasColor())
{
setup();
}
@@ -101,6 +101,12 @@
std::size_t byteswritten(0);
+
+ // We need to remember to properly scale the raw xyz data in
+ // accordance with what the user is setting for values in the header
+ // they are writing to the file. FIXME: this needs to be done
+ // when the point writer turns into just a simple writer of the
+ // liblas::Point::m_format_data + m_extra data
m_point = point;
fill();
@@ -176,10 +182,10 @@
{
liblas::Point& p = m_point;
- m_record.x = static_cast<int32_t>(detail::sround(((p.GetX() - m_header.GetOffsetX()) / m_header.GetScaleX())));
- m_record.y = static_cast<int32_t>(detail::sround(((p.GetY() - m_header.GetOffsetY()) / m_header.GetScaleY())));
- m_record.z = static_cast<int32_t>(detail::sround(((p.GetZ() - m_header.GetOffsetZ()) / m_header.GetScaleZ())));
-
+ m_record.x = static_cast<int32_t>(detail::sround(((p.GetX() - m_header->GetOffsetX()) / m_header->GetScaleX())));
+ m_record.y = static_cast<int32_t>(detail::sround(((p.GetY() - m_header->GetOffsetY()) / m_header->GetScaleY())));
+ m_record.z = static_cast<int32_t>(detail::sround(((p.GetZ() - m_header->GetOffsetZ()) / m_header->GetScaleZ())));
+
Classification::bitset_type clsflags(p.GetClassification());
m_record.classification = static_cast<uint8_t>(clsflags.to_ulong());
diff -r 27172e34ddff -r f9607da58af0 src/detail/writer/writer.cpp
--- a/src/detail/writer/writer.cpp Thu Sep 23 15:49:11 2010 -0500
+++ b/src/detail/writer/writer.cpp Fri Sep 24 10:08:25 2010 -0500
@@ -69,11 +69,6 @@
{
m_header_writer = HeaderWriterPtr(new writer::Header(m_ofs,m_pointCount, header) );
- if (m_header_writer == 0) {
- m_header_writer = HeaderWriterPtr(new writer::Header(m_ofs,m_pointCount, header) );
- } else {
- m_header_writer = HeaderWriterPtr(new writer::Header(m_ofs,m_pointCount, header) );
- }
m_header_writer->write();
return m_header_writer->GetHeader();
}
@@ -89,7 +84,7 @@
}
}
-void WriterImpl::WritePoint(liblas::Point const& point, const liblas::Header& header)
+void WriterImpl::WritePoint(liblas::Point const& point, HeaderPtr header)
{
if (m_point_writer == 0) {
m_point_writer = PointWriterPtr(new writer::Point(m_ofs, m_pointCount, header));
diff -r 27172e34ddff -r f9607da58af0 src/lasindex.cpp
--- a/src/lasindex.cpp Thu Sep 23 15:49:11 2010 -0500
+++ b/src/lasindex.cpp Fri Sep 24 10:08:25 2010 -0500
@@ -43,7 +43,6 @@
#include <liblas/laswriter.hpp>
#include <liblas/detail/index/indexoutput.hpp>
More information about the Liblas-commits
mailing list