This is a library of Useful Functions. If you have any questions please contact Andrew Maclean.
Library contents.
| Subdirectory | Functional Area. |
|---|---|
| Colour | Contains a series of classes for manipulating RGB values. |
| Conversions | Contains classes to effect conversions for output, translating between different formats, rotations and homogenous coordinates. |
| CSVParser | A comma-separated value parser. |
| DateTime | Date, system time and time conversion classes. |
| DTM | Digital Terrain Modelling - routines for calculating volume. |
| FileUtilities | File Utilities - routines for searching for a file and listing all files in directories. These will (optionally) recursively search subdirectories. |
| Examples | Examples that illustrate the use of various components of the library. The directory structure reflects that of the library. |
| GeographicConversions | Classes to convert to and from the various geographic coordinate systems in use. |
| GPSNavigation | Classes that store and hold routes, points and tracks. Great circle navigation routines are also here. |
| GPSParser | This is a library of parsers primarily for NMEA messages. |
| Logger | Use this to log data to/from files. |
| Macros | General macros that may be used by the library. |
| Statistics | Some statistical routines. |
All the library .h and .cpp files are prefixed with "uf". When the libraries are built, all the libraries have a prefix of "uf". Thus is it easy to identify the headers and libraries that belong to this collection of libraries.
This library compiles as static and shared in Windows, Linux and QNX.
In Linux you have a further option regarding building shared libraries. This is called CMAKE_SKIP_RPATH.
If it is ON then runtime paths are not added when using shared libraries. This is useful when you are installing the library in a system directory like /usr/local.
If it is OFF then there is no need to do this as the paths to the library are build in to the code. However do not rename the library or change the path to the library because, if you do, your compiled code will not run.
Note that in QNX you must add -lm to the CMAKE_CXX_FLAGS when you run CMake.
Currently, the Boost libraries are needed for Homogenous Coordinate conversions (in /Conversions).
VTK will be needed for some parts of the library.
The library can be built without Boost or VTK if you set USE_BOOST and/or USE_VTK to OFF when using CMake to configure the library. The values of these settings will be propagated to any CMakeLists.txt files using the library as UF_USE_BOOST as UF_USE_VTK. Thus you can use these values to determine whether to find boost or find VTK in your own code. E.g. In your CMakeLists.txt file, do something like this:
|
# Now depending upon the variables set we determine whether additional # libraries should be included, # Boost IF ( UF_USE_BOOST ) # If FindBoost.cmake is in the modules directory of CMake then comment out the # following line. Otherwise set it to the path where BoostConfig.cmake is. SET ( Boost_DIR ${PROJECT_SOURCE_DIR} ) FIND_PACKAGE(Boost REQUIRED) ENDIF ( UF_USE_BOOST ) IF ( EXISTS ${Boost_INCLUDE_PATH} ) INCLUDE_DIRECTORIES(${Boost_INCLUDE_PATH}) ENDIF ( EXISTS ${Boost_INCLUDE_PATH} ) IF ( EXISTS ${Boost_LIBRARY_PATH} ) LINK_DIRECTORIES(${Boost_LIBRARY_PATH}) ENDIF ( EXISTS ${Boost_LIBRARY_PATH} ) # VTK # FindVTK.cmake is in the modules directory of CMake. #SET( VTK_DIR VTK_DIR-NOTFOUND ) IF ( UF_USE_VTK ) FIND_PACKAGE(VTK REQUIRED) ENDIF ( UF_USE_VTK ) |
To use this library, firstly, download it from the repository into a directory called UF. Then create a build directory called UFBuild. You may also wish to create a build directory for the Examples called UFExamplesBuild. If you are thinking of installing the library then you can install it to a system-wide default library or to a directory you specify. So the directory structure looks something like this:
| MyDevelopmentPath | /UF |
| /UFBuild | |
| /UFExamplesBuild |
If in Linux, cd to UFBuild and type ccmake ../UF. If all goes well CMake will configure a build for you. If Boost or VTK are not on the system, set USE_BOOST and/or USE_VTK to OFF. Decide whether you want shared libraries or static libraries. If you are going to use shared libraries but are not installing the library then make sure CMAKE_SKIP_RPATH is OFF. If you are installing the libraries, then make sure CMAKE_SKIP_RPATH is ON and that the install path is correct. Check that the CMAKE_INSTALL_PREFIX is correct and press "c" and finally "g". Make sure you are in the directory and then type make and finally make install.
| CMAKE_INSTALL_PREFIX | /bin |
| /include/uf-x.y | |
| /lib | |
| /lib/uf-x.y |
Where CMAKE_INSTALL_PREFIX is /usr/local in Linux or c:\Program Files\uf in Windows by default. In linux, if CMAKE_INSTALL_PREFIX is not the default path, you may need to add the directory CMAKE_INSTALL_PREFIX/lib to /etc/ld.so.conf and run ldconf. If CMAKE_SKIP_RPATH is OFF then no library files are installed but binaries and includes will be.
If you are in Windows, the procedure is similar to that in Linux except it is GUI based when using CMake and CMAKE_SKIP_RPATH is meaningless. IF you are using Visual Studio, then right-click on ALL_BUILD and select build. Finally right-click on INSTALL and select build. In Windows you can add the path to the dlls (CMAKE_INSTALL_PREFIX/bin) to the PATH environment variable.
For both Linux and Windows, you can also create an environment variable called UF_DIR. This should point to the directory containing UFConfig.cmake which is either the root of the build tree or the CMAKE_INSTALL_PREFIX/lib/uf<version> directory. Doing this will help FindUF.cmake find the library.
The include files are in a directory called include/uf-x.y and in the lib directory there is a directory called uf-x.y containing the necessary CMake files to find and use the library.
It is proposed that release versions will have an even value for y.
Please note that the Examples directory is not part of the library build.
The CMakeLists.txt file in this directory will show you how to incorporate this library in your own code. This file requires FindUF.cmake to locate the UF library and to set the include and linker paths correctly. It also uses the values of UF_USE_BOOST and UF_USE_VTK to determine if Boost and VTK are needed.
If in Linux, cd to UFExamplesBuild and type ccmake ../UF/Examples. If UF is not found you will get a message to that effect. Then just set UF_DIR to MyDevelopmentPath/BuildUF or to CMAKE_INSTALL_PREFIX/lib/uf-x.y. Press "c" and finally "g". Make sure you are in the directory and then type make and finally make install.
If you are in Windows, the procedure is similar to that in Linux except it is GUI based when using CMake. IF you are using Visual Studio, then right-click on ALL_BUILD and select build. Finally right-click on INSTALL and select build.
CMakeLists.txt is the main file which sets up all that is needed for compiling, linking and installing the library. Here is a description of what this file does and the files that it needs.
CMakeLists.txt when used by CMake or ccmake does the following:
In general the library will build without problems as a static or shared library under Unix. In Windows the libraries will build as static libraries with no problems. However because of the nature of dynamic link libraries (DLLs), some parts of the library will not build as a dll. So we need extra code in some of the the CMakeLists.txt files to address this problem.
Here are some more specific comments:
In /Colour the files will not build as a DLL in Windows. So we need to exclude ufColour.h and ufColour.cpp from building as a dll. This is done by the WRAP_EXCLUDE option in the CMakeLists.txt file in Colour. Note how we copy ufColour.cpp across when installing. This is done towards the end of the file. Of course then we have to include the .cpp file when building an application so in /Examples/Colour/CmakeLists.txt we find ufColour.cpp and add it to the build in this case.
In /Conversions if Boost is present we specifically include ufHomogenousCoordinateConversions.h. Additionally, this library will not build as a DLL, so we use the same technique as we used in Colour. Howerver there is a difference in that there are no source files, just header files. In this case, if we build as a static or shared library in Unix or static in Windows, we need to tell CMake to set the linker language correctly. This can be done by introducing a dummy file ufConversionsDummy.cpp which is is added to the source file list so that CMake can determine that it has to use C++ from the extension. However we can also set the linker language directly by issuing the command: SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES LINKER_LANGUAGE CXX), which has been done here. Note also that the CMakeLists.txt file in /Conversions and /Conversions/Test show a more fine-grained technique of excluding files from a build, in this case if UF_USE_BOOST is off, ufHomogenousCoordinateConversions.h and HomogenousCoordinates.cpp are excluded from the build.
DTM is dependent upon VTK so if VTK is not present then all of this library is excluded from the build.
In /Examples the various CMakeLists.txt files may also exclude/include examples based on the platform and what external libraries they need.
You can use the structure of this library and the cmake files as a model for your library. The steps are as follows: