PageRenderTime 73ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/Utilities/otbliblas/apps/lasindex_test.cpp

https://bitbucket.org/olahlou/otb
C++ | 711 lines | 520 code | 49 blank | 142 comment | 104 complexity | 1501c9463dacc1840ffc4a166f981bb6 MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, LGPL-2.0, CC-BY-SA-3.0, BSD-3-Clause, LGPL-2.1
  1. // lasindex_test.cpp : Defines the entry point for the console application.
  2. //
  3. #include <boost/cstdint.hpp>
  4. #include <iosfwd>
  5. #include <iostream>
  6. #include <cstdio>
  7. #include <bitset>
  8. #include <exception>
  9. #include <fstream>
  10. #include <iostream>
  11. #include <map>
  12. #include <sstream> // std::stringstream
  13. #include <string>
  14. #include <stack>
  15. #include <typeinfo>
  16. #include <vector>
  17. #include <liblas/lasindex.hpp>
  18. using namespace liblas;
  19. using namespace boost;
  20. #ifdef _WIN32
  21. #define compare_no_case(a,b,n) _strnicmp( (a), (b), (n) )
  22. #else
  23. #define compare_no_case(a,b,n) strncasecmp( (a), (b), (n) )
  24. #endif
  25. #define lasindex_test_version "1.0"
  26. #define SAMPLE_AUTHOR "Gary Huber"
  27. #define SAMPLE_COMMENT "This is a test of the LAS file index system in LibLAS"
  28. #define SAMPLE_DATE "7/22/10"
  29. void usage(FILE *debugger)
  30. {
  31. fprintf(debugger,"----------------------------------------------------------\n");
  32. fprintf(debugger," lasindex_test (version %s) usage:\n", lasindex_test_version);
  33. fprintf(debugger,"----------------------------------------------------------\n");
  34. fprintf(debugger,"\n");
  35. fprintf(debugger,"Create index for in file, resave to out file, temporary storage file, max memory usage, sort with Z bin interval:\n");
  36. fprintf(debugger," lasindex_test -i in.las -o out.las -t tempfile -z interval -m maxmemory\n");
  37. fprintf(debugger,"\n");
  38. fprintf(debugger,"-i or --infile (required):\n");
  39. fprintf(debugger," complete input file name and path\n");
  40. fprintf(debugger,"\n");
  41. fprintf(debugger,"-o or --outfile (required unless readonly):\n");
  42. fprintf(debugger," complete output file name and path\n");
  43. fprintf(debugger,"\n");
  44. fprintf(debugger,"-n or --indexfile (required for reading standalone index):\n");
  45. fprintf(debugger," complete output file name and path\n");
  46. fprintf(debugger,"\n");
  47. fprintf(debugger,"-t or --tempfile (required):\n");
  48. fprintf(debugger," complete temporary file name and path used during index building\n");
  49. fprintf(debugger,"\n");
  50. fprintf(debugger,"-b or --zbinheight (optional):\n");
  51. fprintf(debugger," elevation sorting bin height, no z sorting if omitted\n");
  52. fprintf(debugger,"\n");
  53. fprintf(debugger,"-m or --maxmem (optional):\n");
  54. fprintf(debugger," maximum memory to use for index building, defaults to no limit if omitted\n");
  55. fprintf(debugger,"\n");
  56. fprintf(debugger,"-a or --author (optional):\n");
  57. fprintf(debugger," author field for index file record header, 512 max length\n");
  58. fprintf(debugger,"\n");
  59. fprintf(debugger,"-c or --comment (optional):\n");
  60. fprintf(debugger," comment field for index file record header, 512 max length\n");
  61. fprintf(debugger,"\n");
  62. fprintf(debugger,"-d or --date (optional):\n");
  63. fprintf(debugger," date of index creation for index file record header, 512 max length\n");
  64. fprintf(debugger,"\n");
  65. fprintf(debugger,"-r or --readonly (optional):\n");
  66. fprintf(debugger," if set, index is to be read only, not created\n");
  67. fprintf(debugger,"\n");
  68. fprintf(debugger,"-s or --standalone (optional):\n");
  69. fprintf(debugger," if set, index is to be saved in separate index file, not in las file\n");
  70. fprintf(debugger,"\n");
  71. fprintf(debugger,"-x (at least one dimension required for filter):\n");
  72. fprintf(debugger," follow with low and high values for X filter\n");
  73. fprintf(debugger,"\n");
  74. fprintf(debugger,"-y (at least one dimension required for filter):\n");
  75. fprintf(debugger," follow with low and high values for Y filter\n");
  76. fprintf(debugger,"\n");
  77. fprintf(debugger,"-z (at least one dimension required for filter):\n");
  78. fprintf(debugger," follow with low and high values for Z filter\n");
  79. fprintf(debugger,"\n");
  80. fprintf(debugger,"-it (use iterator for filtering):\n");
  81. fprintf(debugger," follow with number of points to be returned in each iteration\n");
  82. fprintf(debugger,"\n");
  83. fprintf(debugger, "\nFor more information, see the full documentation for lasindex_test at:\n"
  84. " http://liblas.org/browser/trunk/doc/lasindex_test.txt\n");
  85. fprintf(debugger,"----------------------------------------------------------\n");
  86. }
  87. std::istream* OpenInput(std::string filename)
  88. {
  89. std::ios::openmode const mode = std::ios::in | std::ios::binary;
  90. std::istream* istrm = 0;
  91. if (compare_no_case(filename.c_str(),"STDIN",5) == 0)
  92. {
  93. istrm = &std::cin;
  94. }
  95. else
  96. {
  97. istrm = new std::ifstream(filename.c_str(), mode);
  98. }
  99. if (!istrm->good())
  100. {
  101. delete istrm;
  102. istrm = 0;
  103. throw std::runtime_error("Reading stream was not able to be created.");
  104. }
  105. return istrm;
  106. }
  107. std::ostream* OpenOutput(std::string filename)
  108. {
  109. std::ios::openmode const mode = std::ios::out | std::ios::binary;
  110. std::ostream* ostrm = 0;
  111. if (compare_no_case(filename.c_str(),"STDOUT",5) == 0)
  112. {
  113. ostrm = &std::cout;
  114. }
  115. else
  116. {
  117. ostrm = new std::ofstream(filename.c_str(), mode);
  118. }
  119. if (!ostrm->good())
  120. {
  121. delete ostrm;
  122. ostrm = 0;
  123. throw std::runtime_error("Writing stream was not able to be created.");
  124. }
  125. return ostrm;
  126. }
  127. void IndexInitError(FILE *debugger)
  128. {
  129. fprintf(debugger, "Unable to initialize index.\n");
  130. }
  131. void IndexFilterNoPoints(FILE *debugger)
  132. {
  133. fprintf(debugger, "No points found in search area.\n");
  134. }
  135. void IndexFilterInitError(FILE *debugger)
  136. {
  137. fprintf(debugger, "Unable to initialize index filter. Invalid values.\n");
  138. }
  139. bool ReportIteratorResults(FILE *debugger, uint32_t resultSize, uint32_t pointCount, uint32_t step)
  140. {
  141. if (resultSize)
  142. {
  143. // do something with the list of points
  144. #ifdef VISUAL_8
  145. fprintf(debugger, "Points within filter area %d of %d, step %d, %s\n", resultSize,
  146. pointCount, step, "Using iterator");
  147. #else // VISUAL_8
  148. fprintf(debugger, "Points within filter area %d of %d, step %d, %s\n", resultSize,
  149. pointCount, step, "Using iterator");
  150. #endif // VISUAL_8
  151. return true;
  152. }
  153. else
  154. {
  155. IndexFilterNoPoints(debugger);
  156. return false;
  157. } // else
  158. } // ReportIteratorResults
  159. int main(int argc, char* argv[])
  160. {
  161. char *tmpfilenme = 0;
  162. char *lasinfilenme = 0;
  163. char *lasoutfilenme = 0;
  164. char *idxinfilenme = 0;
  165. char *authorname = 0;
  166. char *commentfield = 0;
  167. char *datefield = 0;
  168. double zbinheight = 0.0;
  169. double oLowFilterX = 0.0, oHighFilterX = 0.0, oLowFilterY = 0.0, oHighFilterY = 0.0, oLowFilterZ = 0.0, oHighFilterZ = 0.0;
  170. boost::uint32_t maxmem = 0;
  171. boost::uint32_t chunkSize = 100;
  172. int debuglevel = 3;
  173. bool readonly = 0;
  174. bool forcenewindex = 0;
  175. bool boundssetbyuser = 0;
  176. bool writestandaloneindex = 0;
  177. bool useiterator = 0;
  178. FILE *debugger = stderr;
  179. // temporary until argv[] starts to work
  180. // uncomment only one of these blocks
  181. /*------------------------------N1440375----------------------------------*/
  182. /*------------------------build embedded index------------------------------
  183. const char* arggv[] = {"foo", "-t", "C:\\LibLAS\\Samples\\N1440375.tmp",
  184. "-i", "C:\\LibLAS\\Samples\\N1440375.las", "-a", SAMPLE_AUTHOR, "-c", SAMPLE_COMMENT, "-d", SAMPLE_DATE,
  185. "-o", "C:\\LibLAS\\Samples\\N1440375_idx.las"};
  186. argc = 13;
  187. */
  188. /*-----------------build index in standalone file---------------------------
  189. const char* arggv[] = {"foo", "-t", "C:\\LibLAS\\Samples\\N1440375.tmp",
  190. "-i", "C:\\LibLAS\\Samples\\N1440375.las", "-a", SAMPLE_AUTHOR, "-c", SAMPLE_COMMENT, "-d", SAMPLE_DATE,
  191. "-o", "C:\\LibLAS\\Samples\\N1440375_idx.ldx", "-s"};
  192. argc = 14;
  193. */
  194. /*------------------filter with embedded index------------------------------
  195. const char* arggv[] = {"foo",
  196. "-i", "C:\\LibLAS\\Samples\\N1440375_idx.las", "-r"};
  197. argc = 4;
  198. */
  199. /*-------------------filter from standalone file----------------------------
  200. const char* arggv[] = {"foo", "-i", "C:\\LibLAS\\Samples\\N1440375.las",
  201. "-n", "C:\\LibLAS\\Samples\\N1440375_idx.ldx", "-r"};
  202. argc = 6;
  203. */
  204. /*-----------------build embedded index, filter with user bounds------------ */
  205. const char* arggv[] = {"foo", "-t", "C:\\LibLAS\\Samples\\N1440375.tmp",
  206. "-i", "C:\\LibLAS\\Samples\\N1440375.las", "-a", SAMPLE_AUTHOR, "-c", SAMPLE_COMMENT, "-d", SAMPLE_DATE,
  207. "-o", "C:\\LibLAS\\Samples\\N1440375_idx.las",
  208. "-x", "1443000.00", "1444000.00", "-y", "376000.02", "379000.00", "-z", "850.00", "950.00"};
  209. argc = 22;
  210. /*------------filter with embedded index using iterator---------------------
  211. const char* arggv[] = {"foo",
  212. "-i", "C:\\LibLAS\\Samples\\N1440375_idx.las", "-r", "-it", "20000"};
  213. argc = 6;
  214. */
  215. /*---------------------Serpent Mound Model LAS Data-----------------------*/
  216. /*----------------------------build index-----------------------------------
  217. const char* arggv[] = {"foo", "-t", "C:\\LibLAS\\Samples\\Serpent Mound Model LAS Data.tmp",
  218. "-i", "C:\\LibLAS\\Samples\\Serpent Mound Model LAS Data.las", "-a", SAMPLE_AUTHOR, "-c", SAMPLE_COMMENT, "-d", SAMPLE_DATE,
  219. "-o", "C:\\LibLAS\\Samples\\Serpent Mound Model LAS Data_idx.las"};
  220. argc = 13;
  221. */
  222. /*------------------filter with embedded index------------------------------
  223. const char* arggv[] = {"foo",
  224. "-i", "C:\\LibLAS\\Samples\\Serpent Mound Model LAS Data_idx.las", "-r"};
  225. argc = 4;
  226. */
  227. /*---------------------Mount St Helens Oct 4 2004-------------------------*/
  228. /*----------------------------build index-----------------------------------
  229. const char* arggv[] = {"foo", "-t", "C:\\LibLAS\\Mount St Helens Oct 4 2004.tmp",
  230. "-i", "C:\\LibLAS\\Samples\\Mount St Helens Oct 4 2004.las", "-a", SAMPLE_AUTHOR, "-c", SAMPLE_COMMENT, "-d", SAMPLE_DATE,
  231. "-o", "C:\\LibLAS\\Samples\\Mount St Helens Oct 4 2004_idx.las", "-b", "100"};
  232. argc = 15;
  233. */
  234. /*------------------filter with embedded index------------------------------
  235. const char* arggv[] = {"foo",
  236. "-i", "C:\\LibLAS\\Samples\\Mount St Helens Oct 4 2004_idx.las", "-r"};
  237. argc = 4;
  238. */
  239. /*----------------------------Lincoln-------------------------------------*/
  240. /*--------------------------build index-------------------------------------
  241. const char* arggv[] = {"foo", "-t", "C:\\LibLAS\\Samples\\Lincoln.tmp",
  242. "-i", "C:\\LibLAS\\Samples\\Lincoln.las", "-a", SAMPLE_AUTHOR, "-c", SAMPLE_COMMENT, "-d", SAMPLE_DATE,
  243. "-o", "C:\\LibLAS\\Samples\\Lincoln_idx.las"};
  244. argc = 13;
  245. */
  246. /*------------------filter with embedded index------------------------------
  247. const char* arggv[] = {"foo",
  248. "-i", "C:\\LibLAS\\Samples\\Lincoln_idx.las", "-r"};
  249. argc = 4;
  250. */
  251. /*------------------------------flatDataset-------------------------------*/
  252. /*------------------------------build index---------------------------------
  253. const char* arggv[] = {"foo", "-t", "C:\\LibLAS\\flatDataset.tmp",
  254. "-i", "C:\\LibLAS\\Samples\\flatDataset.las", "-a", SAMPLE_AUTHOR, "-c", SAMPLE_COMMENT, "-d", SAMPLE_DATE,
  255. "-o", "C:\\LibLAS\\Samples\\flatDataset_idx.las"};
  256. argc = 13;
  257. */
  258. /*------------------filter with embedded index------------------------------
  259. const char* arggv[] = {"foo",
  260. "-i", "C:\\LibLAS\\Samples\\flatDataset_idx.las", "-r"};
  261. argc = 4;
  262. */
  263. /*------------filter with embedded index using iterator---------------------
  264. const char* arggv[] = {"foo",
  265. "-i", "C:\\LibLAS\\Samples\\flatDataset_idx.las", "-r", "-it", "25"};
  266. argc = 6;
  267. */
  268. /*---------------------------billion_points-------------------------------*/
  269. /*-----------------build index in standalone file---------------------------
  270. const char* arggv[] = {"foo", "-t", "K:\\FME\\billion_points.tmp",
  271. "-i", "D:\\Zips\\FME\\billion_points.las", "-a", SAMPLE_AUTHOR, "-c", SAMPLE_COMMENT, "-d", SAMPLE_DATE,
  272. "-o", "K:\\FME\\billion_points_idx.ldx", "-s", "-it", "5000000"};
  273. argc = 16;
  274. */
  275. /*-------------------filter from standalone file using iterator---------------
  276. const char* arggv[] = {"foo", "-i", "D:\\Zips\\FME\\billion_points.las",
  277. "-n", "K:\\FME\\billion_points_idx.ldx", "-r", "-it", "5000000"};
  278. argc = 8;
  279. */
  280. for (int i = 1; i < argc; i++)
  281. {
  282. if ( strcmp((const char *)arggv[i],"-h") == 0 ||
  283. strcmp((const char *)arggv[i],"--help") == 0
  284. )
  285. {
  286. usage(debugger);
  287. exit(0);
  288. }
  289. else if ( strcmp((const char *)arggv[i],"-t") == 0 ||
  290. strcmp((const char *)arggv[i],"--tempfile") == 0
  291. )
  292. {
  293. i++;
  294. tmpfilenme = (char *)arggv[i];
  295. }
  296. else if ( strcmp((const char *)arggv[i],"-i") == 0 ||
  297. strcmp((const char *)arggv[i],"--infile") == 0
  298. )
  299. {
  300. i++;
  301. lasinfilenme = (char *)arggv[i];
  302. }
  303. else if ( strcmp((const char *)arggv[i],"-o") == 0 ||
  304. strcmp((const char *)arggv[i],"--outfile") == 0
  305. )
  306. {
  307. i++;
  308. lasoutfilenme = (char *)arggv[i];
  309. }
  310. else if ( strcmp((const char *)arggv[i],"-n") == 0 ||
  311. strcmp((const char *)arggv[i],"--indexfile") == 0
  312. )
  313. {
  314. i++;
  315. idxinfilenme = (char *)arggv[i];
  316. }
  317. else if ( strcmp((const char *)arggv[i],"-b") == 0 ||
  318. strcmp((const char *)arggv[i],"--zbinheight") == 0
  319. )
  320. {
  321. i++;
  322. zbinheight = atof((const char *)arggv[i]);
  323. }
  324. else if ( strcmp((const char *)arggv[i],"-m") == 0 ||
  325. strcmp((const char *)arggv[i],"--maxmem") == 0
  326. )
  327. {
  328. i++;
  329. maxmem = atoi((const char *)arggv[i]);
  330. }
  331. else if ( strcmp((const char *)arggv[i],"-a") == 0 ||
  332. strcmp((const char *)arggv[i],"--author") == 0
  333. )
  334. {
  335. i++;
  336. authorname = (char *)arggv[i];
  337. }
  338. else if ( strcmp((const char *)arggv[i],"-c") == 0 ||
  339. strcmp((const char *)arggv[i],"--comment") == 0
  340. )
  341. {
  342. i++;
  343. commentfield = (char *)arggv[i];
  344. }
  345. else if ( strcmp((const char *)arggv[i],"-d") == 0 ||
  346. strcmp((const char *)arggv[i],"--date") == 0
  347. )
  348. {
  349. i++;
  350. datefield = (char *)arggv[i];
  351. }
  352. else if ( strcmp((const char *)arggv[i],"-r") == 0 ||
  353. strcmp((const char *)arggv[i],"--readonly") == 0
  354. )
  355. {
  356. readonly = true;
  357. }
  358. else if ( strcmp((const char *)arggv[i],"-s") == 0 ||
  359. strcmp((const char *)arggv[i],"--standalone") == 0
  360. )
  361. {
  362. writestandaloneindex = true;
  363. }
  364. else if ( strcmp((const char *)arggv[i],"-x") == 0
  365. )
  366. {
  367. i++;
  368. oLowFilterX = atof((const char *)arggv[i]);
  369. i++;
  370. oHighFilterX = atof((const char *)arggv[i]);
  371. boundssetbyuser = true;
  372. }
  373. else if ( strcmp((const char *)arggv[i],"-y") == 0
  374. )
  375. {
  376. i++;
  377. oLowFilterY = atof((const char *)arggv[i]);
  378. i++;
  379. oHighFilterY = atof((const char *)arggv[i]);
  380. boundssetbyuser = true;
  381. }
  382. else if ( strcmp((const char *)arggv[i],"-z") == 0
  383. )
  384. {
  385. i++;
  386. oLowFilterZ = atof((const char *)arggv[i]);
  387. i++;
  388. oHighFilterZ = atof((const char *)arggv[i]);
  389. boundssetbyuser = true;
  390. }
  391. else if ( strcmp((const char *)arggv[i],"-it") == 0
  392. )
  393. {
  394. i++;
  395. chunkSize = atoi((const char *)arggv[i]);
  396. useiterator = true;
  397. }
  398. } // for
  399. fprintf(debugger, "%s\n", lasinfilenme);
  400. IndexData ParamSrc;
  401. IndexData ParamSrc2;
  402. if (lasinfilenme)
  403. {
  404. // open the las file for reading
  405. if (std::istream* istrm = OpenInput(std::string(lasinfilenme)))
  406. {
  407. if (Reader *reader = new Reader(*istrm))
  408. {
  409. Reader *idxreader = NULL;
  410. std::istream* idxstrm = NULL;
  411. if (idxinfilenme)
  412. {
  413. idxstrm = OpenInput(std::string(idxinfilenme));
  414. if (idxstrm)
  415. {
  416. idxreader = new Reader(*idxstrm);
  417. } // if
  418. } // if
  419. if (idxreader || ! idxinfilenme)
  420. {
  421. // open the output stream here whether for embedded index or standalone
  422. std::ostream* ostrm = ! readonly ? OpenOutput(std::string(lasoutfilenme)): 0;
  423. if (ostrm || readonly)
  424. {
  425. // there are many versions of this method tailored to specific index tasks. Look for them
  426. // together in lasindex.hpp. This is version the most generic
  427. if (ParamSrc.SetInitialValues(0, reader, ostrm, idxreader, tmpfilenme, authorname, commentfield, datefield,
  428. zbinheight, maxmem, debuglevel, readonly, writestandaloneindex, forcenewindex, debugger))
  429. {
  430. // Another way to initiate an index would be to
  431. // create a simple index with Index() and then initialize it with the Prep command.
  432. // It would look like this:
  433. // Index index(); if (index.Prep(ParamSrc)) {}
  434. // Prep returns true only if an index is ready to use for filtering
  435. // But here's the other way to do it in which the constructor does the heavy lifting
  436. Index index(ParamSrc);
  437. if (index.IndexReady())
  438. {
  439. // for testing filter bounds set by user
  440. if (useiterator)
  441. {
  442. ParamSrc = IndexData(index);
  443. ParamSrc2 = IndexData(index);
  444. if (ParamSrc.SetFilterValues(index.GetBounds(), index)
  445. && ParamSrc2.SetFilterValues((index.GetMinX() + index.GetMaxX()) * .5, index.GetMaxX(),
  446. (index.GetMinY() + index.GetMaxY()) * .5, index.GetMaxY(), index.GetMinZ(), index.GetMaxZ(), index))
  447. {
  448. // two iterators with different filter bounds
  449. IndexIterator *indexIt = index.Filter(ParamSrc, chunkSize);
  450. IndexIterator *indexIt2 = index.Filter(ParamSrc2, chunkSize);
  451. if (indexIt && indexIt2)
  452. {
  453. for (boost::uint32_t step = 0; step < 1000; ++step)
  454. {
  455. // use any of these to begin the vector with the next point that fits the filter criteria
  456. // that hasn't been scanned yet.
  457. // ex: indexIt->advance(1) starts the vector on the first point that fits the criteria if no points have
  458. // been scanned previously. If there have been previous points scanned then the vector returned
  459. // will start with the next point that fits the criteria beyond those previously scanned.
  460. // ex: indexIt->advance(5) starts the vector on the fifth point that fits the criteria if no points have
  461. // been scanned previously. If there have been previous points scanned then the vector returned
  462. // will start with the fifth point that fits the criteria beyond those previously scanned.
  463. // The following three methods may be used to advance by any positive number X.
  464. //const std::vector<boost::uint32_t>& FilterResult = indexIt->advance(X);
  465. //const std::vector<boost::uint32_t>& FilterResult = (*indexIt)+=X;
  466. //const std::vector<boost::uint32_t>& FilterResult = (*indexIt)+X;
  467. // The following two methods may be used to advance as though X were 1.
  468. // There is no functional difference between pre and post increment;
  469. //const std::vector<boost::uint32_t>& FilterResult = ++(*indexIt);
  470. //const std::vector<boost::uint32_t>& FilterResult = (*indexIt)++;
  471. // Random access to any number point in the file that fits the filter criteria is
  472. // provided with the overloaded [] operator or () operator.
  473. // ex: (*indexIt)[32] would start the array at the 32nd point in the file that fits the criteria
  474. // Any number of non-conforming points may have been skipped to get to the start point
  475. //const std::vector<boost::uint32_t>& FilterResult = (*indexIt)[32];
  476. //const std::vector<boost::uint32_t>& FilterResult = (*indexIt)(0);
  477. // get first or next consecutive range on first iterator
  478. const std::vector<boost::uint32_t>& FilterResult = (*indexIt)++;
  479. if (!ReportIteratorResults(debugger, FilterResult.size(), index.GetPointRecordsCount(), step))
  480. break;
  481. // get first or next consecutive range on 2nd iterator
  482. const std::vector<boost::uint32_t>& FilterResult2 = (*indexIt2)++;
  483. if (!ReportIteratorResults(debugger, FilterResult2.size(), index.GetPointRecordsCount(), step))
  484. break;
  485. // get next range on first iterator
  486. const std::vector<boost::uint32_t>& FilterResult3 = (*indexIt)++;
  487. if (!ReportIteratorResults(debugger, FilterResult3.size(), index.GetPointRecordsCount(), step))
  488. break;
  489. // get a range beginning with the 5th compliant point on 2nd iterator
  490. const std::vector<boost::uint32_t>& FilterResult4 = (*indexIt2)[5];
  491. if (!ReportIteratorResults(debugger, FilterResult4.size(), index.GetPointRecordsCount(), step))
  492. break;
  493. // get a range on first iterator beginning 6 compliant pts beyond last range (skipping 5)
  494. const std::vector<boost::uint32_t>& FilterResult5 = (*indexIt)+6;
  495. if (!ReportIteratorResults(debugger, FilterResult5.size(), index.GetPointRecordsCount(), step))
  496. break;
  497. } // for
  498. } // if
  499. else
  500. IndexFilterInitError(debugger);
  501. delete indexIt;
  502. delete indexIt2;
  503. }
  504. else
  505. IndexFilterInitError(debugger);
  506. } // if useiterator
  507. else if (boundssetbyuser)
  508. {
  509. Bounds<double> filterBounds(oLowFilterX, oLowFilterY, oLowFilterZ,
  510. oHighFilterX, oHighFilterY, oHighFilterZ);
  511. if (ParamSrc.SetFilterValues(filterBounds, index))
  512. {
  513. const std::vector<uint32_t>& FilterResult = index.Filter(ParamSrc);
  514. if (FilterResult.size())
  515. {
  516. // do something with the list of points
  517. std::ostringstream oss;
  518. oss << "Points within filter area " << FilterResult.size()
  519. << " of " << index.GetPointRecordsCount()
  520. << ",\nUser-defined filter bounds" << std::endl;
  521. fprintf(debugger, "%s", oss.str().c_str());
  522. }
  523. else
  524. IndexFilterNoPoints(debugger);
  525. }
  526. else
  527. IndexFilterInitError(debugger);
  528. } // if
  529. else
  530. {
  531. // run 6 programmed filter tests of stored data
  532. double RangeZ, RangeY, RangeX;
  533. const char *CovgStr;
  534. Bounds<double> indexBounds = index.GetBounds();
  535. Bounds<double> filterBounds;
  536. RangeX = index.GetRangeX();
  537. RangeY = index.GetRangeY();
  538. RangeZ = index.GetRangeZ();
  539. for (int loopct = 0; loopct < 6; ++loopct)
  540. {
  541. switch (loopct)
  542. {
  543. case 0:
  544. {
  545. CovgStr = "entire range, all 3 axes";
  546. filterBounds = indexBounds;
  547. break;
  548. } // 0
  549. case 1:
  550. {
  551. CovgStr = "middle half of all 3 axes";
  552. filterBounds = Bounds<double>
  553. (indexBounds.min(0) + .25 * RangeX,
  554. indexBounds.min(1) + .25 * RangeY,
  555. indexBounds.min(2) + .25 * RangeZ,
  556. indexBounds.max(0) - .25 * RangeX,
  557. indexBounds.max(1) - .25 * RangeY,
  558. indexBounds.max(2) - .25 * RangeZ);
  559. break;
  560. } // 1
  561. case 2:
  562. {
  563. CovgStr = "upper left, all Z range";
  564. filterBounds = Bounds<double>
  565. (indexBounds.min(0),
  566. indexBounds.min(1) + .5 * RangeY,
  567. indexBounds.min(2),
  568. indexBounds.min(0) + .5 * RangeX,
  569. indexBounds.max(1),
  570. indexBounds.max(2));
  571. break;
  572. } // 2
  573. case 3:
  574. {
  575. CovgStr = "upper right, all Z range";
  576. filterBounds = Bounds<double>
  577. (indexBounds.min(0) + .5 * RangeX,
  578. indexBounds.min(1) + .5 * RangeY,
  579. indexBounds.min(2),
  580. indexBounds.max(0),
  581. indexBounds.max(1),
  582. indexBounds.max(2));
  583. break;
  584. } // 3
  585. case 4:
  586. {
  587. CovgStr = "lower left, all Z range";
  588. filterBounds = Bounds<double>
  589. (indexBounds.min(0),
  590. indexBounds.min(1),
  591. indexBounds.min(2),
  592. indexBounds.min(0) + .5 * RangeX,
  593. indexBounds.min(1) + .5 * RangeY,
  594. indexBounds.max(2));
  595. break;
  596. } // 4
  597. case 5:
  598. {
  599. CovgStr = "lower right, all Z range";
  600. filterBounds = Bounds<double>
  601. (indexBounds.min(0)+ .5 * RangeX,
  602. indexBounds.min(1),
  603. indexBounds.min(2),
  604. indexBounds.max(0),
  605. indexBounds.min(1) + .5 * RangeY,
  606. indexBounds.max(2));
  607. break;
  608. } // 5
  609. default:
  610. {
  611. CovgStr = "";
  612. break;
  613. }
  614. } // switch
  615. if (ParamSrc.SetFilterValues(filterBounds, index))
  616. {
  617. const std::vector<uint32_t>& FilterResult = index.Filter(ParamSrc);
  618. if (FilterResult.size())
  619. {
  620. // do something with the list of points
  621. std::ostringstream oss;
  622. oss << "Points within filter area " << FilterResult.size()
  623. << " of " << index.GetPointRecordsCount()
  624. << ", " << CovgStr << std::endl;
  625. fprintf(debugger, "%s", oss.str().c_str());
  626. }
  627. else
  628. IndexFilterNoPoints(debugger);
  629. }
  630. else
  631. IndexFilterInitError(debugger);
  632. } // for
  633. } // else
  634. } // if
  635. else
  636. IndexInitError(debugger);
  637. } // if
  638. else
  639. IndexInitError(debugger);
  640. if (ostrm)
  641. {
  642. if (static_cast<std::ofstream&>(*ostrm))
  643. static_cast<std::ofstream&>(*ostrm).close();
  644. } // if
  645. } // if
  646. } // if
  647. if (idxstrm)
  648. {
  649. if (static_cast<std::ifstream&>(*idxstrm))
  650. static_cast<std::ifstream&>(*idxstrm).close();
  651. } // if
  652. delete idxreader;
  653. delete reader;
  654. } // if reader
  655. if (static_cast<std::ifstream&>(*istrm))
  656. static_cast<std::ifstream&>(*istrm).close();
  657. delete istrm;
  658. } // if istrm
  659. } // if input file name
  660. return 0;
  661. }
  662. // } // namespace liblas