Skip to content

Commit

Permalink
started switching to pybind
Browse files Browse the repository at this point in the history
  • Loading branch information
ackhoury committed Jun 7, 2019
1 parent eefbda7 commit 445a1f4
Show file tree
Hide file tree
Showing 19 changed files with 624 additions and 154 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
**.cache
**build
**bin
**.egg-info
**.egg-info
**lib
**.so
**.a
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "deps/pybind11"]
path = deps/pybind11
url = https://github.com/pybind/pybind11.git
31 changes: 31 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 2.8.3)
project(bc_exploration)

set(CMAKE_BUILD_TYPE RELEASE)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bc_exploration)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -O3 -Wall -fpic")

# find current version of python 2.7
execute_process(
COMMAND "python2.7" -c "from distutils import sysconfig; print(sysconfig.get_python_inc())"
OUTPUT_VARIABLE PYTHON_INCLUDE_DIRS
OUTPUT_STRIP_TRAILING_WHITESPACE
)

include_directories(
${PYTHON_INCLUDE_DIRS}
"${PROJECT_SOURCE_DIR}/bc_exploration/cpp/inc/"
"${PROJECT_SOURCE_DIR}/deps/pybind11/include"
)

set(SOURCE_FILES
bc_exploration/cpp/src/exploration/astar.cpp
bc_exploration/cpp/src/exploration/collision.cpp
bc_exploration/cpp/src/exploration/util.cpp
)

#add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES})

add_library(exploration_module SHARED ${PROJECT_SOURCE_DIR} ${SOURCE_FILES} bc_exploration/cpp/src/exploration/python.cpp)
target_link_libraries(exploration_module ${PYTHON_LIBRARIES})
set_target_properties(exploration_module PROPERTIES SUFFIX ".so" PREFIX "_")
33 changes: 27 additions & 6 deletions bc_exploration/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
cmake_minimum_required(VERSION 2.8.3)
project(astar_cpp)
project(bc_exploration)

set(CMAKE_BUILD_TYPE RELEASE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3 -Wall -shared -fpic")
set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -O3 -Wall -fpic")

# find current version of python 2.7
execute_process(
COMMAND "python2.7" -c "from distutils import sysconfig; print(sysconfig.get_python_inc())"
OUTPUT_VARIABLE PYTHON_INCLUDE_DIRS
OUTPUT_STRIP_TRAILING_WHITESPACE
)

include_directories(
${PYTHON_INCLUDE_DIRS}
"${PROJECT_SOURCE_DIR}/inc/"
"${PROJECT_SOURCE_DIR}../../deps/pybind11/include"
)

set(SOURCE_FILES
src/exploration/astar.cpp
src/exploration/collision.cpp
src/exploration/util.cpp
)

file(GLOB all_files "inc/exploration/*.h" "src/exploration/*.cpp")
#add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES})

add_library(exploration SHARED ${all_files})
set_target_properties(exploration PROPERTIES SUFFIX ".so" PREFIX "")
add_library(exploration_module SHARED ${PROJECT_SOURCE_DIR} ${SOURCE_FILES} src/exploration/python.cpp)
target_link_libraries(exploration_module ${PYTHON_LIBRARIES})
set_target_properties(exploration_module PROPERTIES SUFFIX ".so" PREFIX "_")
25 changes: 14 additions & 11 deletions bc_exploration/cpp/inc/exploration/astar.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
#include <cmath>
#include <stack>
#include <vector>
#include <stdexcept>

#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
#include <pybind11/functional.h>

#include "collision.h"

Expand All @@ -16,22 +22,19 @@ struct Node {
Node(const float f, const int idx) : f(f), idx(idx) {}
};

bool operator>(const Node &n1, const Node &n2) {
return n1.f > n2.f;
}
bool operator>(const Node &n1, const Node &n2);

extern "C" bool astar(const int* start, const int* goal,
const uint8_t* occupancy_map, const int* map_shape, int planning_scale,
const uint8_t* obstacle_values, int num_obstacle_values,
float delta, float epsilon, bool allow_diagonal,
int* path);

extern "C" void get_astar_angles(float* angles);
std::vector<float> get_astar_angles();

extern "C" bool oriented_astar(const int* start, const int* goal,
const uint8_t* occupancy_map, const int* map_shape, int costmap_scale,
const bool* footprint_masks, const float* mask_angles, int mask_radius,
const int* outline_coords, int num_coords,
const uint8_t* obstacle_values, int num_obstacle_values,
float delta, float epsilon, bool allow_diagonal,
int* path_idxs, float* path_angles);
std::tuple<bool, std::vector<int>, std::vector<float>> oriented_astar(const int* start, const int* goal,
const uint8_t* occupancy_map, const int* map_shape, int planning_scale,
const bool* footprint_masks, const float* mask_angles, int mask_radius,
const int* outline_coords, int num_coords,
const uint8_t* obstacle_values, int num_obstacle_values,
float delta, float epsilon, bool allow_diagonal);
15 changes: 14 additions & 1 deletion bc_exploration/cpp/inc/exploration/collision.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,20 @@

#include <iostream>

#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
#include <pybind11/functional.h>
#include "safe_array.h"

extern "C" bool check_for_collision(const int* position, const uint8_t* occupancy_map, const int* map_shape,
const bool* footprint_mask, int mask_radius,
const int* outline_coords, int num_coords,
const uint8_t* obstacle_values, int num_obstacle_values);
const uint8_t* obstacle_values, int num_obstacle_values);


bool check_for_collision2(pybind11::safe_array<int, 1> position,
pybind11::safe_array<uint8_t, 2> occupancy_map,
pybind11::safe_array<bool, 2> footprint_mask,
pybind11::safe_array<int, 2> outline_coords,
pybind11::safe_array<uint8_t, 1> obstacle_values);
Loading

0 comments on commit 445a1f4

Please sign in to comment.