libLAS API Reference  1.8.1
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 
68 namespace liblas {
69 
79 {
80 public:
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 
99  Header();
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 
244  PointFormatName GetDataFormatId() const;
245 
247  void SetDataFormatId(PointFormatName v);
248 
256  uint16_t GetDataRecordLength() const;
257 
259  uint32_t GetPointRecordsCount() const;
260 
262  void SetPointRecordsCount(uint32_t v);
263 
265  RecordsByReturnArray const& GetPointRecordsByReturnCount() const;
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 
335  void SetGeoreference();
336 
338  SpatialReference GetSRS() const;
339 
341  void SetSRS(SpatialReference& srs);
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 
377 private:
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 
435 LAS_DLL std::ostream& operator<<(std::ostream& os, liblas::Header const&);
436 
441 class LAS_DLL DefaultHeader : public Singleton<Header>
442 {
443 public:
445 
446 
447 protected:
448  DefaultHeader();
449  DefaultHeader( DefaultHeader const&);
450  DefaultHeader& operator=( DefaultHeader const&);
451 
452 };
453 
454 
455 } // namespace liblas
456 
457 #endif // LIBLAS_LASHEADER_HPP_INCLUDED
static char const *const FileSignature
Official signature of ASPRS LAS file format, always "LASF".
Definition: header.hpp:83
static char const *const SoftwareIdentifier
Default software identifier used by libLAS, always "libLAS X.Y".
Definition: header.hpp:89
~DefaultHeader()
Definition: header.hpp:444
Representation of variable-length record data.
Definition: variablerecord.hpp:59
#define LAS_DLL
Definition: export.hpp:58
std::ostream & operator<<(std::ostream &os, Classification const &cls)
The output stream operator is based on std::bitset<N>::operator<<.
Definition: classification.hpp:247
static char const *const SystemIdentifier
Default system identifier used by libLAS, always "libLAS".
Definition: header.hpp:86
std::vector< uint32_t > RecordsByReturnArray
Array of 5 elements - numbers of points recorded by each return.
Definition: header.hpp:93
bool operator==(Classification const &lhs, Classification const &rhs)
Equal-to operator implemented in terms of Classification::equal.
Definition: classification.hpp:226
Spatial Reference System container for libLAS.
Definition: spatialreference.hpp:69
Namespace grouping all elements of libLAS public interface.
Definition: bounds.hpp:60
Singleton used for all empty points upon construction.
Definition: header.hpp:441
PointFormatName
Versions of point record format.
Definition: version.hpp:89
Definition: schema.hpp:78
Definition: schema.hpp:80
Definition of public header block.
Definition: header.hpp:78
Schema definition.
Definition: schema.hpp:102