1 // $Id$
2 //
3 // (C) Copyright Mateusz Loskot 2008, mateusz@loskot.net
4 // Distributed under the BSD License
5 // (See accompanying file LICENSE.txt or copy at
6 // http://www.opensource.org/licenses/bsd-license.php)
7 //
8 #if defined(_MSC_VER) && defined(USE_VLD)
9 #include <vld.h>
10 #endif
11 // liblas
12 #include <liblas/liblas.hpp>
13 #include <liblas/laspoint.hpp>
14 #include <liblas/lasreader.hpp>
15 #include <liblas/cstdint.hpp>
16 #include <liblas/detail/timer.hpp>
17 //std
18 #include <algorithm>
19 #include <exception>
20 #include <stdexcept>
21 #include <utility>
22 #include <iomanip>
23 #include <iostream>
24 #include <fstream>
25 #include <iterator>
26 #include <cstdlib>
27 #include <cassert>
28 // sample
29 #include "utility.hpp"
30 using namespace std;
31
main()32 int main()
33 {
34 try
35 {
36 //char const* name = "d:\\data\\lidar\\LASFile_1.LAS";
37 //char const* name = "d:\\data\\lidar\\LDR030828_213450_0.LAS";
38 //char const* name = "d:\\data\\lidar\\Sample_LiDAR_LAS_File.las"; // 1.1
39 //char const* name = "d:\\data\\lidar\\Serpent_Mound_Model.las";
40 //char const* name = "d:\\data\\lidar\\gilmer\\000001.las";
41 //char const* name = "d:\\data\\lidar\\iowa\\04164492.las";
42 //char const* name = "d:\\dev\\liblas\\_svn\\trunk\\test\\data\\TO_core_last_clip.las";
43 char const* name = "test.las";
44
45 std::ifstream ifs;
46 if (!liblas::Open(ifs, name))
47 {
48 throw std::runtime_error(std::string("Can not open ") + name);
49 }
50 liblas::LASReader reader(ifs);
51 liblas::LASHeader const& h = reader.GetHeader();
52
53 cout << "File name: " << name << '\n';
54 cout << "Version : " << reader.GetVersion() << '\n';
55 cout << "Signature: " << h.GetFileSignature() << '\n';
56 cout << "Format : " << h.GetDataFormatId() << '\n';
57 cout << "Project : " << h.GetProjectId() << '\n';
58 cout << "Points count: " << h.GetPointRecordsCount() << '\n';
59 cout << "VLRecords count: " << h.GetRecordsCount() << '\n';
60 cout << "Points by return: ";
61 std::copy(h.GetPointRecordsByReturnCount().begin(),
62 h.GetPointRecordsByReturnCount().end(),
63 ostream_iterator<liblas::uint32_t>(std::cout, " "));
64 cout << std::endl;
65
66 liblas::detail::Timer t;
67 t.start();
68
69 typedef std::pair<double, double> minmax_t;
70 minmax_t mx;
71 minmax_t my;
72 minmax_t mz;
73 liblas::uint32_t i = 0;
74 while (reader.ReadNextPoint())
75 {
76 liblas::LASPoint const& p = reader.GetPoint();
77
78 mx.first = std::min<double>(mx.first, p[0]);
79 mx.second = std::max<double>(mx.second, p[0]);
80 my.first = std::min<double>(my.first, p[1]);
81 my.second = std::max<double>(my.second, p[1]);
82 mz.first = std::min<double>(mz.first, p[2]);
83 mz.second = std::max<double>(mz.second, p[2]);
84
85 // Warning: Printing zillion of points may take looong time
86 //cout << i << ". " << p << '\n';
87 i++;
88 }
89 double const d = t.stop();
90
91 if (reader.GetHeader().GetPointRecordsCount() != i)
92 throw std::runtime_error("read incorrect number of point records");
93
94 cout << "Read points: " << i << " (" << d << ")\n"
95 << std::fixed << std::setprecision(6)
96 << "\nX: " << mx
97 << "\nY: " << my
98 << "\nZ: " << mz
99 << std::endl;
100 }
101 catch (std::exception const& e)
102 {
103 std::cout << "Error: " << e.what() << std::endl;
104 }
105 catch (...)
106 {
107 std::cerr << "Unknown error\n";
108 }
109
110 return 0;
111 }
112