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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
|
// $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)
//
#include <liblas/liblas.hpp>
#include <tut/tut.hpp>
#include <fstream>
#include <string>
#include "liblas_test.hpp"
#include "common.hpp"
namespace tut
{
struct lasreader_data
{
std::string file10_;
std::string file12_;
lasreader_data()
: file10_(g_test_data_path + "//TO_core_last_clip.las")
, file12_(g_test_data_path + "//certainty3d-color-utm-feet-navd88.las")
{}
};
typedef test_group<lasreader_data> tg;
typedef tg::object to;
tg test_group_lasreader("liblas::Reader");
// Test user-declared constructor
template<>
template<>
void to::test<1>()
{
std::ifstream ifs;
ifs.open(file10_.c_str(), std::ios::in | std::ios::binary);
liblas::Reader reader(ifs);
ensure_equals(reader.GetHeader().GetVersionMinor(), 0);
}
// Test reading header
template<>
template<>
void to::test<2>()
{
std::ifstream ifs;
ifs.open(file10_.c_str(), std::ios::in | std::ios::binary);
liblas::Reader reader(ifs);
liblas::Header const& hdr = reader.GetHeader();
test_file10_header(hdr);
}
// Test GetPoint method
template<>
template<>
void to::test<3>()
{
std::ifstream ifs;
ifs.open(file10_.c_str(), std::ios::in | std::ios::binary);
liblas::Reader reader(ifs);
// uninitialized point object, a null-point
liblas::Point const& p = reader.GetPoint();
liblas::Point t(&liblas::DefaultHeader::get());
ensure(p == t);
}
// Test ReadPoint and GetPoint pair
template<>
template<>
void to::test<4>()
{
std::ifstream ifs;
ifs.open(file10_.c_str(), std::ios::in | std::ios::binary);
liblas::Reader reader(ifs);
// read 1st point
reader.ReadNextPoint();
test_file10_point1(reader.GetPoint());
// read 2nd point
reader.ReadNextPoint();
test_file10_point2(reader.GetPoint());
// read and skip 3rd point
reader.ReadNextPoint();
// read 4th point
reader.ReadNextPoint();
test_file10_point4(reader.GetPoint());
// read and count remaining points from 5 to 8
unsigned short c = 0;
while (reader.ReadNextPoint())
{
++c;
}
ensure_equals(c, 4);
}
// Test ReadPointAt and GetPoint pair
template<>
template<>
void to::test<5>()
{
std::ifstream ifs;
ifs.open(file10_.c_str(), std::ios::in | std::ios::binary);
liblas::Reader reader(ifs);
// read 1st point
reader.ReadPointAt(0);
test_file10_point1(reader.GetPoint());
// read 4th point
reader.ReadPointAt(3);
test_file10_point4(reader.GetPoint());
// read back to 2nd point
reader.ReadPointAt(1);
test_file10_point2(reader.GetPoint());
}
// Test operator[] and GetPoint pair
template<>
template<>
void to::test<6>()
{
std::ifstream ifs;
ifs.open(file10_.c_str(), std::ios::in | std::ios::binary);
liblas::Reader reader(ifs);
// read 1st point
test_file10_point1(reader[0]);
// read 4th point
test_file10_point4(reader[3]);
// read back to 2nd point
test_file10_point2(reader[1]);
}
// Test seek and GetPoint pair
template<>
template<>
void to::test<7>()
{
std::ifstream ifs;
ifs.open(file10_.c_str(), std::ios::in | std::ios::binary);
liblas::Reader reader(ifs);
// read 1st point
reader.ReadNextPoint();
test_file10_point1(reader.GetPoint());
// seek to 4th point
reader.Seek(4);
// read 4th point
test_file10_point4(reader[3]);
}
// Test summarization and valid values
template<>
template<>
void to::test<8>()
{
std::ifstream ifs;
ifs.open(file12_.c_str(), std::ios::in | std::ios::binary);
liblas::Reader reader(ifs);
liblas::Summary summary;
liblas::CoordinateSummary coord_summary;
bool read = reader.ReadNextPoint();
while (read)
{
summary.AddPoint(reader.GetPoint());
coord_summary.AddPoint(reader.GetPoint());
read = reader.ReadNextPoint();
}
liblas::property_tree::ptree tree = summary.GetPTree();
ensure_equals("Point count not correct",
tree.get<boost::uint32_t>("summary.points.count"),
static_cast<boost::uint32_t>(10126));
ensure_distance("Min X does not match",
tree.get<double>("summary.points.minimum.x"),
6326726.536120,
0.000001);
ensure_distance("Min Y does not match",
tree.get<double>("summary.points.minimum.y"),
2068062.385430,
0.000001);
ensure_distance("Min Z does not match",
tree.get<double>("summary.points.minimum.z"),
2700.5303501,
0.000001);
ensure_distance("Max X does not match",
tree.get<double>("summary.points.maximum.x"),
6330162.951062,
0.000001);
ensure_distance("Max Y does not match",
tree.get<double>("summary.points.maximum.y"),
2071932.240223,
0.000001);
ensure_distance("Max Z does not match",
tree.get<double>("summary.points.maximum.z"),
2975.7118862,
0.000001);
ensure_equals("Min red not correct",
tree.get<boost::uint16_t>("summary.points.minimum.color.red"),
static_cast<boost::uint16_t>(4096));
ensure_equals("Min green not correct",
tree.get<boost::uint16_t>("summary.points.minimum.color.green"),
static_cast<boost::uint16_t>(2304));
ensure_equals("Min blue not correct",
tree.get<boost::uint16_t>("summary.points.minimum.color.blue"),
static_cast<boost::uint16_t>(0));
ensure_equals("Max red not correct",
tree.get<boost::uint16_t>("summary.points.maximum.color.red"),
static_cast<boost::uint16_t>(65280));
ensure_equals("Max green not correct",
tree.get<boost::uint16_t>("summary.points.maximum.color.green"),
static_cast<boost::uint16_t>(64512));
ensure_equals("Max blue not correct",
tree.get<boost::uint16_t>("summary.points.maximum.color.blue"),
static_cast<boost::uint16_t>(56320));
tree = coord_summary.GetPTree();
ensure_distance("Coordinate Summary Min X does not match",
tree.get<double>("summary.points.minimum.x"),
6326726.536120,
0.000001);
ensure_distance("Coordinate Summary Min Y does not match",
tree.get<double>("summary.points.minimum.y"),
2068062.385430,
0.000001);
ensure_distance("Coordinate Summary Min Z does not match",
tree.get<double>("summary.points.minimum.z"),
2700.5303501,
0.000001);
ensure_distance("Coordinate Summary Max X does not match",
tree.get<double>("summary.points.maximum.x"),
6330162.951062,
0.000001);
ensure_distance("Coordinate Summary Max Y does not match",
tree.get<double>("summary.points.maximum.y"),
2071932.240223,
0.000001);
ensure_distance("Coordinate Summary Max Z does not match",
tree.get<double>("summary.points.maximum.z"),
2975.7118862,
0.000001);
}
}
|