Skip to content

Commit c629ef5

Browse files
committed
libLAS removed as a build-time dependency
Now, users wanting to use libLAS should use the new header "mrpt/maps/CPointsMap_liblas.h". See updated docs in this commit. The reason of this change is to avoid >100MB of runtime binaries and headers dependencies for libLAS.
1 parent d3cba76 commit c629ef5

File tree

9 files changed

+208
-268
lines changed

9 files changed

+208
-268
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ include(cmakemodules/script_wxwidgets.cmake REQUIRED) # Check for wxWidgets +
254254
include(cmakemodules/script_libdc1394.cmake REQUIRED) # Check for libdc1394-2
255255
include(cmakemodules/script_assimp.cmake REQUIRED) # Check for system assimp lib (3D models)
256256
include(cmakemodules/script_lib3ds.cmake REQUIRED) # Check for system lib3ds
257-
include(cmakemodules/script_liblas.cmake REQUIRED) # Check for the LAS LiDAR format library
258257
include(cmakemodules/script_libtclap.cmake REQUIRED) # Check for system libtclap
259258
include(cmakemodules/script_zlib.cmake REQUIRED) # Check for zlib
260259
include(cmakemodules/script_jpeg.cmake REQUIRED) # Check for jpeg

cmakemodules/script_liblas.cmake

Lines changed: 0 additions & 52 deletions
This file was deleted.

cmakemodules/script_show_final_summary.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ SHOW_CONFIG_LINE("Intel threading lib (TBB) " CMAKE_MRPT_HAS_TBB)
125125
SHOW_CONFIG_LINE_SYSTEM("lib3ds (3DStudio scenes) " CMAKE_MRPT_HAS_LIB3DS)
126126
SHOW_CONFIG_LINE_SYSTEM("libclang (for ConvertUTF) " CMAKE_MRPT_HAS_CLANG)
127127
SHOW_CONFIG_LINE_SYSTEM("libjpeg (jpeg) " CMAKE_MRPT_HAS_JPEG)
128-
SHOW_CONFIG_LINE_SYSTEM("liblas (ASPRS LAS LiDAR format) " CMAKE_MRPT_HAS_LIBLAS)
129128
SHOW_CONFIG_LINE("mexplus " CMAKE_MRPT_HAS_MATLAB)
130129
SHOW_CONFIG_LINE_SYSTEM("OpenCV (Image manipulation) " CMAKE_MRPT_HAS_OPENCV "[Version: ${MRPT_OPENCV_VERSION}]")
131130
SHOW_CONFIG_LINE_SYSTEM("OpenGL " CMAKE_MRPT_HAS_OPENGL_GLUT)

doc/doxygen-pages/changeLog_doc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- New API to interface ZeroMQ: \ref noncstream_serialization_zmq
2626
- \ref mrpt_maps_grp
2727
- mrpt::maps::COccupancyGridMap2D::loadFromBitmapFile() correct description of `yCentralPixel` parameter.
28+
- mrpt::maps::CPointsMap `liblas` import/export methods are now in a separate header. See \ref mrpt_maps_liblas_grp and \ref dep-liblas
2829
- \ref mrpt_obs_grp
2930
- [ABI change] mrpt::obs::CObservation3DRangeScan:
3031
- Now uses more SSE2 optimized code

doc/doxygen-pages/dependency_liblas.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
<hr>
1818
1919
The <a href="http://www.liblas.org/" >ASPRS LiDAR LAS</a> file format for point cloud datasets.
20-
If available, it will provide the following functionality:
20+
If available, it will provide the functionality of loading/saving mrpt::maps::CPointsMaps to LAS files.
2121
22-
- The following methods:
23-
- mrpt::maps::CPointsMap::saveLASFile()
24-
- mrpt::maps::CPointsMap::loadLASFile()
22+
See: \ref mrpt_maps_liblas_grp
2523
26-
Install this library in Ubuntu/Debian with: `sudo apt-get install liblas-dev liblas-c-dev`
24+
Since MRPT 1.5.0, building MRPT against liblas is not required. In turn, user programs requiring this feature
25+
must make sure of adding the required compiler and linker flags to their programs, and including the
26+
additional file `#include <mrpt/maps/CPointsMap_liblas.h>`.
27+
28+
Install libLAS in Ubuntu/Debian with: `sudo apt-get install liblas-dev liblas-c-dev`
2729
2830
*/
2931

