[Liblas-commits] r1235 - in trunk: . include include/liblas src

liblas-commits at liblas.org liblas-commits at liblas.org
Sat Apr 18 00:06:58 EDT 2009


Author: hobu
Date: Sat Apr 18 00:06:57 2009
New Revision: 1235
URL: http://liblas.org/changeset/1235

Log:
configure support and skeleton for spatialindex

Added:
   trunk/include/liblas/lasindex.hpp
      - copied, changed from r1176, /trunk/include/liblas/lasheader.hpp
   trunk/src/lasindex.cpp
      - copied, changed from r1176, /trunk/src/lasheader.cpp
Modified:
   trunk/configure.ac
   trunk/include/Makefile.am
   trunk/src/Makefile.am

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Sat Apr 18 00:06:57 2009
@@ -215,6 +215,42 @@
 AM_CONDITIONAL([GEOTIFF_IS_CONFIG], [test ! x$GEOTIFF_CONFIG = xno])
 
 
+
+dnl #########################################################################
+dnl Determine SpatialIndex Support
+dnl #########################################################################
+
+AC_ARG_WITH([spatialindex],
+    AC_HELP_STRING([--with-spatialindex=ARG], [libspatialindex library to use (no or path)]),,)
+
+if test "${SPATIALINDEX_CONFIG}" != "no" ; then
+    AC_MSG_CHECKING([for spatialindex RTree.h])
+    if test -f ${with_spatialindex}/include/spatialindex/RTree.h ; then
+        SPATIALINDEX_INC="-I$with_spatialindex/include/"
+        SPATIALINDEX_CONFIG="yes"
+    	AC_MSG_RESULT([yes])
+    else
+        SPATIALINDEX_CONFIG="no"
+    	AC_MSG_RESULT([no])
+    fi
+fi
+    
+AC_MSG_CHECKING([for libspatialindex])
+if test "${SPATIALINDEX_CONFIG}" = "no" ; then
+    HAVE_SPATIALINDEX="no"
+    AC_MSG_RESULT([no])
+else
+    LIBS="-L$with_spatialindex/lib -lspatialindex $LIBS"
+    HAVE_SPATIALINDEX="yes"
+    AC_MSG_RESULT([yes])
+fi
+
+AC_SUBST([SPATIALINDEX_INC])
+AC_SUBST([SPATIALINDEX_PREFIX])
+AM_CONDITIONAL([SPATIALINDEX_IS_CONFIG], [test ! x$SPATIALINDEX_CONFIG = xno])
+
+
+
 dnl Oracle Checks
 
 ORACLE_OCI_REQ_VERSION="10.0.1"
@@ -277,6 +313,14 @@
         LOC_MSG([   - INCLUDE directories...: ${GEOTIFF_INC}])
     fi
 fi
+
+LOC_MSG([  Spatial Index support..: ${HAVE_SPATIALINDEX}])
+if test "${HAVE_GEOTIFF}" != "no" ; then
+    LOC_MSG([   - libspatialindex....: ${SPATIALINDEX_CONFIG}])
+    if test -n "${SPATIALINDEX_INC}" ; then
+        LOC_MSG([   - INCLUDE directories...: ${SPATIALINDEX_INC}])
+    fi
+fi
 LOC_MSG()
 LOC_MSG([  LIBS.....................: ${LIBS}])
 LOC_MSG()

Modified: trunk/include/Makefile.am
==============================================================================
--- trunk/include/Makefile.am	(original)
+++ trunk/include/Makefile.am	Sat Apr 18 00:06:57 2009
@@ -5,11 +5,12 @@
     liblas/exception.hpp \
     liblas/guid.hpp \
     liblas/iterator.hpp \
-    liblas/lasclassification.hpp \					    
+    liblas/lasclassification.hpp \
     liblas/lascolor.hpp \
     liblas/laserror.hpp \
     liblas/lasfile.hpp \
     liblas/lasheader.hpp \
+	liblas/lasindex.hpp \
     liblas/laspoint.hpp \
     liblas/lasreader.hpp \
     liblas/lasvariablerecord.hpp \

Copied: trunk/include/liblas/lasindex.hpp (from r1176, /trunk/include/liblas/lasheader.hpp)
==============================================================================
--- /trunk/include/liblas/lasheader.hpp	(original)
+++ trunk/include/liblas/lasindex.hpp	Sat Apr 18 00:06:57 2009
@@ -2,12 +2,11 @@
  * $Id$
  *
  * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
- * Purpose:  LAS header class 
- * Author:   Mateusz Loskot, mateusz at loskot.net
+ * Purpose:  LAS indexing class 
+ * Author:   Howard Butler, hobu.inc at gmail.com
  *
  ******************************************************************************
- * Copyright (c) 2008, Mateusz Loskot
- * Copyright (c) 2008, Phil Vachon
+ * Copyright (c) 2009, Howard Butler
  *
  * All rights reserved.
  * 
@@ -40,15 +39,9 @@
  * OF SUCH DAMAGE.
  ****************************************************************************/
 
-#ifndef LIBLAS_LASHEADER_HPP_INCLUDED
-#define LIBLAS_LASHEADER_HPP_INCLUDED
+#ifndef LIBLAS_LASINDEX_HPP_INCLUDED
+#define LIBLAS_LASINDEX_HPP_INCLUDED
 
-#include <liblas/lasvariablerecord.hpp>
-#include <liblas/lasspatialreference.hpp>
-#include <liblas/cstdint.hpp>
-#include <liblas/guid.hpp>
-#include <liblas/detail/utility.hpp>
-#include <liblas/detail/fwd.hpp>
 
 //std
 #include <string>
