Changeset 961
- Timestamp:
- 11/06/08 11:18:31 (2 months ago)
- Location:
- trunk/test/unit
- Files:
-
- 2 modified
-
common.hpp (modified) (1 diff)
-
lasreader_iterator_test.cpp (modified) (19 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/common.hpp
r960 r961 38 38 struct bbox_calculator 39 39 { 40 // bbox object will store operation result 40 41 bbox_calculator(liblas::detail::Extents<double>& bbox) 41 42 : empty(true), bbox(bbox) -
trunk/test/unit/lasreader_iterator_test.cpp
- Property svn:keywords set to Id
r956 r961 6 6 // http://www.opensource.org/licenses/bsd-license.php) 7 7 // 8 #include <liblas/cstdint.hpp> 8 9 #include <liblas/iterator.hpp> 9 #include <liblas/cstdint.hpp> 10 #include <liblas/laspoint.hpp> 11 #include <liblas/detail/utility.hpp> 10 12 #include <tut/tut.hpp> 13 #include <algorithm> 11 14 #include <fstream> 12 15 #include <iterator> 16 #include <list> 13 17 #include "liblas_test.hpp" 14 18 #include "common.hpp" 19 using namespace liblas; 15 20 16 21 namespace tut … … 35 40 void to::test<1>() 36 41 { 37 l iblas::lasreader_iterator it;42 lasreader_iterator it; 38 43 } 39 44 … … 44 49 { 45 50 std::ifstream ifs(file10_.c_str(), std::ios::in | std::ios::binary); 46 liblas::LASReader reader(ifs);47 l iblas::lasreader_iterator it(reader);51 LASReader reader(ifs); 52 lasreader_iterator it(reader); 48 53 } 49 54 … … 53 58 void to::test<3>() 54 59 { 55 l iblas::lasreader_iterator it1;56 l iblas::lasreader_iterator it2(it1);60 lasreader_iterator it1; 61 lasreader_iterator it2(it1); 57 62 58 63 ensure(it1 == it2); … … 65 70 { 66 71 std::ifstream ifs(file10_.c_str(), std::ios::in | std::ios::binary); 67 liblas::LASReader reader(ifs);68 l iblas::lasreader_iterator it1(reader);69 l iblas::lasreader_iterator it2(it1);72 LASReader reader(ifs); 73 lasreader_iterator it1(reader); 74 lasreader_iterator it2(it1); 70 75 71 76 ensure(it1 == it2); … … 77 82 void to::test<5>() 78 83 { 79 l iblas::lasreader_iterator it1;80 l iblas::lasreader_iterator it2;84 lasreader_iterator it1; 85 lasreader_iterator it2; 81 86 it1 = it2; 82 87 … … 90 95 { 91 96 std::ifstream ifs(file10_.c_str(), std::ios::in | std::ios::binary); 92 liblas::LASReader reader(ifs);93 l iblas::lasreader_iterator it1(reader);94 l iblas::lasreader_iterator it2;97 LASReader reader(ifs); 98 lasreader_iterator it1(reader); 99 lasreader_iterator it2; 95 100 it1 = it2; 96 101 … … 104 109 { 105 110 std::ifstream ifs(file10_.c_str(), std::ios::in | std::ios::binary); 106 liblas::LASReader reader(ifs);107 l iblas::lasreader_iterator it(reader);111 LASReader reader(ifs); 112 lasreader_iterator it(reader); 108 113 109 114 test_file10_point1(*it); 110 115 } 111 116 112 // Test pointer-to-member operator117 // Test pointer-to-member operator 113 118 template<> 114 119 template<> … … 116 121 { 117 122 std::ifstream ifs(file10_.c_str(), std::ios::in | std::ios::binary); 118 liblas::LASReader reader(ifs);119 l iblas::lasreader_iterator it(reader);123 LASReader reader(ifs); 124 lasreader_iterator it(reader); 120 125 121 126 // test 1st point data record … … 124 129 ensure_distance(it->GetZ(), double(51.53), 0.0001); 125 130 ensure_equals(it->GetIntensity(), 670); 126 ensure_equals(it->GetClassification(), liblas::uint8_t(1));131 ensure_equals(it->GetClassification(), uint8_t(1)); 127 132 ensure_equals(it->GetScanAngleRank(), 0); 128 133 ensure_equals(it->GetUserData(), 3); … … 137 142 { 138 143 std::ifstream ifs(file10_.c_str(), std::ios::in | std::ios::binary); 139 liblas::LASReader reader(ifs);140 l iblas::lasreader_iterator it(reader); // move to 1st point144 LASReader reader(ifs); 145 lasreader_iterator it(reader); // move to 1st point 141 146 ++it; // move to 2nd record 142 147 … … 150 155 { 151 156 std::ifstream ifs(file10_.c_str(), std::ios::in | std::ios::binary); 152 liblas::LASReader reader(ifs);153 l iblas::lasreader_iterator it(reader); // move to 1st point157 LASReader reader(ifs); 158 lasreader_iterator it(reader); // move to 1st point 154 159 it++; // move to 2nd record 155 160 … … 163 168 { 164 169 std::ifstream ifs(file10_.c_str(), std::ios::in | std::ios::binary); 165 liblas::LASReader reader(ifs);166 l iblas::lasreader_iterator it(reader); // move to 1st point167 l iblas::lasreader_iterator end;170 LASReader reader(ifs); 171 lasreader_iterator it(reader); // move to 1st point 172 lasreader_iterator end; 168 173 169 174 ensure_not(end == it); … … 176 181 { 177 182 std::ifstream ifs(file10_.c_str(), std::ios::in | std::ios::binary); 178 liblas::LASReader reader(ifs);179 l iblas::lasreader_iterator it(reader); // move to 1st point180 l iblas::lasreader_iterator end;183 LASReader reader(ifs); 184 lasreader_iterator it(reader); // move to 1st point 185 lasreader_iterator end; 181 186 182 187 ensure(end != it); … … 189 194 { 190 195 std::ifstream ifs(file10_.c_str(), std::ios::in | std::ios::binary); 191 liblas::LASReader reader(ifs);192 liblas::uint32_t const cnt = reader.GetHeader().GetPointRecordsCount();193 l iblas::lasreader_iterator it(reader); // move to 1st point194 l iblas::lasreader_iterator end;195 196 liblas::uint32_t s = 0;196 LASReader reader(ifs); 197 uint32_t const cnt = reader.GetHeader().GetPointRecordsCount(); 198 lasreader_iterator it(reader); // move to 1st point 199 lasreader_iterator end; 200 201 uint32_t s = 0; 197 202 while (end != it) 198 203 { … … 204 209 } 205 210 206 // Test std::distance 211 // Test std::distance operation 207 212 template<> 208 213 template<> … … 210 215 { 211 216 std::ifstream ifs(file10_.c_str(), std::ios::in | std::ios::binary); 212 liblas::LASReader reader(ifs); 213 liblas::uint32_t const cnt = reader.GetHeader().GetPointRecordsCount(); 214 liblas::lasreader_iterator it(reader); // move to 1st point 215 liblas::lasreader_iterator end; 216 217 ensure_equals(std::distance(it, end), cnt); 218 } 219 220 // Test std::advance 217 LASReader reader(ifs); 218 uint32_t const cnt = reader.GetHeader().GetPointRecordsCount(); 219 lasreader_iterator it(reader); // move to 1st point 220 lasreader_iterator end; 221 222 lasreader_iterator::difference_type const d = std::distance(it, end); 223 ensure_equals(d, cnt); 224 } 225 226 // Test std::advance operation 221 227 template<> 222 228 template<> … … 224 230 { 225 231 std::ifstream ifs(file10_.c_str(), std::ios::in | std::ios::binary); 226 liblas::LASReader reader(ifs);227 l iblas::lasreader_iterator it(reader); // move to 1st point232 LASReader reader(ifs); 233 lasreader_iterator it(reader); // move to 1st point 228 234 229 235 std::advance(it, 1); // move to 2nd record … … 233 239 test_file10_point4(*it); 234 240 } 241 242 // Test std::copy algorithm 243 template<> 244 template<> 245 void to::test<16>() 246 { 247 std::ifstream ifs(file10_.c_str(), std::ios::in | std::ios::binary); 248 LASReader reader(ifs); 249 uint32_t const size = reader.GetHeader().GetPointRecordsCount(); 250 251 lasreader_iterator it(reader); 252 lasreader_iterator end; 253 254 typedef std::list<LASPoint> list_t; 255 typedef std::back_insert_iterator<list_t> inserter_t; 256 list_t cache; 257 258 // Test copying LAS records to std::list based cache 259 std::copy(it, end, inserter_t(cache)); 260 ensure_equals(cache.size(), size); 261 262 // Test copied data 263 list_t::const_iterator cit = cache.begin(); // 1st element 264 std::advance(cit, 1); // move to 2nd element in cache 265 test_file10_point2(*cit); 266 std::advance(cit, 2); // move to 4th element in cache 267 test_file10_point4(*cit); 268 } 269 270 // Test std::count algorithm 271 template<> 272 template<> 273 void to::test<17>() 274 { 275 // Construct copy of 2nd point record from tested file 276 LASPoint pt; 277 pt.SetCoordinates(630282.45, 4834500, 51.63); 278 pt.SetIntensity(350); 279 pt.SetClassification(1); 280 pt.SetScanAngleRank(0); 281 pt.SetUserData(3); 282 pt.SetScanFlags(9); 283 pt.SetTime(413665.52880000003); 284 ensure(pt.IsValid()); 285 test_file10_point2(pt); 286 287 std::ifstream ifs(file10_.c_str(), std::ios::in | std::ios::binary); 288 LASReader reader(ifs); 289 lasreader_iterator it(reader); 290 lasreader_iterator end; 291 292 // Count records equal to given point object 293 lasreader_iterator::difference_type const expected = 1; 294 lasreader_iterator::difference_type n = std::count(it, end, pt); 295 ensure_equals(n, expected); 296 } 297 298 299 // Test std::equal algorithm 300 template<> 301 template<> 302 void to::test<18>() 303 { 304 // TODO - mloskot: Can not re-use the reader because libLAS does 305 // not support reset operation yet. In order to reuse reader with mre than one iterator 306 // we have to provide operation to reset reader (set internal pointer to beginning of LAS file, etc.). 307 // So, here we reuse only file stream. 308 //LASReader reader(ifs); 309 310 std::ifstream ifs(file10_.c_str(), std::ios::in | std::ios::binary); 311 312 313 // Copy LAS records to std::list based cache 314 typedef std::list<LASPoint> list_t; 315 typedef std::back_insert_iterator<list_t> inserter_t; 316 list_t cache; 317 { 318 LASReader reader(ifs); 319 lasreader_iterator it(reader); 320 lasreader_iterator end; 321 ensure(it != end); 322 323 std::copy(it, end, inserter_t(cache)); 324 ensure_equals(cache.size(), reader.GetHeader().GetPointRecordsCount()); 325 } 326 327 // Compare LAS file with cache 328 { 329 LASReader reader(ifs); 330 lasreader_iterator it(reader); 331 lasreader_iterator end; 332 ensure(it != end); 333 334 bool eq = std::equal(it, end, cache.begin()); 335 ensure(eq); 336 } 337 } 338 339 // Test std::find algorithm 340 template<> 341 template<> 342 void to::test<19>() 343 { 344 // Construct copy of 2nd point record from tested file 345 LASPoint pt; 346 pt.SetCoordinates(630282.45, 4834500, 51.63); 347 pt.SetIntensity(350); 348 pt.SetClassification(1); 349 pt.SetScanAngleRank(0); 350 pt.SetUserData(3); 351 pt.SetScanFlags(9); 352 pt.SetTime(413665.52880000003); 353 ensure(pt.IsValid()); 354 test_file10_point2(pt); 355 356 std::ifstream ifs(file10_.c_str(), std::ios::in | std::ios::binary); 357 LASReader reader(ifs); 358 lasreader_iterator it(reader); 359 lasreader_iterator end; 360 361 // find 2nd point data record 362 lasreader_iterator fit; 363 fit = std::find(it, end, pt); 364 ensure(fit != end); 365 test_file10_point2(*fit); 366 } 367 368 // Test std::find_if algorithm 369 template<> 370 template<> 371 void to::test<20>() 372 { 373 std::ifstream ifs(file10_.c_str(), std::ios::in | std::ios::binary); 374 LASReader reader(ifs); 375 lasreader_iterator it(reader); 376 lasreader_iterator end; 377 378 // find 2nd point data record comparing XY coordinates 379 lasreader_iterator fit; 380 fit = std::find_if(it, end, is_xy(630282.45, 4834500, 0.0001)); 381 ensure(fit != end); 382 test_file10_point2(*fit); 383 } 384 385 // Test std::for_each algorithm 386 template<> 387 template<> 388 void to::test<21>() 389 { 390 std::ifstream ifs(file10_.c_str(), std::ios::in | std::ios::binary); 391 LASReader reader(ifs); 392 lasreader_iterator it(reader); 393 lasreader_iterator end; 394 395 typedef liblas::detail::Point<double> point_t; 396 typedef liblas::detail::Extents<double> bbox_t; 397 398 LASHeader const& h = reader.GetHeader(); 399 bbox_t lasbbox(point_t(h.GetMinX(), h.GetMinY(), h.GetMinZ()), 400 point_t(h.GetMaxX(), h.GetMaxY(), h.GetMaxZ())); 401 402 // Accumulate points extents to common bounding box 403 bbox_t bbox; 404 std::for_each(it, end, bbox_calculator(bbox)); 405 406 ensure(lasbbox == bbox); 407 } 408 409 235 410 } 236 411
