Skip to content

Commit

Permalink
Merge pull request #100 from gadomski/v0.5
Browse files Browse the repository at this point in the history
Several intertwined changes to our API
  • Loading branch information
gadomski authored Jan 20, 2017
2 parents 424fff9 + 0824ca7 commit 681bf07
Show file tree
Hide file tree
Showing 121 changed files with 1,110 additions and 15,101 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ install:

before_build:
# TODO use build matrix to test with and w/o libfgt
- cmd: cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=C:\projects\local -Dgtest_force_shared_crt=ON -DBUILD_SHARED_LIBS=OFF -DWITH_FGT=ON .
- cmd: cmake -G "Visual Studio 14 2015 Win64" -DEIGEN3_INCLUDE_DIR=C:\projects\eigen-eigen-07105f7124f9 -DCMAKE_INSTALL_PREFIX=C:\projects\local -Dgtest_force_shared_crt=ON -DBUILD_SHARED_LIBS=OFF -DWITH_FGT=ON .

build:
parallel: true
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ before_install:
install:
- scripts/travis-install-cmake.sh && export PATH=$(pwd)/cmake/bin:$PATH
- scripts/travis-install-eigen3.sh
- scripts/travis-install-jsoncpp.sh
- scripts/travis-install-doxygen.sh
- if [ "$CPD_WITH_FGT" = "ON" ]; then scripts/travis-install-fgt.sh; fi

Expand Down
102 changes: 48 additions & 54 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 2.8.12)
set(CPD_LANGUAGES CXX C)
set(CPD_VERSION 0.4.3)
cmake_minimum_required(VERSION 3.1)
set(CPD_LANGUAGES CXX)
set(CPD_VERSION 0.5.0)
set(CPD_SOVERSION 0)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")


# Policies
if(POLICY CMP0048) # Project version
Expand All @@ -20,15 +20,17 @@ if(POLICY CMP0054) # Quoted variables in if statements
cmake_policy(SET CMP0054 NEW)
endif()

# Depdencies

# Upstream
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(Eigen3 REQUIRED)
find_package(Fgt QUIET)
option(WITH_FGT "Build with libfgt" ${Fgt_FOUND})
option(WITH_FGT "Build with fgt" ${Fgt_FOUND})
if(WITH_FGT)
find_package(Fgt REQUIRED)
else()
find_package(Eigen3 REQUIRED)
endif()


