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