23 #include "FileReaderLas.h" 25 LastReturnFilter::LastReturnFilter( ) : liblas::FilterI(eInclusion) {}
27 bool LastReturnFilter::filter(
const liblas::Point& p)
34 if (p.GetReturnNumber() == p.GetNumberOfReturns())
40 if (GetType() == eExclusion && output ==
true)
49 FileReaderLas::FileReaderLas(
void)
55 FileReaderLas::FileReaderLas(
const std::string& filename)
60 FileReaderLas::~FileReaderLas(
void)
68 void FileReaderLas::open(
const std::string& filename)
70 m_filename = filename;
75 void FileReaderLas::close(
void)
83 void FileReaderLas::setCodec(
const std::string& filename){
84 m_ifstream =
new(std::ifstream);
85 m_ifstream->open(m_filename.c_str(),std::ios::in|std::ios::binary);
86 liblas::ReaderFactory f;
87 liblas::Reader reader = f.CreateWithStream(*m_ifstream);
88 m_reader=
new liblas::Reader(reader);
94 liblas::Header
const& FileReaderLas::getHeader()
const{
95 return(m_reader->GetHeader());
98 bool FileReaderLas::isCompressed()
const{
99 return getHeader().Compressed();
102 unsigned long int FileReaderLas::getPointCount()
const{
103 return getHeader().GetPointRecordsCount();
106 bool const& FileReaderLas::readNextPoint(liblas::Point& thePoint){
107 bool returnValue=m_reader->ReadNextPoint();
108 thePoint=m_reader->GetPoint();
112 void FileReaderLas::las2ascii(
const std::string& filename,
bool verbose)
const{
113 std::ofstream fpoints(filename.c_str(),std::ios::out);
115 fpoints <<
"X" <<
"," <<
"Y" <<
"," <<
"Z" << std::endl;
117 std::cout <<
"reset reading" << std::endl;
120 std::cout <<
"going through points" << std::endl;
121 while(m_reader->ReadNextPoint()){
122 liblas::Point
const& thePoint=m_reader->GetPoint();
123 double x=thePoint.GetX();
124 double y=thePoint.GetY();
125 double z=thePoint.GetZ();
126 fpoints.precision(12);
127 fpoints << x <<
"," << y <<
"," << z << std::endl;
132 void FileReaderLas::getExtent(
double& ulx,
double& uly,
double& lrx,
double& lry)
const{
133 const liblas::Header& theHeader=getHeader();
134 ulx=theHeader.GetMinX();
135 uly=theHeader.GetMaxY();
136 lrx=theHeader.GetMaxX();
137 lry=theHeader.GetMinY();
140 double FileReaderLas::getMinZ()
const{
141 return(getHeader().GetMinZ());
144 double FileReaderLas::getMaxZ()
const{
145 return(getHeader().GetMaxZ());
157 void FileReaderLas::addReturnsFilter(std::vector<unsigned short>
const& returns){
158 typedef liblas::ReturnFilter
filter;
159 filter* return_filter;
160 std::vector<boost::uint16_t> returns_t;
162 return_filter=
new filter(returns_t,
true);
164 for(
int index=0;index<returns.size();++index){
165 assert(returns[index]>0);
166 returns_t.push_back(returns[index]);
168 return_filter=
new filter(returns_t,
false);
170 m_filters.push_back(liblas::FilterPtr(return_filter));
173 void FileReaderLas::addClassFilter(std::vector<unsigned short>
const& classes){
175 std::vector<liblas::FilterPtr> filters;
176 std::vector<liblas::Classification> theClasses;
177 for(
int iclass=0;iclass<classes.size();++iclass){
178 liblas::Classification aClass(classes[iclass]);
179 theClasses.push_back(aClass);
181 liblas::FilterPtr class_filter = liblas::FilterPtr(
new liblas::ClassificationFilter(theClasses));
184 class_filter->SetType(liblas::FilterI::eInclusion);
185 m_filters.push_back(class_filter);