Commits

Anonymous committed 05c3d31

Added libLAS example.

Comments (0)

Files changed (3)

libLASTest/CMakeLists.txt

+cmake_minimum_required ( VERSION 2.8)
+PROJECT ( libLASTest )
+SET ( libLASTest_SRCS main.cpp )
+
+SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
+
+find_package( LibLAS			1.6 REQUIRED )  # should be 1.7...?
+
+# Create a target for executable
+ADD_EXECUTABLE(libLASTest ${libLASTest_SRCS})

libLASTest/cmake/FindLibLAS.cmake

+###############################################################################
+#
+# CMake module to search for libLAS library
+#
+# On success, the macro sets the following variables:
+# LIBLAS_FOUND       = if the library found
+# LIBLAS_LIBRARIES   = full path to the library
+# LIBLAS_INCLUDE_DIR = where to find the library headers also defined,
+#                       but not for general use are
+# LIBLAS_LIBRARY     = where to find the PROJ.4 library.
+# LIBLAS_VERSION     = version of library which was found, e.g. "1.2.5"
+#
+# Copyright (c) 2009 Mateusz Loskot <mateusz@loskot.net>
+#
+# Module source: http://github.com/mloskot/workshop/tree/master/cmake/
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+#
+###############################################################################
+MESSAGE(STATUS "Searching for LibLAS ${LibLAS_FIND_VERSION}+ library")
+
+IF(LIBLAS_INCLUDE_DIR)
+  # Already in cache, be silent
+  SET(LIBLAS_FIND_QUIETLY TRUE)
+ENDIF()
+
+IF(WIN32)
+  SET(OSGEO4W_IMPORT_LIBRARY liblas)
+  IF(DEFINED ENV{OSGEO4W_ROOT})
+    SET(OSGEO4W_ROOT_DIR $ENV{OSGEO4W_ROOT})
+    #MESSAGE(STATUS " FindLibLAS: trying OSGeo4W using environment variable OSGEO4W_ROOT=$ENV{OSGEO4W_ROOT}")
+  ELSE()
+    SET(OSGEO4W_ROOT_DIR c:/OSGeo4W)
+    #MESSAGE(STATUS " FindLibLAS: trying OSGeo4W using default location OSGEO4W_ROOT=${OSGEO4W_ROOT_DIR}")
+  ENDIF()
+ENDIF()
+
+
+FIND_PATH(LIBLAS_INCLUDE_DIR
+  liblas.hpp
+  PATH_PREFIXES liblas
+  PATHS
+  /usr/include
+  /usr/local/include
+  /tmp/lasjunk/include
+  ${OSGEO4W_ROOT_DIR}/include)
+
+if(WIN32)
+    SET(LIBLAS_NAMES ${OSGEO4W_IMPORT_LIBRARY} liblas)
+else()
+    SET(LIBLAS_NAMES ${OSGEO4W_IMPORT_LIBRARY} las)
+endif()
+
+FIND_LIBRARY(LIBLAS_LIBRARY
+  NAMES ${LIBLAS_NAMES}
+  PATHS
+  /usr/lib
+  /usr/local/lib
+  /tmp/lasjunk/lib
+  ${OSGEO4W_ROOT_DIR}/lib)
+
+IF(LIBLAS_FOUND)
+  SET(LIBLAS_LIBRARIES ${LIBLAS_LIBRARY})
+ENDIF()
+
+IF(LIBLAS_INCLUDE_DIR)
+  SET(LIBLAS_VERSION 0)
+
+  SET(LIBLAS_VERSION_H "${LIBLAS_INCLUDE_DIR}/liblas/version.hpp")
+  FILE(READ ${LIBLAS_VERSION_H} LIBLAS_VERSION_H_CONTENTS)
+
+  IF (DEFINED LIBLAS_VERSION_H_CONTENTS)
+  
+    # string will be something like "106000", which is xyyzzz (x=major, y=minor, z=patch)
+    string(REGEX REPLACE ".*#define[ \t]LIBLAS_VERSION[ \t]+([0-9]).*" "\\1" LIBLAS_VERSION_MAJOR "${LIBLAS_VERSION_H_CONTENTS}")
+    string(REGEX REPLACE ".*#define[ \t]LIBLAS_VERSION[ \t]+[0-9]([0-9][0-9]).*" "\\1" LIBLAS_VERSION_MINOR "${LIBLAS_VERSION_H_CONTENTS}")
+    string(REGEX REPLACE ".*#define[ \t]LIBLAS_VERSION[ \t]+[0-9][0-9][0-9]([0-9][0-9][0-9]).*"   "\\1" LIBLAS_VERSION_PATCH   "${LIBLAS_VERSION_H_CONTENTS}")
+    #message(FATAL_ERROR "${LIBLAS_VERSION_MAJOR}.${LIBLAS_VERSION_MINOR}.${LIBLAS_VERSION_PATCH}")
+
+    if(NOT ${LIBLAS_VERSION_MAJOR} MATCHES "[0-9]+")
+      message(FATAL_ERROR "libLAS version parsing failed for LIBLAS_VERSION_MAJOR!")
+    endif()
+    if(NOT ${LIBLAS_VERSION_MINOR} MATCHES "[0-9]+")
+      message(FATAL_ERROR "libLAS version parsing failed for LIBLAS_VERSION_MINOR!")
+    endif()
+    if(NOT ${LIBLAS_VERSION_PATCH} MATCHES "[0-9]+")
+      message(FATAL_ERROR "libLAS version parsing failed for LIBLAS_VERSION_PATCH!")
+    endif()
+
+
+    SET(LIBLAS_VERSION "${LIBLAS_VERSION_MAJOR}.${LIBLAS_VERSION_MINOR}.${LIBLAS_VERSION_PATCH}"
+      CACHE INTERNAL "The version string for libLAS library")
+
+    IF (LIBLAS_VERSION VERSION_EQUAL LibLAS_FIND_VERSION OR
+        LIBLAS_VERSION VERSION_GREATER LibLAS_FIND_VERSION)
+      MESSAGE(STATUS "Found libLAS version: ${LIBLAS_VERSION}")
+    ELSE()
+      MESSAGE(FATAL_ERROR "libLS version check failed. Version ${LIBLAS_VERSION} was found, at least version ${LibLAS_FIND_VERSION} is required")
+    ENDIF()
+  ELSE()
+    MESSAGE(FATAL_ERROR "Failed to open ${LIBLAS_VERSION_H} file")
+  ENDIF()
+
+ENDIF()
+
+# Handle the QUIETLY and REQUIRED arguments and set LIBLAS_FOUND to TRUE
+# if all listed variables are TRUE
+INCLUDE(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(libLAS DEFAULT_MSG LIBLAS_LIBRARY LIBLAS_INCLUDE_DIR)

libLASTest/main.cpp

+#include <iostream>
+#include <liblas/liblas.hpp>
+using namespace std;
+
+int main()
+{
+	// see http://www.liblas.org/tutorial/cpp.html
+	std::ifstream ifs;
+
+	ifs.open("C:/Users/no68koc/SkyDrive/Repositories/3D Models/R_BW%283%29_LAS1_2_29860_29890/R_BW(3)_LAS1_2_29860_29890.las", std::ios::in | std::ios::binary);
+
+	liblas::ReaderFactory f;
+	liblas::Reader reader = f.CreateWithStream(ifs);
+
+	liblas::Header const& header = reader.GetHeader();
+
+	std::cout << "Compressed: " << (header.Compressed() == true) ? "true":"false";
+	std::cout << "Signature: " << header.GetFileSignature() << '\n';
+	std::cout << "Points count: " << header.GetPointRecordsCount() << '\n';
+
+	while (reader.ReadNextPoint())
+	{
+		liblas::Point const& p = reader.GetPoint();
+
+		std::cout << p.GetX() << ", " << p.GetY() << ", " << p.GetZ() << "\n";
+	}
+}