@@ -56,338 +49,27 @@
 
 namespace liblas {
 
-/// Definition of public header block.
-/// The header contains set of generic data and metadata
-/// describing a family of ASPRS LAS files. The header is stored
-/// at the beginning of every valid ASPRS LAS file.
-///
-/// \todo  TODO (low-priority): replace static-size char arrays as data members
-///        with std::string and return const-reference to string object.
-///
-class LASHeader
+
+class LASIndex
 {
 public:
 
-    /// Range of allowed ASPRS LAS file format versions.
-    enum FormatVersion
-    {
-        eVersionMajorMin = 1, ///< Minimum of major component
-        eVersionMajorMax = 1, ///< Maximum of major component
-        eVersionMinorMin = 0, ///< Minimum of minor component
-        eVersionMinorMax = 2 ///< Maximum of minor component
-    };
-
-    /// Versions of point record format.
-    enum PointFormat
-    {
-        ePointFormat0 = 0, ///< Point Data Format \e 0
-        ePointFormat1 = 1, ///< Point Data Format \e 1
-        ePointFormat2 = 2, ///< Point Data Format \e 2
-        ePointFormat3 = 3 ///< Point Data Format \e 3
-
-    };
-
-    /// Number of bytes of point record storage in particular format.
-    enum PointSize
-    {
-        ePointSize0 = 20, ///< Size of point record in data format \e 0
-        ePointSize1 = 28, ///< Size of point record in data format \e 1
-        ePointSize2 = 26, ///< Size of point record in data format \e 2
-        ePointSize3 = 34  ///< Size of point record in data format \e 3
-
-    };
-
-    /// Official signature of ASPRS LAS file format, always \b "LASF".
-    static char const* const FileSignature;
-
-    /// Default system identifier used by libLAS, always \b "libLAS".
-    static char const* const SystemIdentifier;
-
-    /// Default software identifier used by libLAS, always \b "libLAS X.Y".
-    static char const* const SoftwareIdentifier;
-
-    /// Default constructor.
-    /// The default constructed header is configured according to the ASPRS
-    /// LAS 1.1 Specification, point data format set to 0.
-    /// Other fields filled with 0.
-    LASHeader();
+    
+    LASIndex();
 
     /// Copy constructor.
-    LASHeader(LASHeader const& other);
+    LASIndex(LASIndex const& other);
 
     /// Assignment operator.
-    LASHeader& operator=(LASHeader const& rhs);
+    LASIndex& operator=(LASIndex const& rhs);
     
     /// Comparison operator.
-    bool operator==(const LASHeader& other) const;
-
-    /// Get ASPRS LAS file signature.
-    /// \return 4-characters long string - \b "LASF".
-    std::string GetFileSignature() const;
-
-    /// Set ASPRS LAS file signature.
-    /// The only value allowed as file signature is \b "LASF",
-    /// defined as FileSignature constant.
-    /// \exception std::invalid_argument - if invalid signature given.
-    /// \param v - string contains file signature, at least 4-bytes long
-    /// with "LASF" as first four bytes.
-    void SetFileSignature(std::string const& v);
-
-    /// Get file source identifier.
-    /// \exception No throw
-    uint16_t GetFileSourceId() const;
-
-    /// Set file source identifier.
-    /// \param v - should be set to a value between 1 and 65535.
-    /// \exception No throw
-    ///
-    /// \todo TODO: Should we warn or throw about type overflow when user passes 65535 + 1 = 0
-    void SetFileSourceId(uint16_t v);
-
-    /// Get value field reserved by the ASPRS LAS Specification.
-    /// \note This field is always filled with 0.
-    ///
-    /// \todo TODO: Should we warn or throw about type overflow when user passes 65535 + 1 = 0
-    uint16_t GetReserved() const;
-
-    /// Set reserved value for the header identifier.
-    /// \param v - should be set to a value between 1 and 65535.
-    /// \exception No throw
-    void SetReserved(uint16_t v);
-
-    /// Get project identifier.
-    /// \return Global Unique Identifier as an instance of liblas::guid class.
-    guid GetProjectId() const;
-
-    /// Set project identifier.
-    void SetProjectId(guid const& v);
-
-    /// Get major component of version of LAS format.
-    /// \return Always 1 is returned as the only valid value.
-    uint8_t GetVersionMajor() const;
-
-    /// Set major component of version of LAS format.
-    /// \exception std::out_of_range - invalid value given.
-    /// \param v - value between eVersionMajorMin and eVersionMajorMax.
-    void SetVersionMajor(uint8_t v);
-
-    /// Get minor component of version of LAS format.
-    /// \return Valid values are 1 or 0.
-    uint8_t GetVersionMinor() const;
-
-    /// Set minor component of version of LAS format.
-    /// \exception std::out_of_range - invalid value given.
-    /// \param v - value between eVersionMinorMin and eVersionMinorMax.
-    void SetVersionMinor(uint8_t v);
-
-    /// Get system identifier.
-    /// Default value is \b "libLAS" specified as the SystemIdentifier constant.
-    /// \param pad - if true the returned string is padded right with spaces and
-    /// its length is 32 bytes, if false (default) no padding occurs and
-    /// length of the returned string is <= 32 bytes.
-    /// \return value of system identifier field.
-    std::string GetSystemId(bool pad = false) const;
-
-    /// Set system identifier.
-    /// \exception std::invalid_argument - if identifier longer than 32 bytes.
-    /// \param v - system identifiers string.
-    void SetSystemId(std::string const& v);
-
-    /// Get software identifier.
-    /// Default value is \b "libLAS 1.0", specified as the SoftwareIdentifier constant.
-    /// \param pad - if true the returned string is padded right with spaces and its length is 32 bytes,
-    /// if false (default) no padding occurs and length of the returned string is <= 32 bytes.
-    /// \return value of generating software identifier field.
-    std::string GetSoftwareId(bool pad = false) const;
-
-    /// Set software identifier.
-    /// \exception std::invalid_argument - if identifier is longer than 32 bytes.
-    /// \param v - software identifiers string.
-    void SetSoftwareId(std::string const& v);
-
-    /// Get day of year of file creation date.
-    /// \todo TODO: Use full date structure instead of Julian date number.
-    uint16_t GetCreationDOY() const;
-
-    /// Set day of year of file creation date.
-    /// \exception std::out_of_range - given value is higher than number 366.
-    /// \todo TODO: Use full date structure instead of Julian date number.
-    void SetCreationDOY(uint16_t v);
-
-    /// Set year of file creation date.
-    /// \todo TODO: Remove if full date structure is used.
-    uint16_t GetCreationYear() const;
-
-    /// Get year of file creation date.
-    /// \exception std::out_of_range - given value is higher than number 9999.
-    /// \todo TODO: Remove if full date structure is used.
-    void SetCreationYear(uint16_t v);
-
-    /// Get number of bytes of generic verion of public header block storage.
-    /// Standard version of the public header block is 227 bytes long.
-    uint16_t GetHeaderSize() const;
-    
-    /// Get number of bytes from the beginning to the first point record.
-    uint32_t GetDataOffset() const;
-
-    /// Set number of bytes from the beginning to the first point record.
-    /// \exception std::out_of_range - if given offset is bigger than 227+2 bytes
-    /// for the LAS 1.0 format and 227 bytes for the LAS 1.1 format.
-    void SetDataOffset(uint32_t v);
-
-    /// Get number of variable-length records.
-    uint32_t GetRecordsCount() const;
-
-    /// Set number of variable-length records.
-    void SetRecordsCount(uint32_t v);
-    
-    /// Get identifier of point data (record) format.
-    PointFormat GetDataFormatId() const;
-
-    /// Set identifier of point data (record) format.
-    void SetDataFormatId(PointFormat v);
-
-    /// \todo To be documented
-    uint16_t GetDataRecordLength() const;
-    
-    /// Get total number of point records stored in the LAS file.
-    uint32_t GetPointRecordsCount() const;
-
-    /// Set number of point records that will be stored in a new LAS file.
-    void SetPointRecordsCount(uint32_t v);
-    
-    /// Get array of the total point records per return.
-    std::vector<uint32_t> const& GetPointRecordsByReturnCount() const;
-
-    /// Set values of 5-elements array of total point records per return.
-    /// \exception std::out_of_range - if index is bigger than 4.
-    /// \param index - subscript (0-4) of array element being updated.
-    /// \param v - new value to assign to array element identified by index.
-    void SetPointRecordsByReturnCount(std::size_t index, uint32_t v);
-    
-    /// Get scale factor for X coordinate.
-    double GetScaleX() const;
-
-    /// Get scale factor for Y coordinate.
-    double GetScaleY() const;
-    
-    /// Get scale factor for Z coordinate.
-    double GetScaleZ() const;
-
-    /// Set values of scale factor for X, Y and Z coordinates.
-    void SetScale(double x, double y, double z);
-
-    /// Get X coordinate offset.
-    double GetOffsetX() const;
-    
-    /// Get Y coordinate offset.
-    double GetOffsetY() const;
-    
-    /// Get Z coordinate offset.
-    double GetOffsetZ() const;
-
-    /// Set values of X, Y and Z coordinates offset.
-    void SetOffset(double x, double y, double z);
-
-    /// Get minimum value of extent of X coordinate.
-    double GetMaxX() const;
-
-    /// Get maximum value of extent of X coordinate.
-    double GetMinX() const;
-
-    /// Get minimum value of extent of Y coordinate.
-    double GetMaxY() const;
-
-    /// Get maximum value of extent of Y coordinate.
-    double GetMinY() const;
-
-    /// Get minimum value of extent of Z coordinate.
-    double GetMaxZ() const;
-
-    /// Get maximum value of extent of Z coordinate.
-    double GetMinZ() const;
-
-    /// Set maximum values of extent of X, Y and Z coordinates.
-    void SetMax(double x, double y, double z);
-
-    /// Set minimum values of extent of X, Y and Z coordinates.
-    void SetMin(double x, double y, double z);
-
-    /// Adds a variable length record to the header
-    void AddVLR(LASVariableRecord const& v);
-    
-    /// Returns a VLR 
-    LASVariableRecord const& GetVLR(uint32_t index) const;
-
-    /// Removes a VLR from the the header.
-    void DeleteVLR(uint32_t index);
-
-    /// Rewrite variable-length record with georeference infomation, if available.
-    void SetGeoreference();
-    
-    /// Fetch the georeference
-    LASSpatialReference GetSRS() const;
-    
-    /// Set the georeference
-    void SetSRS(LASSpatialReference& srs);
-    
+    bool operator==(const LASIndex& other) const;    
 private:
     
-    typedef detail::Point<double> PointScales;
-    typedef detail::Point<double> PointOffsets;
-    typedef detail::Extents<double> PointExtents;
-
-    enum
-    {
-        eDataSignatureSize = 2,
-        eFileSignatureSize = 4,
-        ePointsByReturnSize = 5,
-        eProjectId4Size = 8,
-        eSystemIdSize = 32,
-        eSoftwareIdSize = 32,
-        eHeaderSize = 227,
-        eFileSourceIdMax = 65535
-    };
 
-    // TODO (low-priority): replace static-size char arrays
-    // with std::string and return const-reference to string object.
-    
-    //
-    // Private function members
-    //
-    void Init();
-    void ClearGeoKeyVLRs();
-
-    //
-    // Private data members
-    //
-    char m_signature[eFileSignatureSize];
-    uint16_t m_sourceId;
-    uint16_t m_reserved;
-    uint32_t m_projectId1;
-    uint16_t m_projectId2;
-    uint16_t m_projectId3;
-    uint8_t m_projectId4[eProjectId4Size];
-    uint8_t m_versionMajor;
-    uint8_t m_versionMinor;
-    char m_systemId[eSystemIdSize];
-    char m_softwareId[eSoftwareIdSize];
-    uint16_t m_createDOY;
-    uint16_t m_createYear;
-    uint16_t m_headerSize;
-    uint32_t m_dataOffset;
-    uint32_t m_recordsCount;
-    uint8_t m_dataFormatId;
-    uint16_t m_dataRecordLen;
-    uint32_t m_pointRecordsCount;
-    std::vector<uint32_t> m_pointRecordsByReturn;
-    PointScales m_scales;
-    PointOffsets m_offsets;
-    PointExtents m_extents;
-    std::vector<LASVariableRecord> m_vlrs;
-    LASSpatialReference m_srs;
 };
 
 } // namespace liblas
 
-#endif // LIBLAS_LASHEADER_HPP_INCLUDED
+#endif // LIBLAS_LASINDEX_HPP_INCLUDED

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Sat Apr 18 00:06:57 2009
@@ -9,7 +9,11 @@
 GEOTIFF_CPPFLAGS = @GEOTIFF_INC@ -DHAVE_LIBGEOTIFF=1
 endif
 
-AM_CPPFLAGS = $(GEOTIFF_CPPFLAGS) $(GDAL_CPPFLAGS) -I../include -I../include/detail
+if SPATIALINDEX_IS_CONFIG
+SPATIALINDEX_CPPFLAGS = @SPATIALINDEX_INC@ -DHAVE_SPATIALINDEX=1
+endif
+
+AM_CPPFLAGS = $(GEOTIFF_CPPFLAGS) $(GDAL_CPPFLAGS) $(SPATIALINDEX_CPPFLAGS) -I../include -I../include/detail
 
 lib_LTLIBRARIES = liblas.la
 
@@ -19,6 +23,7 @@
 	laserror.cpp \
 	laspoint.cpp \
 	lasheader.cpp \
+	lasindex.cpp \
 	lasvariablerecord.cpp \
 	lasreader.cpp \
 	laswriter.cpp \

Copied: trunk/src/lasindex.cpp (from r1176, /trunk/src/lasheader.cpp)
==============================================================================
--- /trunk/src/lasheader.cpp	(original)
+++ trunk/src/lasindex.cpp	Sat Apr 18 00:06:57 2009
@@ -2,12 +2,11 @@
  * $Id$
  *
  * Project:  libLAS - http://liblas.org - A BSD library for LAS format data.