# Configuration
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
Expand All @@ -42,37 +44,40 @@ configure_file(cmake/cpd-config.cmake.in "${PROJECT_BINARY_DIR}/cmake/cpd-config
install(FILES "${PROJECT_BINARY_DIR}/cmake/cpd-config.cmake" "${PROJECT_BINARY_DIR}/cmake/cpd-config-version.cmake" DESTINATION lib/cmake/cpd)
configure_file(src/version.cpp.in "${PROJECT_BINARY_DIR}/src/version.cpp")

# Targets
set(library_src

# C++ library
set(library-src
src/affine.cpp
src/affinity.cpp
src/comparer/base.cpp
src/comparer/direct.cpp
src/gauss_transform.cpp
src/nonrigid.cpp
src/normalize.cpp
src/normalization.cpp
src/rigid.cpp
src/transform.cpp
src/utils.cpp
"${PROJECT_BINARY_DIR}/src/version.cpp"
)
if(WITH_FGT)
list(APPEND library_src src/comparer/fgt.cpp)
list(APPEND library-src src/gauss_transform_fgt.cpp)
else()
list(APPEND library-src src/gauss_transform_make_default.cpp)
endif()

add_library(Library-C++ ${library_src})
add_library(Library-C++ ${library-src})
set_target_properties(Library-C++ PROPERTIES
OUTPUT_NAME cpd
VERSION ${CPD_VERSION}
SOVERSION ${CPD_SOVERSION}
)
target_include_directories(Library-C++
INTERFACE $<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include/cpd/vendor>
PRIVATE include include/cpd/vendor)
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
${EIGEN3_INCLUDE_DIR}
)
target_compile_options(Library-C++ PUBLIC -std=c++11)
if(WITH_FGT)
target_link_libraries(Library-C++ PUBLIC Fgt::Library-C++)
target_compile_definitions(Library-C++ PUBLIC CPD_WITH_FGT)
else()
target_include_directories(Library-C++ PUBLIC ${EIGEN3_INCLUDE_DIR})
target_compile_options(Library-C++ PUBLIC -std=c++11)
endif()

option(WITH_STRICT_WARNINGS "Build with stricter warnings" ON)
Expand All @@ -82,48 +87,37 @@ if(WITH_STRICT_WARNINGS)
endif()
endif()

install(TARGETS Library-C++ DESTINATION lib EXPORT cpd-targets)
install(FILES
include/cpd/affine.hpp
include/cpd/exceptions.hpp
include/cpd/logging.hpp
include/cpd/matrix.hpp
include/cpd/nonrigid.hpp
include/cpd/normalize.hpp
include/cpd/probabilities.hpp
include/cpd/rigid.hpp
include/cpd/runner.hpp
include/cpd/utils.hpp
include/cpd/version.hpp
DESTINATION include/cpd
)
install(FILES
include/cpd/comparer/base.hpp
include/cpd/comparer/direct.hpp
DESTINATION include/cpd/comparer
)
if(WITH_FGT)
install(FILES
include/cpd/comparer/fgt.hpp
DESTINATION include/cpd/comparer
)
endif()
install(DIRECTORY include/cpd/vendor DESTINATION include/cpd)
install(EXPORT cpd-targets NAMESPACE Cpd:: DESTINATION lib/cmake/cpd)

# Optional targets
# Tests
option(WITH_TESTS "Build test suite" ON)
if(WITH_TESTS)
enable_testing()
set(GOOGLETEST_DIR "${PROJECT_SOURCE_DIR}/vendor/googletest-release-1.8.0/googletest")
add_subdirectory(${GOOGLETEST_DIR})
add_subdirectory(test)
add_subdirectory("${PROJECT_SOURCE_DIR}/vendor/googletest-release-1.8.0/googletest")
add_subdirectory(tests)
endif()


# Install
install(TARGETS Library-C++ DESTINATION lib EXPORT cpd-targets)
install(DIRECTORY include/cpd DESTINATION include)
install(EXPORT cpd-targets NAMESPACE Cpd:: DESTINATION lib/cmake/cpd)


# Docs
find_package(Doxygen QUIET)
option(WITH_DOCS "Add documentation target" ${Doxygen_FOUND})
if(WITH_DOCS)
find_package(Doxygen REQUIRED)
configure_file(docs/Doxyfile.in "${PROJECT_BINARY_DIR}/docs/Doxyfile")
add_custom_target(docs COMMAND ${DOXYGEN_EXECUTABLE} "${PROJECT_BINARY_DIR}/docs/Doxyfile")
add_custom_target(doc COMMAND ${DOXYGEN_EXECUTABLE} "${PROJECT_BINARY_DIR}/docs/Doxyfile")
endif()


# Components
find_package(jsoncpp QUIET)
option(WITH_JSONCPP "Build with jsoncpp" ${jsoncpp_FOUND})
if(WITH_JSONCPP)
find_package(jsoncpp REQUIRED)
set(CMAKE_WITH_JSONCPP ON)
add_subdirectory(components/jsoncpp)
endif()
46 changes: 39 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,39 @@ Basic, default usage can be accomplished via some namespace-level methods:
int main(int argc, char** argv) {
cpd::Matrix fixed = load_points_from_somewhere();
cpd::Matrix moving = load_points_from_somewhere();
cpd::Rigid::Result result = cpd::rigid(fixed, moving);
cpd::RigidResult result = cpd::rigid(fixed, moving);
return 0;
}
```
More advanced configuration can be accomplished by using a `Runner`:
Configuration is possible via `Rigid`, `Nonrigid`, and `Affine`:
```cpp
#include <cpd/rigid.hpp>
#include <cpd/runner.hpp>
int main(int argc, char** argv) {
cpd::Matrix fixed = load_points_from_somewhere();
cpd::Matrix moving = load_points_from_somewhere();
cpd::Runner<cpd::Rigid> runner;
runner.correspondence(true).outliers(0.2);
cpd::Rigid::Result result = runner.run(fixed, moving);
cpd::Rigid rigid;
rigid.correspondence(true).outliers(0.2);
cpd::RigidResult result = runner.run(fixed, moving);
return 0;
}
```

If cpd is built with the `jsoncpp` component (see `examples/` for a demonstration of the CMake configuration), the results of the cpd run can be converted to json:

```cpp
#include <iostream>
#include <cpd/jsoncpp.hpp>
#include <cpd/rigid.hpp>

int main(int argc, char** argv) {
cpd::Matrix fixed = load_points_from_somewhere();
cpd::Matrix moving = load_points_from_somewhere();
cpd::RigidResult result = cpd::rigid(fixed, moving);
std::cout << cpd::to_json(result) << std::endl;
return 0;
}
```
Expand All @@ -62,6 +79,7 @@ See `examples/` in this code repository for some basic usage examples, including
**cpd** depends on and [CMake](https://cmake.org/) and [Eigen](http://eigen.tuxfamily.org/index.php?title=Main_Page) at build time only — no runtime dependencies.
For additional speed, it can also built with [fgt](https://github.com/gadomski/fgt).
For json output of results, it can be built with [jsoncpp](https://github.com/open-source-parsers/jsoncpp).
### On OSX
Expand Down Expand Up @@ -100,6 +118,14 @@ target_link_libraries(my-great-library

The `Cpd::Library-C++` target includes all the interface settings you need, so you shouldn't need any other calls to get set up.

If you'd like to enable json support, use the jsoncpp component:

```cmake
find_package(Cpd COMPONENTS jsoncpp REQUIRED)
add_library(my-great-library the_code.cpp)
target_link_libraries(my-great-library PUBLIC Cpd::Library-C++ Cpd::Jsoncpp)
```

## OpenMP

Both fgt and Eigen support OpenMP for some operations.
Expand All @@ -124,9 +150,15 @@ If you require some of that old functionality, use the [v0.2](https://github.com
If you need armadillo-5.x, which is required for the old **cpd** but is no longer available from the armadillo website, you can use [my mirror](https://github.com/gadomski/armadillo).
Thanks for your understanding during this switch.

## Publications

This library has been used in the following publications:

- Gadomski, P.J. (December 2016). *Measuring Glacier Surface Velocities With LiDAR: A Comparison of Three-Dimensional Change Detection Methods*. Master's thesis, University of Houston, Geosensing Systems Engineering and Sciences.

## License

This library is GPL2, copyright 2016 Peter J. Gadomski.
This library is GPL2, copyright 2017 Peter J. Gadomski.
See LICENSE.txt for the full license text.

This work is directly inspired by Andriy Myronenko's reference implementation, and we owe him many thanks.
13 changes: 11 additions & 2 deletions cmake/cpd-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,17 @@ macro(find_dependency dep)
endif()
endmacro()

set(CPD_WITH_FGT @WITH_FGT@)
if(${CPD_WITH_FGT})
if(@WITH_FGT@)
find_dependency(Fgt @Fgt_VERSION@ EXACT)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/cpd-targets.cmake")

foreach(component ${Cpd_FIND_COMPONENTS})
if("jsoncpp" STREQUAL ${component})
include("${CMAKE_CURRENT_LIST_DIR}/cpd-${component}-targets.cmake")
find_dependency(jsoncpp)
else()
set(Cpd_FOUND FALSE)
message(FATAL_ERROR "Unsupported component: ${component}")
endif()
endforeach()
9 changes: 9 additions & 0 deletions cmake/cpd_test.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function(cpd_test name)
set(src ${name}.cpp)
set(target ${name}-test)
add_executable(${target} ${src})
set_target_properties(${target} PROPERTIES OUTPUT_NAME ${name})
add_test(NAME ${name} COMMAND ${target})
target_link_libraries(${target} PRIVATE Library-C++ ${ARGN} gtest_main)
target_include_directories(${target} PRIVATE "${PROJECT_BINARY_DIR}")
endfunction()
21 changes: 21 additions & 0 deletions components/jsoncpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
add_library(Jsoncpp src/jsoncpp.cpp)
target_link_libraries(Jsoncpp PUBLIC Library-C++ jsoncpp_lib)
set_target_properties(Jsoncpp PROPERTIES
OUTPUT_NAME cpd-jsoncpp
VERSION ${CPD_VERSION}
SOVERSION ${CPD_SOVERSION}
)
target_include_directories(Jsoncpp
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/components/jsoncpp/include>
$<INSTALL_INTERFACE:include>
)
target_compile_definitions(Jsoncpp PUBLIC CPD_WITH_JSONCPP)

install(TARGETS Jsoncpp DESTINATION lib EXPORT cpd-jsoncpp-targets)
install(DIRECTORY include/cpd DESTINATION include)
install(EXPORT cpd-jsoncpp-targets NAMESPACE Cpd:: DESTINATION lib/cmake/cpd)

if(WITH_TESTS)
add_subdirectory(tests)
endif()
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// cpd - Coherent Point Drift
// Copyright (C) 2016 Pete Gadomski <[email protected]>
// Copyright (C) 2017 Pete Gadomski <[email protected]>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -15,24 +15,19 @@
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

/// \file
/// Exceptions.

#pragma once

namespace cpd {
#include <cpd/affine.hpp>
#include <cpd/nonrigid.hpp>
#include <cpd/rigid.hpp>
#include <json/json.h>
#include <ostream>

/// Base class for all cpd errors.
class cpd_error : public std::runtime_error {
public:
cpd_error(const std::string& what)
: std::runtime_error(what) {}
};
namespace cpd {

/// The requested comparer is unknown.
class unknown_comparer : public cpd_error {
public:
unknown_comparer(const std::string& name)
: cpd_error(name) {}
};
Json::Value to_json(const Result& result);
Json::Value to_json(const RigidResult& result);
Json::Value to_json(const AffineResult& result);
Json::Value to_json(const NonrigidResult& result);
Json::Value to_json(const Matrix& matrix);
}
Loading

0 comments on commit 681bf07

Please sign in to comment.