diff --git a/.github/workflows/ros_workspace.yml b/.github/workflows/ros_workspace.yml index 15fe40af..e2fbd93c 100644 --- a/.github/workflows/ros_workspace.yml +++ b/.github/workflows/ros_workspace.yml @@ -152,7 +152,7 @@ jobs: submodules: recursive - name: Setup ROS environment - uses: ros-tooling/setup-ros@v0.3 + uses: ros-tooling/setup-ros@v0.4 - name: ROS 1 CI Action if: ${{ matrix.ros_version == 1 }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 886edb90..982f8d76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,16 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) project(apriltag VERSION 3.3.0 LANGUAGES C CXX) +if (MSVC) + add_compile_definitions("_CRT_SECURE_NO_WARNINGS") +endif() + if(POLICY CMP0077) cmake_policy(SET CMP0077 NEW) endif() + option(BUILD_SHARED_LIBS "Build shared libraries" ON) +option(BUILD_EXAMPLES "Build example binaries" ON) option(ASAN "Use AddressSanitizer for debug builds to detect memory issues" OFF) if (ASAN) @@ -38,150 +44,20 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") endif() -aux_source_directory(common COMMON_SRC) -set(APRILTAG_SRCS apriltag.c apriltag_pose.c apriltag_quad_thresh.c) - -# Library -file(GLOB TAG_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tag*.c) -add_library(${PROJECT_NAME} ${APRILTAG_SRCS} ${COMMON_SRC} ${TAG_FILES}) - -if (MSVC) - add_compile_definitions("_CRT_SECURE_NO_WARNINGS") -else() - find_package(Threads REQUIRED) - target_link_libraries(${PROJECT_NAME} PUBLIC Threads::Threads m) -endif() - -set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION 3 VERSION ${PROJECT_VERSION}) -set_target_properties(${PROJECT_NAME} PROPERTIES DEBUG_POSTFIX "d") - -include(GNUInstallDirs) -target_include_directories(${PROJECT_NAME} PUBLIC - "$" - "$" - "$/apriltag") - - -# install header file hierarchy -file(GLOB HEADER_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h common/*.h) -list(REMOVE_ITEM HEADER_FILES apriltag_detect.docstring.h apriltag_py_type.docstring.h) - -foreach(HEADER ${HEADER_FILES}) - string(REGEX MATCH "(.*)[/\\]" DIR ${HEADER}) - install(FILES ${HEADER} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${DIR}) -endforeach() - -# export library -set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated") -set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake") -set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake") -set(targets_export_name "${PROJECT_NAME}Targets") -set(config_install_dir "share/${PROJECT_NAME}/cmake") - -# Include module with fuction 'write_basic_package_version_file' -include(CMakePackageConfigHelpers) - -# Configure 'Config.cmake' -# Use variables: -# * targets_export_name -# * PROJECT_NAME -configure_package_config_file( - "CMake/apriltagConfig.cmake.in" - "${project_config}" - INSTALL_DESTINATION "${config_install_dir}" -) +# build main library +add_subdirectory(libs/apriltag) -# Configure 'ConfigVersion.cmake' -# Note: PROJECT_VERSION is used as a VERSION -write_basic_package_version_file("${version_config}" COMPATIBILITY SameMajorVersion) - - -# install library -install(TARGETS ${PROJECT_NAME} EXPORT ${targets_export_name} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) - -install(EXPORT ${targets_export_name} - NAMESPACE apriltag:: - DESTINATION ${config_install_dir}) - -install(FILES ${project_config} ${version_config} DESTINATION ${config_install_dir}) - -export(TARGETS apriltag - NAMESPACE apriltag:: - FILE ${generated_dir}/${targets_export_name}.cmake) - - -# install pkgconfig file -configure_file(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) -install(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") - - -# Python wrapper +## Python wrapper include(CMakeDependentOption) cmake_dependent_option(BUILD_PYTHON_WRAPPER "Builds Python wrapper" ON BUILD_SHARED_LIBS OFF) if(BUILD_PYTHON_WRAPPER) - SET(Python_ADDITIONAL_VERSIONS 3) - find_package(PythonLibs) - execute_process(COMMAND which python3 OUTPUT_QUIET RESULT_VARIABLE Python3_NOT_FOUND) - execute_process(COMMAND python3 -c "import numpy" RESULT_VARIABLE Numpy_NOT_FOUND) -endif(BUILD_PYTHON_WRAPPER) - -if (NOT Python3_NOT_FOUND AND NOT Numpy_NOT_FOUND AND PYTHONLIBS_FOUND AND BUILD_PYTHON_WRAPPER) - # TODO deal with both python2/3 - execute_process(COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/python_build_flags.py OUTPUT_VARIABLE PY_OUT) - set(PY_VARS CFLAGS LDFLAGS LINKER EXT_SUFFIX) - cmake_parse_arguments(PY "" "${PY_VARS}" "" ${PY_OUT}) - separate_arguments(PY_CFLAGS) - list(REMOVE_ITEM PY_CFLAGS -flto) - separate_arguments(PY_LDFLAGS) - - foreach(X detect py_type) - add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/apriltag_${X}.docstring.h - COMMAND < ${CMAKE_CURRENT_SOURCE_DIR}/apriltag_${X}.docstring sed 's/\"/\\\\\"/g\; s/^/\"/\; s/$$/\\\\n\"/\;' > apriltag_${X}.docstring.h - WORKING_DIRECTORY ${PROJECT_BINARY_DIR}) - endforeach() - - add_custom_command(OUTPUT apriltag_pywrap.o - COMMAND ${CMAKE_C_COMPILER} ${PY_CFLAGS} -I${PROJECT_BINARY_DIR} -c -o apriltag_pywrap.o ${CMAKE_CURRENT_SOURCE_DIR}/apriltag_pywrap.c - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/apriltag_pywrap.c ${PROJECT_BINARY_DIR}/apriltag_detect.docstring.h ${PROJECT_BINARY_DIR}/apriltag_py_type.docstring.h) - add_custom_command(OUTPUT apriltag${PY_EXT_SUFFIX} - COMMAND ${PY_LINKER} ${PY_LDFLAGS} -Wl,-rpath,lib apriltag_pywrap.o $ -o apriltag${PY_EXT_SUFFIX} - DEPENDS ${PROJECT_NAME} apriltag_pywrap.o) - add_custom_target(apriltag_python ALL - DEPENDS apriltag${PY_EXT_SUFFIX}) - -execute_process(COMMAND python3 -m site --user-site OUTPUT_VARIABLE PY_DEST) -string(STRIP ${PY_DEST} PY_DEST) -install(FILES ${PROJECT_BINARY_DIR}/apriltag${PY_EXT_SUFFIX} DESTINATION ${PY_DEST}) -endif (NOT Python3_NOT_FOUND AND NOT Numpy_NOT_FOUND AND PYTHONLIBS_FOUND AND BUILD_PYTHON_WRAPPER) + # build python wrapper + add_subdirectory(libs/apriltag_python) +endif() # Examples -# apriltag_demo -add_executable(apriltag_demo example/apriltag_demo.c) -target_link_libraries(apriltag_demo ${PROJECT_NAME}) - -# opencv_demo -set(_OpenCV_REQUIRED_COMPONENTS core imgproc videoio highgui) -find_package(OpenCV COMPONENTS ${_OpenCV_REQUIRED_COMPONENTS} QUIET CONFIG) -if(OpenCV_FOUND) - # NB: contrib required for TickMeter in OpenCV 2.4. This is only required for 16.04 backwards compatibility and can be removed in the future. - # If we add it to the find_package initially, the demo won't build for newer OpenCV versions - if(OpenCV_VERSION VERSION_LESS "3.0.0") - list(APPEND _OpenCV_REQUIRED_COMPONENTS contrib) - find_package(OpenCV COMPONENTS ${_OpenCV_REQUIRED_COMPONENTS} CONFIG) - endif() - - add_executable(opencv_demo example/opencv_demo.cc) - target_link_libraries(opencv_demo apriltag ${OpenCV_LIBRARIES}) - set_target_properties(opencv_demo PROPERTIES CXX_STANDARD 11) - install(TARGETS opencv_demo RUNTIME DESTINATION bin) -else() - message(STATUS "OpenCV not found: Not building demo") -endif(OpenCV_FOUND) - -# install example programs -install(TARGETS apriltag_demo RUNTIME DESTINATION bin) +if(BUILD_EXAMPLES) + # build examples + add_subdirectory(example) +endif() \ No newline at end of file diff --git a/Makefile b/Makefile index 32574ad3..fcd3ca68 100644 --- a/Makefile +++ b/Makefile @@ -6,9 +6,13 @@ AR = ar CFLAGS = -std=gnu99 -fPIC -Wall -Wno-unused-parameter -Wno-unused-function CFLAGS += -I. -O3 -fno-strict-overflow +ROOT := $(shell pwd) +APRILTAG_DIR := $(ROOT)/libs/apriltag +APRILTAG_SRC_DIR := $(APRILTAG_DIR)/src + #APRILTAG_SRCS := $(shell ls *.c common/*.c) -APRILTAG_SRCS := apriltag.c apriltag_pose.c apriltag_quad_thresh.c common/g2d.c common/getopt.c common/homography.c common/image_u8.c common/image_u8x3.c common/image_u8x4.c common/matd.c common/pam.c common/pjpeg.c common/pjpeg-idct.c common/pnm.c common/string_util.c common/svd22.c common/time_util.c common/unionfind.c common/workerpool.c common/zarray.c common/zhash.c common/zmaxheap.c tag16h5.c tag25h9.c tag36h11.c tagCircle21h7.c tagCircle49h12.c tagCustom48h12.c tagStandard41h12.c tagStandard52h13.c -APRILTAG_HEADERS := $(shell ls *.h common/*.h) +APRILTAG_SRCS := $(APRILTAG_SRC_DIR)/apriltag.c $(APRILTAG_SRC_DIR)/apriltag_pose.c $(APRILTAG_SRC_DIR)/apriltag_quad_thresh.c $(APRILTAG_SRC_DIR)/common/g2d.c $(APRILTAG_SRC_DIR)/common/getopt.c $(APRILTAG_SRC_DIR)/common/homography.c $(APRILTAG_SRC_DIR)/common/image_u8.c $(APRILTAG_SRC_DIR)/common/image_u8x3.c $(APRILTAG_SRC_DIR)/common/image_u8x4.c $(APRILTAG_SRC_DIR)/common/matd.c $(APRILTAG_SRC_DIR)/common/pam.c $(APRILTAG_SRC_DIR)/common/pjpeg.c $(APRILTAG_SRC_DIR)/common/pjpeg-idct.c $(APRILTAG_SRC_DIR)/common/pnm.c $(APRILTAG_SRC_DIR)/common/string_util.c $(APRILTAG_SRC_DIR)/common/svd22.c $(APRILTAG_SRC_DIR)/common/time_util.c $(APRILTAG_SRC_DIR)/common/workerpool.c $(APRILTAG_SRC_DIR)/common/zarray.c $(APRILTAG_SRC_DIR)/common/zhash.c $(APRILTAG_SRC_DIR)/common/zmaxheap.c $(APRILTAG_SRC_DIR)/tag16h5.c $(APRILTAG_SRC_DIR)/tag25h9.c $(APRILTAG_SRC_DIR)/tag36h11.c $(APRILTAG_SRC_DIR)/tagCircle21h7.c $(APRILTAG_SRC_DIR)/tagCircle49h12.c $(APRILTAG_SRC_DIR)/tagCustom48h12.c $(APRILTAG_SRC_DIR)/tagStandard41h12.c $(APRILTAG_SRC_DIR)/tagStandard52h13.c +APRILTAG_HEADERS := $(shell ls $(APRILTAG_DIR)/include/apriltag/*.h $(APRILTAG_DIR)/include/apriltag/common/*.h) APRILTAG_OBJS := $(APRILTAG_SRCS:%.c=%.o) TARGETS := libapriltag.a libapriltag.so @@ -20,7 +24,7 @@ all: $(TARGETS) install: libapriltag.so @chmod +x install.sh @./install.sh $(PREFIX)/lib libapriltag.so - @./install.sh $(PREFIX)/include/apriltag $(APRILTAG_HEADERS) + @./install.sh $(PREFIX)/ $(APRILTAG_HEADERS) @ldconfig libapriltag.a: $(APRILTAG_OBJS) @@ -37,5 +41,5 @@ libapriltag.so: $(APRILTAG_OBJS) .PHONY: clean clean: - @rm -rf *.o common/*.o $(TARGETS) + @rm -rf $(APRILTAG_SRC_DIR)/*.o $(APRILTAG_SRC_DIR)/common/*.o $(TARGETS) @$(MAKE) -C example clean diff --git a/README.md b/README.md index 11fa75ac..cca437fb 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,6 @@ AprilTag is the subject of the following papers. [Flexible Layouts for Fiducial Tags](https://april.eecs.umich.edu/papers/details.php?name=krogius2019iros) - Usage ===== [User Guide](https://github.com/AprilRobotics/apriltag/wiki/AprilTag-User-Guide) @@ -25,7 +24,7 @@ Install Officially only Linux operating systems are supported, although users have had success installing on Windows too. -The default installation will place headers in /usr/local/include and shared library in /usr/local/lib. It also installs a pkg-config script into /usr/local/lib/pkgconfig and will install a python wrapper if python3 is installed. +The default installation will place headers in /usr/local/include and shared libraries in /usr/local/lib. It also installs a pkg-config script into /usr/local/lib/pkgconfig and will install a python wrapper if python3 is installed. ## cmake If you have CMake installed, then do: diff --git a/common/unionfind.c b/common/unionfind.c deleted file mode 100644 index ae429910..00000000 --- a/common/unionfind.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (C) 2013-2016, The Regents of The University of Michigan. -All rights reserved. -This software was developed in the APRIL Robotics Lab under the -direction of Edwin Olson, ebolson@umich.edu. This software may be -available under alternative licensing terms; contact the address above. -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -The views and conclusions contained in the software and documentation are those -of the authors and should not be interpreted as representing official policies, -either expressed or implied, of the Regents of The University of Michigan. -*/ - -#include "unionfind.h" -#include -#include diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt new file mode 100644 index 00000000..79eeeb65 --- /dev/null +++ b/example/CMakeLists.txt @@ -0,0 +1,34 @@ +## Build Examples + +### Note +# apriltag targets are in the same build tree so can be used directly without installation +# or including the build-generated apriltagsTargets.cmake file +# +# Typical usage would be to build and *install* the apriltag libraries and then, for your project use +# find_package(apriltag REQUIRED) +# target_link_libraries(my_application PRIVATE apriltag::detector apriltag::utils apriltag::tags) + +# apriltag_demo +add_executable(apriltag_demo apriltag_demo.c) +target_link_libraries(apriltag_demo PRIVATE apriltag-detector apriltag-utils apriltag-tags) + +set(_OpenCV_REQUIRED_COMPONENTS core imgproc videoio highgui) +find_package(OpenCV COMPONENTS ${_OpenCV_REQUIRED_COMPONENTS} QUIET CONFIG) +if(OpenCV_FOUND) + # NB: contrib required for TickMeter in OpenCV 2.4. This is only required for 16.04 backwards compatibility and can be removed in the future. + # If we add it to the find_package initially, the demo won't build for newer OpenCV versions + if(OpenCV_VERSION VERSION_LESS "3.0.0") + list(APPEND _OpenCV_REQUIRED_COMPONENTS contrib) + find_package(OpenCV COMPONENTS ${_OpenCV_REQUIRED_COMPONENTS} CONFIG) + endif() + + add_executable(opencv_demo opencv_demo.cc) + target_link_libraries(opencv_demo apriltag-detector apriltag-tags apriltag-utils ${OpenCV_LIBRARIES}) + set_target_properties(opencv_demo PROPERTIES CXX_STANDARD 11) + install(TARGETS opencv_demo RUNTIME DESTINATION bin) +else() + message(STATUS "OpenCV not found: Not building demo") +endif(OpenCV_FOUND) + +# install example programs +install(TARGETS apriltag_demo RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) \ No newline at end of file diff --git a/example/apriltag_demo.c b/example/apriltag_demo.c index 6de90540..273f0212 100644 --- a/example/apriltag_demo.c +++ b/example/apriltag_demo.c @@ -41,20 +41,20 @@ either expressed or implied, of the Regents of The University of Michigan. #include #endif -#include "apriltag.h" -#include "tag36h11.h" -#include "tag25h9.h" -#include "tag16h5.h" -#include "tagCircle21h7.h" -#include "tagCircle49h12.h" -#include "tagCustom48h12.h" -#include "tagStandard41h12.h" -#include "tagStandard52h13.h" - -#include "common/getopt.h" -#include "common/image_u8.h" -#include "common/pjpeg.h" -#include "common/zarray.h" +#include "apriltag/apriltag.h" +#include "apriltag/tag36h11.h" +#include "apriltag/tag25h9.h" +#include "apriltag/tag16h5.h" +#include "apriltag/tagCircle21h7.h" +#include "apriltag/tagCircle49h12.h" +#include "apriltag/tagCustom48h12.h" +#include "apriltag/tagStandard41h12.h" +#include "apriltag/tagStandard52h13.h" + +#include "apriltag/common/getopt.h" +#include "apriltag/common/image_u8.h" +#include "apriltag/common/pjpeg.h" +#include "apriltag/common/zarray.h" #define HAMM_HIST_MAX 10 diff --git a/example/opencv_demo.cc b/example/opencv_demo.cc index b43a46eb..856563de 100644 --- a/example/opencv_demo.cc +++ b/example/opencv_demo.cc @@ -31,16 +31,16 @@ either expressed or implied, of the Regents of The University of Michigan. #include "opencv2/opencv.hpp" extern "C" { -#include "apriltag.h" -#include "tag36h11.h" -#include "tag25h9.h" -#include "tag16h5.h" -#include "tagCircle21h7.h" -#include "tagCircle49h12.h" -#include "tagCustom48h12.h" -#include "tagStandard41h12.h" -#include "tagStandard52h13.h" -#include "common/getopt.h" +#include "apriltag/apriltag.h" +#include "apriltag/tag36h11.h" +#include "apriltag/tag25h9.h" +#include "apriltag/tag16h5.h" +#include "apriltag/tagCircle21h7.h" +#include "apriltag/tagCircle49h12.h" +#include "apriltag/tagCustom48h12.h" +#include "apriltag/tagStandard41h12.h" +#include "apriltag/tagStandard52h13.h" +#include "apriltag/common/getopt.h" } using namespace std; diff --git a/CMake/apriltagConfig.cmake.in b/libs/apriltag/CMake/apriltagConfig.cmake.in similarity index 100% rename from CMake/apriltagConfig.cmake.in rename to libs/apriltag/CMake/apriltagConfig.cmake.in diff --git a/libs/apriltag/CMake/apriltagHelperFunctions.cmake b/libs/apriltag/CMake/apriltagHelperFunctions.cmake new file mode 100644 index 00000000..cec8884f --- /dev/null +++ b/libs/apriltag/CMake/apriltagHelperFunctions.cmake @@ -0,0 +1,28 @@ +# Helper Functions +function(set_apriltag_lib_property_defaults target_name) + set_target_properties(${target_name} PROPERTIES SOVERSION 3 VERSION ${PROJECT_VERSION}) + set_target_properties(${target_name} PROPERTIES DEBUG_POSTFIX "d") + set_target_properties(${target_name} PROPERTIES POSITION_INDEPENDENT_CODE ON) +endfunction() + +function(set_apriltag_named_exports_only target_name) + set_target_properties(${target_name} PROPERTIES + C_VISIBILITY_PRESET hidden + CXX_VISIBILITY_PRESET hidden + VISIBILITY_INLINES_HIDDEN ON + WINDOWS_EXPORT_ALL_SYMBOLS OFF + # multiple libs sharing same auto-generated header so override default to use apriltag_EXPORTS + DEFINE_SYMBOL apriltag_EXPORTS + ) +endfunction() + +function(set_apriltag_export_all target_name) + set_target_properties(${target_name} PROPERTIES + C_VISIBILITY_PRESET default + CXX_VISIBILITY_PRESET default + VISIBILITY_INLINES_HIDDEN OFF + WINDOWS_EXPORT_ALL_SYMBOLS ON + # multiple libs sharing same auto-generated header so override default to use apriltag_EXPORTS + DEFINE_SYMBOL apriltag_EXPORTS + ) +endfunction() \ No newline at end of file diff --git a/libs/apriltag/CMakeLists.txt b/libs/apriltag/CMakeLists.txt new file mode 100644 index 00000000..b4e18406 --- /dev/null +++ b/libs/apriltag/CMakeLists.txt @@ -0,0 +1,298 @@ +include(GNUInstallDirs) +include(GenerateExportHeader) +include(CMake/apriltagHelperFunctions.cmake) + +### Build Apriltag Libraries +## The following targets are built +## apriltag-detector (Apriltag's core functionality with only API functions exported) +## apriltag-tags (Apriltag's tag libraries) +## apriltag- e.g apriltag-tagStandard41h12 (Individual libraries for each tag family) +## apriltag-utils (Utility functions used in the examples) +## apriltag *(Legacy build with all functionality (detector, tags, utils) exported) + +### Notes +# CMake Object Libraries are used where possible to minimize repeat compilation of common code +# *except* where object libraries would break the export definitions, especially on Windows +# (https://gitlab.kitware.com/cmake/cmake/-/issues/20057) +# CMake Interface targets are used to share properties with other targets + +set(HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) +set(HEADERS_COMMON_DIR ${HEADERS_DIR}/apriltag/common) + +# Common Souce + +set(HEADERS_COMMON + ${HEADERS_COMMON_DIR}/debug_print.h + ${HEADERS_COMMON_DIR}/image_types.h + ${HEADERS_COMMON_DIR}/image_u8.h + ${HEADERS_COMMON_DIR}/image_u8x3.h + ${HEADERS_COMMON_DIR}/math_util.h + ${HEADERS_COMMON_DIR}/pnm.h + ${HEADERS_COMMON_DIR}/time_util.h + ${HEADERS_COMMON_DIR}/zarray.h +) + +set(SRC_COMMON + src/common/image_u8.c + src/common/image_u8x3.c + src/common/pnm.c + src/common/time_util.c +) + +add_library(common OBJECT ${SRC_COMMON} ${HEADERS_COMMON}) + +set_target_properties(common PROPERTIES POSITION_INDEPENDENT_CODE ON) +set_apriltag_export_all(common) +target_include_directories(common + PUBLIC + "$" + "$" +) + +# includes interface target +# used to overcome object libraries not passing on their include_dirs +add_library(${PROJECT_NAME}-include INTERFACE) + +target_include_directories(${PROJECT_NAME}-include + INTERFACE + "$/${PROJECT_NAME}" + "$" + # include cmake-generated apriltag_export.h + "$" +) + +set_target_properties(${PROJECT_NAME}-include PROPERTIES EXPORT_NAME includes) + +# Use interface targets to manage dependencies for different targets +add_library(${PROJECT_NAME}-link-libs INTERFACE) +add_library(${PROJECT_NAME}-utils-link-libs INTERFACE) +if (MSVC) + add_compile_definitions("_CRT_SECURE_NO_WARNINGS") +else() + find_package(Threads REQUIRED) + target_link_libraries(${PROJECT_NAME}-link-libs INTERFACE Threads::Threads m) + target_link_libraries(${PROJECT_NAME}-utils-link-libs INTERFACE m) +endif() + +# Detector Library +set(HEADERS_DETECTOR_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include/apriltag) + +set(HEADERS_DETECTOR + ${HEADERS_DETECTOR_DIR}/apriltag.h + ${HEADERS_DETECTOR_DIR}/apriltag_pose.h + ${HEADERS_DETECTOR_DIR}/common/g2d.h + ${HEADERS_DETECTOR_DIR}/common/homography.h + ${HEADERS_DETECTOR_DIR}/common/matd.h + ${HEADERS_DETECTOR_DIR}/common/postscript_utils.h + ${HEADERS_DETECTOR_DIR}/common/pthreads_cross.h + ${HEADERS_DETECTOR_DIR}/common/svd22.h + ${HEADERS_DETECTOR_DIR}/common/timeprofile.h + ${HEADERS_DETECTOR_DIR}/common/unionfind.h + ${HEADERS_DETECTOR_DIR}/common/workerpool.h + ${HEADERS_DETECTOR_DIR}/common/zmaxheap.h +) + +SET(SRC_DETECTOR + src/apriltag.c + src/apriltag_pose.c + src/apriltag_quad_thresh.c + src/common/g2d.c + src/common/homography.c + src/common/matd.c + src/common/pthreads_cross.cpp + src/common/svd22.c + src/common/workerpool.c + src/common/zmaxheap.c + ${HEADERS_DETECTOR} +) + +add_library(${PROJECT_NAME}-detector + ${SRC_COMMON} + ${SRC_DETECTOR} + ${HEADERS_COMMON} + ${HEADERS_DETECTOR} +) + +target_link_libraries(${PROJECT_NAME}-detector + PUBLIC + ${PROJECT_NAME}-include + ${PROJECT_NAME}-link-libs +) + +set_apriltag_lib_property_defaults(${PROJECT_NAME}-detector) +set_apriltag_named_exports_only(${PROJECT_NAME}-detector) +set_target_properties(${PROJECT_NAME}-detector PROPERTIES EXPORT_NAME detector) +# auto generate headers used for all libs here - ensure this call after +# set_apriltag_named_exports_only() as that fn overrides DEFINE_SYMBOL +generate_export_header(${PROJECT_NAME}-detector BASE_NAME apriltag) + +# Tag Family Libraries +set(TAG_FAMILIES + tag16h5 + tag25h9 + tag36h10 + tag36h11 + tagCircle21h7 + tagCircle49h12 + tagCustom48h12 + tagStandard41h12 + tagStandard52h13 +) + +set(TARGETS_TAGS "") +set(HEADERS_TAGS "") +set(SRC_TAGS "") + +foreach(TAG_FAMILY ${TAG_FAMILIES}) + # for each tag family + set(TAG_FAMILY_HEADER ${HEADERS_DETECTOR_DIR}/${TAG_FAMILY}.h) + set(TAG_FAMILY_SRC src/${TAG_FAMILY}.c) + + set(TAG_TARGET ${PROJECT_NAME}-${TAG_FAMILY}) + + # create Tag-Family object target + add_library(${TAG_TARGET} ${TAG_FAMILY_SRC} ${TAG_FAMILY_HEADER}) + set_apriltag_lib_property_defaults(${TAG_TARGET}) + set_apriltag_named_exports_only(${TAG_TARGET}) + set_target_properties(${TAG_TARGET} PROPERTIES EXPORT_NAME ${TAG_FAMILY}) + target_link_libraries(${TAG_TARGET} PUBLIC ${PROJECT_NAME}-include) + + LIST(APPEND TARGETS_TAGS ${TAG_TARGET}) + LIST(APPEND HEADERS_TAGS ${TAG_FAMILY_HEADER}) + LIST(APPEND SRC_TAGS ${TAG_FAMILY_SRC}) +endforeach() + +# All-Tag-Families library +add_library(${PROJECT_NAME}-tags ${SRC_TAGS} ${SRC_HEADERS}) + +set_target_properties(${PROJECT_NAME}-tags PROPERTIES EXPORT_NAME tags) +set_apriltag_lib_property_defaults(${PROJECT_NAME}-tags) +set_apriltag_named_exports_only(${PROJECT_NAME}-tags) +target_link_libraries(${PROJECT_NAME}-tags PUBLIC ${PROJECT_NAME}-include) + +# Utils Library +add_library(utils-object OBJECT) + +set_target_properties(utils-object PROPERTIES POSITION_INDEPENDENT_CODE ON) +set_apriltag_export_all(utils-object) +target_include_directories(utils-object PRIVATE "$") + +set(HEADERS_UTIL + ${HEADERS_COMMON_DIR}/getopt.h + ${HEADERS_COMMON_DIR}/image_u8x4.h + ${HEADERS_COMMON_DIR}/pam.h + ${HEADERS_COMMON_DIR}/pjpeg.h + ${HEADERS_COMMON_DIR}/string_util.h + ${HEADERS_COMMON_DIR}/zhash.h +) + +target_sources(utils-object + PRIVATE + src/common/string_util.c + src/common/pjpeg-idct.c + src/common/pjpeg.c + src/common/image_u8x4.c + src/common/getopt.c + src/common/pam.c + src/common/zhash.c + src/common/zarray.c + ${HEADERS_UTIL} +) + +add_library(${PROJECT_NAME}-utils "$" "$") + +set_apriltag_lib_property_defaults(${PROJECT_NAME}-utils) +set_apriltag_export_all(${PROJECT_NAME}-utils) +set_target_properties(${PROJECT_NAME}-utils PROPERTIES EXPORT_NAME utils) +target_link_libraries(${PROJECT_NAME}-utils + PUBLIC + ${PROJECT_NAME}-include + ${PROJECT_NAME}-utils-link-libs +) + +# install library header file hierarchy +install(DIRECTORY ${HEADERS_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +#install apriltag_exports.h +install(FILES "$" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/) + +# Combined Apriltag Library to support legacy builds +add_library(${PROJECT_NAME} + ${SRC_DETECTOR} + ${SRC_TAGS} + ${HEADERS_DETECTOR} + ${HEADERS_TAGS} + "$" + "$" +) + +target_link_libraries(${PROJECT_NAME} + PUBLIC + ${PROJECT_NAME}-include + ${PROJECT_NAME}-link-libs + ${PROJECT_NAME}-utils-link-libs +) + +set_apriltag_lib_property_defaults(${PROJECT_NAME}) +set_apriltag_export_all(${PROJECT_NAME}) + +# export library +set(generated_dir ${CMAKE_CURRENT_BINARY_DIR}/generated) +set(version_config ${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake) +set(project_config ${generated_dir}/${PROJECT_NAME}Config.cmake) +set(targets_export_name ${PROJECT_NAME}Targets) +set(config_install_dir share/${PROJECT_NAME}/cmake) + +# Include module with fuction 'write_basic_package_version_file' +include(CMakePackageConfigHelpers) + +# Configure 'Config.cmake' +# Use variables: +# * targets_export_name +# * PROJECT_NAME +configure_package_config_file( + "CMake/apriltagConfig.cmake.in" + "${project_config}" + INSTALL_DESTINATION "${config_install_dir}" +) + +# Configure 'ConfigVersion.cmake' +# Note: PROJECT_VERSION is used as a VERSION +write_basic_package_version_file("${version_config}" COMPATIBILITY SameMajorVersion) + + +set(APRILTAG_INSTALL_TARGETS + ${PROJECT_NAME}-include + ${PROJECT_NAME}-link-libs + ${PROJECT_NAME}-utils-link-libs + ${PROJECT_NAME}-detector + ${PROJECT_NAME}-tags + ${TARGETS_TAGS} + ${PROJECT_NAME}-utils + ${PROJECT_NAME} +) + +# install library +install(TARGETS ${APRILTAG_INSTALL_TARGETS} EXPORT ${targets_export_name} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) + +install(EXPORT ${targets_export_name} + NAMESPACE apriltag:: + DESTINATION ${config_install_dir}) + +install(FILES ${project_config} ${version_config} DESTINATION ${config_install_dir}) + +export(TARGETS ${APRILTAG_INSTALL_TARGETS} + NAMESPACE apriltag:: + FILE ${generated_dir}/${targets_export_name}.cmake +) + +# install pkgconfig file +configure_file(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig +) \ No newline at end of file diff --git a/apriltag.pc.in b/libs/apriltag/apriltag.pc.in similarity index 100% rename from apriltag.pc.in rename to libs/apriltag/apriltag.pc.in diff --git a/apriltag.h b/libs/apriltag/include/apriltag/apriltag.h similarity index 88% rename from apriltag.h rename to libs/apriltag/include/apriltag/apriltag.h index 2d772cda..f0cb36d5 100644 --- a/apriltag.h +++ b/libs/apriltag/include/apriltag/apriltag.h @@ -40,6 +40,8 @@ extern "C" { #include "common/timeprofile.h" #include "common/pthreads_cross.h" +#include "apriltag_export.h" + #define APRILTAG_TASKS_PER_THREAD_TARGET 10 struct quad @@ -231,45 +233,45 @@ struct apriltag_detection }; // don't forget to add a family! -apriltag_detector_t *apriltag_detector_create(); +APRILTAG_EXPORT apriltag_detector_t *apriltag_detector_create(); // add a family to the apriltag detector. caller still "owns" the family. // a single instance should only be provided to one apriltag detector instance. -void apriltag_detector_add_family_bits(apriltag_detector_t *td, apriltag_family_t *fam, int bits_corrected); +APRILTAG_EXPORT void apriltag_detector_add_family_bits(apriltag_detector_t *td, apriltag_family_t *fam, int bits_corrected); -// Tunable, but really, 2 is a good choice. Values of >=3 -// consume prohibitively large amounts of memory, and otherwise -// you want the largest value possible. -static inline void apriltag_detector_add_family(apriltag_detector_t *td, apriltag_family_t *fam) -{ - apriltag_detector_add_family_bits(td, fam, 2); -} +APRILTAG_EXPORT void apriltag_detector_add_family(apriltag_detector_t *td, apriltag_family_t *fam); // does not deallocate the family. -void apriltag_detector_remove_family(apriltag_detector_t *td, apriltag_family_t *fam); +APRILTAG_EXPORT void apriltag_detector_remove_family(apriltag_detector_t *td, apriltag_family_t *fam); // unregister all families, but does not deallocate the underlying tag family objects. -void apriltag_detector_clear_families(apriltag_detector_t *td); +APRILTAG_EXPORT void apriltag_detector_clear_families(apriltag_detector_t *td); // Destroy the april tag detector (but not the underlying // apriltag_family_t used to initialize it.) -void apriltag_detector_destroy(apriltag_detector_t *td); +APRILTAG_EXPORT void apriltag_detector_destroy(apriltag_detector_t *td); // Detect tags from an image and return an array of // apriltag_detection_t*. You can use apriltag_detections_destroy to // free the array and the detections it contains, or call // _detection_destroy and zarray_destroy yourself. -zarray_t *apriltag_detector_detect(apriltag_detector_t *td, image_u8_t *im_orig); +APRILTAG_EXPORT zarray_t *apriltag_detector_detect(apriltag_detector_t *td, image_u8_t *im_orig); // Call this method on each of the tags returned by apriltag_detector_detect -void apriltag_detection_destroy(apriltag_detection_t *det); +APRILTAG_EXPORT void apriltag_detection_destroy(apriltag_detection_t *det); // destroys the array AND the detections within it. -void apriltag_detections_destroy(zarray_t *detections); +APRILTAG_EXPORT void apriltag_detections_destroy(zarray_t *detections); // Renders the apriltag. // Caller is responsible for calling image_u8_destroy on the image -image_u8_t *apriltag_to_image(apriltag_family_t *fam, int idx); +APRILTAG_EXPORT image_u8_t *apriltag_to_image(apriltag_family_t *fam, unsigned int idx); + +// Add exported calls to allow image to be destroyed +APRILTAG_EXPORT void apriltag_image_destroy(image_u8_t * im); + +// Add exported calls to allow image to be written to pnm file +APRILTAG_EXPORT int apriltag_image_write_pnm(image_u8_t * im, const char* path); #ifdef __cplusplus } diff --git a/apriltag_pose.h b/libs/apriltag/include/apriltag/apriltag_pose.h similarity index 95% rename from apriltag_pose.h rename to libs/apriltag/include/apriltag/apriltag_pose.h index 7ef55656..0c16bb5b 100644 --- a/apriltag_pose.h +++ b/libs/apriltag/include/apriltag/apriltag_pose.h @@ -4,9 +4,7 @@ extern "C" { #endif - #include "apriltag.h" -#include "common/matd.h" typedef struct { apriltag_detection_t* det; @@ -67,7 +65,7 @@ void estimate_tag_pose_orthogonal_iteration( * @outparam pose * @return Object-space error of returned pose. */ -double estimate_tag_pose(apriltag_detection_info_t* info, apriltag_pose_t* pose); +APRILTAG_EXPORT double estimate_tag_pose(apriltag_detection_info_t* info, apriltag_pose_t* pose); #ifdef __cplusplus } diff --git a/common/debug_print.h b/libs/apriltag/include/apriltag/common/debug_print.h similarity index 100% rename from common/debug_print.h rename to libs/apriltag/include/apriltag/common/debug_print.h diff --git a/common/g2d.h b/libs/apriltag/include/apriltag/common/g2d.h similarity index 100% rename from common/g2d.h rename to libs/apriltag/include/apriltag/common/g2d.h diff --git a/common/getopt.h b/libs/apriltag/include/apriltag/common/getopt.h similarity index 100% rename from common/getopt.h rename to libs/apriltag/include/apriltag/common/getopt.h diff --git a/common/homography.h b/libs/apriltag/include/apriltag/common/homography.h similarity index 100% rename from common/homography.h rename to libs/apriltag/include/apriltag/common/homography.h diff --git a/common/image_types.h b/libs/apriltag/include/apriltag/common/image_types.h similarity index 100% rename from common/image_types.h rename to libs/apriltag/include/apriltag/common/image_types.h diff --git a/common/image_u8.h b/libs/apriltag/include/apriltag/common/image_u8.h similarity index 100% rename from common/image_u8.h rename to libs/apriltag/include/apriltag/common/image_u8.h diff --git a/common/image_u8x3.h b/libs/apriltag/include/apriltag/common/image_u8x3.h similarity index 100% rename from common/image_u8x3.h rename to libs/apriltag/include/apriltag/common/image_u8x3.h diff --git a/common/image_u8x4.h b/libs/apriltag/include/apriltag/common/image_u8x4.h similarity index 100% rename from common/image_u8x4.h rename to libs/apriltag/include/apriltag/common/image_u8x4.h diff --git a/common/matd.h b/libs/apriltag/include/apriltag/common/matd.h similarity index 100% rename from common/matd.h rename to libs/apriltag/include/apriltag/common/matd.h diff --git a/common/math_util.h b/libs/apriltag/include/apriltag/common/math_util.h similarity index 100% rename from common/math_util.h rename to libs/apriltag/include/apriltag/common/math_util.h diff --git a/common/pam.h b/libs/apriltag/include/apriltag/common/pam.h similarity index 100% rename from common/pam.h rename to libs/apriltag/include/apriltag/common/pam.h diff --git a/common/pjpeg.h b/libs/apriltag/include/apriltag/common/pjpeg.h similarity index 100% rename from common/pjpeg.h rename to libs/apriltag/include/apriltag/common/pjpeg.h diff --git a/common/pnm.h b/libs/apriltag/include/apriltag/common/pnm.h similarity index 100% rename from common/pnm.h rename to libs/apriltag/include/apriltag/common/pnm.h diff --git a/common/postscript_utils.h b/libs/apriltag/include/apriltag/common/postscript_utils.h similarity index 100% rename from common/postscript_utils.h rename to libs/apriltag/include/apriltag/common/postscript_utils.h diff --git a/common/pthreads_cross.h b/libs/apriltag/include/apriltag/common/pthreads_cross.h similarity index 97% rename from common/pthreads_cross.h rename to libs/apriltag/include/apriltag/common/pthreads_cross.h index 897a3335..779091df 100644 --- a/common/pthreads_cross.h +++ b/libs/apriltag/include/apriltag/common/pthreads_cross.h @@ -1,81 +1,81 @@ -/** -Copyright John Schember - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -#ifndef __CPTHREAD_H__ -#define __CPTHREAD_H__ - -#ifdef _WIN32 -#include -#include -#else -#include -#include -#endif - -#ifdef _WIN32 - -typedef CRITICAL_SECTION pthread_mutex_t; -typedef void pthread_mutexattr_t; -typedef void pthread_attr_t; -typedef void pthread_condattr_t; -typedef void pthread_rwlockattr_t; -typedef HANDLE pthread_t; -typedef CONDITION_VARIABLE pthread_cond_t; - -#ifdef __cplusplus -extern "C" { -#endif -int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); -int pthread_join(pthread_t thread, void **value_ptr); -int pthread_detach(pthread_t); - -int pthread_mutex_init(pthread_mutex_t *mutex, pthread_mutexattr_t *attr); -int pthread_mutex_destroy(pthread_mutex_t *mutex); -int pthread_mutex_lock(pthread_mutex_t *mutex); -int pthread_mutex_unlock(pthread_mutex_t *mutex); - -int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr); -int pthread_cond_destroy(pthread_cond_t *cond); -int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex); -int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime); -int pthread_cond_signal(pthread_cond_t *cond); -int pthread_cond_broadcast(pthread_cond_t *cond); - -int sched_yield(void); -#ifdef __cplusplus -} -#endif -#endif - - -#ifdef __cplusplus -extern "C" { -#endif -unsigned int pcthread_get_num_procs(); - -void ms_to_timespec(struct timespec *ts, unsigned int ms); -unsigned int timespec_to_ms(const struct timespec *abstime); -#ifdef __cplusplus -} -#endif - -#endif /* __CPTHREAD_H__ */ +/** +Copyright John Schember + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#ifndef __CPTHREAD_H__ +#define __CPTHREAD_H__ + +#ifdef _WIN32 +#include +#include +#else +#include +#include +#endif + +#ifdef _WIN32 + +typedef CRITICAL_SECTION pthread_mutex_t; +typedef void pthread_mutexattr_t; +typedef void pthread_attr_t; +typedef void pthread_condattr_t; +typedef void pthread_rwlockattr_t; +typedef HANDLE pthread_t; +typedef CONDITION_VARIABLE pthread_cond_t; + +#ifdef __cplusplus +extern "C" { +#endif +int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); +int pthread_join(pthread_t thread, void **value_ptr); +int pthread_detach(pthread_t); + +int pthread_mutex_init(pthread_mutex_t *mutex, pthread_mutexattr_t *attr); +int pthread_mutex_destroy(pthread_mutex_t *mutex); +int pthread_mutex_lock(pthread_mutex_t *mutex); +int pthread_mutex_unlock(pthread_mutex_t *mutex); + +int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr); +int pthread_cond_destroy(pthread_cond_t *cond); +int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex); +int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime); +int pthread_cond_signal(pthread_cond_t *cond); +int pthread_cond_broadcast(pthread_cond_t *cond); + +int sched_yield(void); +#ifdef __cplusplus +} +#endif +#endif + + +#ifdef __cplusplus +extern "C" { +#endif +unsigned int pcthread_get_num_procs(); + +void ms_to_timespec(struct timespec *ts, unsigned int ms); +unsigned int timespec_to_ms(const struct timespec *abstime); +#ifdef __cplusplus +} +#endif + +#endif /* __CPTHREAD_H__ */ diff --git a/common/string_util.h b/libs/apriltag/include/apriltag/common/string_util.h similarity index 100% rename from common/string_util.h rename to libs/apriltag/include/apriltag/common/string_util.h diff --git a/common/svd22.h b/libs/apriltag/include/apriltag/common/svd22.h similarity index 100% rename from common/svd22.h rename to libs/apriltag/include/apriltag/common/svd22.h diff --git a/common/time_util.h b/libs/apriltag/include/apriltag/common/time_util.h similarity index 100% rename from common/time_util.h rename to libs/apriltag/include/apriltag/common/time_util.h diff --git a/common/timeprofile.h b/libs/apriltag/include/apriltag/common/timeprofile.h similarity index 100% rename from common/timeprofile.h rename to libs/apriltag/include/apriltag/common/timeprofile.h diff --git a/common/unionfind.h b/libs/apriltag/include/apriltag/common/unionfind.h similarity index 100% rename from common/unionfind.h rename to libs/apriltag/include/apriltag/common/unionfind.h diff --git a/common/workerpool.h b/libs/apriltag/include/apriltag/common/workerpool.h similarity index 100% rename from common/workerpool.h rename to libs/apriltag/include/apriltag/common/workerpool.h diff --git a/common/zarray.h b/libs/apriltag/include/apriltag/common/zarray.h similarity index 100% rename from common/zarray.h rename to libs/apriltag/include/apriltag/common/zarray.h diff --git a/common/zhash.h b/libs/apriltag/include/apriltag/common/zhash.h similarity index 100% rename from common/zhash.h rename to libs/apriltag/include/apriltag/common/zhash.h diff --git a/common/zmaxheap.h b/libs/apriltag/include/apriltag/common/zmaxheap.h similarity index 100% rename from common/zmaxheap.h rename to libs/apriltag/include/apriltag/common/zmaxheap.h diff --git a/tag16h5.h b/libs/apriltag/include/apriltag/tag16h5.h similarity index 94% rename from tag16h5.h rename to libs/apriltag/include/apriltag/tag16h5.h index d868c818..068f36ea 100644 --- a/tag16h5.h +++ b/libs/apriltag/include/apriltag/tag16h5.h @@ -34,8 +34,8 @@ either expressed or implied, of the Regents of The University of Michigan. extern "C" { #endif -apriltag_family_t *tag16h5_create(); -void tag16h5_destroy(apriltag_family_t *tf); +APRILTAG_EXPORT apriltag_family_t *tag16h5_create(); +APRILTAG_EXPORT void tag16h5_destroy(apriltag_family_t *tf); #ifdef __cplusplus } diff --git a/tag25h9.h b/libs/apriltag/include/apriltag/tag25h9.h similarity index 94% rename from tag25h9.h rename to libs/apriltag/include/apriltag/tag25h9.h index 9197c8b3..834bfa3b 100644 --- a/tag25h9.h +++ b/libs/apriltag/include/apriltag/tag25h9.h @@ -34,8 +34,8 @@ either expressed or implied, of the Regents of The University of Michigan. extern "C" { #endif -apriltag_family_t *tag25h9_create(); -void tag25h9_destroy(apriltag_family_t *tf); +APRILTAG_EXPORT apriltag_family_t *tag25h9_create(); +APRILTAG_EXPORT void tag25h9_destroy(apriltag_family_t *tf); #ifdef __cplusplus } diff --git a/tag36h10.h b/libs/apriltag/include/apriltag/tag36h10.h similarity index 94% rename from tag36h10.h rename to libs/apriltag/include/apriltag/tag36h10.h index a60ae6c5..0f125ae3 100644 --- a/tag36h10.h +++ b/libs/apriltag/include/apriltag/tag36h10.h @@ -34,8 +34,8 @@ either expressed or implied, of the Regents of The University of Michigan. extern "C" { #endif -apriltag_family_t *tag36h10_create(); -void tag36h10_destroy(apriltag_family_t *tf); +APRILTAG_EXPORT apriltag_family_t *tag36h10_create(); +APRILTAG_EXPORT void tag36h10_destroy(apriltag_family_t *tf); #ifdef __cplusplus } diff --git a/tag36h11.h b/libs/apriltag/include/apriltag/tag36h11.h similarity index 94% rename from tag36h11.h rename to libs/apriltag/include/apriltag/tag36h11.h index 62038782..1cb5ab0e 100644 --- a/tag36h11.h +++ b/libs/apriltag/include/apriltag/tag36h11.h @@ -34,8 +34,8 @@ either expressed or implied, of the Regents of The University of Michigan. extern "C" { #endif -apriltag_family_t *tag36h11_create(); -void tag36h11_destroy(apriltag_family_t *tf); +APRILTAG_EXPORT apriltag_family_t *tag36h11_create(); +APRILTAG_EXPORT void tag36h11_destroy(apriltag_family_t *tf); #ifdef __cplusplus } diff --git a/tagCircle21h7.h b/libs/apriltag/include/apriltag/tagCircle21h7.h similarity index 93% rename from tagCircle21h7.h rename to libs/apriltag/include/apriltag/tagCircle21h7.h index a051db64..e58af0a8 100644 --- a/tagCircle21h7.h +++ b/libs/apriltag/include/apriltag/tagCircle21h7.h @@ -34,8 +34,8 @@ either expressed or implied, of the Regents of The University of Michigan. extern "C" { #endif -apriltag_family_t *tagCircle21h7_create(); -void tagCircle21h7_destroy(apriltag_family_t *tf); +APRILTAG_EXPORT apriltag_family_t *tagCircle21h7_create(); +APRILTAG_EXPORT void tagCircle21h7_destroy(apriltag_family_t *tf); #ifdef __cplusplus } diff --git a/tagCircle49h12.h b/libs/apriltag/include/apriltag/tagCircle49h12.h similarity index 93% rename from tagCircle49h12.h rename to libs/apriltag/include/apriltag/tagCircle49h12.h index 4b4c0846..e922b039 100644 --- a/tagCircle49h12.h +++ b/libs/apriltag/include/apriltag/tagCircle49h12.h @@ -34,8 +34,8 @@ either expressed or implied, of the Regents of The University of Michigan. extern "C" { #endif -apriltag_family_t *tagCircle49h12_create(); -void tagCircle49h12_destroy(apriltag_family_t *tf); +APRILTAG_EXPORT apriltag_family_t *tagCircle49h12_create(); +APRILTAG_EXPORT void tagCircle49h12_destroy(apriltag_family_t *tf); #ifdef __cplusplus } diff --git a/tagCustom48h12.h b/libs/apriltag/include/apriltag/tagCustom48h12.h similarity index 93% rename from tagCustom48h12.h rename to libs/apriltag/include/apriltag/tagCustom48h12.h index 564a98a6..a749266b 100644 --- a/tagCustom48h12.h +++ b/libs/apriltag/include/apriltag/tagCustom48h12.h @@ -34,8 +34,8 @@ either expressed or implied, of the Regents of The University of Michigan. extern "C" { #endif -apriltag_family_t *tagCustom48h12_create(); -void tagCustom48h12_destroy(apriltag_family_t *tf); +APRILTAG_EXPORT apriltag_family_t *tagCustom48h12_create(); +APRILTAG_EXPORT void tagCustom48h12_destroy(apriltag_family_t *tf); #ifdef __cplusplus } diff --git a/tagStandard41h12.h b/libs/apriltag/include/apriltag/tagStandard41h12.h similarity index 93% rename from tagStandard41h12.h rename to libs/apriltag/include/apriltag/tagStandard41h12.h index 7f2c33b2..d8c7130b 100644 --- a/tagStandard41h12.h +++ b/libs/apriltag/include/apriltag/tagStandard41h12.h @@ -34,8 +34,8 @@ either expressed or implied, of the Regents of The University of Michigan. extern "C" { #endif -apriltag_family_t *tagStandard41h12_create(); -void tagStandard41h12_destroy(apriltag_family_t *tf); +APRILTAG_EXPORT apriltag_family_t *tagStandard41h12_create(); +APRILTAG_EXPORT void tagStandard41h12_destroy(apriltag_family_t *tf); #ifdef __cplusplus } diff --git a/tagStandard52h13.h b/libs/apriltag/include/apriltag/tagStandard52h13.h similarity index 93% rename from tagStandard52h13.h rename to libs/apriltag/include/apriltag/tagStandard52h13.h index aeeb8e3e..168d5f7d 100644 --- a/tagStandard52h13.h +++ b/libs/apriltag/include/apriltag/tagStandard52h13.h @@ -34,8 +34,8 @@ either expressed or implied, of the Regents of The University of Michigan. extern "C" { #endif -apriltag_family_t *tagStandard52h13_create(); -void tagStandard52h13_destroy(apriltag_family_t *tf); +APRILTAG_EXPORT apriltag_family_t *tagStandard52h13_create(); +APRILTAG_EXPORT void tagStandard52h13_destroy(apriltag_family_t *tf); #ifdef __cplusplus } diff --git a/apriltag.c b/libs/apriltag/src/apriltag.c similarity index 97% rename from apriltag.c rename to libs/apriltag/src/apriltag.c index 30862288..86cafc5c 100644 --- a/apriltag.c +++ b/libs/apriltag/src/apriltag.c @@ -30,7 +30,7 @@ of the authors and should not be interpreted as representing official policies, either expressed or implied, of the Regents of The University of Michigan. */ -#include "apriltag.h" +#include "apriltag/apriltag.h" #include #include @@ -39,20 +39,19 @@ either expressed or implied, of the Regents of The University of Michigan. #include #include -#include "common/image_u8.h" -#include "common/image_u8x3.h" -#include "common/zarray.h" -#include "common/matd.h" -#include "common/homography.h" -#include "common/timeprofile.h" -#include "common/math_util.h" -#include "common/g2d.h" -#include "common/debug_print.h" +#include "apriltag/common/image_u8.h" +#include "apriltag/common/image_u8x3.h" +#include "apriltag/common/zarray.h" +#include "apriltag/common/matd.h" +#include "apriltag/common/homography.h" +#include "apriltag/common/timeprofile.h" +#include "apriltag/common/math_util.h" +#include "apriltag/common/g2d.h" +#include "apriltag/common/debug_print.h" +#include "apriltag/common/postscript_utils.h" #include "apriltag_math.h" -#include "common/postscript_utils.h" - #ifndef M_PI # define M_PI 3.141592653589793238462643383279502884196 #endif @@ -344,6 +343,14 @@ void apriltag_detector_add_family_bits(apriltag_detector_t *td, apriltag_family_ quick_decode_init(fam, bits_corrected); } +void apriltag_detector_add_family(apriltag_detector_t *td, apriltag_family_t *fam) +{ + // Tunable, but really, 2 is a good choice. Values of >=3 + // consume prohibitively large amounts of memory, and otherwise + // you want the largest value possible. + apriltag_detector_add_family_bits(td, fam, 2); +} + void apriltag_detector_clear_families(apriltag_detector_t *td) { for (int i = 0; i < zarray_size(td->tag_families); i++) { @@ -1424,14 +1431,17 @@ void apriltag_detections_destroy(zarray_t *detections) zarray_destroy(detections); } -image_u8_t *apriltag_to_image(apriltag_family_t *fam, int idx) +image_u8_t *apriltag_to_image(apriltag_family_t *fam, unsigned int idx) { - assert(fam != NULL); - assert(idx >= 0 && idx < fam->ncodes); + image_u8_t *im = NULL; + + if(fam == NULL || idx >= fam->ncodes){ + return im; + } uint64_t code = fam->codes[idx]; - image_u8_t *im = image_u8_create(fam->total_width, fam->total_width); + im = image_u8_create(fam->total_width, fam->total_width); int white_border_width = fam->width_at_border + (fam->reversed_border ? 0 : 2); int white_border_start = (fam->total_width - white_border_width)/2; @@ -1451,3 +1461,11 @@ image_u8_t *apriltag_to_image(apriltag_family_t *fam, int idx) } return im; } + +void apriltag_image_destroy(image_u8_t * im){ + image_u8_destroy(im); +} + +int apriltag_image_write_pnm(image_u8_t * im, const char* path){ + return image_u8_write_pnm(im,path); +} \ No newline at end of file diff --git a/apriltag_math.h b/libs/apriltag/src/apriltag_math.h similarity index 100% rename from apriltag_math.h rename to libs/apriltag/src/apriltag_math.h diff --git a/apriltag_pose.c b/libs/apriltag/src/apriltag_pose.c similarity index 99% rename from apriltag_pose.c rename to libs/apriltag/src/apriltag_pose.c index 6043cb85..79dd5c18 100644 --- a/apriltag_pose.c +++ b/libs/apriltag/src/apriltag_pose.c @@ -1,9 +1,9 @@ #include #include -#include "common/debug_print.h" -#include "apriltag_pose.h" -#include "common/homography.h" +#include "apriltag/apriltag_pose.h" +#include "apriltag/common/debug_print.h" +#include "apriltag/common/homography.h" /** diff --git a/apriltag_quad_thresh.c b/libs/apriltag/src/apriltag_quad_thresh.c similarity index 99% rename from apriltag_quad_thresh.c rename to libs/apriltag/src/apriltag_quad_thresh.c index 3317a50c..3a1dfa2f 100644 --- a/apriltag_quad_thresh.c +++ b/libs/apriltag/src/apriltag_quad_thresh.c @@ -34,14 +34,14 @@ either expressed or implied, of the Regents of The University of Michigan. #include #include -#include "apriltag.h" -#include "common/image_u8x3.h" -#include "common/zarray.h" -#include "common/unionfind.h" -#include "common/timeprofile.h" -#include "common/zmaxheap.h" -#include "common/postscript_utils.h" -#include "common/math_util.h" +#include "apriltag/apriltag.h" +#include "apriltag/common/image_u8x3.h" +#include "apriltag/common/zarray.h" +#include "apriltag/common/unionfind.h" +#include "apriltag/common/timeprofile.h" +#include "apriltag/common/zmaxheap.h" +#include "apriltag/common/postscript_utils.h" +#include "apriltag/common/math_util.h" #ifdef _WIN32 static inline long int random(void) diff --git a/common/doubles.h b/libs/apriltag/src/common/doubles.h similarity index 97% rename from common/doubles.h rename to libs/apriltag/src/common/doubles.h index fd5fc829..1cb2bc15 100644 --- a/common/doubles.h +++ b/libs/apriltag/src/common/doubles.h @@ -28,5 +28,5 @@ either expressed or implied, of the Regents of The University of Michigan. #pragma once #define TNAME double -#include "doubles_floats_impl.h" +#include "common/doubles_floats_impl.h" #undef TNAME diff --git a/common/doubles_floats_impl.h b/libs/apriltag/src/common/doubles_floats_impl.h similarity index 99% rename from common/doubles_floats_impl.h rename to libs/apriltag/src/common/doubles_floats_impl.h index 1817e083..49dec55b 100644 --- a/common/doubles_floats_impl.h +++ b/libs/apriltag/src/common/doubles_floats_impl.h @@ -30,8 +30,8 @@ either expressed or implied, of the Regents of The University of Michigan. #include #include -#include "matd.h" -#include "math_util.h" +#include "common/matd.h" +#include "common/math_util.h" // XXX Write unit tests for me! // XXX Rewrite matd_coords in terms of this. diff --git a/common/floats.h b/libs/apriltag/src/common/floats.h similarity index 97% rename from common/floats.h rename to libs/apriltag/src/common/floats.h index 22f839fa..ee3bc533 100644 --- a/common/floats.h +++ b/libs/apriltag/src/common/floats.h @@ -28,5 +28,5 @@ either expressed or implied, of the Regents of The University of Michigan. #pragma once #define TNAME float -#include "doubles_floats_impl.h" +#include "common/doubles_floats_impl.h" #undef TNAME diff --git a/common/g2d.c b/libs/apriltag/src/common/g2d.c similarity index 99% rename from common/g2d.c rename to libs/apriltag/src/common/g2d.c index 4645f206..d2bf09c2 100644 --- a/common/g2d.c +++ b/libs/apriltag/src/common/g2d.c @@ -30,8 +30,8 @@ either expressed or implied, of the Regents of The University of Michigan. #include #include -#include "g2d.h" -#include "common/math_util.h" +#include "apriltag/common/g2d.h" +#include "apriltag/common/math_util.h" #ifdef _WIN32 static inline long int random(void) diff --git a/common/getopt.c b/libs/apriltag/src/common/getopt.c similarity index 99% rename from common/getopt.c rename to libs/apriltag/src/common/getopt.c index e6450897..80319f5d 100644 --- a/common/getopt.c +++ b/libs/apriltag/src/common/getopt.c @@ -32,10 +32,10 @@ either expressed or implied, of the Regents of The University of Michigan. #include #include -#include "zhash.h" -#include "zarray.h" -#include "getopt.h" -#include "common/math_util.h" +#include "apriltag/common/zhash.h" +#include "apriltag/common/zarray.h" +#include "apriltag/common/getopt.h" +#include "apriltag/common/math_util.h" #define GOO_BOOL_TYPE 1 #define GOO_STRING_TYPE 2 diff --git a/common/homography.c b/libs/apriltag/src/common/homography.c similarity index 99% rename from common/homography.c rename to libs/apriltag/src/common/homography.c index 48e7f02d..704152e8 100644 --- a/common/homography.c +++ b/libs/apriltag/src/common/homography.c @@ -27,10 +27,10 @@ either expressed or implied, of the Regents of The University of Michigan. #include -#include "common/matd.h" -#include "common/zarray.h" -#include "common/homography.h" -#include "common/math_util.h" +#include "apriltag/common/matd.h" +#include "apriltag/common/zarray.h" +#include "apriltag/common/homography.h" +#include "apriltag/common/math_util.h" // correspondences is a list of float[4]s, consisting of the points x // and y concatenated. We will compute a homography such that y = Hx diff --git a/common/image_u8.c b/libs/apriltag/src/common/image_u8.c similarity index 99% rename from common/image_u8.c rename to libs/apriltag/src/common/image_u8.c index eef6c046..1f06c948 100644 --- a/common/image_u8.c +++ b/libs/apriltag/src/common/image_u8.c @@ -31,9 +31,9 @@ either expressed or implied, of the Regents of The University of Michigan. #include #include -#include "common/image_u8.h" -#include "common/pnm.h" -#include "common/math_util.h" +#include "apriltag/common/image_u8.h" +#include "apriltag/common/pnm.h" +#include "apriltag/common/math_util.h" // least common multiple of 64 (sandy bridge cache line) and 24 (stride // needed for RGB in 8-wide vector processing) @@ -202,7 +202,7 @@ int image_u8_write_pnm(const image_u8_t *im, const char *path) FILE *f = fopen(path, "wb"); int res = 0; - if (f == NULL) { + if (f == NULL || im == NULL) { res = -1; goto finish; } diff --git a/common/image_u8x3.c b/libs/apriltag/src/common/image_u8x3.c similarity index 98% rename from common/image_u8x3.c rename to libs/apriltag/src/common/image_u8x3.c index 1463e5f1..13ff9c3d 100644 --- a/common/image_u8x3.c +++ b/libs/apriltag/src/common/image_u8x3.c @@ -31,10 +31,9 @@ either expressed or implied, of the Regents of The University of Michigan. #include #include -#include "math_util.h" -#include "pnm.h" - -#include "image_u8x3.h" +#include "apriltag/common/image_u8x3.h" +#include "apriltag/common/math_util.h" +#include "apriltag/common/pnm.h" // least common multiple of 64 (sandy bridge cache line) and 48 (stride needed // for 16byte-wide RGB processing). (It's possible that 48 would be enough). diff --git a/common/image_u8x4.c b/libs/apriltag/src/common/image_u8x4.c similarity index 98% rename from common/image_u8x4.c rename to libs/apriltag/src/common/image_u8x4.c index 35205374..4e8aa812 100644 --- a/common/image_u8x4.c +++ b/libs/apriltag/src/common/image_u8x4.c @@ -30,9 +30,9 @@ either expressed or implied, of the Regents of The University of Michigan. #include #include -#include "pam.h" -#include "pnm.h" -#include "image_u8x4.h" +#include "apriltag/common/pam.h" +#include "apriltag/common/pnm.h" +#include "apriltag/common/image_u8x4.h" // least common multiple of 64 (sandy bridge cache line) and 64 (stride needed // for 16byte-wide RGBA processing). diff --git a/common/matd.c b/libs/apriltag/src/common/matd.c similarity index 99% rename from common/matd.c rename to libs/apriltag/src/common/matd.c index 54449d9f..22924114 100644 --- a/common/matd.c +++ b/libs/apriltag/src/common/matd.c @@ -33,10 +33,10 @@ either expressed or implied, of the Regents of The University of Michigan. #include #include -#include "common/math_util.h" -#include "common/svd22.h" -#include "common/matd.h" -#include "common/debug_print.h" +#include "apriltag/common/math_util.h" +#include "apriltag/common/svd22.h" +#include "apriltag/common/matd.h" +#include "apriltag/common/debug_print.h" // a matd_t with rows=0 cols=0 is a SCALAR. diff --git a/common/pam.c b/libs/apriltag/src/common/pam.c similarity index 99% rename from common/pam.c rename to libs/apriltag/src/common/pam.c index 2076d396..c827591b 100644 --- a/common/pam.c +++ b/libs/apriltag/src/common/pam.c @@ -30,7 +30,7 @@ either expressed or implied, of the Regents of The University of Michigan. #include #include -#include "pam.h" +#include "apriltag/common/pam.h" pam_t *pam_create_from_file(const char *inpath) { diff --git a/common/pjpeg-idct.c b/libs/apriltag/src/common/pjpeg-idct.c similarity index 100% rename from common/pjpeg-idct.c rename to libs/apriltag/src/common/pjpeg-idct.c diff --git a/common/pjpeg.c b/libs/apriltag/src/common/pjpeg.c similarity index 99% rename from common/pjpeg.c rename to libs/apriltag/src/common/pjpeg.c index acc61f07..3c622b38 100644 --- a/common/pjpeg.c +++ b/libs/apriltag/src/common/pjpeg.c @@ -31,11 +31,11 @@ either expressed or implied, of the Regents of The University of Michigan. #include #include -#include "pjpeg.h" +#include "apriltag/common/pjpeg.h" -#include "image_u8.h" -#include "image_u8x3.h" -#include "debug_print.h" +#include "apriltag/common/image_u8.h" +#include "apriltag/common/image_u8x3.h" +#include "apriltag/common/debug_print.h" // https://www.w3.org/Graphics/JPEG/itu-t81.pdf diff --git a/common/pnm.c b/libs/apriltag/src/common/pnm.c similarity index 99% rename from common/pnm.c rename to libs/apriltag/src/common/pnm.c index fe77dde6..72936792 100644 --- a/common/pnm.c +++ b/libs/apriltag/src/common/pnm.c @@ -29,7 +29,7 @@ either expressed or implied, of the Regents of The University of Michigan. #include #include -#include "pnm.h" +#include "apriltag/common/pnm.h" pnm_t *pnm_create_from_file(const char *path) { diff --git a/common/pthreads_cross.cpp b/libs/apriltag/src/common/pthreads_cross.cpp similarity index 95% rename from common/pthreads_cross.cpp rename to libs/apriltag/src/common/pthreads_cross.cpp index f7721912..2fa2c752 100644 --- a/common/pthreads_cross.cpp +++ b/libs/apriltag/src/common/pthreads_cross.cpp @@ -1,259 +1,259 @@ -/** -Copyright John Schember - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - */ - -#include "common/pthreads_cross.h" -#include - -#ifdef _WIN32 - -typedef struct { - SRWLOCK lock; - bool exclusive; -} pthread_rwlock_t; - -int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr); -int pthread_rwlock_destroy(pthread_rwlock_t *rwlock); -int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock); -int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock); -int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock); -int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock); -int pthread_rwlock_unlock(pthread_rwlock_t *rwlock); - -int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) -{ - (void) attr; - - if (thread == NULL || start_routine == NULL) - return 1; - - *thread = (HANDLE) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, arg, 0, NULL); - if (*thread == NULL) - return 1; - return 0; -} - -int pthread_join(pthread_t thread, void **value_ptr) -{ - (void)value_ptr; - WaitForSingleObject(thread, INFINITE); - CloseHandle(thread); - return 0; -} - -int pthread_detach(pthread_t thread) -{ - CloseHandle(thread); - return 0; -} - -int pthread_mutex_init(pthread_mutex_t *mutex, pthread_mutexattr_t *attr) -{ - (void)attr; - - if (mutex == NULL) - return 1; - - InitializeCriticalSection(mutex); - return 0; -} - -int pthread_mutex_destroy(pthread_mutex_t *mutex) -{ - if (mutex == NULL) - return 1; - DeleteCriticalSection(mutex); - return 0; -} - -int pthread_mutex_lock(pthread_mutex_t *mutex) -{ - if (mutex == NULL) - return 1; - EnterCriticalSection(mutex); - return 0; -} - -int pthread_mutex_unlock(pthread_mutex_t *mutex) -{ - if (mutex == NULL) - return 1; - LeaveCriticalSection(mutex); - return 0; -} - -int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr) -{ - (void)attr; - if (cond == NULL) - return 1; - InitializeConditionVariable(cond); - return 0; -} - -int pthread_cond_destroy(pthread_cond_t *cond) -{ - /* Windows does not have a destroy for conditionals */ - (void)cond; - return 0; -} - -int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) -{ - if (cond == NULL || mutex == NULL) - return 1; - return pthread_cond_timedwait(cond, mutex, NULL); -} - -int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, - const struct timespec *abstime) -{ - if (cond == NULL || mutex == NULL) - return 1; - if (!SleepConditionVariableCS(cond, mutex, timespec_to_ms(abstime))) - return 1; - return 0; -} - -int pthread_cond_signal(pthread_cond_t *cond) -{ - if (cond == NULL) - return 1; - WakeConditionVariable(cond); - return 0; -} - -int pthread_cond_broadcast(pthread_cond_t *cond) -{ - if (cond == NULL) - return 1; - WakeAllConditionVariable(cond); - return 0; -} - -int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr) -{ - (void)attr; - if (rwlock == NULL) - return 1; - InitializeSRWLock(&(rwlock->lock)); - rwlock->exclusive = false; - return 0; -} - -int pthread_rwlock_destroy(pthread_rwlock_t *rwlock) -{ - (void)rwlock; - return 0; -} - -int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock) -{ - if (rwlock == NULL) - return 1; - AcquireSRWLockShared(&(rwlock->lock)); - return 0; -} - -int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock) -{ - if (rwlock == NULL) - return 1; - return !TryAcquireSRWLockShared(&(rwlock->lock)); -} - -int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock) -{ - if (rwlock == NULL) - return 1; - AcquireSRWLockExclusive(&(rwlock->lock)); - rwlock->exclusive = true; - return 0; -} - -int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock) -{ - BOOLEAN ret; - - if (rwlock == NULL) - return 1; - - ret = TryAcquireSRWLockExclusive(&(rwlock->lock)); - if (ret) - rwlock->exclusive = true; - return ret; -} - -int pthread_rwlock_unlock(pthread_rwlock_t *rwlock) -{ - if (rwlock == NULL) - return 1; - - if (rwlock->exclusive) { - rwlock->exclusive = false; - ReleaseSRWLockExclusive(&(rwlock->lock)); - } else { - ReleaseSRWLockShared(&(rwlock->lock)); - } - return 0; -} - -int sched_yield() { - return (int)SwitchToThread(); -} - -void ms_to_timespec(struct timespec *ts, unsigned int ms) -{ - if (ts == NULL) - return; - ts->tv_sec = (ms / 1000) + time(NULL); - ts->tv_nsec = (ms % 1000) * 1000000; -} - -unsigned int timespec_to_ms(const struct timespec *abstime) -{ - DWORD t; - - if (abstime == NULL) - return INFINITE; - - t = ((abstime->tv_sec - time(NULL)) * 1000) + (abstime->tv_nsec / 1000000); - if (t < 0) - t = 1; - return t; -} - -unsigned int pcthread_get_num_procs() -{ - SYSTEM_INFO sysinfo; - - GetSystemInfo(&sysinfo); - return sysinfo.dwNumberOfProcessors; -} - -#else - -#include -unsigned int pcthread_get_num_procs() -{ - return (unsigned int)sysconf(_SC_NPROCESSORS_ONLN); -} -#endif +/** +Copyright John Schember + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + */ + +#include "apriltag/common/pthreads_cross.h" +#include + +#ifdef _WIN32 + +typedef struct { + SRWLOCK lock; + bool exclusive; +} pthread_rwlock_t; + +int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr); +int pthread_rwlock_destroy(pthread_rwlock_t *rwlock); +int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock); +int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock); +int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock); +int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock); +int pthread_rwlock_unlock(pthread_rwlock_t *rwlock); + +int pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) +{ + (void) attr; + + if (thread == NULL || start_routine == NULL) + return 1; + + *thread = (HANDLE) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, arg, 0, NULL); + if (*thread == NULL) + return 1; + return 0; +} + +int pthread_join(pthread_t thread, void **value_ptr) +{ + (void)value_ptr; + WaitForSingleObject(thread, INFINITE); + CloseHandle(thread); + return 0; +} + +int pthread_detach(pthread_t thread) +{ + CloseHandle(thread); + return 0; +} + +int pthread_mutex_init(pthread_mutex_t *mutex, pthread_mutexattr_t *attr) +{ + (void)attr; + + if (mutex == NULL) + return 1; + + InitializeCriticalSection(mutex); + return 0; +} + +int pthread_mutex_destroy(pthread_mutex_t *mutex) +{ + if (mutex == NULL) + return 1; + DeleteCriticalSection(mutex); + return 0; +} + +int pthread_mutex_lock(pthread_mutex_t *mutex) +{ + if (mutex == NULL) + return 1; + EnterCriticalSection(mutex); + return 0; +} + +int pthread_mutex_unlock(pthread_mutex_t *mutex) +{ + if (mutex == NULL) + return 1; + LeaveCriticalSection(mutex); + return 0; +} + +int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr) +{ + (void)attr; + if (cond == NULL) + return 1; + InitializeConditionVariable(cond); + return 0; +} + +int pthread_cond_destroy(pthread_cond_t *cond) +{ + /* Windows does not have a destroy for conditionals */ + (void)cond; + return 0; +} + +int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) +{ + if (cond == NULL || mutex == NULL) + return 1; + return pthread_cond_timedwait(cond, mutex, NULL); +} + +int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, + const struct timespec *abstime) +{ + if (cond == NULL || mutex == NULL) + return 1; + if (!SleepConditionVariableCS(cond, mutex, timespec_to_ms(abstime))) + return 1; + return 0; +} + +int pthread_cond_signal(pthread_cond_t *cond) +{ + if (cond == NULL) + return 1; + WakeConditionVariable(cond); + return 0; +} + +int pthread_cond_broadcast(pthread_cond_t *cond) +{ + if (cond == NULL) + return 1; + WakeAllConditionVariable(cond); + return 0; +} + +int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr) +{ + (void)attr; + if (rwlock == NULL) + return 1; + InitializeSRWLock(&(rwlock->lock)); + rwlock->exclusive = false; + return 0; +} + +int pthread_rwlock_destroy(pthread_rwlock_t *rwlock) +{ + (void)rwlock; + return 0; +} + +int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock) +{ + if (rwlock == NULL) + return 1; + AcquireSRWLockShared(&(rwlock->lock)); + return 0; +} + +int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock) +{ + if (rwlock == NULL) + return 1; + return !TryAcquireSRWLockShared(&(rwlock->lock)); +} + +int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock) +{ + if (rwlock == NULL) + return 1; + AcquireSRWLockExclusive(&(rwlock->lock)); + rwlock->exclusive = true; + return 0; +} + +int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock) +{ + BOOLEAN ret; + + if (rwlock == NULL) + return 1; + + ret = TryAcquireSRWLockExclusive(&(rwlock->lock)); + if (ret) + rwlock->exclusive = true; + return ret; +} + +int pthread_rwlock_unlock(pthread_rwlock_t *rwlock) +{ + if (rwlock == NULL) + return 1; + + if (rwlock->exclusive) { + rwlock->exclusive = false; + ReleaseSRWLockExclusive(&(rwlock->lock)); + } else { + ReleaseSRWLockShared(&(rwlock->lock)); + } + return 0; +} + +int sched_yield() { + return (int)SwitchToThread(); +} + +void ms_to_timespec(struct timespec *ts, unsigned int ms) +{ + if (ts == NULL) + return; + ts->tv_sec = (ms / 1000) + time(NULL); + ts->tv_nsec = (ms % 1000) * 1000000; +} + +unsigned int timespec_to_ms(const struct timespec *abstime) +{ + DWORD t; + + if (abstime == NULL) + return INFINITE; + + t = ((abstime->tv_sec - time(NULL)) * 1000) + (abstime->tv_nsec / 1000000); + if (t < 0) + t = 1; + return t; +} + +unsigned int pcthread_get_num_procs() +{ + SYSTEM_INFO sysinfo; + + GetSystemInfo(&sysinfo); + return sysinfo.dwNumberOfProcessors; +} + +#else + +#include +unsigned int pcthread_get_num_procs() +{ + return (unsigned int)sysconf(_SC_NPROCESSORS_ONLN); +} +#endif diff --git a/common/string_util.c b/libs/apriltag/src/common/string_util.c similarity index 99% rename from common/string_util.c rename to libs/apriltag/src/common/string_util.c index 7c64c131..07ae8868 100644 --- a/common/string_util.c +++ b/libs/apriltag/src/common/string_util.c @@ -32,8 +32,8 @@ either expressed or implied, of the Regents of The University of Michigan. #include #include -#include "string_util.h" -#include "zarray.h" +#include "apriltag/common/string_util.h" +#include "apriltag/common/zarray.h" struct string_buffer { diff --git a/common/svd22.c b/libs/apriltag/src/common/svd22.c similarity index 100% rename from common/svd22.c rename to libs/apriltag/src/common/svd22.c diff --git a/common/time_util.c b/libs/apriltag/src/common/time_util.c similarity index 99% rename from common/time_util.c rename to libs/apriltag/src/common/time_util.c index 7a25f424..0c6d3b4f 100644 --- a/common/time_util.c +++ b/libs/apriltag/src/common/time_util.c @@ -27,7 +27,7 @@ either expressed or implied, of the Regents of The University of Michigan. #include #include -#include "time_util.h" +#include "apriltag/common/time_util.h" struct timeutil_rest { diff --git a/common/workerpool.c b/libs/apriltag/src/common/workerpool.c similarity index 97% rename from common/workerpool.c rename to libs/apriltag/src/common/workerpool.c index a0170ef8..095e9a69 100644 --- a/common/workerpool.c +++ b/libs/apriltag/src/common/workerpool.c @@ -28,7 +28,7 @@ either expressed or implied, of the Regents of The University of Michigan. #define _GNU_SOURCE // Possible fix for 16.04 #define __USE_GNU -#include "common/pthreads_cross.h" +#include "apriltag/common/pthreads_cross.h" #include #include #include @@ -38,8 +38,8 @@ either expressed or implied, of the Regents of The University of Michigan. #include #endif -#include "workerpool.h" -#include "debug_print.h" +#include "apriltag/common/workerpool.h" +#include "apriltag/common/debug_print.h" struct workerpool { int nthreads; diff --git a/common/zarray.c b/libs/apriltag/src/common/zarray.c similarity index 98% rename from common/zarray.c rename to libs/apriltag/src/common/zarray.c index 43e6a7e0..ee80a6e4 100644 --- a/common/zarray.c +++ b/libs/apriltag/src/common/zarray.c @@ -28,7 +28,7 @@ either expressed or implied, of the Regents of The University of Michigan. #include #include -#include "zarray.h" +#include "apriltag/common/zarray.h" int zstrcmp(const void * a_pp, const void * b_pp) { diff --git a/common/zhash.c b/libs/apriltag/src/common/zhash.c similarity index 99% rename from common/zhash.c rename to libs/apriltag/src/common/zhash.c index 914f530e..4061a237 100644 --- a/common/zhash.c +++ b/libs/apriltag/src/common/zhash.c @@ -30,7 +30,7 @@ either expressed or implied, of the Regents of The University of Michigan. #include #include -#include "zhash.h" +#include "apriltag/common/zhash.h" // force a rehash when our capacity is less than this many times the size #define ZHASH_FACTOR_CRITICAL 2 diff --git a/common/zmaxheap.c b/libs/apriltag/src/common/zmaxheap.c similarity index 99% rename from common/zmaxheap.c rename to libs/apriltag/src/common/zmaxheap.c index e04d03ef..51861458 100644 --- a/common/zmaxheap.c +++ b/libs/apriltag/src/common/zmaxheap.c @@ -32,8 +32,8 @@ either expressed or implied, of the Regents of The University of Michigan. #include #include -#include "zmaxheap.h" -#include "debug_print.h" +#include "apriltag/common/zmaxheap.h" +#include "apriltag/common/debug_print.h" #ifdef _WIN32 static inline long int random(void) diff --git a/tag16h5.c b/libs/apriltag/src/tag16h5.c similarity index 99% rename from tag16h5.c rename to libs/apriltag/src/tag16h5.c index 775f33c7..75f9a154 100644 --- a/tag16h5.c +++ b/libs/apriltag/src/tag16h5.c @@ -26,7 +26,7 @@ either expressed or implied, of the Regents of The University of Michigan. */ #include -#include "tag16h5.h" +#include "apriltag/tag16h5.h" static uint64_t codedata[30] = { 0x00000000000027c8UL, diff --git a/tag25h9.c b/libs/apriltag/src/tag25h9.c similarity index 99% rename from tag25h9.c rename to libs/apriltag/src/tag25h9.c index ddf31a2e..0317b279 100644 --- a/tag25h9.c +++ b/libs/apriltag/src/tag25h9.c @@ -26,7 +26,7 @@ either expressed or implied, of the Regents of The University of Michigan. */ #include -#include "tag25h9.h" +#include "apriltag/tag25h9.h" static uint64_t codedata[35] = { 0x000000000156f1f4UL, diff --git a/tag36h10.c b/libs/apriltag/src/tag36h10.c similarity index 99% rename from tag36h10.c rename to libs/apriltag/src/tag36h10.c index 44a129e7..e294089c 100644 --- a/tag36h10.c +++ b/libs/apriltag/src/tag36h10.c @@ -1,5 +1,5 @@ #include -#include "tag36h10.h" +#include "apriltag/tag36h10.h" static uint64_t codedata[2320] = { 0x00000001a42f9469UL, diff --git a/tag36h11.c b/libs/apriltag/src/tag36h11.c similarity index 99% rename from tag36h11.c rename to libs/apriltag/src/tag36h11.c index 94acacaa..d21c5bb9 100644 --- a/tag36h11.c +++ b/libs/apriltag/src/tag36h11.c @@ -26,7 +26,7 @@ either expressed or implied, of the Regents of The University of Michigan. */ #include -#include "tag36h11.h" +#include "apriltag/tag36h11.h" static uint64_t codedata[587] = { 0x0000000d7e00984bUL, diff --git a/tagCircle21h7.c b/libs/apriltag/src/tagCircle21h7.c similarity index 99% rename from tagCircle21h7.c rename to libs/apriltag/src/tagCircle21h7.c index 8dad3feb..cbafec19 100644 --- a/tagCircle21h7.c +++ b/libs/apriltag/src/tagCircle21h7.c @@ -26,7 +26,7 @@ either expressed or implied, of the Regents of The University of Michigan. */ #include -#include "tagCircle21h7.h" +#include "apriltag/tagCircle21h7.h" static uint64_t codedata[38] = { 0x0000000000157863UL, diff --git a/tagCircle49h12.c b/libs/apriltag/src/tagCircle49h12.c similarity index 99% rename from tagCircle49h12.c rename to libs/apriltag/src/tagCircle49h12.c index 02456fab..8816e84c 100644 --- a/tagCircle49h12.c +++ b/libs/apriltag/src/tagCircle49h12.c @@ -26,7 +26,7 @@ either expressed or implied, of the Regents of The University of Michigan. */ #include -#include "tagCircle49h12.h" +#include "apriltag/tagCircle49h12.h" static uint64_t codedata[65535] = { 0x0000c6c921d8614aUL, diff --git a/tagCustom48h12.c b/libs/apriltag/src/tagCustom48h12.c similarity index 99% rename from tagCustom48h12.c rename to libs/apriltag/src/tagCustom48h12.c index cd908e10..906582f3 100644 --- a/tagCustom48h12.c +++ b/libs/apriltag/src/tagCustom48h12.c @@ -26,7 +26,7 @@ either expressed or implied, of the Regents of The University of Michigan. */ #include -#include "tagCustom48h12.h" +#include "apriltag/tagCustom48h12.h" static uint64_t codedata[42211] = { 0x0000d6c8ae76dff0UL, diff --git a/tagStandard41h12.c b/libs/apriltag/src/tagStandard41h12.c similarity index 99% rename from tagStandard41h12.c rename to libs/apriltag/src/tagStandard41h12.c index 6d77eb95..5d9c4bda 100644 --- a/tagStandard41h12.c +++ b/libs/apriltag/src/tagStandard41h12.c @@ -26,7 +26,7 @@ either expressed or implied, of the Regents of The University of Michigan. */ #include -#include "tagStandard41h12.h" +#include "apriltag/tagStandard41h12.h" static uint64_t codedata[2115] = { 0x000001bd8a64ad10UL, diff --git a/tagStandard52h13.c b/libs/apriltag/src/tagStandard52h13.c similarity index 99% rename from tagStandard52h13.c rename to libs/apriltag/src/tagStandard52h13.c index 30e2b62f..320f5001 100644 --- a/tagStandard52h13.c +++ b/libs/apriltag/src/tagStandard52h13.c @@ -26,7 +26,7 @@ either expressed or implied, of the Regents of The University of Michigan. */ #include -#include "tagStandard52h13.h" +#include "apriltag/tagStandard52h13.h" static uint64_t codedata[48714] = { 0x0004064a19651ff1UL, diff --git a/libs/apriltag_python/CMakeLists.txt b/libs/apriltag_python/CMakeLists.txt new file mode 100644 index 00000000..87296e3d --- /dev/null +++ b/libs/apriltag_python/CMakeLists.txt @@ -0,0 +1,44 @@ +## Build Python Wrapper + +# Build list of include directives +get_target_property(APRILTAG_INCLUDES_LIST ${PROJECT_NAME}-include INTERFACE_INCLUDE_DIRECTORIES) +set(ADDITIONAL_INCLUDE_DIRECTIVES "") +foreach(ITEM ${APRILTAG_INCLUDES_LIST}) + LIST(APPEND ADDITIONAL_INCLUDE_DIRECTIVES "-I\"${ITEM}\"") +endforeach() + +if(BUILD_PYTHON_WRAPPER) + SET(Python_ADDITIONAL_VERSIONS 3) + find_package(PythonLibs) + execute_process(COMMAND which python3 OUTPUT_QUIET RESULT_VARIABLE Python3_NOT_FOUND) + execute_process(COMMAND python3 -c "import numpy" RESULT_VARIABLE Numpy_NOT_FOUND) +endif(BUILD_PYTHON_WRAPPER) + +if (NOT Python3_NOT_FOUND AND NOT Numpy_NOT_FOUND AND PYTHONLIBS_FOUND AND BUILD_PYTHON_WRAPPER) + # TODO deal with both python2/3 + execute_process(COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/python_build_flags.py OUTPUT_VARIABLE PY_OUT) + set(PY_VARS CFLAGS LDFLAGS LINKER EXT_SUFFIX) + cmake_parse_arguments(PY "" "${PY_VARS}" "" ${PY_OUT}) + separate_arguments(PY_CFLAGS) + list(REMOVE_ITEM PY_CFLAGS -flto) + separate_arguments(PY_LDFLAGS) + + foreach(X detect py_type) + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/apriltag_${X}.docstring.h + COMMAND < ${CMAKE_CURRENT_SOURCE_DIR}/apriltag_${X}.docstring sed 's/\"/\\\\\"/g\; s/^/\"/\; s/$$/\\\\n\"/\;' > apriltag_${X}.docstring.h + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + endforeach() + + add_custom_command(OUTPUT apriltag_pywrap.o + COMMAND ${CMAKE_C_COMPILER} ${PY_CFLAGS} -I${CMAKE_CURRENT_BINARY_DIR} ${ADDITIONAL_INCLUDE_DIRECTIVES} -c -o apriltag_pywrap.o ${CMAKE_CURRENT_SOURCE_DIR}/apriltag_pywrap.c + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/apriltag_pywrap.c ${CMAKE_CURRENT_BINARY_DIR}/apriltag_detect.docstring.h ${CMAKE_CURRENT_BINARY_DIR}/apriltag_py_type.docstring.h) + add_custom_command(OUTPUT apriltag${PY_EXT_SUFFIX} + COMMAND ${PY_LINKER} ${PY_LDFLAGS} -lm -Wl,-rpath,lib apriltag_pywrap.o "$" "$" -o apriltag${PY_EXT_SUFFIX} + DEPENDS ${PROJECT_NAME} apriltag_pywrap.o) + add_custom_target(apriltag_python ALL + DEPENDS apriltag${PY_EXT_SUFFIX}) + +execute_process(COMMAND python3 -m site --user-site OUTPUT_VARIABLE PY_DEST) +string(STRIP ${PY_DEST} PY_DEST) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/apriltag${PY_EXT_SUFFIX} DESTINATION ${PY_DEST}) +endif (NOT Python3_NOT_FOUND AND NOT Numpy_NOT_FOUND AND PYTHONLIBS_FOUND AND BUILD_PYTHON_WRAPPER) diff --git a/apriltag_detect.docstring b/libs/apriltag_python/apriltag_detect.docstring similarity index 100% rename from apriltag_detect.docstring rename to libs/apriltag_python/apriltag_detect.docstring diff --git a/apriltag_py_type.docstring b/libs/apriltag_python/apriltag_py_type.docstring similarity index 100% rename from apriltag_py_type.docstring rename to libs/apriltag_python/apriltag_py_type.docstring diff --git a/apriltag_pywrap.c b/libs/apriltag_python/apriltag_pywrap.c similarity index 97% rename from apriltag_pywrap.c rename to libs/apriltag_python/apriltag_pywrap.c index e17d48ec..01ed76a2 100644 --- a/apriltag_pywrap.c +++ b/libs/apriltag_python/apriltag_pywrap.c @@ -6,16 +6,16 @@ #include #include -#include "apriltag.h" -#include "tag36h10.h" -#include "tag36h11.h" -#include "tag25h9.h" -#include "tag16h5.h" -#include "tagCircle21h7.h" -#include "tagCircle49h12.h" -#include "tagCustom48h12.h" -#include "tagStandard41h12.h" -#include "tagStandard52h13.h" +#include "apriltag/apriltag.h" +#include "apriltag/tag36h10.h" +#include "apriltag/tag36h11.h" +#include "apriltag/tag25h9.h" +#include "apriltag/tag16h5.h" +#include "apriltag/tagCircle21h7.h" +#include "apriltag/tagCircle49h12.h" +#include "apriltag/tagCustom48h12.h" +#include "apriltag/tagStandard41h12.h" +#include "apriltag/tagStandard52h13.h" #define SUPPORTED_TAG_FAMILIES(_) \ diff --git a/python_build_flags.py b/libs/apriltag_python/python_build_flags.py similarity index 100% rename from python_build_flags.py rename to libs/apriltag_python/python_build_flags.py