libs/maps/include/mrpt/maps/CPointsMap.h

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ namespace maps
4848
* - mrpt::obs::CObservationRange: IRs, Sonars, etc.
4949
* - mrpt::obs::CObservationVelodyneScan
5050
*
51-
* If built against liblas, this class also provides method for loading and saving in the standard LAS LiDAR point cloud format: saveLASFile(), loadLASFile()
51+
* Loading and saving in the standard LAS LiDAR point cloud format is supported by installing `libLAS` and including the
52+
* header `<mrpt/maps/CPointsMaps_liblas.h>` in your program. Since MRPT 1.5.0 there is no need to build MRPT against libLAS to use this feature.
53+
* See LAS functions in \ref mrpt_maps_liblas_grp.
5254
*
5355
* \sa CMetricMap, CPoint, mrpt::utils::CSerializable
5456
* \ingroup mrpt_maps_grp
@@ -274,43 +276,6 @@ namespace maps
274276
/** Load the point cloud from a PCL PCD file (requires MRPT built against PCL) \return false on any error */
275277
virtual bool loadPCDFile(const std::string &filename);
276278

277-
278-
/** Optional settings for saveLASFile() */
279-
struct MAPS_IMPEXP LAS_WriteParams
280-
{
281-
// None.
282-
};
283-
284-
/** Optional settings for loadLASFile() */
285-
struct MAPS_IMPEXP LAS_LoadParams
286-
{
287-
// None.
288-
};
289-
290-
/** Extra information gathered from the LAS file header */
291-
struct MAPS_IMPEXP LAS_HeaderInfo
292-
{
293-
std::string FileSignature;
294-
std::string SystemIdentifier;
295-
std::string SoftwareIdentifier;
296-
std::string project_guid;
297-
std::string spatial_reference_proj4; //!< Proj.4 string describing the Spatial Reference System.
298-
uint16_t creation_year;//!< Creation date (Year number)
299-
uint16_t creation_DOY; //!< Creation day of year
300-
301-
LAS_HeaderInfo() : creation_year(0),creation_DOY(0)
302-
{}
303-
};
304-
305-
/** Save the point cloud as an ASPRS LAS binary file (requires MRPT built against liblas). Refer to http://www.liblas.org/
306-
* \return false on any error */
307-
virtual bool saveLASFile(const std::string &filename, const LAS_WriteParams & params = LAS_WriteParams() ) const;
308-
309-
/** Load the point cloud from an ASPRS LAS binary file (requires MRPT built against liblas). Refer to http://www.liblas.org/
310-
* \note Color (RGB) information will be taken into account if using the derived class mrpt::maps::CColouredPointsMap
311-
* \return false on any error */
312-
virtual bool loadLASFile(const std::string &filename, LAS_HeaderInfo &out_headerInfo, const LAS_LoadParams &params = LAS_LoadParams() );
313-
314279
/** @} */ // End of: File input/output methods
315280
// --------------------------------------------------
316281

@@ -796,10 +761,16 @@ namespace maps
796761
}
797762
return true;
798763
}
799-
800-
801764
/** @} */
802765

766+
/** Users normally don't need to call this. Called by this class or children classes, set m_largestDistanceFromOriginIsUpdated=false, invalidates the kd-tree cache, and such. */
767+
inline void mark_as_modified() const
768+
{
769+
m_largestDistanceFromOriginIsUpdated=false;
770+
m_boundingBoxIsUpdated = false;
771+
kdtree_mark_as_outdated();
772+
}
773+
803774
protected:
804775
std::vector<float> x,y,z; //!< The point coordinates
805776

@@ -818,15 +789,6 @@ namespace maps
818789
mutable bool m_boundingBoxIsUpdated;
819790
mutable float m_bb_min_x,m_bb_max_x, m_bb_min_y,m_bb_max_y, m_bb_min_z,m_bb_max_z;
820791

