Monday, October 8, 2018

Nana CMake file for Ubuntu

Nana is a "cross-platform library for GUI programming in modern C++ style". More information is available on this website http://nanapro.org/en-us/.

I wanted to use this library with a simple C++ application on Ubuntu. So I created a CMake project with the following folders (see the screenshot below).

Following the getting started and installation instructions here http://nanapro.org/en-us/blog/2016/05/an-introduction-to-nana-c-library/, I downloaded the nana source files, placed them under the nana folder and compiled them into the static library libnana.a.

Next, I created a simple Hello World C++ source file and placed under the src folder.

I then created a CMakeLists.txt file that describes the project and dependencies.

cmake_minimum_required(VERSION 2.8.6)
project(runnana)

find_package (Threads REQUIRED)
find_package (X11 REQUIRED)
find_package(Freetype REQUIRED)

set (CMAKE_BUILD_TYPE Debug)
set (LIBRARY_OUTPUT_PATH bin)

set (CMAKE_CXX_STANDARD 14)
set (CMAKE_CXX_STANDARD_REQUIRED ON)

set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ./bin)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ./bin)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ./bin)

set (NANA_INCLUDE nana/include)
set (NANA_LINK nana/build/bin)

include_directories (
 ${FREETYPE_INCLUDE_DIRS}
 ${X11_INCLUDE_DIR}
 ${NANA_INCLUDE}
)
link_directories (
 ${NANA_LINK}
)
set (RUNNANA_LINK_LIBS
 stdc++fs
 nana
 ${X11_LIBRARIES}
 ${CMAKE_THREAD_LIBS_INIT}
 rt
 Xft
 png
 asound
 fontconfig
 ${FREETYPE_LIBRARIES}
)
set (RUNNANA_INCLUDE
 include
)

file (GLOB RUNNANA_SOURCES "src/*.c*")
add_executable (runnana ${RUNNANA_SOURCES})
target_include_directories (runnana PUBLIC ${RUNNANA_INCLUDE})
target_link_libraries (runnana ${RUNNANA_LINK_LIBS} stdc++fs)

Using this CMake file, I can easily build the project and compile the simple hello world executable, as shown below.



The example hello world application.




Monday, September 24, 2018

Use CMake to build Visual Studio C++ projects with PDAL on Windows

The tutorial on the PDAL website https://pdal.io/development/writing.html provides the details on developing and compiling a simple C++ program using the PDAL API on *nux. I followed the steps but encountered errors trying to compile the example on Windows 10. The following screenshot shows the compilation errors - the Microsoft Visual Studio linker could not find some external symbols such as __imp_htonl_ among others.


 
To fix the compilation errors, the Windows library ws2_32.lib needs to be linked to the final executable. This can be done in the following steps:
  1. Add the library ws2_32 to the CMakeLists.txt file, as shown below.

  2. Run CMake to build the Visual Studio project files.

    C:\> cmake -G"Visual Studio 15 2017 Win64" ..


    The project files are generated.

  3. Open up the solution project in Visual Studio. Then build the solution.

    The project is successfully built and the executable is generated.

Monday, August 20, 2018

Android Studio: Resolving a "Didn't find class "some.class.name" on path: DexPathList" error

I encountered this error message when trying to run an Android project in Android Studio.
08-15 21:05:44.338 7789-7789/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dom925.cadmon.tampa, PID: 7789
java.lang.RuntimeException: Unable to instantiate application com.dom925.cadmon.tampa.App: java.lang.ClassNotFoundException: Didn't find class "com.dom925.cadmon.tampa.App" on path: DexPathList[[zip file "/data/app/com.dom925.cadmon.tampa-1/base.apk"],nativeLibraryDirectories=[/data/app/com.dom925.cadmon.tampa-1/lib/x86, /system/lib, /vendor/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:802)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5377)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)



The cause to this particular problem was some missing plugins in the Android app's build.gradle file. As I was adding some Kotlin code to the project, the Gradle build system needs to recognize the Kotlin classes. If the plugins are not included, the Gradle build system will not be able to run the Kotlin code. 

The app's build.gradle file with missing Kotlin plugins
So adding in the Kotlin plugins kotlin-android and/or kotlin-android-extension as shown below solved the problem.
 

Monday, August 13, 2018

How to find the cause of a lint error while generating a signed Android APK

Sometimes when generating a signed APK of an Android App from Android Studio, I would encounter a cryptic lint error message:

Lint found fatal errors while assembling a release target.

To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
}
...




The message suggests to disable the lint checking but it would probably not be to your benefit to ignore the error.

After some digging around, I found that lint checking outputs a report which you can read to identify the source of the problem. The report can be found in the application's source build directory e.g. /your/Android/app/build/reports/ and named as lint-results-release-fatal.html




If you open up the report in a browser, the cause of the lint error can be easily seen. In this example, the reason for the compilation error is a missing language translation.
 

Monday, May 21, 2018

Perform a 2D geo-registration of a LiDAR LAS file to a GeoTiff image with Cloud Compare

