Skip to content

Commit

Permalink
Merge pull request #3 from Aquaveo/python_wrapping
Browse files Browse the repository at this point in the history
Python wrapping
  • Loading branch information
gagelarsen authored Oct 15, 2018
2 parents e317bb9 + 837d2b8 commit a2da22c
Show file tree
Hide file tree
Showing 136 changed files with 16,297 additions and 1,299 deletions.
3 changes: 0 additions & 3 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,3 @@ build_script:
echo 'XMS_VERSION: '+$env:XMS_VERSION
echo 'CONAN_REFERENCE: '+$env:CONAN_REFERENCE
- python build.py

test_script:
- python test.py
20 changes: 17 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,21 @@ test_package/build/
*.out
*.app

# Doxygen files
# Doxygen
Doxygen/*.tag
Doxygen/html/*.css
Doxygen/html/*.html
Doxygen/html/*.js
Doxygen/html/*.png
Doxygen/html/search
Doxygen/html/pydocs/*
Doxygen/doxy_warn.log
Doxygen/html/
Doxygen/xmsextractor.tag
Doxygen/sphinx_warnings.log

# Test Files
test_files/*_out.*

# Build directories
build/*
build_py/*
output_files/*
45 changes: 28 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ env:
- CONAN_CHANNEL: "stable"
- CONAN_LOGIN_USERNAME: $CONAN_USER_SECRET
- CONAN_PASSWORD: $CONAN_PASSWORD_SECRET
- AQUAVEO_CONAN: https://conan.aquaveo.com
- CONAN_REMOTES: $AQUAVEO_CONAN
- GH_REPO_NAME: xmsstamper
- DOXYFILE: $TRAVIS_BUILD_DIR/Doxygen/Doxyfile
Expand All @@ -26,10 +27,15 @@ osx: &osx
language: generic

stages:
# Builds configurations and runs tests on library
# Also test documentation for undocumented code
- name: test
if: NOT tag IS present
# Builds configurations and runs tests on library and publishes library to conan
- name: deploy
if: tag =~ ^\d+\.\d+\.\d+$
# This needs to be done on tags so that we have python package to read from.
- name: documentation

# Global Lifecycle Steps
# See: https://docs.travis-ci.com/user/customizing-the-build/#The-Build-Lifecycle
Expand All @@ -53,23 +59,6 @@ after_success:
jobs:
include:
# --- TEST STAGE ------------------------------------------------------------------------------------------------
- stage: test
if: branch = master
addons:
apt:
packages:
- doxygen
- doxygen-doc
- doxygen-latex
- doxygen-gui
- graphviz
<<: *linux
env: TASK_NAME="DOXYGEN Generation"
script:
- cd $TRAVIS_BUILD_DIR
- chmod +x generateDocumentationAndDeploy.sh
- ./generateDocumentationAndDeploy.sh

# GCC 5
- stage: test
<<: *linux
Expand Down Expand Up @@ -141,3 +130,25 @@ jobs:
osx_image: xcode9.2
env: CONAN_APPLE_CLANG_VERSIONS=9.0 CONAN_UPLOAD=$AQUAVEO_CONAN CONAN_BUILD_TYPES=Release CONAN_ARCHS=x86_64
after_success: true

# DOCUMENTATION
- stage: documentation
dist: trusty
compiler: gcc
language: cpp
addons:
apt:
packages:
- doxygen
- doxygen-doc
- doxygen-latex
- doxygen-gui
- graphviz
<<: *linux
env: TASK_NAME=Documentation
script:
- cd $TRAVIS_BUILD_DIR
- chmod +x generateDocumentationAndDeploy.sh
- sudo docker run -v $PWD:/home/conan -e "TRAVIS_BUILD_DIR=/home/conan" -e "TRAVIS_BUILD_NUMBER=${TRAVIS_BUILD_NUMBER}" -e "TRAVIS_COMMIT=${TRAVIS_COMMIT}" -e "DOXYFILE=/home/conan/Doxygen/Doxyfile" -e "SPHINX_CONF=/home/conan/pydocs/source/conf.py" -e "GH_REPO_NAME=${GH_REPO_NAME}" -e "GH_REPO_REF=${GH_REPO_REF}" -e "GH_REPO_TOKEN=${GH_REPO_TOKEN}" -e "TRAVIS_TAG=${TRAVIS_TAG}" lasote/conangcc6 /bin/sh generateDocumentationAndDeploy.sh


96 changes: 57 additions & 39 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@ cmake_minimum_required(VERSION 3.1.2)
cmake_policy(SET CMP0015 NEW) # Link Directory Pathing
set(CMAKE_DEBUG_POSTFIX _d)

project(xmsstamper C CXX)

if (APPLE)
set(CMAKE_POSITION_INDEPENDENT_CODE False)
else()
set(CMAKE_POSITION_INDEPENDENT_CODE True)
endif()

set(BUILD_TESTING NO CACHE BOOL "Enable/Disable testing")
set(IS_PYTHON_BUILD NO CACHE BOOL "Set this if you want to build the python bindings.")
set(IS_CONDA_BUILD NO CACHE BOOL "Set this if you want to make a conda package.")
set(PYTHON_TARGET_VERSION 3.6 CACHE STRING "Version of python to link to for python wrapping.")
set(CONDA_PREFIX "" CACHE PATH "Path to the conda environment used to build.")
set(IS_PYTHON_BUILD NO CACHE BOOL "Set this if you want to build the python bindings.")
set(XMSSTAMPER_TEST_PATH "../test_files/" CACHE PATH "Path to test files for testing")
set(XMS_TEST_PATH ${PROJECT_SOURCE_DIR}/test_files/ CACHE PATH "Path to test files for testing")
set(XMS_VERSION "\"99.99.99\"" CACHE STRING "Library Version")

project(xmsstamper C CXX)
if(IS_PYTHON_BUILD AND BUILD_TESTING)
message(FATAL_ERROR "Cannot build python module when testing is enabled")
endif()

add_definitions(-DXMS_VERSION=\"${XMS_VERSION}\")

if(WIN32)
if(XMS_BUILD)
Expand All @@ -38,6 +45,43 @@ else() # If we are not using conda, we are using conan
set(EXT_LIBS ${CONAN_LIBS})
endif(IS_CONDA_BUILD)

message(STATUS "External Include Dirs: ${EXT_INCLUDE_DIRS}")
message(STATUS "External Lib Dirs: ${EXT_LIB_DIRS}")
message(STATUS "Extneral Libs: ${EXT_LIBS}")

if(IS_PYTHON_BUILD)
# linux and mac builds for conan (on TRAVISCI) use a docker that has python
# 2.7 as system python. We do not have control over that docker image so we
# can't change this and it is fine for building conan packages and checking
# that we don't have errors in the python wrapping. We have conda recipes
# for building python packages that target other versions of python.
find_package(PythonLibs ${PYTHON_TARGET_VERSION} EXACT REQUIRED)

message("PYTHON_INCLUDE: ${PYTHON_INCLUDE_DIRS}")
message("PYTHON_LIBS: ${PYTHON_LIBRARIES}")

# Pybind11 module
if(IS_CONDA_BUILD)
include("${CONDA_PREFIX}/share/cmake/pybind11/pybind11Targets.cmake")
include("${CONDA_PREFIX}/share/cmake/pybind11/FindPythonLibsNew.cmake")
include("${CONDA_PREFIX}/share/cmake/pybind11/pybind11Config.cmake")
include("${CONDA_PREFIX}/share/cmake/pybind11/pybind11ConfigVersion.cmake")
include("${CONDA_PREFIX}/share/cmake/pybind11/pybind11Tools.cmake")

else()
include("${CONAN_PYBIND11_ROOT}/share/cmake/pybind11/pybind11Targets.cmake")
include("${CONAN_PYBIND11_ROOT}/share/cmake/pybind11/FindPythonLibsNew.cmake")
include("${CONAN_PYBIND11_ROOT}/share/cmake/pybind11/pybind11Config.cmake")
include("${CONAN_PYBIND11_ROOT}/share/cmake/pybind11/pybind11ConfigVersion.cmake")
include("${CONAN_PYBIND11_ROOT}/share/cmake/pybind11/pybind11Tools.cmake")
endif()

list(APPEND EXT_INCLUDE_DIRS
${PYTHON_INCLUDE_DIRS}
)

endif()

message("External Include Dirs: ${EXT_INCLUDE_DIRS}")
message("External Lib Dirs: ${EXT_LIB_DIRS}")
message("Extneral Libs: ${EXT_LIBS}")
Expand All @@ -50,6 +94,7 @@ link_directories(${EXT_LIB_DIRS})
set(xmsstamper_sources
xmsstamper/stamper/XmStamper.cpp
xmsstamper/stamper/XmStamperIo.cpp
xmsstamper/stamper/TutStamping.cpp
xmsstamper/stamper/detail/XmBathymetryIntersector.cpp
xmsstamper/stamper/detail/XmBreaklines.cpp
xmsstamper/stamper/detail/XmGuideBankUtil.cpp
Expand All @@ -63,6 +108,7 @@ set(xmsstamper_sources
set(xmsstamper_headers
xmsstamper/stamper/XmStamper.h
xmsstamper/stamper/XmStamperIo.h
xmsstamper/stamper/TutStamping.t.h
xmsstamper/stamper/detail/XmBathymetryIntersector.h
xmsstamper/stamper/detail/XmBathymetryIntersector.t.h
xmsstamper/stamper/detail/XmBreaklines.h
Expand All @@ -82,6 +128,7 @@ set(xmsstamper_py
#Stamper
xmsstamper/python/stamper/stamper_py.cpp
xmsstamper/python/stamper/XmStamper_py.cpp
xmsstamper/python/stamper/XmStamperIo_py.cpp
)

set(xmsstamper_py_headers
Expand All @@ -90,7 +137,7 @@ set(xmsstamper_py_headers

# Tests
if (BUILD_TESTING)
add_definitions(-DXMSSTAMPER_TEST_PATH="${XMSSTAMPER_TEST_PATH}/")
add_definitions(-DXMS_TEST_PATH="${XMS_TEST_PATH}/")
add_definitions(-DCXX_TEST -DCXXTEST4)

list(APPEND xmsstamper_sources
Expand Down Expand Up @@ -134,39 +181,13 @@ endif()

#Pybind11
if(IS_PYTHON_BUILD)
# linux and mac builds for conan (on TRAVISCI) use a docker that has python
# 2.7 as system python. We do not have control over that docker image so we
# can't change this and it is fine for building conan packages and checking
# that we don't have errors in the python wrapping. We have conda recipes
# for building python packages that target other versions of python.
find_package(PythonLibs ${PYTHON_TARGET_VERSION} EXACT REQUIRED)

message("PYTHON_INCLUDE: ${PYTHON_INCLUDE_DIRS}")
message("PYTHON_LIBS: ${PYTHON_LIBRARIES}")

# Pybind11 module
if(IS_CONDA_BUILD)
include("${CONDA_PREFIX}/share/cmake/pybind11/pybind11Targets.cmake")
include("${CONDA_PREFIX}/share/cmake/pybind11/FindPythonLibsNew.cmake")
include("${CONDA_PREFIX}/share/cmake/pybind11/pybind11Config.cmake")
include("${CONDA_PREFIX}/share/cmake/pybind11/pybind11ConfigVersion.cmake")
include("${CONDA_PREFIX}/share/cmake/pybind11/pybind11Tools.cmake")

else()
include("${CONAN_PYBIND11_ROOT}/share/cmake/pybind11/pybind11Targets.cmake")
include("${CONAN_PYBIND11_ROOT}/share/cmake/pybind11/FindPythonLibsNew.cmake")
include("${CONAN_PYBIND11_ROOT}/share/cmake/pybind11/pybind11Config.cmake")
include("${CONAN_PYBIND11_ROOT}/share/cmake/pybind11/pybind11ConfigVersion.cmake")
include("${CONAN_PYBIND11_ROOT}/share/cmake/pybind11/pybind11Tools.cmake")
endif()

pybind11_add_module(xmsstamper_py
${xmsstamper_py} ${xmsstamper_py_headers}
)
target_include_directories(xmsstamper_py
PRIVATE
${EXT_LIBS}
PYTHON_INCLUDE_DIRS
${PYTHON_INCLUDE_DIRS}
)
target_link_libraries(xmsstamper_py
PRIVATE
Expand All @@ -177,23 +198,20 @@ if(IS_PYTHON_BUILD)
LINKER_LANGUAGE CXX
)

execute_process(COMMAND python -c "import os; print('${PYTHON_SITE_PACKAGES}'.replace('${CONDA_PREFIX}' + os.sep, ''))" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES_TRIMMED OUTPUT_STRIP_TRAILING_WHITESPACE)

# Install recipe
install(
TARGETS xmsstamper_py
ARCHIVE DESTINATION ${PYTHON_SITE_PACKAGES_TRIMMED}
LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES_TRIMMED}
TARGETS xmsstamper_py
ARCHIVE DESTINATION "site-packages"
LIBRARY DESTINATION "site-packages"
)

endif()


# Install recipe
install(
TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
ARCHIVE DESTINATION "lib"
LIBRARY DESTINATION "lib"
)
foreach (header IN LISTS xmsstamper_headers xmsstamper_py_headers)
get_filename_component(subdir "${header}" DIRECTORY)
Expand Down
4 changes: 2 additions & 2 deletions Doxygen/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -2077,8 +2077,8 @@ SKIP_FUNCTION_MACROS = YES
# the path). If a tag file is not located in the directory in which doxygen is
# run, you must also specify the path to the tagfile here.

TAGFILES = xmsstamper.tag=https://aquaveo.github.io/xmscore/ \
xmsstamper.tag=https://aquaveo.github.io/xmsinterp/ \
TAGFILES = xmscore.tag=https://aquaveo.github.io/xmscore/ \
xmsinterp.tag=https://aquaveo.github.io/xmsinterp/ \

# When a file name is specified after GENERATE_TAGFILE, doxygen will create a
# tag file that is based on the input files it reads. See section "Linking to
Expand Down
64 changes: 53 additions & 11 deletions Doxygen/Stamper_Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,63 @@
# Stamper Tutorial {#Stamper_Tutorial}

## Introduction {#Intro_Stamper}
The purpose of this tutorial is to provide explanation on how to use the class defined in xmsstamper to trace a given point through a velocity vector field grid. The example provided in this tutorial refers to a test case that is in the xmsstamper/stamper/detail/XmStampInterpCrossSection.cpp source file.
The purpose of this tutorial is to provide explanation on how to use the classes defined in xmsng to perform feature stamping. The examples provided in this tutorial refer to test cases that are in the xmsng/tutorial/TutStamping.cpp source file.

## Example - Simple Stamper with Cross Sections {#Example_Simple_Stamper}
This is the "hello world" example for using the stamper library.
The xmsng library contains classes for performing feature stamping. The basic idea is to associate cross sections with a center line to produce a new feature (a "fill" embankment, a "cut" channel). The output from the feature stamp is a TIN and a set of break lines defining distinct characteristics of the new feature, such as the center line, shoulder, toe, and end cap.

This example shows how to insert a man-made structure into a natural topography or bathymetry set.
The xms::StStamperIo class is used to set up the inputs to the stamp operation and it also contains the outputs of the operation in the member variables m_outTin and m_outBreakLines;

The basic steps to define a linear stamped feature include:
## Example - Fill Embankment Feature Stamp {#Example_FillEmbankment}
The following example shows how to use the stamper to make a simple fill embankment. The testing code for this example is TutStampingTests::test_StampFillEmbankment.

1. Define the stamping coverage and centerline (or focal point) of the stamped feature.
2. Assign attributes to the centerline including the elevation profile along the centerline and the cross sections along the centerline.
3. Stamp the feature. This converts the centerline and its attributes to another coverage containing all the extents and details of the feature and a scatter set defining the elevation for the feature.
\snippet xmsstamper/stamper/TutStamping.cpp snip_testStampFillEmbankment

![Simple XmStamper Cross Section Tutorial](xmsstamper_testCrossSectionTutorial.PNG)
The output from this test looks like the following image.

In this example we specify the black centerline and the 2 green cross sections just in from each end, with their shoulder points. Then we stamp the feature to calculate the green interpolated shoulder lines and green cross sections at the other centerline points with 2 outside and 2 between the specified cross sections.
![Stamp fill embankment](doxygen/html/images/tutStamp_FillEmbankment.png)

## Example - Cut Embankment Feature Stamp {#Example_CutEmbankment}
The following example shows how to use the stamper to make a simple cut embankment. This is just like the fill embankment but we have flipped the specified cross sections. The testing code for this example is TutStampingTests::test_StampCutEmbankment.

\snippet xmsstamper/stamper/TutStamping.cpp snip_testStampCutEmbankment

The output from this test looks like the following image.

![Stamp cut embankment](doxygen/html/images/tutStamp_CutEmbankment.png)

## Example - Wing Wall with Fill Embankment Feature Stamp {#Example_WingWall}
The following example shows how to use the stamper to make a fill embankment with a wing wall end cap with a specified angle. An angle can be specified with all end caps and it will affect the orientation of the end cap from the center line to the shoulder. The wing wall has an additional angle that can be specified that changes the orientation from the shoulder to the toe. The testing code for this example is TutStampingTests::test_StampWingWall.

\snippet xmsstamper/stamper/TutStamping.cpp snip_testStampWingWall

The output from this test looks like the following image.

![Stamp fill embankment with a wing wall end cap](doxygen/html/images/tutStamp_WingWall.png)

## Example - Sloped Abutment with Fill Embankment Feature Stamp {#Example_SlopedAbutment}
The following example shows how to use the stamper to make a fill embankment with a sloped abutment end cap. The testing code for this example is TutStampingTests::test_StampSlopedAbutment.

\snippet xmsstamper/stamper/TutStamping.cpp snip_testStampSlopedAbutment

The output from this test looks like the following image.

![Stamp fill embankment with a sloped abutment end cap](doxygen/html/images/tutStamp_SlopedAbutment.png)

## Example - Guidebank with Fill Embankment Feature Stamp {#Example_Guidebank}
The following example shows how to use the stamper to make a fill embankment with a guidebank end cap. The testing code for this example is TutStampingTests::test_StampGuidebank.

\snippet xmsstamper/stamper/TutStamping.cpp snip_testStampGuidebank

The output from this test looks like the following image.

![Stamp fill embankment with a guidebank end cap](doxygen/html/images/tutStamp_Guidebank.png)

## Example - Fill Embankment Feature Stamp Intersecting Bathymetry {#Example_Bathymetry}
The following example shows how to use the stamper to make a fill embankment with an underlying bathymetry. The stamp is intersected and potentially cut off by the bathymetry. The testing code for this example is TutStampingTests::test_StampIntersectBathymetry.

\snippet xmsstamper/stamper/TutStamping.cpp snip_testStampIntersectBathymetry

The output from this test looks like the following image. The red triangles are the bathymetry.

![Stamp fill embankment cut off by bathymetry](doxygen/html/images/tutStamp_Intersect.png)

\snippet xmsstamper/stamper/detail/XmStampInterpCrossSection.cpp snip_test_Example_XmStamper_testCrossSectionTutorial
2 changes: 2 additions & 0 deletions Doxygen/doxy_warn.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
error: Tag file `xmscore.tag' does not exist or is not a file. Skipping it...
error: Tag file `xmsinterp.tag' does not exist or is not a file. Skipping it...
Binary file added Doxygen/html/images/tutStamp_CutEmbankment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Doxygen/html/images/tutStamp_FillEmbankment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Doxygen/html/images/tutStamp_Guidebank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Doxygen/html/images/tutStamp_Intersect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Doxygen/html/images/tutStamp_SlopedAbutment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Doxygen/html/images/tutStamp_WingWall.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions Doxygen/sphinx_warnings.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

Warning, treated as error:
D:\code\xmsstamper\pydocs\source\index.rst:6:Title overline too short.

*******************
XmsStamper |version|
*******************
Loading

0 comments on commit a2da22c

Please sign in to comment.