42#ifndef LIBLAS_LASINDEX_HPP_INCLUDED
43#define LIBLAS_LASINDEX_HPP_INCLUDED
49#include <liblas/detail/index/indexcell.hpp>
61#define LIBLAS_INDEX_MAXMEMDEFAULT 10000000
62#define LIBLAS_INDEX_MINMEMDEFAULT 1000000
63#define LIBLAS_INDEX_VERSIONMAJOR 1
64#define LIBLAS_INDEX_VERSIONMINOR 2
65#define LIBLAS_INDEX_MAXSTRLEN 512
66#define LIBLAS_INDEX_MAXCELLS 250000
67#define LIBLAS_INDEX_OPTPTSPERCELL 100
68#define LIBLAS_INDEX_MAXPTSPERCELL 1000
69#define LIBLAS_INDEX_RESERVEFILTERDEFAULT 1000000
73#define LIBLAS_INDEX_PADLASTVLR
139 bool m_indexBuilt, m_tempFileStarted, m_readerCreated, m_readOnly, m_writestandaloneindex, m_forceNewIndex;
140 int m_debugOutputLevel;
141 uint8_t m_versionMajor, m_versionMinor;
142 uint32_t m_pointRecordsCount, m_maxMemoryUsage, m_cellsX, m_cellsY, m_cellsZ, m_totalCells,
144 liblas::detail::TempFileOffsetType m_tempFileWrittenBytes;
145 double m_rangeX, m_rangeY, m_rangeZ, m_cellSizeZ, m_cellSizeX, m_cellSizeY;
146 std::string m_tempFileName;
147 std::string m_indexAuthor;
148 std::string m_indexComment;
149 std::string m_indexDate;
150 std::vector<uint32_t> m_filterResult;
152 FILE *m_tempFile, *m_outputFile;
155 void SetValues(
void);
156 bool IndexInit(
void);
157 void ClearOldIndex(
void);
158 bool BuildIndex(
void);
160 uint32_t GetDefaultReserve(
void);
162 void SetCellFilterBounds(
IndexData & ParamSrc);
164 bool FilterPointSeries(uint32_t & PointID, uint32_t & PointsScanned,
165 uint32_t
const PointsToIgnore, uint32_t
const x, uint32_t
const y, uint32_t
const z,
166 liblas::detail::ConsecPtAccumulator
const ConsecutivePts,
IndexIterator *Iterator,
168 bool VLRInteresting(int32_t MinCellX, int32_t MinCellY, int32_t MaxCellX, int32_t MaxCellY,
170 bool CellInteresting(int32_t x, int32_t y,
IndexData const& ParamSrc);
171 bool SubCellInteresting(int32_t SubCellID, int32_t XCellID, int32_t YCellID,
IndexData const& ParamSrc);
172 bool ZCellInteresting(int32_t ZCellID,
IndexData const& ParamSrc);
173 bool FilterOnePoint(int32_t x, int32_t y, int32_t z, int32_t PointID, int32_t LastPointID,
bool &LastPtRead,
176 bool IdentifyCell(
Point const& CurPt, uint32_t& CurCellX, uint32_t& CurCellY)
const;
178 bool IdentifyCellZ(
Point const& CurPt, uint32_t& CurCellZ)
const;
180 bool IdentifySubCell(
Point const& CurPt, uint32_t x, uint32_t y, uint32_t& CurSubCell)
const;
184 bool LoadCellFromTempFile(liblas::detail::IndexCell *CellBlock,
185 uint32_t CurCellX, uint32_t CurCellY);
187 FILE *OpenTempFile(
void);
189 void CloseTempFile(
void);
192 bool SaveIndexInLASFile(
void);
194 bool SaveIndexInStandAloneFile(
void);
196 void CalcRangeX(
void) {m_rangeX = (m_bounds.max)(0) - (m_bounds.min)(0);}
197 void CalcRangeY(
void) {m_rangeY = (m_bounds.
max)(1) - (m_bounds.
min)(1);}
198 void CalcRangeZ(
void) {m_rangeZ = (m_bounds.
max)(2) - (m_bounds.
min)(2);}
201 bool FileError(
const char *Reporter);
202 bool InputFileError(
const char *Reporter)
const;
203 bool OutputFileError(
const char *Reporter)
const;
204 bool DebugOutputError(
const char *Reporter)
const;
205 bool PointCountError(
const char *Reporter)
const;
206 bool PointBoundsError(
const char *Reporter)
const;
207 bool MemoryError(
const char *Reporter)
const;
208 bool InitError(
const char *Reporter)
const;
209 bool InputBoundsError(
const char *Reporter)
const;
212 bool OutputCellStats(IndexCellDataBlock& CellBlock)
const;
213 bool OutputCellGraph(std::vector<uint32_t> CellPopulation, uint32_t MaxPointsPerCell)
const;
225 double LowFilterZ,
double HighFilterZ, uint32_t ChunkSize);
229 double GetMinX(
void)
const {
return (m_bounds.min)(0);}
230 double GetMaxX(
void)
const {
return (m_bounds.max)(0);}
231 double GetMinY(
void)
const {
return (m_bounds.min)(1);}
232 double GetMaxY(
void)
const {
return (m_bounds.max)(1);}
233 double GetMinZ(
void)
const {
return (m_bounds.min)(2);}
234 double GetMaxZ(
void)
const {
return (m_bounds.max)(2);}
277 void SetMinX(
double minX) {(m_bounds.min)(0, minX);}
278 void SetMaxX(
double maxX) {(m_bounds.max)(0, maxX);}
279 void SetMinY(
double minY) {(m_bounds.min)(1, minY);}
280 void SetMaxY(
double maxY) {(m_bounds.max)(1, maxY);}
281 void SetMinZ(
double minZ) {(m_bounds.min)(2, minZ);}
282 void SetMaxZ(
double maxZ) {(m_bounds.max)(2, maxZ);}
359 const char *tmpfilenme = 0,
const char *indexauthor = 0,
360 const char *indexcomment = 0,
const char *indexdate = 0,
double zbinht = 0.0,
362 bool writestandaloneindex = 0,
bool forcenewindex = 0, FILE *debugger = 0);
366 const char *indexcomment = 0,
const char *indexdate = 0,
double zbinht = 0.0,
371 const char *indexcomment = 0,
const char *indexdate = 0,
double zbinht = 0.0,
383 const char *indexcomment = 0,
const char *indexdate = 0,
double zbinht = 0.0,
389 const char *indexcomment = 0,
const char *indexdate = 0,
double zbinht = 0.0,
393 bool SetFilterValues(
double LowFilterX,
double HighFilterX,
double LowFilterY,
double HighFilterY,
double LowFilterZ,
double HighFilterZ,
403 void SetValues(
void);
404 bool CalcFilterEnablers(
void);
480 IndexIterator(
Index *IndexSrc,
double LowFilterX,
double HighFilterX,
double LowFilterY,
double HighFilterY,
481 double LowFilterZ,
double HighFilterZ, uint32_t ChunkSize);
490 void ResetPosition(
void);
491 uint8_t MinMajorVersion(
void) {
return(1);}
492 uint8_t MinMinorVersion(
void) {
return(2);}
496 const std::vector<uint32_t>&
advance(int32_t n);
516 inline const std::vector<uint32_t>&
operator[](int32_t n) {
return ((*
this)(n));}
518 bool ValidateIndexVersion(uint8_t VersionMajor, uint8_t VersionMinor) {
return (VersionMajor > MinMajorVersion() || (VersionMajor == MinMajorVersion() && VersionMinor >= MinMinorVersion()));}
521template <
typename T,
typename Q>
525 if (
static_cast<size_t>(pos) +
sizeof(T) > src.size())
526 throw std::out_of_range(
"liblas::detail::ReadVLRData_n: array index out of range");
528 memcpy(&dest, &src[pos],
sizeof(T));
530 LIBLAS_SWAP_BYTES_N(dest,
sizeof(T));
532 pos = pos +
static_cast<Q
>(
sizeof(T));
535template <
typename T,
typename Q>
539 if (
static_cast<size_t>(pos) +
sizeof(T) > src.size())
540 throw std::out_of_range(
"liblas::detail::ReadVLRDataNoInc_n: array index out of range");
542 memcpy(&dest, &src[pos],
sizeof(T));
544 LIBLAS_SWAP_BYTES_N(dest,
sizeof(T));
547template <
typename T,
typename Q>
551 if (
static_cast<size_t>(pos) +
static_cast<size_t>(srclen) > src.size())
552 throw std::out_of_range(
"liblas::detail::ReadeVLRData_str: array index out of range");
554 memcpy(dest, &src[pos], srclen);
556 pos = pos +
static_cast<Q
>(srclen);
559template <
typename T,
typename Q>
563 if (
static_cast<size_t>(pos) +
static_cast<size_t>(srclen) > src.size())
564 throw std::out_of_range(
"liblas::detail::ReadVLRDataNoInc_str: array index out of range");
566 std::memcpy(dest, &src[pos], srclen);
Definition bounds.hpp:176
T max(std::size_t const &index) const
Definition bounds.hpp:307
T min(std::size_t const &index) const
Definition bounds.hpp:287
bool SetReadOrBuildAloneValues(Reader *reader, std::ostream *ofs, const char *tmpfilenme, const char *indexauthor=0, const char *indexcomment=0, const char *indexdate=0, double zbinht=0.0, uint32_t maxmem=LIBLAS_INDEX_MAXMEMDEFAULT, int debugoutputlevel=0, FILE *debugger=0)
int32_t m_HighZBorderCell
Definition index.hpp:423
IndexData(Index const &index)
bool SetFilterValues(double LowFilterX, double HighFilterX, double LowFilterY, double HighFilterY, double LowFilterZ, double HighFilterZ, Index const &index)
int32_t m_HighYCellCompletelyIn
Definition index.hpp:420
FILE * m_debugger
Definition index.hpp:427
IndexIterator * GetIterator(void)
Definition index.hpp:430
void SetIndexAuthor(const char *indexauthor)
Definition index.hpp:456
bool SetBuildEmbedValues(Reader *reader, std::ostream *ofs, const char *tmpfilenme, const char *indexauthor=0, const char *indexcomment=0, const char *indexdate=0, double zbinht=0.0, uint32_t maxmem=LIBLAS_INDEX_MAXMEMDEFAULT, int debugoutputlevel=0, FILE *debugger=0)
bool SetBuildAloneValues(Reader *reader, std::ostream *ofs, const char *tmpfilenme, const char *indexauthor=0, const char *indexcomment=0, const char *indexdate=0, double zbinht=0.0, uint32_t maxmem=LIBLAS_INDEX_MAXMEMDEFAULT, int debugoutputlevel=0, FILE *debugger=0)
const char * m_indexAuthor
Definition index.hpp:415
const char * GetTempFileName(void) const
Definition index.hpp:441
const char * m_indexDate
Definition index.hpp:417
bool m_noFilterX
Definition index.hpp:426
int32_t m_HighYBorderCell
Definition index.hpp:422
void SetTmpFileName(const char *tmpfilenme)
Definition index.hpp:455
int GetDebugOutputLevel(void) const
Definition index.hpp:440
FILE * GetDebugger(void) const
Definition index.hpp:434
int32_t m_LowZBorderCell
Definition index.hpp:423
double GetMaxFilterX(void) const
Definition index.hpp:446
int32_t m_LowXCellCompletelyIn
Definition index.hpp:420
Reader * m_idxreader
Definition index.hpp:409
bool GetReadOnly(void) const
Definition index.hpp:435
double m_LowYBorderPartCell
Definition index.hpp:419
double m_HighXBorderPartCell
Definition index.hpp:419
const char * GetIndexDateStr(void) const
Reader * m_reader
Definition index.hpp:408
double GetMaxFilterZ(void) const
Definition index.hpp:450
uint32_t m_maxMemoryUsage
Definition index.hpp:424
bool SetReadAloneValues(Reader *reader, Reader *idxreader, int debugoutputlevel=0, FILE *debugger=0)
bool m_writestandaloneindex
Definition index.hpp:426
bool SetFilterValues(Bounds< double > const &src, Index const &index)
IndexIterator * m_iterator
Definition index.hpp:410
void SetIterator(IndexIterator *setIt)
Definition index.hpp:429
friend class Index
Definition index.hpp:348
void SetMaxMem(uint32_t maxmem)
Definition index.hpp:460
double m_HighYBorderPartCell
Definition index.hpp:419
bool m_readOnly
Definition index.hpp:426
double GetMinFilterZ(void) const
Definition index.hpp:449
int m_debugOutputLevel
Definition index.hpp:425
void SetDebugOutputLevel(int debugoutputlevel)
Definition index.hpp:461
IndexData(IndexData const &other)
Copy constructor.
int32_t m_HighXCellCompletelyIn
Definition index.hpp:420
void SetReadOnly(bool readonly)
Definition index.hpp:462
void SetReader(Reader *reader)
Definition index.hpp:452
void SetStandaloneIndex(bool writestandaloneindex)
Definition index.hpp:463
bool SetReadOrBuildEmbedValues(Reader *reader, std::ostream *ofs, const char *tmpfilenme, const char *indexauthor=0, const char *indexcomment=0, const char *indexdate=0, double zbinht=0.0, uint32_t maxmem=LIBLAS_INDEX_MAXMEMDEFAULT, int debugoutputlevel=0, FILE *debugger=0)
int32_t m_HighZCellCompletelyIn
Definition index.hpp:421
uint32_t GetMaxMemoryUsage(void) const
Definition index.hpp:438
bool m_noFilterY
Definition index.hpp:426
const char * GetIndexCommentStr(void) const
void SetIStream(std::istream *ifs)
Definition index.hpp:453
double GetMinFilterX(void) const
Definition index.hpp:445
double GetCellSizeZ(void) const
Definition index.hpp:433
const char * GetIndexAuthorStr(void) const
Bounds< double > m_filter
Definition index.hpp:411
int32_t m_LowYCellCompletelyIn
Definition index.hpp:420
void ClampFilterBounds(Bounds< double > const &m_bounds)
int32_t m_HighXBorderCell
Definition index.hpp:422
void SetCellSizeZ(double cellsizez)
Definition index.hpp:459
bool SetReadEmbedValues(Reader *reader, int debugoutputlevel=0, FILE *debugger=0)
int32_t m_LowZCellCompletelyIn
Definition index.hpp:421
bool GetStandaloneIndex(void) const
Definition index.hpp:436
int32_t m_LowYBorderCell
Definition index.hpp:422
void SetIndexDate(const char *indexdate)
Definition index.hpp:458
double m_cellSizeZ
Definition index.hpp:418
friend class IndexIterator
Definition index.hpp:349
double GetMaxFilterY(void) const
Definition index.hpp:448
IndexData & operator=(IndexData const &rhs)
Assignment operator.
double GetMinFilterY(void) const
Definition index.hpp:447
const char * m_tempFileName
Definition index.hpp:414
bool m_indexValid
Definition index.hpp:426
std::ostream * m_ofs
Definition index.hpp:413
void SetOStream(std::ostream *ofs)
Definition index.hpp:454
std::istream * m_ifs
Definition index.hpp:412
const char * m_indexComment
Definition index.hpp:416
bool m_forceNewIndex
Definition index.hpp:426
bool GetForceNewIndex(void) const
Definition index.hpp:437
bool SetInitialValues(std::istream *ifs=0, Reader *reader=0, std::ostream *ofs=0, Reader *idxreader=0, const char *tmpfilenme=0, const char *indexauthor=0, const char *indexcomment=0, const char *indexdate=0, double zbinht=0.0, uint32_t maxmem=LIBLAS_INDEX_MAXMEMDEFAULT, int debugoutputlevel=0, bool readonly=0, bool writestandaloneindex=0, bool forcenewindex=0, FILE *debugger=0)
void SetIndexComment(const char *indexcomment)
Definition index.hpp:457
Reader * GetReader(void) const
Definition index.hpp:439
bool m_noFilterZ
Definition index.hpp:426
int32_t m_LowXBorderCell
Definition index.hpp:422
double m_LowXBorderPartCell
Definition index.hpp:419
void SetDebugger(FILE *debugger)
Definition index.hpp:464
IndexIterator & operator=(IndexIterator const &rhs)
Assignment operator.
uint32_t m_conformingPtsFound
Definition index.hpp:477
IndexIterator(Index *IndexSrc, Bounds< double > const &BoundsSrc, uint32_t ChunkSize)
const std::vector< uint32_t > & operator()(int32_t n)
returns filter-compliant points as though the first point returned is element n in a zero-based array
uint32_t m_advance
Definition index.hpp:474
uint32_t m_curVLR
Definition index.hpp:475
const std::vector< uint32_t > & operator--()
returns set of filter-compliant points skipping backwards 1 from the end of the last set
Definition index.hpp:504
uint32_t m_curCellStartPos
Definition index.hpp:475
friend class Index
Definition index.hpp:469
IndexIterator(Index *IndexSrc, IndexData const &IndexDataSrc, uint32_t ChunkSize)
const std::vector< uint32_t > & operator++()
returns next set of filter-compliant points with no skipped points
Definition index.hpp:500
uint32_t m_curCellX
Definition index.hpp:475
uint32_t m_totalPointsScanned
Definition index.hpp:475
IndexIterator(IndexIterator const &other)
Copy constructor.
const std::vector< uint32_t > & operator--(int)
returns set of filter-compliant points skipping backwards 1 from the end of the last set
Definition index.hpp:506
Index * m_index
Definition index.hpp:473
IndexData m_indexData
Definition index.hpp:472
bool ValidateIndexVersion(uint8_t VersionMajor, uint8_t VersionMinor)
tests viability of index for filtering with iterator
Definition index.hpp:518
const std::vector< uint32_t > & operator-(int32_t n)
returns set of filter-compliant points beginning n points backwards from the end of the last set,...
Definition index.hpp:514
uint32_t m_chunkSize
Definition index.hpp:474
const std::vector< uint32_t > & operator[](int32_t n)
returns filter-compliant points as though the first point returned is element n in a zero-based array
Definition index.hpp:516
uint32_t m_ptsScannedCurVLR
Definition index.hpp:476
uint32_t m_ptsScannedCurCell
Definition index.hpp:475
uint32_t m_curCellY
Definition index.hpp:475
const std::vector< uint32_t > & operator+=(int32_t n)
returns next set of filter-compliant points with n-1 skipped points, for n<0 acts like -=()
Definition index.hpp:508
const std::vector< uint32_t > & operator+(int32_t n)
returns next set of filter-compliant points with n-1 skipped points, for n<0 acts like -()
Definition index.hpp:510
IndexIterator(Index *IndexSrc, double LowFilterX, double HighFilterX, double LowFilterY, double HighFilterY, double LowFilterZ, double HighFilterZ, uint32_t ChunkSize)
const std::vector< uint32_t > & operator++(int)
returns next set of filter-compliant points with no skipped points
Definition index.hpp:502
const std::vector< uint32_t > & advance(int32_t n)
n=0 or n=1 gives next sequence with no gap, n>1 skips n-1 filter-compliant points,...
const std::vector< uint32_t > & operator-=(int32_t n)
returns set of filter-compliant points beginning n points backwards from the end of the last set,...
Definition index.hpp:512
uint8_t GetVersionMinor(void) const
Definition index.hpp:270
const std::vector< uint32_t > & Filter(IndexData &ParamSrc)
Header * GetIndexHeader(void)
Definition index.hpp:261
bool GetForceNewIndex(void) const
Definition index.hpp:256
void SetIndexAuthorStr(const char *ias)
Definition index.hpp:274
double GetMaxY(void) const
Definition index.hpp:232
Reader * GetIndexReader(void) const
Definition index.hpp:263
Index & operator=(Index const &rhs)
Assignment operator.
double GetMaxX(void) const
Definition index.hpp:230
void SetMaxX(double maxX)
Definition index.hpp:278
Header * GetPointHeader(void)
Definition index.hpp:260
bool IndexFailed(void) const
Definition index.hpp:217
int GetDebugOutputLevel(void) const
Definition index.hpp:258
double GetRangeX(void) const
Definition index.hpp:236
void SetCellsX(uint32_t cellsX)
Definition index.hpp:284
uint8_t GetVersionMajor(void) const
Definition index.hpp:269
void SetMinY(double minY)
Definition index.hpp:279
uint32_t GetDataVLR_ID(void) const
Definition index.hpp:249
bool Prep(IndexData const &ParamSrc)
void SetMinZ(double minZ)
Definition index.hpp:281
void SetPointRecordsCount(uint32_t prc)
Definition index.hpp:283
uint32_t GetPointRecordsCount(void) const
Definition index.hpp:241
Index(Index const &other)
Copy constructor.
double GetRangeZ(void) const
Definition index.hpp:238
FILE * GetDebugger(void) const
Definition index.hpp:253
bool GetReadOnly(void) const
Definition index.hpp:254
void SetIndexCommentStr(const char *ics)
Definition index.hpp:275
double GetMaxZ(void) const
Definition index.hpp:234
const char * GetIndexCommentStr(void) const
void SetCellsZ(uint32_t cellsZ)
Definition index.hpp:286
uint32_t GetCellsY(void) const
Definition index.hpp:244
double GetMinX(void) const
Definition index.hpp:229
double GetCellSizeZ(void) const
Definition index.hpp:251
uint32_t GetCellsX(void) const
Definition index.hpp:243
bool IndexReady(void) const
Definition index.hpp:218
uint32_t GetMaxMemoryUsage(void) const
Definition index.hpp:257
IndexIterator * Filter(IndexData const &ParamSrc, uint32_t ChunkSize)
void SetCellsY(uint32_t cellsY)
Definition index.hpp:285
void SetIndexDateStr(const char *ids)
Definition index.hpp:276
void SetMinX(double minX)
Definition index.hpp:277
double GetRangeY(void) const
Definition index.hpp:237
bool GetStandaloneIndex(void) const
Definition index.hpp:255
IndexIterator * Filter(double LowFilterX, double HighFilterX, double LowFilterY, double HighFilterY, double LowFilterZ, double HighFilterZ, uint32_t ChunkSize)
void SetDataVLR_ID(uint32_t DataVLR_ID)
Definition index.hpp:273
Bounds< double > const & GetBounds(void) const
Definition index.hpp:239
const char * GetTempFileName(void) const
Definition index.hpp:264
Reader * GetReader(void) const
Definition index.hpp:262
Index(IndexData const &ParamSrc)
double GetMinY(void) const
Definition index.hpp:231
uint32_t GetCellsZ(void) const
Definition index.hpp:246
IndexIterator * Filter(Bounds< double > const &BoundsSrc, uint32_t ChunkSize)
double GetMinZ(void) const
Definition index.hpp:233
const char * GetIndexAuthorStr(void) const
void SetMaxZ(double maxZ)
Definition index.hpp:282
const char * GetIndexDateStr(void) const
void SetMaxY(double maxY)
Definition index.hpp:280
Point data record composed with X, Y, Z coordinates and attributes.
Definition point.hpp:69
Defines public interface to LAS reader implementation.
Definition reader.hpp:67
Representation of variable-length record data.
Definition variablerecord.hpp:60
#define LAS_DLL
Definition export.hpp:58
#define LIBLAS_INDEX_MAXMEMDEFAULT
Definition index.hpp:61
Namespace grouping all elements of libLAS public interface.
Definition bounds.hpp:60
void ReadVLRData_n(T &dest, IndexVLRData const &src, Q &pos)
Definition index.hpp:522
std::vector< IndexCellRow > IndexCellDataBlock
Definition index.hpp:77
std::vector< uint8_t > IndexVLRData
Definition index.hpp:75
void ReadVLRDataNoInc_n(T &dest, IndexVLRData const &src, Q const &pos)
Definition index.hpp:536
void ReadeVLRData_str(char *dest, IndexVLRData const &src, T const srclen, Q &pos)
Definition index.hpp:548
void ReadVLRDataNoInc_str(char *dest, IndexVLRData const &src, T const srclen, Q pos)
Definition index.hpp:560
std::vector< liblas::detail::IndexCell > IndexCellRow
Definition index.hpp:76