主要代码文件为index.hpp index.cpp
index.hpp中定义了几个宏
//最大内存限制,默认为10M
#define LIBLAS_INDEX_MAXMEMDEFAULT 10000000 // 10 megs default
//最小内存,默认为1M
#define LIBLAS_INDEX_MINMEMDEFAULT 1000000 // 1 meg at least has to be allowed
//最大格网数量,不超过25万个
#define LIBLAS_INDEX_MAXCELLS 250000
//平均每个格网中的点个数,默认值100
#define LIBLAS_INDEX_OPTPTSPERCELL 100
//平均每个格网中最大点数,整个cpp中未找到它的引用,没用过,没啥意义
#define LIBLAS_INDEX_MAXPTSPERCELL 1000
索引部分主要有两个类,IndexData、Index。IndexData为Index提供索引的相关参数,构建索引前必须构建IndexData对象。IndexData对象参数值的设定直接关系到Index对象索引的构建情况。
(1)构建IndexData 对象
IndexData类提供了三个构造函数,无参、拷贝构造函数、Index对象初始化函数。由于Index和IndexData对象中有相同属性:m_reader等,所以可以相互初始化这些属性。
(2)设置索引构建参数
liblas提供了多个参数设置函数。SetInitialValues可以设置所有参数,函数原型
bool SetInitialValues(std::istream *ifs = 0, Reader*reader = 0, std::ostream *ofs = 0, Reader *idxreader = 0,
const char *tmpfilenme = 0, constchar *indexauthor = 0,
const char *indexcomment = 0, constchar *indexdate = 0,doublezbinht = 0.0,
boost::uint32_t maxmem =LIBLAS_INDEX_MAXMEMDEFAULT, intdebugoutputlevel = 0, bool readonly = 0,
boolwritestandaloneindex = 0,bool forcenewindex =0, FILE *debugger = 0);
ifs:输入的las文件;reader:输入文件对应的Reader对象;ofs:输出文件,如果设置索引为单独文件则此为输出的索引文件,如果设置索引包含在源las文件中,则会创建一个新文件,该文件包含索引+源las文件。tmpfilenme:新文件的名字;indexauthor、indexcomment、indexdate:索引文件的一些基本信息;
zbinht:Z方向的格网大小;maxmen:内存限制;debugoutputlevel:调试信息输出级别;writestandaloneindex:为1,则会将索引文件单独作为一个文件,为0则索引文件跟源las文件为一个文件;forcenewindex:如果为1,则不管是否存在索引文件,均会新建索引,若为0,则已存在索引时不会重建;
(3)构建Index对象
liblas::IndexindexPt(indexData);
(4)设置查询器
indexData.SetFilterValues(dftXMin,dftXMax,dftYMin,dftYMax,dftZMin,dftZMax,indexPt);
(5)执行查询
constvector<boost::uint32_t> resultPtsIDVec = indexPt.Filter(indexData);
代码
const char *pSrcFileName = "D:\\pipeline_5G.las"; const char *pIndexTempFilePath = "D:\\temp_index"; const char *pTempFileName = "IndexTemp"; //const char *pDesFileName = "D:\\dem.tif"; std::ifstream ifs; ifs.open(pSrcFileName, std::ios::in | std::ios::binary); if (ifs == NULL) { cout<<"null"<<endl; } std::ofstream ofs; ofs.open(pIndexTempFilePath, std::ios::out | std ::ios ::binary); //std::ifstream ifsIndex; //ifsIndex.open(pIndexFilePath, std::ios::in | std::ios::binary); liblas::ReaderFactory f ; liblas::Reader reader = f.CreateWithStream(ifs); //liblas::Reader readerID = f.CreateWithStream(ifsIndex); liblas::Header const& header = reader.GetHeader(); printf("Points count: %d\n",header.GetPointRecordsCount()); //计算最大最小值 double dXMin = header.GetMinX(); double dXMax = header.GetMaxX(); double dYMin = header.GetMinY(); double dYMax = header.GetMaxY(); double dZMin = header.GetMinZ(); double dZMax = header.GetMaxZ(); const char *pIndexAut = "ryb"; const char *pIndexComm = "test1"; const char *pIndexDate = "20140923"; liblas::IndexData indexData; indexData.SetInitialValues(&ifs,&reader,&ofs,NULL,pTempFileName,pIndexAut,pIndexComm,pIndexDate,0,1000000000U,2,false,false,false,0); indexData.SetBuildEmbedValues(&reader,&ofs,pTempFileName,pIndexAut,pIndexComm,pIndexDate,0,100000000U,2,0);//设置索引文件包含于las文件中 liblas::Index indexPt(indexData); cout<<"Cell size is X:"<<indexPt.GetCellsX()<<" Y "<<indexPt.GetCellsY()<<" Z "<<indexPt.GetCellsZ()<<endl; double dftXMin = dXMin; double dftXMax = dXMax; double dftYMin = dYMin + 500; double dftYMax = dYMax - 220; double dftZMax = dZMax - 100; double dftZMin = dZMin + 20; indexData.SetFilterValues(dftXMin,dftXMax,dftYMin,dftYMax,dftZMin,dftZMax,indexPt); const vector<boost::uint32_t> resultPtsIDVec = indexPt.Filter(indexData); double tt21 = MPI_Wtime(); cout<<resultPtsIDVec.size()<<endl;
原文地址:http://blog.csdn.net/rybgis/article/details/39505405