Recently I received LiDAR LAS point clouds generated without using accurate GPS positioning. As a result, the data is not placed at the correct geographic location in the world. To rectify this, I used Cloud Compare to so-called geo-register the point clouds to the world using GeoTiff images as reference.

The following illustrates how it was done:

Load the GeoTiff image as reference
  1. Start Cloud Compare.


  2. Select File | Open.

    The Open file(s) dialog box appears.

  3. Browse and select the reference GeoTiff raster file, e.g. autzen.tif. Click Open.

    The Result type prompt appears.

  4. Click No to load as a texture map instead of converting to a point cloud.

    The Global shift/scale dialog box appears.

  5. Accept the defaults. Click Yes.

    The GeoTiff image is loaded.
Load the LAS file
  1. Select File | Open.


  2. Browse and choose the LAS file, e.g. autzen.las. Click Open.

    The Open LAS File dialog box appears.
  3. Click Apply.

    The Global shift/scale dialog box appears.

  4. Click Yes to accept the defaults.

    The LAS file is loaded.
 Setup the display
  1. In the vertical tool bar on the left, click the Set Current View Mode icon
    and choose Orthographic projection.

    Note: we do not want the perspective projection display to mislead us as to the location of the features
  2. Optional. Select Edit | Colors | Height Ramp. Click OK in the Gradient color dialog box to display the point cloud with a height color gradient for better visualization.


Perform the rectification
  1.  In the DB Tree pane, select the point cloud to rectify, e.g. autzen.las.
  2. In the top tool bar, click the Translate/Rotate icon .

    The Translate/Rotate widget appears in the top right corner.
  3. In the Rotation field, select Z. Toggle off Tz.

    Note: we only want to move horizontally in the 2D plane.
  4. Look for matching features in the point cloud and the GeoTiff image.



  5. To translate the point cloud, press down the mouse right button and drag the point cloud to the new location. To rotate the point cloud, press down the mouse left button and rotate the point cloud.

    Note 1: To toggle the display of the point cloud, toggle on/off the Visible property in the Properties pane on the left.
    Note 2: To zoom in/out/pane around, pause the Translate/Rotate widget by clicking the widget's Pause icon.
  6. In the Translate/Rotate widget, click the Tick icon to save the changes.

    The point cloud is rectified.


Monday, May 14, 2018

Use PDAL to apply a vertical datum geoid correction to a LAS file

PDAL can be used to apply a vertical datum correction to LAS files, e.g. to convert LiDAR data in ellipsoidal heights to mean sea level using a geoid such as the EGM2008. PDAL uses geoids in gtx format and can be downloaded from http://download.osgeo.org/proj/vdatum/

The following steps show how to perform a vertical datum correction with the reprojection filter of PDAL:
  1. Optional. Download an appropriate geoid file e.g. egm08_25.gtx for EGM2008 from http://download.osgeo.org/proj/vdatum/ and place it in a folder e.g. D:\Temp\PDAL\
  2. Open up the OSGeo4W Shell.
  3. In the Command Prompt, type in the following command:

    D:\> pdal translate -i input.las -o output.laz reprojection --filters.reprojection.in_srs="EPSG:32610+4326" --filters.reprojection.out_srs="+init=EPSG:32610 +geoidgrids=D:/Temp/PDAL/egm08_25.gtx" --writers.las.compression="true" --writers.las.a_srs="EPSG:32610+3855" -v 4

    where
    --filters.reprojection.in_srs specifies the source coordinate reference system EPSG:32610 or UTM 10 North  and the source vertical datum of EPSG:4326 which is the WGS84 Ellipsoid

    --filters.reprojection.out_srs specifies the destination coordinate reference system EPSG:32610 (the same as the input) and the EGM2008 grid file to apply

    --writers.las.a_srs tells PDAL to write the destination coordinate reference system of EPSG:32610 and vertical datum EPSG:3855 (which is the EGM2008 datum) to the output file.


  4. Press RETURN.

    Processing messages appear. The input las file is reprojected to the EGM2008 vertical datum.

  5. Optional. Overlay the input and output LAS files in a viewer and observe the vertical offset in a profile as shown below.

Monday, May 7, 2018

Using PDAL to perform simple translation transformations on LAS files

Sometimes for whatever reason you may want to apply a simple linear translation (dx, dy, dz) transformation shift on a LiDAR las file. PDAL has a transformation filter that you can use to perform the shifting, but you have to pass in the translation amounts as part of a 4x4 homogeneous transformation matrix.

A 4x4 transformation matrix that performs translations has the following form:
[1 0 0 dx]
[0 1 0 dy]
[0 0 1 dz]
[0 0 0 1]

So to use PDAL to perform a simple translation, just replace the dx, dy, dz with the translation amounts and pass the matrix to the PDAL transformation filter.

The following example command performs a vertical shift of +5.0 to the input las file.
C:> pdal translate -i input.las -o output.laz -f transformation   --filters.transformation.matrix="1 0 0 0 0 1 0 0 0 0 1 5.0 0 0 0 1"  --writers.las.compression="true" -v 4


The following screen shot shows a profile of the input and output las files with the output las file visibly shifted 5.0 above the input las file.


Related Posts with Thumbnails