diff --git a/.github/workflows/github-opengjk-examples.yml b/.github/workflows/github-opengjk-examples.yml new file mode 100644 index 0000000..32336b5 --- /dev/null +++ b/.github/workflows/github-opengjk-examples.yml @@ -0,0 +1,55 @@ +name: Run all demos +run-name: ${{ github.actor }} is running +on: [push] +jobs: + C: + runs-on: ubuntu-latest + container: mmontanari/devenv:buildenv-fedora + steps: + - name: Check out repository code + uses: actions/checkout@v3 + - run: cmake -E make_directory build + - run: cmake -E chdir build cmake -DCMAKE_BUILD_TYPE=Release .. + - run: cmake --build build + - run: cmake -E chdir build/examples/c/ ./example_lib_opengjk_ce + + Cython: + runs-on: ubuntu-latest + container: mmontanari/devenv:buildenv-ubuntu + steps: + - name: Check out repository code + uses: actions/checkout@v3 + - run: cd examples/cython/ && python3 setup.py build_ext --inplace && python3 pygjk_trial.py + - run: cd examples/cython/ && pytest test.py + + CSharp: + runs-on: ubuntu-latest + container: mono:latest + steps: + - name: Check out repository code + uses: actions/checkout@v3 + - run: apt-get update && apt-get install gcc cmake -y + - run: cmake -E make_directory build + - run: cmake -E chdir build cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_MONO=ON .. + - run: cmake --build build + - run: cmake -E chdir build make install + - run: cd examples/cs/ && mcs -out:main.exe main.cs && mono main.exe + + GO: + runs-on: ubuntu-latest + container: mmontanari/devenv:buildenv-fedora + steps: + - uses: actions/checkout@v3 + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.15 + - run: cd examples/go/openGJK && go build && go test -v + + Octave: + runs-on: ubuntu-latest + container: gnuoctave/octave:7.3.0 + steps: + - name: Check out repository code + uses: actions/checkout@v3 + - run: cd examples/matlab/; octave runme.m diff --git a/CMakeLists.txt b/CMakeLists.txt index b243977..8c5e8d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,15 +21,16 @@ # FOR A PARTICULAR PURPOSE. See GNU General Public License for details. # # User options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . -option(BUILD_EXAMPLE "Build demo" ON) +option(BUILD_EXAMPLE "Build demo" ON ) +option(BUILD_MONO "Build C# example" OFF) # CMake setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cmake_minimum_required(VERSION 3.0) # You can downgrade to 2.8, but I don't maintain it anymore cmake_policy(SET CMP0048 NEW) cmake_policy(SET CMP0063 NEW) # Visibility of preset and hidden lines on shared libs -set( CMAKE_C_VISIBILITY_PRESET hidden) -set( CMAKE_VISIBILITY_INLINES_HIDDEN TRUE) +# set( CMAKE_C_VISIBILITY_PRESET hidden) +set( CMAKE_VISIBILITY_INLINES_HIDDEN FALSE) set( CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) # Project setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . @@ -58,26 +59,34 @@ elseif (CMAKE_C_COMPILER_ID STREQUAL "MSVC") endif() # Target . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . -add_library( ${PROJECT_NAME} - STATIC + +if(BUILD_MONO) + add_compile_definitions(CS_MONO_BUILD) +endif(BUILD_MONO) + +add_library( obj_openGJK + OBJECT ${CMAKE_CURRENT_SOURCE_DIR}/openGJK.c ${CMAKE_CURRENT_SOURCE_DIR}/include/openGJK/openGJK.h ) -target_include_directories( ${PROJECT_NAME} +target_include_directories( obj_openGJK PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_BINARY_DIR} ) -target_link_libraries(${PROJECT_NAME} PRIVATE m) +target_link_libraries(obj_openGJK PRIVATE m) -set_target_properties(${PROJECT_NAME} +set_target_properties(obj_openGJK PROPERTIES C_STANDARD 11 PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include/openGJK/openGJK.h + POSITION_INDEPENDENT_CODE 1 ) +add_library(opengjk_ce SHARED $) + # Build demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . if(BUILD_EXAMPLE) add_subdirectory(examples/c) @@ -85,11 +94,11 @@ endif(BUILD_EXAMPLE) # Install . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . if (UNIX) - install(TARGETS ${PROJECT_NAME} PERMISSIONS WORLD_WRITE ) set(DESTDIR "/usr") - INSTALL(TARGETS ${PROJECT_NAME} + INSTALL(TARGETS opengjk_ce LIBRARY DESTINATION "${DESTDIR}/lib" PUBLIC_HEADER DESTINATION "${DESTDIR}/include" + PERMISSIONS WORLD_WRITE ) endif (UNIX) diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt index c599e74..10fac5a 100644 --- a/examples/c/CMakeLists.txt +++ b/examples/c/CMakeLists.txt @@ -25,12 +25,12 @@ project(example_lib_opengjk_ce VERSION 1.0.0 ) -add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/main.c) -target_link_libraries(${PROJECT_NAME} lib_opengjk_ce) +add_executable(example_lib_opengjk_ce ${CMAKE_CURRENT_SOURCE_DIR}/main.c) +target_link_libraries(example_lib_opengjk_ce obj_openGJK m) # Copy input files for this example after build add_custom_command( - TARGET ${PROJECT_NAME} POST_BUILD + TARGET example_lib_opengjk_ce POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/userP.dat ${CMAKE_CURRENT_BINARY_DIR}/userP.dat diff --git a/examples/cs/main.cs b/examples/cs/main.cs index 8be1370..5cb1023 100644 --- a/examples/cs/main.cs +++ b/examples/cs/main.cs @@ -34,10 +34,13 @@ using System.Runtime.InteropServices; public class Tester { - - [DllImport("libopenGJKlib", EntryPoint="csFunction", CallingConvention = CallingConvention.StdCall)] +#if UNIX + [DllImport("libopengjk_ce.so", EntryPoint="csFunction", CallingConvention = CallingConvention.StdCall)] +#else + [DllImport("libopengjk_ce", EntryPoint = "csFunction", CallingConvention = CallingConvention.StdCall)] +#endif - static extern double gjk(int na, double [,] ia, int nb, double [,] ib); + static extern double compute_minimum_distance(int na, double [,] ia, int nb, double [,] ib); public static void Main(string[] args) { @@ -51,13 +54,12 @@ public class Tester var inCoordsB = new double[3,9] { {-0.0 , -2.3 , -8.1 , -4.3 ,-2.5 , -7.1 , -1.0 , -3.3 , -6.0} , { -5.5 , -1.0 ,- 4.0 ,- 5.0 ,-1.0, -1.0, -1.5, -0.5 , -1.4} ,{ -0.0 , 2.0, -2.4, -2.2, -2.3 , -2.4 , -0.3 , -0.3 , -0.2} }; // Invoke GJK to compute distance - dist = gjk( nCoordsA, inCoordsA, nCoordsB, inCoordsB ); + dist = compute_minimum_distance( nCoordsA, inCoordsA, nCoordsB, inCoordsB ); // Output results var s = string.Format("{0:0.##}", dist); var message = string.Format("The distance between {0} is {1}","A and B",s); Console.WriteLine(message); - Console.WriteLine("Press any key to exit"); - Console.ReadLine(); + } } diff --git a/examples/cython/pygjk_trial.py b/examples/cython/pygjk_trial.py index 3b68b7a..d0f05be 100644 --- a/examples/cython/pygjk_trial.py +++ b/examples/cython/pygjk_trial.py @@ -1,38 +1,30 @@ -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # -# ##### # # # # -# #### ##### ###### # # # # # # # # -# # # # # # ## # # # # # # -# # # # # ##### # # # # #### # ### # -# # # ##### # # # # # # # # # # # -# # # # # # ## # # # # # # # -# #### # ###### # # ##### ##### # # # -# # -# This file is part of openGJK. # -# # -# OpenGJK is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# any later version. # -# # -# OpenGJK is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See The # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with OpenGJK. If not, see . # -# # -# openGJK: open-source Gilbert-Johnson-Keerthi algorithm # -# Copyright (C) Mattia Montanari 2018 - 2020 # -# http://iel.eng.ox.ac.uk/?page_id=504 # -# # -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# _____ _ _ __ # +# / ____| | | |/ / # +# ___ _ __ ___ _ __ | | __ | | ' / # +# / _ \| '_ \ / _ \ '_ \| | |_ |_ | | < # +# | (_) | |_) | __/ | | | |__| | |__| | . \ # +# \___/| .__/ \___|_| |_|\_____|\____/|_|\_\ # +# | | # +# |_| # +# # +# Copyright 2022 Mattia Montanari, University of Oxford # +# # +# 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 the Free Software # +# Foundation, either version 3 of the License. You should have received a copy # +# of the GNU General Public License along with this program. If not, visit # +# # +# https://www.gnu.org/licenses/ # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # +# FOR A PARTICULAR PURPOSE. See GNU General Public License for details. # import numpy as np import openGJK_cython as opengjk -a = np.array([[1.,1.,1.],[1.,1.,1.]]) -b = np.array([[11.,1.,1.],[1.,1.,1.]]) +a = np.array([[1.0,1.0,1.0],[1.0,1.0,1.0]]) +b = np.array([[-1.,-1.,-1.],[-1.,-1.,-1.]]) d = opengjk.pygjk(a,b) -print(d) \ No newline at end of file +print("Distance is:" , d) \ No newline at end of file diff --git a/examples/cython/setup.py b/examples/cython/setup.py index 5805e75..48f074e 100644 --- a/examples/cython/setup.py +++ b/examples/cython/setup.py @@ -34,8 +34,7 @@ from Cython.Build import cythonize exts = Extension( "openGJK_cython", sources = ["openGJK_cython.pyx"], - extra_compile_args=['-I../../include/','-fopenmp'], - extra_link_args=['-fopenmp'], + extra_compile_args=['-I../../include/'] ) setup( diff --git a/examples/matlab/main.m b/examples/matlab/main.m index 741e5b8..ab555a4 100644 --- a/examples/matlab/main.m +++ b/examples/matlab/main.m @@ -32,31 +32,33 @@ B = -A; dist = openGJK( A, B ); fprintf('The minimum distance between A and B is %.2f\n',dist); -% VISUALISE RESULTS -% .. create new figure -figure('units','centimeters', 'WindowStyle','normal', 'color','w',... - 'Position',[0 8.5 9 6],'defaultAxesColorOrder',parula,... - 'Renderer','opengl') -% .. adjust properties -axis equal tight off; hold all; -% .. display body A -DT = delaunayTriangulation(A'); -[K,~] = convexHull(DT); -trisurf(K,DT.Points(:,1),DT.Points(:,2),DT.Points(:,3),... - 'EdgeColor','none','FaceColor',[.4 1 .9 ],... - 'FaceLighting','flat' ) -% .. display body B -DT = delaunayTriangulation(B'); -[K,~] = convexHull(DT); -trisurf(K,DT.Points(:,1),DT.Points(:,2),DT.Points(:,3),... - 'EdgeColor','none','FaceColor',[.4 1 .8 ],... - 'FaceLighting','flat' ) -% .. represent the computed distance as a sphere -[x,y,z] = sphere(100); -surf(x.*dist/2,y.*dist/2,z.*dist/2,'facecolor',[.9 .9 .9],... - 'EdgeColor','none','FaceLighting','flat','SpecularColorReflectance',0,... - 'SpecularStrength',1,'SpecularExponent',10,'facealpha',.7) -% ... adjust point of view -view(42,21) -% ... add light -light('Position',[5 -10 20],'Style','local'); +% VISUALISE RESULTS ONLY IN MATLAB +if(exist('OCTAVE_VERSION', 'builtin') == 0) + % .. create new figure + figure('units','centimeters', 'WindowStyle','normal', 'color','w',... + 'Position',[0 8.5 9 6],'defaultAxesColorOrder',parula,... + 'Renderer','opengl') + % .. adjust properties + axis equal tight off; hold all; + % .. display body A + DT = delaunayTriangulation(A'); + [K,~] = convexHull(DT); + trisurf(K,DT.Points(:,1),DT.Points(:,2),DT.Points(:,3),... + 'EdgeColor','none','FaceColor',[.4 1 .9 ],... + 'FaceLighting','flat' ) + % .. display body B + DT = delaunayTriangulation(B'); + [K,~] = convexHull(DT); + trisurf(K,DT.Points(:,1),DT.Points(:,2),DT.Points(:,3),... + 'EdgeColor','none','FaceColor',[.4 1 .8 ],... + 'FaceLighting','flat' ) + % .. represent the computed distance as a sphere + [x,y,z] = sphere(100); + surf(x.*dist/2,y.*dist/2,z.*dist/2,'facecolor',[.9 .9 .9],... + 'EdgeColor','none','FaceLighting','flat','SpecularColorReflectance',0,... + 'SpecularStrength',1,'SpecularExponent',10,'facealpha',.7) + % ... adjust point of view + view(42,21) + % ... add light + light('Position',[5 -10 20],'Style','local'); +end \ No newline at end of file diff --git a/examples/matlab/runme.m b/examples/matlab/runme.m index bc1a1d1..0d7edf0 100644 --- a/examples/matlab/runme.m +++ b/examples/matlab/runme.m @@ -29,35 +29,20 @@ else optflug = '-O'; end % SELECT SILET COMPILATION MODE. -if 1 +if 1 silflag = '-silent'; else silflag = '-v'; end -% TRY COMPILING MEX FILE -fprintf('Compiling mex function... ') -try -mex(fullfile('..','..','openGJK.c'),... % Source of openGJK +% COMPILE MEX FILE +mex(fullfile('..','..','openGJK.c'),... '-largeArrayDims', ... % Support large arrays - optflug, ... % Compiler flag for debug/optimisation - fullfile('-I','..','..','include'),... % Folder to header files - '-outdir', pwd, ... % Ouput directory for writing mex function + optflug, ... + ['-I',fullfile('..','..','include')],... % Folder to header files '-output', 'openGJK',... % Name of ouput mex file '-DMATLAB_MEX_BUILD',... % Define variable for mex function in source files - silflag ) % Silent/verbose flag - - % File compiled without errors. Return path and name of mex file - fprintf('completed!\n') - fprintf('The following mex file has been generated:') - fprintf('\t%s\n',[pwd,filesep,'openGJK.',mexext]) -catch - % Build failed, refer to documentation - fprintf('\n\n ERROR DETECTED! Mex file cannot be compiled.\n') - fprintf('\tFor more information, see ') - fprintf('this documentation page.\n\n') - return -end + silflag ) % RUN EXAMPLE fprintf('Running example... ')