- * Purpose:  LAS header class 
- * Author:   Mateusz Loskot, mateusz at loskot.net
+ * Purpose:  LAS indexing class 
+ * Author:   Howard Butler, hobu.inc at gmail.com
  *
  ******************************************************************************
- * Copyright (c) 2008, Mateusz Loskot
- * Copyright (c) 2008, Phil Vachon
+ * Copyright (c) 2009, Howard Butler
  *
  * All rights reserved.
  * 
@@ -40,728 +39,48 @@
  * OF SUCH DAMAGE.
  ****************************************************************************/
 
-#include <liblas/lasheader.hpp>
+#include <liblas/lasindex.hpp>
 #include <liblas/cstdint.hpp>
 #include <liblas/guid.hpp>
-#include <liblas/detail/utility.hpp>
-#include <liblas/lasspatialreference.hpp>
-
-// GeoTIFF
-#ifdef HAVE_LIBGEOTIFF
-#include <geotiff.h>
-#include <geo_simpletags.h>
-#include "geo_normalize.h"
-#include "geo_simpletags.h"
-#include "geovalues.h"
-#include "geotiffio.h"
-#endif // HAVE_LIBGEOTIFF
 
 //std
-#include <algorithm>
-#include <fstream>
-#include <stdexcept>
-#include <string>
-#include <vector>
-#include <cstring> // std::memset, std::memcpy, std::strncpy
-#include <cassert>
-#include <ctime>
+// #include <algorithm>
+// #include <fstream>
+// #include <stdexcept>
+// #include <string>
+// #include <vector>
+// #include <cstring> // std::memset, std::memcpy, std::strncpy
+// #include <cassert>
+// #include <ctime>
 
 
 namespace liblas
 {
 
-char const* const LASHeader::FileSignature = "LASF";
-char const* const LASHeader::SystemIdentifier = "libLAS";
-char const* const LASHeader::SoftwareIdentifier = "libLAS 1.2";
-
-LASHeader::LASHeader()
+LASIndex::LASIndex()
 {
-    Init();
 }
 
-LASHeader::LASHeader(LASHeader const& other) :
-    m_sourceId(other.m_sourceId),
-    m_reserved(other.m_reserved),
-    m_projectId1(other.m_projectId1),
-    m_projectId2(other.m_projectId2),
-    m_projectId3(other.m_projectId3),
-    m_versionMajor(other.m_versionMajor),
-    m_versionMinor(other.m_versionMinor),
-    m_createDOY(other.m_createDOY),
-    m_createYear(other.m_createYear),
-    m_headerSize(other.m_headerSize),
-    m_dataOffset(other.m_dataOffset),
-    m_recordsCount(other.m_recordsCount),
-    m_dataFormatId(other.m_dataFormatId),
-    m_dataRecordLen(other.m_dataRecordLen),
-    m_pointRecordsCount(other.m_pointRecordsCount),
-    m_scales(other.m_scales),
-    m_offsets(other.m_offsets),
-    m_extents(other.m_extents),
-    m_srs(other.m_srs)
+LASIndex::LASIndex(LASIndex const& other) 
 {
-    void* p = 0;
-
-    p = std::memcpy(m_signature, other.m_signature, eFileSignatureSize);
-    assert(p == m_signature);
-    p = std::memcpy(m_projectId4, other.m_projectId4, eProjectId4Size); 
-    assert(p == m_projectId4);
-    p = std::memcpy(m_systemId, other.m_systemId, eSystemIdSize);
-    assert(p == m_systemId);
-    p = std::memcpy(m_softwareId, other.m_softwareId, eSoftwareIdSize);
-    assert(p == m_softwareId);
-    std::vector<uint32_t>(other.m_pointRecordsByReturn).swap(m_pointRecordsByReturn);
-    assert(ePointsByReturnSize >= m_pointRecordsByReturn.size());
-    
-    std::vector<LASVariableRecord>(other.m_vlrs).swap(m_vlrs);
 
 }
 
-LASHeader& LASHeader::operator=(LASHeader const& rhs)
+LASIndex& LASIndex::operator=(LASIndex const& rhs)
 {
     if (&rhs != this)
     {
-        void* p = 0;
-        p = std::memcpy(m_signature, rhs.m_signature, eFileSignatureSize);
-        assert(p == m_signature);
-        m_sourceId = rhs.m_sourceId;
-        m_reserved = rhs.m_reserved;
-        m_projectId1 = rhs.m_projectId1;
-        m_projectId2 = rhs.m_projectId2;
-        m_projectId3 = rhs.m_projectId3;
-        p = std::memcpy(m_projectId4, rhs.m_projectId4, eProjectId4Size); 
-        assert(p == m_projectId4);
-        m_versionMajor = rhs.m_versionMajor;
-        m_versionMinor = rhs.m_versionMinor;
-        p = std::memcpy(m_systemId, rhs.m_systemId, eSystemIdSize);
-        assert(p == m_systemId);
-        p = std::memcpy(m_softwareId, rhs.m_softwareId, eSoftwareIdSize);
-        assert(p == m_softwareId);
-        m_createDOY = rhs.m_createDOY;
-        m_createYear = rhs.m_createYear;
-        m_headerSize = rhs.m_headerSize;
-        m_dataOffset = rhs.m_dataOffset;
-        m_recordsCount = rhs.m_recordsCount;
-//        m_recordsCount = 0;
-        m_dataFormatId = rhs.m_dataFormatId;
-        m_dataRecordLen = rhs.m_dataRecordLen;
-        m_pointRecordsCount = rhs.m_pointRecordsCount;
-        
-        std::vector<uint32_t>(rhs.m_pointRecordsByReturn).swap(m_pointRecordsByReturn);
-        assert(ePointsByReturnSize >= m_pointRecordsByReturn.size());
-
-        std::vector<LASVariableRecord>(rhs.m_vlrs).swap(m_vlrs);
-        m_scales = rhs.m_scales;
-        m_offsets = rhs.m_offsets;
-        m_extents = rhs.m_extents;
-        m_srs = rhs.m_srs;
     }
     return *this;
 }
 
-bool LASHeader::operator==(LASHeader const& other) const
+bool LASIndex::operator==(LASIndex const& other) const
 {
     if (&other == this) return true;
-    
-    if (m_signature != other.m_signature) return false;
-    if (m_sourceId != other.m_sourceId) return false;
-    if (m_reserved != other.m_reserved) return false;
-    if (m_projectId1 != other.m_projectId1) return false;
-    if (m_projectId2 != other.m_projectId2) return false;
-    if (m_projectId3 != other.m_projectId3) return false;
-    if (m_projectId4 != other.m_projectId4) return false;
-    if (m_versionMajor != other.m_versionMajor) return false;
-    if (m_versionMinor != other.m_versionMinor) return false;
-    if (m_systemId != other.m_systemId) return false;
-    if (m_softwareId != other.m_softwareId) return false;
-    if (m_createDOY != other.m_createDOY) return false;
-    if (m_createYear != other.m_createYear) return false;
-    if (m_headerSize != other.m_headerSize) return false;
-    if (m_dataOffset != other.m_dataOffset) return false;
-    if (m_recordsCount != other.m_recordsCount) return false;
-    if (m_dataFormatId != other.m_dataFormatId) return false;
-    if (m_dataRecordLen != other.m_dataRecordLen) return false;
-    if (m_pointRecordsCount != other.m_pointRecordsCount) return false;
-    if (m_pointRecordsByReturn != other.m_pointRecordsByReturn) return false;
-    if (m_scales != other.m_scales) return false;
-    if (m_offsets != other.m_offsets) return false;
-    if (m_extents != other.m_extents) return false;
-    
-    return true;
-}
-
-
-std::string LASHeader::GetFileSignature() const
-{
-    return std::string(m_signature, eFileSignatureSize);
-}
-
-void LASHeader::SetFileSignature(std::string const& v)
-{
-    if (0 != v.compare(0, eFileSignatureSize, FileSignature))
-        throw std::invalid_argument("invalid file signature");
-
-    std::strncpy(m_signature, v.c_str(), eFileSignatureSize);
-}
-
-uint16_t LASHeader::GetFileSourceId() const
-{
-    return m_sourceId;
-}
-
-void LASHeader::SetFileSourceId(uint16_t v)
-{
-    // TODO: Should we warn or throw about type overflow occuring when
-    //       user passes 65535 + 1 = 0
-    m_sourceId = v;
-}
-
-uint16_t LASHeader::GetReserved() const
-{
-    return m_reserved;
-}
-
-void LASHeader::SetReserved(uint16_t v)
-{
-    // TODO: Should we warn or throw about type overflow occuring when
-    //       user passes 65535 + 1 = 0
-    m_reserved = v;
-}
-
-liblas::guid LASHeader::GetProjectId() const
-{
-    return liblas::guid(m_projectId1, m_projectId2, m_projectId3, m_projectId4);
-}
-
-void LASHeader::SetProjectId(guid const& v)
-{
-    v.output_data(m_projectId1, m_projectId2, m_projectId3, m_projectId4);
-}
-
-uint8_t LASHeader::GetVersionMajor() const
-{
-    return m_versionMajor;
-}
-
-void LASHeader::SetVersionMajor(uint8_t v)
-{
-    if (eVersionMajorMin > v || v > eVersionMajorMax)
-        throw std::out_of_range("version major out of range");
-
-    m_versionMajor = v;
-}
-
-uint8_t LASHeader::GetVersionMinor() const
-{
-    return m_versionMinor;
-}
-
-void LASHeader::SetVersionMinor(uint8_t v)
-{
-    if (v > eVersionMinorMax)
-        throw std::out_of_range("version minor out of range");
-    
-    m_versionMinor = v;
-    
-    uint32_t size = 0;
-    uint32_t const dataSignatureSize = 2;
-    
-    // Add the signature if we're a 1.0 file    
-    if (eVersionMinorMin == m_versionMinor) {
-        size = dataSignatureSize; 
-    } 
-
-    SetDataOffset(GetHeaderSize()+size);
-    
-}
-
-std::string LASHeader::GetSystemId(bool pad /*= false*/) const
-{
-    // copy array of chars and trim zeros if smaller than 32 bytes
-    std::string tmp(std::string(m_systemId, eSystemIdSize).c_str());
-
-    // pad right side with spaces
-    if (pad && tmp.size() < eSystemIdSize)
-    {
-        tmp.resize(eSystemIdSize, 0);
-        assert(tmp.size() == eSystemIdSize);
-    }
-
-    assert(tmp.size() <= eSystemIdSize);
-    return tmp;
-}
-
-void LASHeader::SetSystemId(std::string const& v)
-{
-    if (v.size() > eSystemIdSize)
-        throw std::invalid_argument("system id too long");
-
-    std::fill(m_systemId, m_systemId + eSystemIdSize, 0);
-    std::strncpy(m_systemId, v.c_str(), eSystemIdSize);
-}
-
-std::string LASHeader::GetSoftwareId(bool pad /*= false*/) const
-{
-    std::string tmp(std::string(m_softwareId, eSoftwareIdSize).c_str());
-
-    // pad right side with spaces
-    if (pad && tmp.size() < eSoftwareIdSize)
-    {
-        tmp.resize(eSoftwareIdSize, 0);
-        assert(tmp.size() == eSoftwareIdSize);
-    }
-
-    assert(tmp.size() <= eSoftwareIdSize);
-    return tmp;
-}
-
-void LASHeader::SetSoftwareId(std::string const& v)
-{
-    if (v.size() > eSoftwareIdSize)
-        throw std::invalid_argument("generating software id too long");
-    
-//    m_softwareId = v;
-    std::fill(m_softwareId, m_softwareId + eSoftwareIdSize, 0);
-    std::strncpy(m_softwareId, v.c_str(), eSoftwareIdSize);
-}
-
-uint16_t LASHeader::GetCreationDOY() const
-{
-    return m_createDOY;
-}
-
-void LASHeader::SetCreationDOY(uint16_t v)
-{
-    if (v > 366)
-        throw std::out_of_range("day of year out of range");
-
-    m_createDOY = v;
-}
-
-uint16_t LASHeader::GetCreationYear() const
-{
-    return m_createYear;
-}
-
-void LASHeader::SetCreationYear(uint16_t v)
-{
-    // mloskot: I've taken these values arbitrarily
-    if (v > 9999)
-        throw std::out_of_range("year out of range");
-
-    m_createYear = v;
-}
-
-uint16_t LASHeader::GetHeaderSize() const
-{
-    return eHeaderSize;
-}
-
-uint32_t LASHeader::GetDataOffset() const
-{
-    return m_dataOffset;
-}
-
-void LASHeader::SetDataOffset(uint32_t v)
-{
-    uint32_t const dataSignatureSize = 2;
-    uint16_t const hsize = GetHeaderSize();
-
-    if ( (m_versionMinor == 0 && v < hsize + dataSignatureSize) ||
-         (m_versionMinor == 1 && v < hsize) ||
-         (m_versionMinor == 2 && v < hsize) )
-    {
-        throw std::out_of_range("data offset out of range");
-    }
-
-    m_dataOffset = v;
-}
-
-uint32_t LASHeader::GetRecordsCount() const
-{
-    return m_recordsCount;
-}
-
-void LASHeader::SetRecordsCount(uint32_t v)
-{
-    m_recordsCount = v;
-}
-
-LASHeader::PointFormat LASHeader::GetDataFormatId() const
-{
-    if (ePointFormat0 == m_dataFormatId)
-        return ePointFormat0;
-    else if (ePointFormat1 == m_dataFormatId)
-        return ePointFormat1;
-    else if (ePointFormat2 == m_dataFormatId)
-        return ePointFormat2;
-    else
-        return ePointFormat3;
-}
-
-void LASHeader::SetDataFormatId(LASHeader::PointFormat v)
-{
-    m_dataFormatId = static_cast<uint8_t>(v);
-
-    if (ePointFormat0 == m_dataFormatId)
-        m_dataRecordLen = ePointSize0;
-    else if (ePointFormat1 == m_dataFormatId) 
-        m_dataRecordLen = ePointSize1;
-    else if (ePointFormat2 == m_dataFormatId)
-        m_dataRecordLen = ePointSize2;
-    else if (ePointFormat3 == m_dataFormatId)
-        m_dataRecordLen = ePointSize3;
-    else
-        m_dataRecordLen = ePointSize3;
-}
-
-uint16_t LASHeader::GetDataRecordLength() const
-{
-    // NOTE: assertions below are used to check if our assumption is correct,
-    // for debugging purpose only.
-
-    if (ePointFormat0 == m_dataFormatId)
-    {
-        assert(ePointSize0 == m_dataRecordLen);
-        return ePointSize0;
-    }
-    if (ePointFormat1 == m_dataFormatId)
-    {
-        assert(ePointSize1 == m_dataRecordLen);
-        return ePointSize1;
-    }
-    if (ePointFormat2 == m_dataFormatId)
-    {
-        assert(ePointSize2 == m_dataRecordLen);
-        return ePointSize2;
-    }
-    else
-    {
-        assert(ePointSize3 == m_dataRecordLen);
-        return ePointSize3;
-    }
-}
-
-uint32_t LASHeader::GetPointRecordsCount() const
-{
-    return m_pointRecordsCount;
-}
-
-void LASHeader::SetPointRecordsCount(uint32_t v)
-{
-    m_pointRecordsCount = v;
-}
-
-std::vector<uint32_t> const& LASHeader::GetPointRecordsByReturnCount() const
-{
-    return m_pointRecordsByReturn;
-}
-
-void LASHeader::SetPointRecordsByReturnCount(std::size_t index, uint32_t v)
-{
-    assert(m_pointRecordsByReturn.size() == LASHeader::ePointsByReturnSize);
-
-    uint32_t& t = m_pointRecordsByReturn.at(index);
-    t = v;
-}
-
-
-double LASHeader::GetScaleX() const
-{
-    return m_scales.x;
-}
-
-double LASHeader::GetScaleY() const
-{
-    return m_scales.y;
-}
-
-double LASHeader::GetScaleZ() const
-{
-    return m_scales.z;
-}
-
-void LASHeader::SetScale(double x, double y, double z)
-{
-    double const minscale = 0.01;
-    m_scales.x = (0 == x) ? minscale : x;
-    m_scales.y = (0 == y) ? minscale : y;
-    m_scales.z = (0 == z) ? minscale : z;
-}
-
-double LASHeader::GetOffsetX() const
-{
-    return m_offsets.x;
-}
-
-double LASHeader::GetOffsetY() const
-{
-    return m_offsets.y;
-}
-
-double LASHeader::GetOffsetZ() const
-{
-    return m_offsets.z;
-}
-
-void LASHeader::SetOffset(double x, double y, double z)
-{
-    m_offsets = PointOffsets(x, y, z);
-}
-
-double LASHeader::GetMaxX() const
-{
-    return m_extents.max.x;
-}
-
-double LASHeader::GetMinX() const
-{
-    return m_extents.min.x;
-}
-
-double LASHeader::GetMaxY() const
-{
-    return m_extents.max.y;
-}
-
-double LASHeader::GetMinY() const
-{
-    return m_extents.min.y;
-}
-
-double LASHeader::GetMaxZ() const
-{
-    return m_extents.max.z;
-}
-
-double LASHeader::GetMinZ() const
-{
-    return m_extents.min.z;
-}
-
-void LASHeader::SetMax(double x, double y, double z)
-{
-    m_extents.max = detail::Point<double>(x, y, z);
-}
-
-void LASHeader::SetMin(double x, double y, double z)
-{
-    m_extents.min = detail::Point<double>(x, y, z);
-}
-
-void LASHeader::AddVLR(LASVariableRecord const& v) 
-{
-    m_vlrs.push_back(v);
-
-    uint32_t end_size = 0;
-    std::vector<LASVariableRecord>::const_iterator i;
         
-    // Calculate a new data offset size
-    for (i = m_vlrs.begin(); i != m_vlrs.end(); ++i) 
-    {
-        end_size += (*i).GetTotalSize();
-    }
-
-    uint32_t size = 0;
-    uint32_t const dataSignatureSize = 2;
-    
-    // Add the signature if we're a 1.0 file    
-    if (eVersionMinorMin == m_versionMinor) {
-        size = end_size + dataSignatureSize; 
-    } else {
-        size = end_size;
-    }
-
-    SetDataOffset(GetHeaderSize()+size);
-
-    // We're assuming that the reader or writer has reset 
-    // the VLR count to 0 before adding them back with AddVLR  
-    // FIXME I think this is still broken - hobu
-    m_recordsCount += 1;
-}
-
-LASVariableRecord const& LASHeader::GetVLR(uint32_t index) const 
-{
-    return m_vlrs[index];
-}
-
-void LASHeader::DeleteVLR(uint32_t index) 
-{    
-    if (index >= m_vlrs.size())
-        throw std::out_of_range("index is out of range");
-
-    std::vector<LASVariableRecord>::iterator i = m_vlrs.begin() + index;
-
-    // Deal with the dataoffset when deleting
-    uint32_t size = (*i).GetTotalSize();
-
-    m_vlrs.erase(i);
-    m_recordsCount = static_cast<uint32_t>(m_vlrs.size());
-    
-    SetDataOffset(GetDataOffset() - size);
-    
-}
-
-
-void LASHeader::Init()
-{
-    // Initialize public header block with default
-    // values according to LAS 1.2
-
-    m_versionMajor = 1;
-    m_versionMinor = 2;
-    m_dataFormatId = ePointFormat0;
-    m_dataRecordLen = ePointSize0;
-
-
-    std::time_t now;
-    std::tm *ptm;
-
-    std::time(&now);
-    ptm = std::gmtime(&now);
-    
-    m_createDOY = static_cast<uint16_t>(ptm->tm_yday);
-    m_createYear = static_cast<uint16_t>(ptm->tm_year + 1900);
-    
-    m_headerSize = eHeaderSize;
-
-    m_sourceId = m_reserved = m_projectId2 = m_projectId3 = uint16_t();
-    m_projectId1 = uint32_t();
-    std::memset(m_projectId4, 0, sizeof(m_projectId4)); 
-
-    m_dataOffset = eHeaderSize; // excluding 2 bytes of Point Data Start Signature
-    m_recordsCount = 0;
-    m_pointRecordsCount = 0;
-
-    std::memset(m_signature, 0, eFileSignatureSize);
-    std::strncpy(m_signature, FileSignature, eFileSignatureSize);
-//    m_signature = LASHeader::FileSignature;
-
-    std::memset(m_systemId, 0, eSystemIdSize);
-    std::strncpy(m_systemId, SystemIdentifier, eSystemIdSize);
-//    m_systemId = LASHeader::SystemIdentifier;
-
-    std::memset(m_softwareId, 0, eSoftwareIdSize);
-    std::strncpy(m_softwareId, SoftwareIdentifier, eSoftwareIdSize);
-//    m_softwareId = LASHeader::SoftwareIdentifier;
-
-    m_pointRecordsByReturn.resize(ePointsByReturnSize);
-
-    // Zero scale value is useless, so we need to use a small value.
-    SetScale(0.01, 0.01, 0.01);
-}
-
-void LASHeader::ClearGeoKeyVLRs()
-{
-    std::string const uid("LASF_Projection");
-
-    uint32_t beg_size = 0;
-    uint32_t end_size = 0;
-
-    std::vector<LASVariableRecord> vlrs = m_vlrs;
-    std::vector<LASVariableRecord>::const_iterator i;
-    std::vector<LASVariableRecord>::iterator j;
-
-    for (i = m_vlrs.begin(); i != m_vlrs.end(); ++i)
-    {
-        LASVariableRecord record = *i;
-        beg_size += (*i).GetTotalSize();
-
-        std::string user = record.GetUserId(true);
-        if (uid == user.c_str())
-        {
-            uint16_t id = record.GetRecordId();
-
-            if (34735 == id)
-            {
-                // Geotiff SHORT key
-                for(j = vlrs.begin(); j != vlrs.end(); ++j)
-                {
-                    if (*j == *i)
-                    {
-                        vlrs.erase(j);
-                        break;
-                    }
-                }
-            }
-            else if (34736 == id)
-            {
-                // Geotiff DOUBLE key
-                for(j = vlrs.begin(); j != vlrs.end(); ++j)
-                {
-                    if (*j == *i)
-                    {
-                        vlrs.erase(j);
-                        break;
-                    }
-                }
-            }        
-            else if (34737 == id)
-            {
-                // Geotiff ASCII key
-                for (j = vlrs.begin(); j != vlrs.end(); ++j)
-                {
-                    if (*j == *i)
-                    {
-                        vlrs.erase(j);
-                        break;
-                    }
-                }
-            }
-        } // uid == user
-    }
-    
-    // Copy our list of surviving VLRs back to our member variable
-    // and update header information
-    m_vlrs = vlrs;
-    m_recordsCount = static_cast<uint32_t>(m_vlrs.size());
-    
-    // Calculate a new data offset size
-    for (i = m_vlrs.begin(); i != m_vlrs.end(); ++i) 
-    {
-        end_size += (*i).GetTotalSize();
-    }
-
-    uint32_t size = 0;
-    uint32_t const dataSignatureSize = 2;
-    
-    // Add the signature if we're a 1.0 file    
-    if (eVersionMinorMin == m_versionMinor)
-    {
-        size = end_size + dataSignatureSize; 
-    }
-    else
-    {
-        size = end_size;
-    }
-
-    SetDataOffset(GetHeaderSize()+size);
-
-}
-void LASHeader::SetGeoreference() 
-{    
-    std::vector<LASVariableRecord> vlrs = m_srs.GetVLRs();
-
-    // Wipe the GeoTIFF-related VLR records off of the LASHeader
-    ClearGeoKeyVLRs();
-
-    std::vector<LASVariableRecord>::const_iterator i;
-
-    for (i = vlrs.begin(); i != vlrs.end(); ++i) 
-    {
-        AddVLR(*i);
-    }
-
+    return true;
 }
 
-LASSpatialReference LASHeader::GetSRS() const
-{
-    return m_srs;
-}
-void LASHeader::SetSRS(LASSpatialReference& srs)
-{
-    m_srs = srs;
-}
 
 
 } // namespace liblas


More information about the Liblas-commits mailing list