Commit a89881ae authored by Julie Brossard's avatar Julie Brossard
Browse files

Refactored code

parent 69cf05c7
language: cpp
git:
depth: 3
env:
global:
- OTB_URL=https://www.orfeo-toolbox.org/packages/archives/OTB
# - OTB_URL=https://www.orfeo-toolbox.org/packages/ci/latest
- OTB_VER=7.0.0
matrix:
include:
- os: linux
dist: bionic
compiler: gcc
sudo: required
before_install:
- sudo apt-get install -y
ninja-build
libglvnd-dev
libglu1-mesa-dev
python3-numpy
python3-dev
env:
- OTB_OS=Linux64
- OTB_PKG_EXT=run
- os: osx
osx_image: xcode10.2
compiler: clang
before_install:
- brew install ninja libomp git-lfs
env:
- OTB_OS=Darwin64
- OTB_PKG_EXT=run
- os: windows
before_install:
- choco install python3 --params "/InstallDir:C:\Python3"
- choco install ninja
- export PATH="/c/Python3:/c/ProgramData/chocolatey/lib/ninja/tools:$PATH"
- /c/Python3/Scripts/pip install numpy
- eval "$(python vcvars_proxy.py
'c:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/Common7/Tools/VsDevCmd.bat'
'-arch=amd64'
'-host_arch=amd64'
'-vcvars_ver=14.0')"
- export CC=cl.exe
- export CXX=cl.exe
- export CC_FOR_BUILD=cl.exe
- export CXX_FOR_BUILD=cl.exe
env:
- OTB_OS=Win64
- OTB_PKG_EXT=zip
install:
- export OTB_PKG="OTB-${OTB_VER}-${OTB_OS}.${OTB_PKG_EXT}"
- wget ${OTB_URL}/${OTB_PKG}
- if [ "$OTB_PKG_EXT" = "run" ]; then chmod +x ${OTB_PKG} ; ./${OTB_PKG} --target xdk ; fi
- if [ "$OTB_PKG_EXT" = "zip" ]; then 7z x -y ${OTB_PKG} ; mv OTB-${OTB_VER}-${OTB_OS} xdk ; fi
- if [ "$TRAVIS_OS_NAME" = "windows" ]; then
source xdk/otbenv.bash;
else
source xdk/otbenv.profile;
fi
# build_wrapping is needed if you use Python wrappers in your module
- ctest -S xdk/share/otb/swig/build_wrapping.cmake -VV
# NamespaceHandler is needed if you have target conflicts between OTB and your module
# - ctest -DNAMESPACE:STRING="OTB" -S xdk/lib/cmake/OTB-6.7/NamespaceHandler.cmake
# LFS install needed if you use OTB/Data
# - git lfs install
script:
- ctest -VV -S ./ci.cmake
cmake_minimum_required(VERSION 2.8)
project(LISOTBModule)
# This module create a library, with the same name as the module
set(LISOTBModule_LIBRARIES LISOTBModule)
......@@ -9,7 +8,7 @@ if(NOT OTB_SOURCE_DIR)
# Handle the compilation outside OTB source tree: find where OTB is built/installed
find_package(OTB REQUIRED)
list(APPEND CMAKE_MODULE_PATH ${OTB_CMAKE_DIR})
include(${OTB_USE_FILE})
include(UseOTB)
# The Python interpreter is needed for Python tests
set(Python_ADDITIONAL_VERSIONS "3")
......@@ -21,16 +20,3 @@ else()
otb_module_impl()
endif()
# Execute and Copy during installation
install(DIRECTORY python_src DESTINATION ${CMAKE_INSTALL_PREFIX})
install(DIRECTORY python_include DESTINATION ${CMAKE_INSTALL_PREFIX})
#if(UNIX)
#install(CODE "execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate_diapOTBEnv.sh ${CMAKE_INSTALL_PREFIX})")
#install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/scripts/diapOTBEnv.sh PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ DESTINATION #${CMAKE_INSTALL_PREFIX})
#endif()
# Build our library
add_library( histo_utils SHARED histo_utils.cxx )
target_link_libraries(histo_utils ${OTB_LIBRARIES})
# This macro creates the application EmptyApp. It must be linked to
# OTBApplicationEngine. Since the module has its own library,
# the variable ${otb-module}_LIBRARIES only contains this library, which doesn't
# drag OTBApplicationEngine, so we need to add it explicitely.
message(${${otb-module}_LIBRARIES})
# Install for executables and libraries
install(TARGETS histo_utils
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib/static)
# Create the ComputeCloudMask OTB application
otb_create_application(NAME ComputeCloudMask
SOURCES otbComputeCloudMask.cxx
LINK_LIBRARIES ${OTB_LIBRARIES})
OTB_CREATE_APPLICATION(NAME ComputeCloudMask
SOURCES otbComputeCloudMask.cxx
#LINK_LIBRARIES ${OTB_LIBRARIES})
LINK_LIBRARIES ${${otb-module}_LIBRARIES}
)
# Create the ComputeSnowMask OTB application
otb_create_application(NAME ComputeSnowMask
OTB_CREATE_APPLICATION(NAME ComputeSnowMask
SOURCES otbComputeSnowMask.cxx
LINK_LIBRARIES ${OTB_LIBRARIES})
LINK_LIBRARIES ${${otb-module}_LIBRARIES}
)
# Create the ComputeContour OTB application
otb_create_application(NAME ComputeContours
OTB_CREATE_APPLICATION(NAME ComputeContours
SOURCES otbComputeContours.cxx
LINK_LIBRARIES ${OTB_LIBRARIES})
LINK_LIBRARIES ${${otb-module}_LIBRARIES}
)
# Create the ComputeSnowLine OTB application
otb_create_application(NAME ComputeSnowLine
SOURCES otbComputeSnowLine.cxx
LINK_LIBRARIES ${OTB_LIBRARIES} histo_utils)
#OTB_CREATE_APPLICATION(NAME ComputeSnowLine
# SOURCES otbComputeSnowLine.cxx
# LINK_LIBRARIES ${${otb-module}_LIBRARIES})
# Create the ComputeNbPixels OTB application
otb_create_application(NAME ComputeNbPixels
OTB_CREATE_APPLICATION(NAME ComputeNbPixels
SOURCES otbComputeNbPixels.cxx
LINK_LIBRARIES ${OTB_LIBRARIES})
LINK_LIBRARIES ${${otb-module}_LIBRARIES}
)
......@@ -93,6 +93,9 @@ public:
InputImageType * inDEMImage = GetParameterImage<InputImageType>("dem");
// Instantiating object (compute min/max from dem image)
m_Filter = StreamingMinMaxImageFilterType::New();
......@@ -139,6 +142,8 @@ public:
StreamingMinMaxImageFilterType::Pointer m_Filter;
ComposeImageFilterType::Pointer m_ComposeFilter;
};
}
......
......@@ -4,6 +4,7 @@
#include "itkNarySnowMaskImageFilter.h"
#include "otbImage.h"
#include "histo_utils.h"
namespace otb
{
......@@ -105,6 +106,9 @@ public:
m_SnowMaskFilter->SetInput(3, img_cloud_refine);
m_SnowMaskFilter->SetInput(4, img_all_cloud);
if(IsParameterEnabled("slopeflag")){
InputImageType::Pointer img_slope_flag = GetParameterImage<InputImageType>("slopeflag");
m_SnowMaskFilter->SetInput(5, img_slope_flag);
......
# This script is a prototype for the future CI, it may evolve rapidly in a near future
set(REMOTE_MODULE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
set (ENV{LANG} "C") # Only ascii output
# Get project name
file(STRINGS "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" _project_match REGEX "^project *\\(")
string(REGEX REPLACE "^project *\\( *([a-zA-Z0-9]+) *\\)" "\\1" otb-module ${_project_match})
# Build Configuration : Release, Debug..
if(ci_build_type)
set (CTEST_BUILD_CONFIGURATION ${ci_build_type})
else()
set (CTEST_BUILD_CONFIGURATION "Release")
endif()
set (CTEST_CMAKE_GENERATOR "Ninja")
# detect short sha
if(NOT DEFINED ENV{TRAVIS_COMMIT})
execute_process(COMMAND git log -1 --pretty=format:%h
WORKING_DIRECTORY ${REMOTE_MODULE_SOURCE_DIR}
OUTPUT_VARIABLE ci_short_sha)
else()
set(ci_short_sha "$ENV{TRAVIS_COMMIT}")
endif()
set(CTEST_PROJECT_NAME "${otb-module}")
set(CTEST_DROP_METHOD "https")
set(CTEST_DROP_SITE "cdash.orfeo-toolbox.org")
set(CTEST_DROP_LOCATION "/submit.php?project=OTB")
set(CTEST_DROP_SITE_CDASH TRUE)
set(CTEST_BUILD_NAME "${CTEST_PROJECT_NAME} ($ENV{TRAVIS_BRANCH})")
set(CTEST_SITE "$ENV{TRAVIS_OS_NAME}")
set(compiler_name "$ENV{TRAVIS_COMPILER}")
if("${CTEST_SITE}" STREQUAL "linux")
set(CTEST_SITE "${CTEST_SITE}-$ENV{TRAVIS_DIST}")
elseif("${CTEST_SITE}" STREQUAL "osx")
set(CTEST_SITE "${CTEST_SITE}-$ENV{TRAVIS_OSX_IMAGE}")
elseif("${CTEST_SITE}" STREQUAL "windows")
set(CTEST_SITE "${CTEST_SITE}-server1803")
set(compiler_name "vc140")
endif()
set(CTEST_SITE "${CTEST_SITE}-${compiler_name}")
# Detect "skip testing"
if(DEFINED ENV{CI_SKIP_TESTING})
set(ci_skip_testing 1)
endif()
# Directory variable
set (CTEST_SOURCE_DIRECTORY "${REMOTE_MODULE_SOURCE_DIR}")
if(BUILD_DIR)
set (CTEST_BINARY_DIRECTORY "${BUILD_DIR}")
else()
set (CTEST_BINARY_DIRECTORY "${REMOTE_MODULE_SOURCE_DIR}/build/")
endif()
if(INSTALL_DIR)
set (CTEST_INSTALL_DIRECTORY "${INSTALL_DIR}")
else()
set (CTEST_INSTALL_DIRECTORY "${REMOTE_MODULE_SOURCE_DIR}/install/")
endif()
set (PROJECT_SOURCE_DIR "${REMOTE_MODULE_SOURCE_DIR}")
# Ctest command value
set (CMAKE_COMMAND "cmake")
# Set the CONFIGURE_OPTIONS variable
set (all_options
"BUILD_SHARED_LIBS:BOOL=ON
BUILD_TESTING:BOOL=ON
OTB_BUILD_MODULE_AS_STANDALONE:BOOL=ON
CMAKE_PREFIX_PATH:PATH=${REMOTE_MODULE_SOURCE_DIR}/xdk
CMAKE_INSTALL_PREFIX:PATH=${CTEST_INSTALL_DIRECTORY}
CMAKE_BUILD_TYPE=${CTEST_BUILD_CONFIGURATION}")
if(UNIX AND NOT APPLE)
set(all_options
"${all_options}
OpenGL_GL_PREFERENCE=GLVND")
endif()
if(APPLE)
set(all_options
"${all_options}
CMAKE_MACOSX_RPATH=TRUE")
endif()
string (REPLACE "\n" ";" rm_options ${all_options})
foreach(item ${rm_options})
set( CONFIGURE_OPTIONS "${CONFIGURE_OPTIONS}-D${item};")
endforeach(item)
# Sources are already checked out : do nothing for update
set(CTEST_GIT_UPDATE_CUSTOM "${CMAKE_COMMAND}" "-E" "echo" "No update")
# Look for a GIT command-line client.
find_program(CTEST_GIT_COMMAND NAMES git git.cmd)
# Add bin dir to PATH for testing on Windows
if(WIN32)
file(TO_NATIVE_PATH "${CTEST_BINARY_DIRECTORY}/bin" RM_BUILD_BIN_DIR_NATIVE)
set(ENV{PATH} "$ENV{PATH};${RM_BUILD_BIN_DIR_NATIVE}" )
endif()
# Get Data from OTB :
# - Use this flag to get the full data
set(RM_GET_FULL_DATA OFF)
# - Or give a list of patterns
set(RM_DATA_PATTERNS)
set(RM_DATA_REF develop)
if (RM_GET_FULL_DATA OR RM_DATA_PATTERNS)
message(STATUS "Retrieve data files from OTB")
execute_process(COMMAND git clone -b ${RM_DATA_REF} --depth 1 -n https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb.git
WORKING_DIRECTORY ${REMOTE_MODULE_SOURCE_DIR})
if(RM_GET_FULL_DATA)
message(STATUS " Get full data")
else()
string(REPLACE ";" "," lfs_includes "${RM_DATA_PATTERNS}")
message(STATUS " Get paths: ${RM_DATA_PATTERNS}")
execute_process(COMMAND git config lfs.fetchinclude "${lfs_includes}"
WORKING_DIRECTORY ${REMOTE_MODULE_SOURCE_DIR}/otb)
endif()
execute_process(COMMAND git lfs fetch
WORKING_DIRECTORY ${REMOTE_MODULE_SOURCE_DIR}/otb)
execute_process(COMMAND git reset HEAD *
WORKING_DIRECTORY ${REMOTE_MODULE_SOURCE_DIR}/otb
OUTPUT_QUIET)
execute_process(COMMAND git checkout -- Data/*
WORKING_DIRECTORY ${REMOTE_MODULE_SOURCE_DIR}/otb)
set( CONFIGURE_OPTIONS "${CONFIGURE_OPTIONS}-DOTB_DATA_ROOT:PATH=${REMOTE_MODULE_SOURCE_DIR}/otb/Data;")
endif()
# End of configuration
ctest_start (Experimental TRACK RemoteModules)
ctest_update()
# --------------------------- Configure ----------------------------------------
ctest_configure(BUILD "${CTEST_BINARY_DIRECTORY}"
SOURCE "${REMOTE_MODULE_SOURCE_DIR}"
OPTIONS "${CONFIGURE_OPTIONS}"
RETURN_VALUE _configure_rv
CAPTURE_CMAKE_ERROR _configure_error
)
# Configure log
file ( WRITE
"${REMOTE_MODULE_SOURCE_DIR}/log/configure_return_value_log.txt" "${_configure_rv}")
file ( WRITE
"${REMOTE_MODULE_SOURCE_DIR}/log/configure_cmake_error_log.txt" "${_configure_error}")
if ( NOT _configure_rv EQUAL 0 )
# stop processing here
ctest_submit()
message( FATAL_ERROR "An error occurs during ctest_configure.")
endif()
# ------------------------------ Build -----------------------------------------
if(ci_skip_install)
message(STATUS "Skip install")
if (ci_build_target)
message(STATUS "Building target: ${ci_build_target}")
set(CTEST_BUILD_TARGET ${ci_build_target})
else()
set(CTEST_BUILD_TARGET)
endif()
else()
set(CTEST_BUILD_TARGET install)
endif()
ctest_build(BUILD "${CTEST_BINARY_DIRECTORY}"
RETURN_VALUE _build_rv
CAPTURE_CMAKE_ERROR _build_error
)
# Build log
file ( WRITE
"${REMOTE_MODULE_SOURCE_DIR}/log/build_return_value_log.txt" "${_build_rv}")
file ( WRITE
"${REMOTE_MODULE_SOURCE_DIR}/log/build_cmake_error_log.txt" "${_build_error}")
if ( NOT _build_rv EQUAL 0 )
message( SEND_ERROR "An error occurs during ctest_build.")
endif()
# ----------------------------- Test -------------------------------------------
if(ci_skip_testing)
message(STATUS "Skip testing")
set(_test_rv 0)
else()
ctest_test(PARALLEL_LEVEL 2
RETURN_VALUE _test_rv
CAPTURE_CMAKE_ERROR _test_error
)
# Test log
file ( WRITE
"${REMOTE_MODULE_SOURCE_DIR}/log/test_return_value_log.txt" "${_test_rv}")
file ( WRITE
"${REMOTE_MODULE_SOURCE_DIR}/log/test_cmake_error_log.txt" "${_test_error}")
endif()
if ( NOT _test_rv EQUAL 0 )
message( SEND_ERROR "An error occurs during ctest_test.")
endif()
# ----------------------------- Submit -----------------------------------------
if(ci_skip_submit)
message(STATUS "Skip submit")
else()
ctest_submit()
endif()
......@@ -37,7 +37,6 @@ short get_elev_snowline_from_bin(const itk::Statistics::ImageToHistogramFilter<i
*/
int compute_nb_pixels_between_bounds(const std::string & infname, const int lowerbound, const int upperbound);
/**
* \fn void print_histogram (const itk::Statistics::ImageToHistogramFilter<itk::VectorImage<short, 2> >::HistogramType & histogram, const char * histo_file)
* \brief Print histogram values to file (useful to validate)
......
set(DOCUMENTATION "OTB module for snow cover extent detection algorithm LIS.")
set(DOCUMENTATION "LIS (Let It Snow) OTB Module.")
# otb_module() defines the module dependencies of ExternalTemplate.
# otb_module() defines the module dependencies of LISOTBModule.
# LISOTBModule depends on:
# - OTBCommon (base dependency of all modules)
# - OTBApplicationEngine (because we build an application in the module, see 'app' folder)
#
#
# The tests of module LISOTBModule drag additional dependencies:
# - OTBTestKernel (needed for any test driver)
# - OTBCommandLine (needed to run tests on applications)
......@@ -12,22 +12,21 @@ set(DOCUMENTATION "OTB module for snow cover extent detection algorithm LIS.")
#
# The option ENABLE_SHARED is needed because this module creates a shared
# library. It generates a header with usefull export macros
# (ExternalTemplateExport.h), so that other binaries can link to this library.
# (LISOTBModuleExport.h), so that other binaries can link to this library.
# define the dependencies of the include module and the tests
otb_module(LISOTBModule
ENABLE_SHARED
DEPENDS
OTBCommon
OTBBoost
OTBApplicationEngine
OTBConvolution
OTBMetadata
OTBStatistics
OTBImageBase
OTBImageIO
OTBITK
TEST_DEPENDS
OTBTestKernel
OTBCommandLine
OTBSWIG
DESCRIPTION
"${DOCUMENTATION}"
)
)
\ No newline at end of file
# ${otb-module} will be the name of this module, and also the name of its
# library. It will not need to be changed when this module is renamed.
set(${otb-module}_SRC
histo_utils.cxx
)
add_library(${otb-module} ${${otb-module}_SRC})
target_link_libraries(${otb-module} ${OTBCommon_LIBRARIES} ${OTBImageIO_LIBRARIES} ${OTBApplicationEngine_LIBRARIES} ${OTBITK_LIBRARIES} )
otb_module_target(${otb-module})
##${otb-module} will be the name of this module and will not need to be
#changed when this module is renamed.
set(${otb-module}_SRC
histo_utils.cxx
)
add_library(${otb-module} ${${otb-module}_SRC})
# note : ${${otb-module}_LIBRARIES} contains all dependencies declared in otb-module.cmake
target_link_libraries(${otb-module} ${${otb-module}_LIBRARIES})
otb_module_target(${otb-module})
......@@ -171,6 +171,8 @@ short compute_snowline(const std::string & infname, const std::string & inmasksn
return compute_snowline_internal(imageToVectorImageFilter->GetOutput(), min, max, dz, fsnow_lim, fclear_lim, reverse, offset, center_offset, histo_file);
}
short compute_snowline_internal(const itk::VectorImage<short, 2>::Pointer compose_image, const short min, const short max, const int dz, const float fsnow_lim, const float fclear_lim, const bool reverse, const int offset, const int center_offset, const char* histo_file)
{
typedef itk::VectorImage<short, 2> VectorImageType;
......
import sys
import subprocess
import itertools
import os
def validate_pair(ob):
try:
if not (len(ob) == 2):
print("Unexpected result:", ob, file=sys.stderr)
raise ValueError
except:
return False
return True
def consume(iter):
try:
while True: next(iter)
except StopIteration:
pass
def get_environment_from_batch_command(env_cmd, initial=None):
"""
Take a command (either a single command or list of arguments)
and return the environment created after running that command.
Note that if the command must be a batch file or .cmd file, or the
changes to the environment will not be captured.
If initial is supplied, it is used as the initial environment passed
to the child process.
"""
if not isinstance(env_cmd, (list, tuple)):
env_cmd = [env_cmd]
# construct the command that will alter the environment
env_cmd = subprocess.list2cmdline(env_cmd)
# create a tag so we can tell in the output when the proc is done
tag = b'Done running command'
# construct a cmd.exe command to do accomplish this
cmd = 'cmd.exe /s /c "{env_cmd} && echo "{tag}" && set"'.format(**vars())
# launch the process
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=initial)
# parse the output sent to stdout
lines = proc.stdout
# consume whatever output occurs until the tag is reached
consume(itertools.takewhile(lambda l: tag not in l, lines))
# define a way to handle each KEY=VALUE line
handle_line = lambda l: l.decode('mbcs').rstrip(" ;\r\n").split('=',1)
# parse key/values into pairs
pairs = map(handle_line, lines)
# make sure the pairs are valid
valid_pairs = filter(validate_pair, pairs)
# construct a dictionary of the pairs
result = dict(valid_pairs)
# let the process finish
proc.communicate()
return result
def get_vcvars_for_bash(env_cmd):
backup = os.environ.copy()
frozen_keys=[]
for k in backup.keys():
if not k in ['LIB', 'INCLUDE', 'LIBPATH', 'PATH']:
frozen_keys.append(k)
vc_env = get_environment_from_batch_command( env_cmd )
for k,v in vc_env.items():
k = k.upper()
if k in frozen_keys:
continue
v = ":".join(subprocess.check_output(["cygpath","-u",p]).decode("utf-8").rstrip(" \n") for p in v.split(";"))
v = v.replace("'",r"\'")
print("export %(k)s='%(v)s'" % locals())
if __name__ == '__main__':
get_vcvars_for_bash(sys.argv[1:])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment