Changeset 641:7f52a619352d
- Timestamp:
- 05/13/08 21:43:08 (2 years ago)
- Branch:
- default
- Convert:
- svn:1766ff46-f334-0410-ab20-d63176f87757/trunk@708
- Files:
-
- 12 edited
-
include/liblas/detail/reader.hpp (modified) (1 diff)
-
include/liblas/detail/reader10.hpp (modified) (1 diff)
-
include/liblas/detail/reader11.hpp (modified) (1 diff)
-
include/liblas/detail/utility.hpp (modified) (2 diffs)
-
include/liblas/lasheader.hpp (modified) (3 diffs)
-
include/liblas/lasreader.hpp (modified) (3 diffs)
-
include/liblas/lasrecordheader.hpp (modified) (5 diffs)
-
src/detail/reader10.cpp (modified) (4 diffs)
-
src/detail/reader11.cpp (modified) (2 diffs)
-
src/lasheader.cpp (modified) (5 diffs)
-
src/lasreader.cpp (modified) (1 diff)
-
src/lasrecordheader.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
include/liblas/detail/reader.hpp
r586 r641 64 64 virtual bool ReadPointAt(std::size_t n, PointRecord& record) = 0; 65 65 virtual bool ReadPointAt(std::size_t n, PointRecord& record, double& time) = 0; 66 virtual bool ReadVLR(LASHeader& header) = 0; 66 67 67 68 virtual std::istream& GetStream() = 0; -
include/liblas/detail/reader10.hpp
r586 r641 64 64 bool ReadPointAt(std::size_t n, PointRecord& record); 65 65 bool ReadPointAt(std::size_t n, PointRecord& record, double& time); 66 bool ReadVLR(LASHeader& header); 66 67 67 68 std::istream& GetStream(); -
include/liblas/detail/reader11.hpp
r586 r641 63 63 bool ReadPointAt(std::size_t n, PointRecord& record); 64 64 bool ReadPointAt(std::size_t n, PointRecord& record, double& time); 65 bool ReadVLR(LASHeader& header); 65 66 66 67 std::istream& GetStream(); -
include/liblas/detail/utility.hpp
r586 r641 78 78 }; 79 79 80 struct VariableLengthRecordHeader 81 { 82 VariableLengthRecord Header()80 class VariableLengthRecord 81 { 82 VariableLengthRecord() 83 83 : reserved(0), record_id(0), record_length_after_header(0) 84 84 { … … 98 98 uint16_t record_length_after_header; 99 99 int8_t description[eDescriptionSize]; 100 uint8_t data; 100 101 }; 101 102 -
include/liblas/lasheader.hpp
r585 r641 47 47 #include <liblas/guid.hpp> 48 48 #include <liblas/detail/utility.hpp> 49 #include <liblas/lasrecordheader.hpp> 49 50 //std 50 51 #include <string> … … 291 292 void SetMin(double x, double y, double z); 292 293 294 void AddVLR(LASVLR const& v); 295 LASVLR const& GetVLR(int index) const; 296 293 297 private: 294 298 … … 343 347 PointOffsets m_offsets; 344 348 PointExtents m_extents; 349 std::vector<LASVLR> m_vlrs; 345 350 }; 346 351 -
include/liblas/lasreader.hpp
r585 r641 46 46 #include <liblas/lasheader.hpp> 47 47 #include <liblas/laspoint.hpp> 48 #include <liblas/lasrecordheader.hpp> 48 49 #include <liblas/detail/fwd.hpp> 49 50 // std … … 66 67 LASHeader const& GetHeader() const; 67 68 LASPoint const& GetPoint() const; 69 std::vector<LASVLR> const& GetVLRs() const; 68 70 69 71 bool ReadNextPoint(); 70 72 bool ReadPointAt(std::size_t n); 73 bool ReadVLR(); 71 74 72 75 // The operator is not const because it updates file stream position. … … 89 92 LASPoint m_point; 90 93 detail::PointRecord m_record; 94 std::vector<LASVLR> m_vlrs; 91 95 92 96 }; -
include/liblas/lasrecordheader.hpp
r587 r641 46 46 // std 47 47 #include <string> 48 #include <vector> 48 49 49 50 namespace liblas { 50 51 51 52 /// Representation of variable-length record data. 52 class LAS RecordHeader53 class LASVLR 53 54 { 54 55 public: … … 57 58 /// Zero-initialization of record data. 58 59 /// \exception No throw 59 LAS RecordHeader();60 LASVLR(); 60 61 61 62 /// Copy constructor. 62 63 /// Construction of new record object as a copy of existing one. 63 64 /// \exception No throw 64 LASRecordHeader(LASRecordHeader const& other); 65 LASVLR(LASVLR const& other); 66 67 ~LASVLR(); 65 68 66 69 /// Assignment operator. … … 68 71 /// assignment of another one. 69 72 /// \exception No throw 70 LAS RecordHeader& operator=(LASRecordHeaderconst& rhs);73 LASVLR& operator=(LASVLR const& rhs); 71 74 72 75 /// Get record signature (LAS 1.0) or reserved bytes (LAS 1.1). 73 76 /// \exception No throw 74 77 uint16_t GetReserved() const; 78 79 void SetReserved(uint16_t); 75 80 76 81 /// Get identifier of user which created the record. 77 82 /// The character data is up to 16 bytes long. 78 83 /// \exception No throw 79 std::string const& GetUserId() const; 84 std::string GetUserId(bool pad /*= false*/); 85 86 void SetUserId(std::string const&); 80 87 81 88 /// Get identifier of record. … … 83 90 /// \exception No throw 84 91 uint16_t GetRecordId() const; 92 93 void SetRecordId(uint16_t); 85 94 86 95 /// Get record length after the header. 87 96 /// \exception No throw 88 uint16_t GeRecordLength() const; 97 uint16_t GetRecordLength() const; 98 99 void SetRecordLength(uint16_t); 89 100 90 101 /// Get text description of data in the record. 91 102 /// The character data is up to 32 bytes long. 92 103 /// \exception No throw 93 std::string const& GetDescription() const; 104 std::string GetDescription(bool pad /*= false*/); 105 106 void SetDescription(std::string const&); 107 108 /// Get the data for this VLR 109 std::vector<uint8_t> GetData() const; 110 111 void SetData(std::vector<uint8_t> const&); 94 112 95 113 /// Compare actual header object against the other. 96 114 /// \exception No throw 97 bool equal(LAS RecordHeaderconst& other) const;115 bool equal(LASVLR const& other) const; 98 116 99 117 private: 100 118 119 enum 120 { 121 eUIDSize = 16, 122 eDescriptionSize = 32 123 }; 124 101 125 uint16_t m_reserved; 102 126 uint16_t m_recordId; 103 127 uint16_t m_recordLength; // after header 104 std::string m_userId; // [16] 105 std::string m_desc; // [32] 128 129 char m_userId[eUIDSize]; 130 char m_desc[eDescriptionSize]; 131 std::vector<uint8_t> m_data; 106 132 }; 107 133 108 134 /// Equality operator. 109 /// Implemented in terms of LAS RecordHeader::equal member function.135 /// Implemented in terms of LASVLR::equal member function. 110 136 /// \exception No throw 111 inline bool operator==(LAS RecordHeader const& lhs, LASRecordHeaderconst& rhs)137 inline bool operator==(LASVLR const& lhs, LASVLR const& rhs) 112 138 { 113 139 return lhs.equal(rhs); … … 117 143 /// Implemented in terms of LASRecordHeader::equal member function. 118 144 /// \exception No throw 119 inline bool operator!=(LAS RecordHeader const& lhs, LASRecordHeaderconst& rhs)145 inline bool operator!=(LASVLR const& lhs, LASVLR const& rhs) 120 146 { 121 147 return (!(lhs == rhs)); -
src/detail/reader10.cpp
r640 r641 42 42 #include <liblas/detail/reader10.hpp> 43 43 #include <liblas/detail/utility.hpp> 44 #include <liblas/lasrecordheader.hpp> 44 45 #include <liblas/liblas.hpp> 45 46 #include <liblas/lasheader.hpp> … … 210 211 m_recordlength = header.GetDataRecordLength(); 211 212 213 214 return true; 215 } 216 217 bool ReaderImpl::ReadVLR(LASHeader& header) { 218 219 VLRHeader vlrh = { 0 }; 220 221 m_ifs.seekg(header.GetHeaderSize(), std::ios::beg); 222 223 for (uint32_t i = 0; i < header.GetRecordsCount(); ++i) 224 { 225 read_n(vlrh, m_ifs, sizeof(VLRHeader)); 226 227 int16_t count = vlrh.recordLengthAfterHeader / sizeof(uint8_t); 228 uint8_t *rawdata = new uint8_t[count]; 229 230 read_n(rawdata, m_ifs, vlrh.recordLengthAfterHeader); 231 232 std::vector<uint8_t> data; 233 for (int j=0; j< count; ++j) { 234 data.push_back(rawdata[j]); 235 } 236 237 LASVLR vlr; 238 vlr.SetReserved(vlrh.reserved); 239 vlr.SetUserId(std::string(vlrh.userId)); 240 vlr.SetDescription(std::string(vlrh.description)); 241 vlr.SetRecordLength(vlrh.recordLengthAfterHeader); 242 vlr.SetRecordId(vlrh.recordId); 243 vlr.SetData(data); 244 delete[] rawdata; 245 header.AddVLR(vlr); 246 } 212 247 // TODO: Under construction 213 248 // Testing reading of VLRecords with GeoKeys … … 216 251 return true; 217 252 } 218 219 253 bool ReaderImpl::ReadGeoreference(LASHeader const& header) 220 254 { … … 227 261 ST_TIFF *st = ST_Create(); 228 262 229 m_ifs.seekg(header.GetHeaderSize(), std::ios::beg); 230 231 for (uint32_t i = 0; i < header.GetRecordsCount(); ++i) 232 { 233 read_n(vlrh, m_ifs, sizeof(VLRHeader)); 234 235 if (uid == vlrh.userId && 34735 == vlrh.recordId) 263 // m_ifs.seekg(header.GetHeaderSize(), std::ios::beg); 264 265 printf("Records count: %d\n", (int)header.GetRecordsCount()); 266 267 for (uint16_t i = 0; i < header.GetRecordsCount(); ++i) 268 { 269 LASVLR record = header.GetVLR(i); 270 std::vector<uint8_t> data = record.GetData(); 271 272 printf("record.GetUserId(): '%s' record.GetRecordId: %d\n", record.GetUserId(true).c_str(), record.GetRecordId()); 273 if (uid == record.GetUserId(true).c_str() && 34735 == record.GetRecordId()) 236 274 { 237 int16_t count = vlrh.recordLengthAfterHeader / sizeof(int16_t); 275 printf("uid == record.GetUserId(true).c_str() && 34735 == record.GetRecordId()\n"); 276 277 int16_t count = data.size()/sizeof(int16_t); 278 279 printf("count for int16_t: %d\n", count); 238 280 uint16_t *geokeys = new uint16_t[count]; 239 read_n(geokeys, m_ifs, vlrh.recordLengthAfterHeader); 240 ST_SetKey( st, vlrh.recordId, count, STT_SHORT, geokeys ); 281 for (int j = 0; j< count; ++j) { 282 geokeys[j] = (uint16_t)data[j]; 283 } 284 ST_SetKey( st, record.GetRecordId(), count, STT_SHORT, geokeys ); 241 285 delete[] geokeys; 286 242 287 } 243 else if (uid == vlrh.userId && 34736 == vlrh.recordId) 288 289 if (uid == record.GetUserId(true).c_str() && 34736 == record.GetRecordId()) 244 290 { 245 int count = vlrh.recordLengthAfterHeader / sizeof(double); 246 double *values = new double[count]; 247 read_n(values, m_ifs, vlrh.recordLengthAfterHeader); 248 ST_SetKey( st, vlrh.recordId, count, STT_DOUBLE, values ); 249 delete[] values; 250 } 251 else if (uid == vlrh.userId && 34737 == vlrh.recordId) 291 printf("uid == record.GetUserId(true).c_str() && 34736 == record.GetRecordId()\n"); 292 293 int count = data.size() / sizeof(double); 294 printf("count for int: %d\n", count); 295 296 double *geokeys = new double[count]; 297 for (int j = 0; j< count; ++j) { 298 geokeys[j] = (double)data[j]; 299 } 300 ST_SetKey( st, record.GetRecordId(), count, STT_DOUBLE, geokeys ); 301 delete[] geokeys; 302 303 } 304 305 if (uid == record.GetUserId(true).c_str() && 34737 == record.GetRecordId()) 252 306 { 253 uint8_t count = vlrh.recordLengthAfterHeader / sizeof(uint8_t); 254 char *values = new char[count]; 255 read_n(values, m_ifs, vlrh.recordLengthAfterHeader); 256 ST_SetKey( st, vlrh.recordId, count, STT_ASCII, values ); 257 delete[] values; 258 } 259 else 260 { 261 std::istream::pos_type const pos = m_ifs.tellg(); 262 m_ifs.seekg(pos + std::istream::pos_type(vlrh.recordLengthAfterHeader)); 263 } 307 printf("uid == record.GetUserId(true).c_str() && 34737 == record.GetRecordId()\n"); 308 309 uint8_t count = data.size()/sizeof(uint8_t); 310 311 printf("count for string: %d data.size(): %d", count, (int)data.size()); 312 313 char *geokeys = new char[count]; 314 for (int j = 0; j< count; ++j) { 315 geokeys[j] = (uint8_t)data[j]; 316 } 317 // geokeys[count] = '\0'; 318 printf("Geokeys: '%s'", geokeys); 319 ST_SetKey( st, record.GetRecordId(), count, STT_ASCII, geokeys ); 320 delete[] geokeys; 321 322 323 } 324 // else if (uid == record.GetUserId() && record.GetRecordId()) 325 // { 326 // int count = vlrh.recordLengthAfterHeader / sizeof(double); 327 // double *values = new double[count]; 328 // read_n(values, m_ifs, vlrh.recordLengthAfterHeader); 329 // ST_SetKey( st, vlrh.recordId, count, STT_DOUBLE, values ); 330 // delete[] values; 331 // } 332 // else if (uid == record.GetUserId() && record.GetRecordId()) 333 // { 334 // uint8_t count = vlrh.recordLengthAfterHeader / sizeof(uint8_t); 335 // char *values = new char[count]; 336 // read_n(values, m_ifs, vlrh.recordLengthAfterHeader); 337 // ST_SetKey( st, vlrh.recordId, count, STT_ASCII, values ); 338 // delete[] values; 339 // } 340 // else 341 // { 342 // std::istream::pos_type const pos = m_ifs.tellg(); 343 // m_ifs.seekg(pos + std::istream::pos_type(vlrh.recordLengthAfterHeader)); 344 // } 264 345 } 265 346 266 347 GTIF *gtif = GTIFNewSimpleTags( st ); 267 GTIFDefn defn;348 GTIFDefn defn; 268 349 if (GTIFGetDefn(gtif, &defn)) 269 350 { 270 printf( "PROJ.4 Definition: %s\n", GTIFGetProj4Defn(&defn)); 271 } 272 GTIFPrint(gtif,0,0); 351 printf( "char PROJ.4 Definition: %s\n", GTIFGetProj4Defn(&defn)); 352 } 273 353 GTIFFree( gtif ); 274 354 ST_Destroy( st ); -
src/detail/reader11.cpp
r588 r641 45 45 #include <liblas/lasheader.hpp> 46 46 #include <liblas/laspoint.hpp> 47 #include <liblas/lasrecordheader.hpp> 48 47 49 // std 48 50 #include <fstream> … … 294 296 } 295 297 298 bool ReaderImpl::ReadVLR(LASHeader& header) { 299 300 VLRHeader vlrh = { 0 }; 301 LASVLR vlr; 302 303 return true; 304 } 305 296 306 }}} // namespace liblas::detail::v11 -
src/lasheader.cpp
r588 r641 99 99 std::vector<uint32_t>(other.m_pointRecordsByReturn).swap(m_pointRecordsByReturn); 100 100 assert(ePointsByReturnSize >= m_pointRecordsByReturn.size()); 101 102 std::vector<LASVLR>(other.m_vlrs).swap(m_vlrs); 101 103 102 104 } … … 134 136 assert(ePointsByReturnSize >= m_pointRecordsByReturn.size()); 135 137 138 std::vector<LASVLR>(rhs.m_vlrs).swap(m_vlrs); 136 139 m_scales = rhs.m_scales; 137 140 m_offsets = rhs.m_offsets; … … 183 186 throw std::invalid_argument("invalid file signature"); 184 187 185 // m_signature = v;186 187 188 std::strncpy(m_signature, v.c_str(), eFileSignatureSize); 188 189 } … … 261 262 if (v.size() > eSystemIdSize) 262 263 throw std::invalid_argument("system id too long"); 263 264 // m_systemId = v;265 264 266 265 std::fill(m_systemId, m_systemId + eSystemIdSize, 0); … … 496 495 } 497 496 497 void LASHeader::AddVLR(LASVLR const& v) 498 { 499 m_vlrs.push_back(v); 500 } 501 LASVLR const& LASHeader::GetVLR(int index) const { 502 return m_vlrs[index]; 503 } 498 504 void LASHeader::Init() 499 505 { -
src/lasreader.cpp
r588 r641 148 148 if (!ret) 149 149 throw std::runtime_error("public header block reading failure"); 150 151 ret = m_pimpl->ReadVLR(m_header); 152 if (!ret) 153 throw std::runtime_error("public vlr header block reading failure"); 154 150 155 } 151 156 -
src/lasrecordheader.cpp
r588 r641 9 9 * Copyright (c) 2008, Phil Vachon 10 10 * Copyright (c) 2008, Mateusz Loskot, mateusz@loskot.net 11 * Copyright (c) 2008, Howard Butler, hobu.inc@gmail.com 11 12 * 12 13 * All rights reserved. … … 43 44 #include <liblas/lasrecordheader.hpp> 44 45 #include <liblas/cstdint.hpp> 46 45 47 // std 48 #include <algorithm> 49 #include <stdexcept> 46 50 #include <string> 51 #include <vector> 52 #include <cstring> // std::memset, std::memcpy, std::strncpy 53 #include <cassert> 47 54 48 55 namespace liblas { 49 56 50 LAS RecordHeader::LASRecordHeader() :57 LASVLR::LASVLR() : 51 58 m_reserved(0), m_recordId(0), m_recordLength(0) 52 59 { 53 } 54 55 LASRecordHeader::LASRecordHeader(LASRecordHeader const& other) : 60 std::memset(m_userId, 0, eUIDSize); 61 std::memset(m_desc, 0, eDescriptionSize); 62 63 m_data.resize(40); 64 65 } 66 67 LASVLR::LASVLR(LASVLR const& other) : 56 68 m_reserved(other.m_reserved), 57 69 m_recordId(other.m_recordId), 58 m_recordLength(other.m_recordLength), 59 m_userId(other.m_userId), 60 m_desc(other.m_desc) 61 { 62 } 63 64 LASRecordHeader& LASRecordHeader::operator=(LASRecordHeader const& rhs) 65 { 70 m_recordLength(other.m_recordLength) 71 { 72 void* p = 0; 73 74 p = std::memcpy(m_userId, other.m_userId, eUIDSize); 75 assert(p == m_userId); 76 77 p = std::memcpy(m_desc, other.m_desc, eDescriptionSize); 78 assert(p == m_desc); 79 80 std::vector<uint8_t>(other.m_data).swap(m_data); 81 } 82 83 LASVLR::~LASVLR() 84 { 85 86 } 87 88 LASVLR& LASVLR::operator=(LASVLR const& rhs) 89 { 90 void* p = 0; 66 91 if (this != &rhs) 67 92 { … … 69 94 m_recordId = rhs.m_recordId; 70 95 m_recordLength = rhs.m_recordLength; 71 m_userId = rhs.m_userId; 72 m_desc = rhs.m_desc; 96 97 p = std::memcpy(m_userId, rhs.m_userId, eUIDSize); 98 assert(p == m_userId); 99 100 p = std::memcpy(m_desc, rhs.m_desc, eDescriptionSize); 101 assert(p == m_desc); 102 103 std::vector<uint8_t>(rhs.m_data).swap(m_data); 73 104 } 74 105 return (*this); 75 106 } 76 107 77 uint16_t LAS RecordHeader::GetReserved() const108 uint16_t LASVLR::GetReserved() const 78 109 { 79 110 return m_reserved; 80 111 } 81 112 82 std::string const& LASRecordHeader::GetUserId() const 83 { 84 return m_userId; 85 } 86 87 uint16_t LASRecordHeader::GetRecordId() const 113 void LASVLR::SetReserved(uint16_t id) 114 { 115 m_reserved = id; 116 } 117 118 std::string LASVLR::GetUserId(bool pad /*= false*/) 119 { 120 // copy array of chars and trim zeros if smaller than 32 bytes 121 std::string tmp(std::string(m_userId, eUIDSize).c_str()); 122 123 // pad right side with spaces 124 if (pad && tmp.size() < eUIDSize) 125 { 126 tmp.resize(eUIDSize, 0); 127 assert(tmp.size() == eUIDSize); 128 } 129 130 assert(tmp.size() <= eUIDSize); 131 return tmp; 132 } 133 134 void LASVLR::SetUserId(std::string const& v) 135 { 136 if (v.size() > eUIDSize) 137 throw std::invalid_argument("user id too long"); 138 139 140 std::fill(m_userId, m_userId + eUIDSize, 0); 141 std::strncpy(m_userId, v.c_str(), eUIDSize); 142 } 143 144 145 uint16_t LASVLR::GetRecordId() const 88 146 { 89 147 return m_recordId; 90 148 } 91 149 92 uint16_t LASRecordHeader::GeRecordLength() const 150 void LASVLR::SetRecordId(uint16_t v) { 151 m_recordId = v; 152 } 153 154 uint16_t LASVLR::GetRecordLength() const 93 155 { 94 156 return m_recordLength; 95 157 } 96 158 97 std::string const& LASRecordHeader::GetDescription() const 98 { 99 return m_desc; 100 } 101 102 bool LASRecordHeader::equal(LASRecordHeader const& other) const 159 void LASVLR::SetRecordLength(uint16_t v) { 160 m_recordLength = v; 161 } 162 163 std::string LASVLR::GetDescription(bool pad /*= false*/) 164 { 165 // copy array of chars and trim zeros if smaller than 32 bytes 166 std::string tmp(std::string(m_desc, eDescriptionSize).c_str()); 167 168 // pad right side with spaces 169 if (pad && tmp.size() < eDescriptionSize) 170 { 171 tmp.resize(eDescriptionSize, 0); 172 assert(tmp.size() == eDescriptionSize); 173 } 174 175 assert(tmp.size() <= eDescriptionSize); 176 return tmp; 177 } 178 179 void LASVLR::SetDescription(std::string const& v) 180 { 181 if (v.size() > eDescriptionSize) 182 throw std::invalid_argument("description is too long"); 183 184 185 std::fill(m_desc, m_desc + eDescriptionSize, 0); 186 std::strncpy(m_desc, v.c_str(), eDescriptionSize); 187 } 188 189 190 std::vector<uint8_t> LASVLR::GetData() const 191 { 192 return m_data; 193 } 194 195 void LASVLR::SetData(const std::vector<uint8_t>& v) 196 { 197 std::vector<uint8_t> m_data(v); 198 } 199 200 bool LASVLR::equal(LASVLR const& other) const 103 201 { 104 202 return (m_recordId == other.m_recordId
Note: See TracChangeset
for help on using the changeset viewer.
