1 /****************************************************************************** 2 * Copyright (c) 2011, Michael P. Gerlek (mpg@flaxen.com) 3 * 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following 8 * conditions are met: 9 * 10 * * Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in 14 * the documentation and/or other materials provided 15 * with the distribution. 16 * * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the 17 * names of its contributors may be used to endorse or promote 18 * products derived from this software without specific prior 19 * written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 32 * OF SUCH DAMAGE. 33 ****************************************************************************/ 34 35 #pragma once 36 37 #include <limits> 38 #include <string> 39 #include <vector> 40 41 #include <pdal/SpatialReference.hpp> 42 #include <pdal/util/IStream.hpp> 43 #include <pdal/util/OStream.hpp> 44 45 namespace pdal 46 { 47 48 static const int WKT_RECORD_ID = 2112; 49 static const uint16_t GEOTIFF_DIRECTORY_RECORD_ID = 34735; 50 static const uint16_t GEOTIFF_DOUBLES_RECORD_ID = 34736; 51 static const uint16_t GEOTIFF_ASCII_RECORD_ID = 34737; 52 static const uint16_t LASZIP_RECORD_ID = 22204; 53 static const uint16_t EXTRA_BYTES_RECORD_ID = 4; 54 static const uint16_t PDAL_METADATA_RECORD_ID = 12; 55 static const uint16_t PDAL_PIPELINE_RECORD_ID = 13; 56 57 static const char TRANSFORM_USER_ID[] = "LASF_Projection"; 58 static const char SPEC_USER_ID[] = "LASF_Spec"; 59 static const char LIBLAS_USER_ID[] = "liblas"; 60 static const char LASZIP_USER_ID[] = "laszip encoded"; 61 static const char PDAL_USER_ID[] = "PDAL"; 62 63 class LasVLR; 64 typedef std::vector<LasVLR> VlrList; 65 66 class PDAL_DLL LasVLR 67 { 68 public: 69 static const uint16_t MAX_DATA_SIZE; 70 LasVLR(const std::string & userId,uint16_t recordId,const std::string & description,std::vector<uint8_t> & data)71 LasVLR(const std::string& userId, uint16_t recordId, 72 const std::string& description, std::vector<uint8_t>& data) : 73 m_userId(userId), m_recordId(recordId), m_description(description), 74 m_data(std::move(data)), m_recordSig(0) 75 {} LasVLR()76 LasVLR() : m_recordId(0), m_recordSig(0) 77 {} 78 userId() const79 std::string userId() const 80 { return m_userId;} recordId() const81 uint16_t recordId() const 82 { return m_recordId; } description() const83 std::string description() const 84 { return m_description; } 85 matches(const std::string & userId) const86 bool matches(const std::string& userId) const 87 { return userId == m_userId; } matches(const std::string & userId,uint16_t recordId) const88 bool matches(const std::string& userId, uint16_t recordId) const 89 { return matches(userId) && (recordId == m_recordId); } 90 data() const91 const char* data() const 92 { return (const char *)m_data.data(); } data()93 char* data() 94 { return (char *)m_data.data(); } isEmpty() const95 bool isEmpty() const 96 { return m_data.size() == 0; } dataLen() const97 uint64_t dataLen() const 98 { return m_data.size(); } setDataLen(uint64_t size)99 void setDataLen(uint64_t size) 100 { m_data.resize((size_t)size); } 101 void write(OLeStream& out, uint16_t recordSig); 102 bool read(ILeStream& in, size_t limit); 103 104 friend OLeStream& operator<<(OLeStream& out, const LasVLR& v); 105 friend std::istream& operator>>(std::istream& in, LasVLR& v); 106 friend std::ostream& operator<<(std::ostream& out, const LasVLR& v); 107 108 protected: 109 std::string m_userId; 110 uint16_t m_recordId; 111 std::string m_description; 112 std::vector<uint8_t> m_data; 113 uint16_t m_recordSig; 114 }; 115 116 class ExtLasVLR : public LasVLR 117 { 118 public: ExtLasVLR(const std::string & userId,uint16_t recordId,const std::string & description,std::vector<uint8_t> & data)119 ExtLasVLR(const std::string& userId, uint16_t recordId, 120 const std::string& description, std::vector<uint8_t>& data) : 121 LasVLR(userId, recordId, description, data) 122 {} ExtLasVLR()123 ExtLasVLR() 124 {} 125 126 bool read(ILeStream& in, uintmax_t limit); 127 128 friend OLeStream& operator<<(OLeStream& out, const ExtLasVLR& v); 129 friend std::istream& operator>>(std::istream& in, ExtLasVLR& v); 130 friend std::ostream& operator<<(std::ostream& out, const ExtLasVLR& v); 131 }; 132 133 } // namespace pdal 134