9 #ifndef CPOINTSMAP_LIBLAS_H 10 #define CPOINTSMAP_LIBLAS_H 13 #include <liblas/liblas.hpp> 14 #include <liblas/reader.hpp> 15 #include <liblas/writer.hpp> 60 template <
class POINTSMAP>
62 const POINTSMAP &ptmap,
63 const std::string &filename,
67 ofs.open(filename.c_str(), std::ios::out | std::ios::binary);
71 std::cerr <<
"[saveLASFile] Couldn't write to file: " << filename << std::endl;
78 const size_t nPts = ptmap.size();
80 header.SetPointRecordsCount(nPts);
84 liblas::Writer writer(ofs,header);
86 const bool has_color = ptmap.hasColorPoints();
87 const float col_fract = 255.0f;
89 liblas::Point pt(&header);
91 for (
size_t i=0;i<nPts;i++)
94 ptmap.getPoint(i, x,y,z, R,G,B);
102 col.SetRed( static_cast<uint16_t>(R*col_fract) );
103 col.SetGreen( static_cast<uint16_t>(G*col_fract) );
104 col.SetBlue( static_cast<uint16_t>(B*col_fract) );
108 if (!writer.WritePoint(pt))
110 std::cerr <<
"[saveLASFile] liblas returned error writing point #" << i <<
" to file.\n";
120 template <
class POINTSMAP>
123 const std::string &filename,
131 ifs.open(filename.c_str(), std::ios::in | std::ios::binary);
135 std::cerr <<
"[loadLASFile] Couldn't open file: " << filename << std::endl;
141 liblas::Reader reader(ifs);
145 liblas::Header
const&
header = reader.GetHeader();
146 const size_t nPts = header.GetPointRecordsCount();
152 #if LIBLAS_VERSION_NUM < 1800 153 out_headerInfo.
project_guid = header.GetProjectId().to_string();
155 out_headerInfo.
project_guid = boost::lexical_cast<std::string>(header.GetProjectId());
163 const bool has_color = ptmap.hasColorPoints();
164 const float col_fract = 1.0f/255.0f;
165 while (reader.ReadNextPoint())
167 liblas::Point
const& p = reader.GetPoint();
171 liblas::Color
const& col = p.GetColor();
172 ptmap.insertPoint( p.GetX(),p.GetY(),p.GetZ(), col.GetRed()*col_fract,col.GetGreen()*col_fract,col.GetBlue()*col_fract );
176 ptmap.insertPoint( p.GetX(),p.GetY(),p.GetZ() );
180 if (ptmap.size()!=nPts)
181 cerr <<
"[loadLASFile] Header says point count is " << nPts <<
" but only " << ptmap.size() <<
" were really parsed in.\n";
183 ptmap.mark_as_modified();
Optional settings for loadLASFile()
bool saveLASFile(const POINTSMAP &ptmap, const std::string &filename, const LAS_WriteParams ¶ms=LAS_WriteParams())
Save the point cloud as an ASPRS LAS binary file (requires MRPT built against liblas).
nv_oem6_header_t header
Novatel frame: NV_OEM6_BESTPOS.
bool loadLASFile(POINTSMAP &ptmap, const std::string &filename, LAS_HeaderInfo &out_headerInfo, const LAS_LoadParams ¶ms=LAS_LoadParams())
Load the point cloud from an ASPRS LAS binary file (requires MRPT built against liblas).
Optional settings for saveLASFile()
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t x(y+z)