821-
822-
/** Called only by this class or children classes, set m_largestDistanceFromOriginIsUpdated=false and such. */
823-
inline void mark_as_modified() const
824-
{
825-
m_largestDistanceFromOriginIsUpdated=false;
826-
m_boundingBoxIsUpdated = false;
827-
kdtree_mark_as_outdated();
828-
}
829-
830792
/** This is a common version of CMetricMap::insertObservation() for point maps (actually, CMetricMap::internal_insertObservation),
831793
* so derived classes don't need to worry implementing that method unless something special is really necesary.
832794
* See mrpt::maps::CPointsMap for the enumeration of types of observations which are accepted. */
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/* +---------------------------------------------------------------------------+
2+
| Mobile Robot Programming Toolkit (MRPT) |
3+
| http://www.mrpt.org/ |
4+
| |
5+
| Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6+
| See: http://www.mrpt.org/Authors - All rights reserved. |
7+
| Released under BSD License. See details in http://www.mrpt.org/License |
8+
+---------------------------------------------------------------------------+ */
9+
#ifndef CPOINTSMAP_LIBLAS_H
10+
#define CPOINTSMAP_LIBLAS_H
11+
12+
/** \file Include this file in your user application only if you have libLAS installed in your system */
13+
#include <liblas/liblas.hpp>
14+
#include <liblas/reader.hpp>
15+
#include <liblas/writer.hpp>
16+
17+
#include <mrpt/maps/CPointsMap.h>
18+
#include <string>
19+
#include <iostream>
20+
#include <fstream>
21+
22+
namespace mrpt
23+
{
24+
/** \ingroup mrpt_maps_grp */
25+
namespace maps
26+
{
27+
/** \addtogroup mrpt_maps_liblas_grp libLAS interface for CPointsMap (in #include <mrpt/maps/CPointsMaps_liblas.h>)
28+
* \ingroup mrpt_maps_grp
29+
* @{ */
30+
31+
/** Optional settings for saveLASFile() */
32+
struct LAS_WriteParams
33+
{
34+
// None.
35+
};
36+
37+
/** Optional settings for loadLASFile() */
38+
struct LAS_LoadParams
39+
{
40+
// None.
41+
};
42+
43+
/** Extra information gathered from the LAS file header */
44+
struct LAS_HeaderInfo
45+
{
46+
std::string FileSignature;
47+
std::string SystemIdentifier;
48+
std::string SoftwareIdentifier;
49+
std::string project_guid;
50+
std::string spatial_reference_proj4; //!< Proj.4 string describing the Spatial Reference System.
51+
uint16_t creation_year;//!< Creation date (Year number)
52+
uint16_t creation_DOY; //!< Creation day of year
53+
54+
LAS_HeaderInfo() : creation_year(0),creation_DOY(0)
55+
{}
56+
};
57+
58+
/** Save the point cloud as an ASPRS LAS binary file (requires MRPT built against liblas). Refer to http://www.liblas.org/
59+
* \return false on any error */
60+
inline bool saveLASFile(
61+
const mrpt::maps::CPointsMaps &ptmap,
62+
const std::string &filename,
63+
const LAS_WriteParams & params = LAS_WriteParams() )
64+
{
65+
std::ofstream ofs;
66+
ofs.open(filename.c_str(), ios::out | ios::binary);
67+
68+
if (!ofs.is_open())
69+
{
70+
cerr << "[saveLASFile] Couldn't write to file: " << filename << endl;
71+
return false;
72+
}
73+
74+
// Fill-in header:
75+
// ---------------------------------
76+
liblas::Header header;
77+
const size_t nPts = ptmap.size();
78+
79+
header.SetPointRecordsCount(nPts);
80+
81+
// Create writer:
82+
// ---------------------------------
83+
liblas::Writer writer(ofs,header);
84+
85+
const bool has_color = ptmap.hasColorPoints();
86+
const float col_fract = 255.0f;
87+
88+
liblas::Point pt(&header);
89+
liblas::Color col;
90+
for (size_t i=0;i<nPts;i++)
91+
{
92+
float x,y,z,R,G,B;
93+
ptmap.getPoint(i, x,y,z, R,G,B);
94+
95+
pt.SetX(x);
96+
pt.SetY(y);
97+
pt.SetZ(z);
98+
99+
if (has_color)
100+
{
101+
col.SetRed( static_cast<uint16_t>(R*col_fract) );
102+
col.SetGreen( static_cast<uint16_t>(G*col_fract) );
103+
col.SetBlue( static_cast<uint16_t>(B*col_fract) );
104+
pt.SetColor(col);
105+
}
106+
107+
if (!writer.WritePoint(pt))
108+
{
109+
std::cerr << "[saveLASFile] liblas returned error writing point #" << i << " to file.\n";
110+
return false;
111+
}
112+
}
113+
return true; // All ok.
114+
}
115+
116+
/** Load the point cloud from an ASPRS LAS binary file (requires MRPT built against liblas). Refer to http://www.liblas.org/
117+
* \note Color (RGB) information will be taken into account if using the derived class mrpt::maps::CColouredPointsMap
118+
* \return false on any error */
119+
inline bool loadLASFile(
120+
mrpt::maps::CPointsMaps &ptmap,
121+
const std::string &filename,
122+
LAS_HeaderInfo &out_headerInfo,
123+
const LAS_LoadParams &params = LAS_LoadParams() )
124+
{
125+
using namespace std;
126+
ptmap.clear();
127+
128+
ifstream ifs;
129+
ifs.open(filename.c_str(), ios::in | ios::binary);
130+
131+
if (!ifs.is_open())
132+
{
133+
cerr << "[loadLASFile] Couldn't open file: " << filename << endl;
134+
return false;
135+
}
136+
137+
// Create LAS reader:
138+
// ---------------------
139+
liblas::Reader reader(ifs);
140+
141+
// Parse header info:
142+
// ---------------------
143+
liblas::Header const& header = reader.GetHeader();
144+
const size_t nPts = header.GetPointRecordsCount();
145+
ptmap.reserve(nPts);
146+
147+
out_headerInfo.FileSignature = header.GetFileSignature();
148+
out_headerInfo.SystemIdentifier = header.GetSystemId();
149+
out_headerInfo.SoftwareIdentifier = header.GetSoftwareId();
150+
#if LIBLAS_VERSION_NUM < 1800
151+
out_headerInfo.project_guid = header.GetProjectId().to_string();
152+
#else
153+
out_headerInfo.project_guid = boost::lexical_cast<std::string>(header.GetProjectId());
154+
#endif
155+
out_headerInfo.spatial_reference_proj4 = header.GetSRS().GetProj4();
156+
out_headerInfo.creation_year = header.GetCreationYear();
157+
out_headerInfo.creation_DOY = header.GetCreationDOY();
158+
159+
// Load points:
160+
// ---------------------
161+
const bool has_color = ptmap.hasColorPoints();
162+
const float col_fract = 1.0f/255.0f;
163+
while (reader.ReadNextPoint())
164+
{
165+
liblas::Point const& p = reader.GetPoint();
166+
167+
if (has_color)
168+
{
169+
liblas::Color const& col = p.GetColor();
170+
ptmap.insertPoint( p.GetX(),p.GetY(),p.GetZ(), col.GetRed()*col_fract,col.GetGreen()*col_fract,col.GetBlue()*col_fract );
171+
}
172+
else
173+
{
174+
ptmap.insertPoint( p.GetX(),p.GetY(),p.GetZ() );
175+
}
176+
}
177+
178+
if (ptmap.size()!=nPts)
179+
cerr << "[loadLASFile] Header says point count is " << nPts << " but only " << ptmap.size() << " were really parsed in.\n";
180+
181+
ptmap.mark_as_modified();
182+
183+
return true; // All ok.
184+
}
185+
/** @} */
186+
}
187+
} // End of namespaces
188+
189+
#endif

0 commit comments

Comments
 (0)