libLAS API Reference (svn-trunk)
header.hpp
Go to the documentation of this file.
1/******************************************************************************
2 * $Id$
3 *
4 * Project: libLAS - http://liblas.org - A BSD library for LAS format data.
5 * Purpose: LAS header class
6 * Author: Mateusz Loskot, mateusz@loskot.net
7 *
8 ******************************************************************************
9 * Copyright (c) 2010, Mateusz Loskot
10 * Copyright (c) 2008, Phil Vachon
11 *
12 * All rights reserved.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following
16 * conditions are met:
17 *
18 * * Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * * Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in
22 * the documentation and/or other materials provided
23 * with the distribution.
24 * * Neither the name of the Martin Isenburg or Iowa Department
25 * of Natural Resources nor the names of its contributors may be
26 * used to endorse or promote products derived from this software
27 * without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
32 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
33 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
34 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
35 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
36 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
37 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
38 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
39 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
40 * OF SUCH DAMAGE.
41 ****************************************************************************/
42
43#ifndef LIBLAS_LASHEADER_HPP_INCLUDED
44#define LIBLAS_LASHEADER_HPP_INCLUDED
45
46#include <boost/uuid/uuid.hpp>
47#include <liblas/bounds.hpp>
48#include <liblas/schema.hpp>
51#include <liblas/version.hpp>
52#include <liblas/external/property_tree/ptree.hpp>
53#include <liblas/export.hpp>
54#include <liblas/detail/singleton.hpp>
55// boost
56#include <boost/foreach.hpp>
57#include <boost/uuid/uuid.hpp>
58#include <boost/uuid/uuid_generators.hpp>
59#include <boost/uuid/uuid_io.hpp>
60
61//std
62#include <cstddef>
63#include <string>
64#include <vector>
65#include <sstream>
66#include <cmath>
67
68namespace liblas {
69
79{
80public:
81
83 static char const* const FileSignature;
84
86 static char const* const SystemIdentifier;
87
89 static char const* const SoftwareIdentifier;
90
93 typedef std::vector<uint32_t> RecordsByReturnArray;
94
100
102 Header(Header const& other);
103
105 Header& operator=(Header const& rhs);
106
108 bool operator==(const Header& other) const;
109
112 std::string GetFileSignature() const;
113
120 void SetFileSignature(std::string const& v);
121
124 uint16_t GetFileSourceId() const;
125
131 void SetFileSourceId(uint16_t v);
132
137 uint16_t GetReserved() const;
138
142 void SetReserved(uint16_t v);
143
146 boost::uuids::uuid GetProjectId() const;
147
149 void SetProjectId(boost::uuids::uuid const& v);
150
153 uint8_t GetVersionMajor() const;
154
158 void SetVersionMajor(uint8_t v);
159
162 uint8_t GetVersionMinor() const;
163
167 void SetVersionMinor(uint8_t v);
168
175 std::string GetSystemId(bool pad = false) const;
176
180 void SetSystemId(std::string const& v);
181
187 std::string GetSoftwareId(bool pad = false) const;
188
192 void SetSoftwareId(std::string const& v);
193
196 uint16_t GetCreationDOY() const;
197
201 void SetCreationDOY(uint16_t v);
202
205 uint16_t GetCreationYear() const;
206
210 void SetCreationYear(uint16_t v);
211
214 uint16_t GetHeaderSize() const;
215
218 void SetHeaderSize(uint16_t v);
219
221 uint32_t GetDataOffset() const;
222
226 void SetDataOffset(uint32_t v);
227
229 uint32_t GetHeaderPadding() const;
230
235 void SetHeaderPadding(uint32_t v);
236
238 uint32_t GetRecordsCount() const;
239
241 void SetRecordsCount(uint32_t v);
242
245
248
256 uint16_t GetDataRecordLength() const;
257
259 uint32_t GetPointRecordsCount() const;
260
262 void SetPointRecordsCount(uint32_t v);
263
266
271 void SetPointRecordsByReturnCount(std::size_t index, uint32_t v);
272
274 double GetScaleX() const;
275
277 double GetScaleY() const;
278
280 double GetScaleZ() const;
281
283 void SetScale(double x, double y, double z);
284
286 double GetOffsetX() const;
287
289 double GetOffsetY() const;
290
292 double GetOffsetZ() const;
293
295 void SetOffset(double x, double y, double z);
296
298 double GetMaxX() const;
299
301 double GetMinX() const;
302
304 double GetMaxY() const;
305
307 double GetMinY() const;
308
310 double GetMaxZ() const;
311
313 double GetMinZ() const;
314
316 void SetMax(double x, double y, double z);
317
319 void SetMin(double x, double y, double z);
320
322 void AddVLR(VariableRecord const& v);
323
325 VariableRecord const& GetVLR(uint32_t index) const;
326
328 const std::vector<VariableRecord>& GetVLRs() const;
329
331 void DeleteVLR(uint32_t index);
332 void DeleteVLRs(std::string const& name, uint16_t id);
333
336
339
342
344 Schema const& GetSchema() const;
345
347 void SetSchema(const Schema& format);
348
352 const Bounds<double>& GetExtent() const;
353
358 void SetExtent(Bounds<double> const& extent);
359
362 liblas::property_tree::ptree GetPTree() const;
363
366 bool Compressed() const;
367
369 void SetCompressed(bool b);
370
371 uint32_t GetVLRBlockSize() const;
372
373 void to_rst(std::ostream& os) const;
374 void to_xml(std::ostream& os) const;
375 void to_json(std::ostream& os) const;
376
377private:
378
379 typedef detail::Point<double> PointScales;
380 typedef detail::Point<double> PointOffsets;
381
382 enum
383 {
384 eDataSignatureSize = 2,
385 eFileSignatureSize = 4,
386 ePointsByReturnSize = 7,
387 eProjectId4Size = 8,
388 eSystemIdSize = 32,
389 eSoftwareIdSize = 32,
390 eHeaderSize = 227,
391 eFileSourceIdMax = 65535
392 };
393
394 // TODO (low-priority): replace static-size char arrays
395 // with std::string and return const-reference to string object.
396
397 //
398 // Private function members
399 //
400 void Init();
401
402 //
403 // Private data members
404 //
405 char m_signature[eFileSignatureSize]; // TODO: replace with boost::array --mloskot
406 boost::uint16_t m_sourceId;
407 boost::uint16_t m_reserved;
408 boost::uuids::uuid m_projectGuid;
409 // boost::uint32_t m_projectId1;
410 // boost::uint16_t m_projectId2;
411 // boost::uint16_t m_projectId3;
412 // boost::uint8_t m_projectId4[eProjectId4Size];
413 boost::uint8_t m_versionMajor;
414 boost::uint8_t m_versionMinor;
415
416 char m_systemId[eSystemIdSize]; // TODO: replace with boost::array --mloskot
417 char m_softwareId[eSoftwareIdSize];
418 uint16_t m_createDOY;
419 uint16_t m_createYear;
420 uint16_t m_headerSize;
421 uint32_t m_dataOffset;
422 uint32_t m_recordsCount;
423 uint32_t m_pointRecordsCount;
424 RecordsByReturnArray m_pointRecordsByReturn;
425 PointScales m_scales;
426 PointOffsets m_offsets;
427 Bounds<double> m_extent;
428 std::vector<VariableRecord> m_vlrs;
429 SpatialReference m_srs;
430 Schema m_schema;
431 bool m_isCompressed;
432 uint32_t m_headerPadding;
433};
434
435LAS_DLL std::ostream& operator<<(std::ostream& os, liblas::Header const&);
436
441class LAS_DLL DefaultHeader : public Singleton<Header>
442{
443public:
445
446
447protected:
451
452};
453
454
455} // namespace liblas
456
457#endif // LIBLAS_LASHEADER_HPP_INCLUDED
Definition bounds.hpp:176
DefaultHeader(DefaultHeader const &)
~DefaultHeader()
Definition header.hpp:444
DefaultHeader & operator=(DefaultHeader const &)
Definition of public header block.
Definition header.hpp:79
Header(Header const &other)
Copy constructor.
uint16_t GetCreationDOY() const
Get day of year of file creation date.
SpatialReference GetSRS() const
Fetch the georeference.
boost::uuids::uuid GetProjectId() const
Get project identifier.
void DeleteVLR(uint32_t index)
Removes a VLR from the the header.
double GetMinY() const
Get maximum value of extent of Y coordinate.
std::string GetSystemId(bool pad=false) const
Get system identifier.
void SetMin(double x, double y, double z)
Set minimum values of extent of X, Y and Z coordinates.
double GetOffsetZ() const
Get Z coordinate offset.
std::vector< uint32_t > RecordsByReturnArray
Array of 5 elements - numbers of points recorded by each return.
Definition header.hpp:93
uint16_t GetReserved() const
Get value field reserved by the ASPRS LAS Specification.
static char const *const SoftwareIdentifier
Default software identifier used by libLAS, always "libLAS X.Y".
Definition header.hpp:89
void SetSRS(SpatialReference &srs)
Set the georeference.
void to_rst(std::ostream &os) const
void SetGeoreference()
Rewrite variable-length record with georeference infomation, if available.
void DeleteVLRs(std::string const &name, uint16_t id)
bool Compressed() const
Returns true iff the file is compressed (laszip), as determined by the high bit in the point type.
void SetMax(double x, double y, double z)
Set maximum values of extent of X, Y and Z coordinates.
void SetCompressed(bool b)
Sets whether or not the points are compressed.
uint32_t GetRecordsCount() const
Get number of variable-length records.
Header()
Default constructor.
Header & operator=(Header const &rhs)
Assignment operator.
void SetOffset(double x, double y, double z)
Set values of X, Y and Z coordinates offset.
double GetMaxX() const
Get minimum value of extent of X coordinate.
const Bounds< double > & GetExtent() const
Return the liblas::Bounds.
void to_json(std::ostream &os) const
uint32_t GetPointRecordsCount() const
Get total number of point records stored in the LAS file.
double GetMaxZ() const
Get minimum value of extent of Z coordinate.
void SetDataOffset(uint32_t v)
Set number of bytes from the beginning to the first point record.
const std::vector< VariableRecord > & GetVLRs() const
Returns all of the VLRs.
uint32_t GetVLRBlockSize() const
uint16_t GetHeaderSize() const
Get number of bytes of generic verion of public header block storage.
double GetMinX() const
Get maximum value of extent of X coordinate.
double GetScaleX() const
Get scale factor for X coordinate.
void SetReserved(uint16_t v)
Set reserved value for the header identifier.
liblas::property_tree::ptree GetPTree() const
Returns a property_tree that contains all of the header data in a structured format.
void SetHeaderPadding(uint32_t v)
Set the number of bytes from the end of the VLRs in the header to the beginning of point data.
void SetFileSignature(std::string const &v)
Set ASPRS LAS file signature.
uint32_t GetHeaderPadding() const
Get number of bytes from the end of the VLRs to the GetDataOffset.
void AddVLR(VariableRecord const &v)
Adds a variable length record to the header.
static char const *const SystemIdentifier
Default system identifier used by libLAS, always "libLAS".
Definition header.hpp:86
void SetHeaderSize(uint16_t v)
Sets the header size.
void SetVersionMajor(uint8_t v)
Set major component of version of LAS format.
std::string GetSoftwareId(bool pad=false) const
Get software identifier.
PointFormatName GetDataFormatId() const
Get identifier of point data (record) format.
void SetFileSourceId(uint16_t v)
Set file source identifier.
void SetScale(double x, double y, double z)
Set values of scale factor for X, Y and Z coordinates.
void SetSoftwareId(std::string const &v)
Set software identifier.
void SetExtent(Bounds< double > const &extent)
Set the liblas::Bounds.
void to_xml(std::ostream &os) const
double GetScaleZ() const
Get scale factor for Z coordinate.
double GetOffsetX() const
Get X coordinate offset.
double GetOffsetY() const
Get Y coordinate offset.
void SetCreationDOY(uint16_t v)
Set day of year of file creation date.
void SetVersionMinor(uint8_t v)
Set minor component of version of LAS format.
uint8_t GetVersionMinor() const
Get minor component of version of LAS format.
void SetCreationYear(uint16_t v)
Get year of file creation date.
void SetPointRecordsByReturnCount(std::size_t index, uint32_t v)
Set values of 5-elements array of total point records per return.
void SetRecordsCount(uint32_t v)
Set number of variable-length records.
static char const *const FileSignature
Official signature of ASPRS LAS file format, always "LASF".
Definition header.hpp:83
double GetMaxY() const
Get minimum value of extent of Y coordinate.
void SetSystemId(std::string const &v)
Set system identifier.
double GetScaleY() const
Get scale factor for Y coordinate.
double GetMinZ() const
Get maximum value of extent of Z coordinate.
uint16_t GetFileSourceId() const
Get file source identifier.
void SetProjectId(boost::uuids::uuid const &v)
Set project identifier.
uint32_t GetDataOffset() const
Get number of bytes from the beginning to the first point record.
std::string GetFileSignature() const
Get ASPRS LAS file signature.
uint8_t GetVersionMajor() const
Get major component of version of LAS format.
void SetDataFormatId(PointFormatName v)
Set identifier of point data (record) format.
Schema const & GetSchema() const
Returns the schema.
uint16_t GetCreationYear() const
Set year of file creation date.
void SetPointRecordsCount(uint32_t v)
Set number of point records that will be stored in a new LAS file.
VariableRecord const & GetVLR(uint32_t index) const
Returns a VLR.
RecordsByReturnArray const & GetPointRecordsByReturnCount() const
Get array of the total point records per return.
void SetSchema(const Schema &format)
Sets the schema.
uint16_t GetDataRecordLength() const
The length in bytes of each point.
bool operator==(const Header &other) const
Comparison operator.
Schema definition.
Definition schema.hpp:103
Spatial Reference System container for libLAS.
Definition spatialreference.hpp:70
Representation of variable-length record data.
Definition variablerecord.hpp:60
#define LAS_DLL
Definition export.hpp:58
Namespace grouping all elements of libLAS public interface.
Definition bounds.hpp:60
std::ostream & operator<<(std::ostream &os, Classification const &cls)
The output stream operator is based on std::bitset<N>::operator<<.
Definition classification.hpp:247
PointFormatName
Versions of point record format.
Definition version.hpp:91
Definition schema.hpp:80
Definition schema.hpp:78