### Define Installation Targets Source: https://github.com/coal-library/coal/blob/devel/src/CMakeLists.txt Specifies the installation paths for the library, headers, and export configuration. ```cmake install( TARGETS ${LIBRARY_NAME} EXPORT ${TARGETS_EXPORT_NAME} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) ``` -------------------------------- ### Set Target Properties and Installation Source: https://github.com/coal-library/coal/blob/devel/python/CMakeLists.txt Configures output naming, directory paths, and RPATH settings for the library installation. ```cmake set_target_properties( ${PYTHON_LIB_NAME} PROPERTIES PREFIX "" SUFFIX "${PYTHON_EXT_SUFFIX}" OUTPUT_NAME "${PYTHON_LIB_NAME}" LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/python/${PROJECT_NAME}" # On Windows, shared library are treat as binary RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/python/${PROJECT_NAME}" ) if(IS_ABSOLUTE ${PYTHON_SITELIB}) set(ABSOLUTE_PYTHON_SITELIB ${PYTHON_SITELIB}) else() set(ABSOLUTE_PYTHON_SITELIB ${CMAKE_INSTALL_PREFIX}/${PYTHON_SITELIB}) endif() set(${PYTHON_LIB_NAME}_INSTALL_DIR ${ABSOLUTE_PYTHON_SITELIB}/${PROJECT_NAME}) if(UNIX) GET_RELATIVE_RPATH( ${${PYTHON_LIB_NAME}_INSTALL_DIR} ${PYTHON_LIB_NAME}_INSTALL_RPATH ) set_target_properties( ${PYTHON_LIB_NAME} PROPERTIES INSTALL_RPATH "${${PYTHON_LIB_NAME}_INSTALL_RPATH}" ) endif() install( TARGETS ${PYTHON_LIB_NAME} EXPORT ${TARGETS_EXPORT_NAME} DESTINATION ${${PYTHON_LIB_NAME}_INSTALL_DIR} ) ``` -------------------------------- ### Setup hpp-fcl Backward Compatibility Source: https://github.com/coal-library/coal/blob/devel/CMakeLists.txt Generates and installs configuration files to maintain compatibility with hpp-fcl when enabled. ```cmake if( COAL_BACKWARD_COMPATIBILITY_WITH_HPP_FCL AND NOT BUILD_STANDALONE_PYTHON_INTERFACE ) include(CMakePackageConfigHelpers) write_basic_package_version_file( hpp-fclConfigVersion.cmake VERSION 3.0.0 COMPATIBILITY AnyNewerVersion ) install( FILES hpp-fclConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/hpp-fclConfigVersion.cmake DESTINATION lib/cmake/hpp-fcl COMPONENT hpp-fcl-compatibility ) include("${JRL_CMAKE_MODULES}/install-helpers.cmake") ADD_INSTALL_TARGET(NAME hpp-fcl-compatibility COMPONENT hpp-fcl-compatibility) endif() ``` -------------------------------- ### Finalize Project Setup Source: https://github.com/coal-library/coal/blob/devel/CMakeLists.txt Finalizes the project configuration process. ```cmake SETUP_PROJECT_FINALIZE() ``` -------------------------------- ### Run Build and Test with Pixi Source: https://github.com/coal-library/coal/blob/devel/development/build.md Use this command to install dependencies, configure, build, and test the project using Pixi. The build output will be placed in the 'build' directory. ```bash pixi run test ``` -------------------------------- ### Install Coal using Conda Source: https://github.com/coal-library/coal/blob/devel/README.md Install the Coal library from the conda-forge channel. This is the recommended method for installation. ```bash conda install coal -c conda-forge ``` -------------------------------- ### Build and Install Python Files Source: https://github.com/coal-library/coal/blob/devel/python-nb/CMakeLists.txt This section iterates through a list of Python files, builds them using a custom PYTHON_BUILD command, and installs them to the Python site-packages directory. It also adds a dependency for the main Python target. ```cmake ADD_SOURCE_GROUP(PYTHON_LIB_SOURCES) set(PYTHON_FILES __init__.py windows_dll_manager.py) foreach(pyfile ${PYTHON_FILES}) message(STATUS "Building python file ${pyfile}") PYTHON_BUILD(${MODULE_DIR} ${pyfile}) install( FILES ${MODULE_DIR}/${pyfile} DESTINATION ${Python_SITELIB}/${MODULE_DIR} ) endforeach(pyfile) ``` -------------------------------- ### Install Python Scripts Source: https://github.com/coal-library/coal/blob/devel/python/CMakeLists.txt Iterates through a list of Python files to build and install them into the designated Python library directory. ```cmake set(PYTHON_FILES __init__.py viewer.py windows_dll_manager.py) foreach(python ${PYTHON_FILES}) PYTHON_BUILD(${PROJECT_NAME} ${python}) install( FILES "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/${python}" DESTINATION ${${PYTHON_LIB_NAME}_INSTALL_DIR} ) endforeach(python) ``` -------------------------------- ### Configure Eigen and Include Directories Source: https://github.com/coal-library/coal/blob/devel/src/CMakeLists.txt Links the Eigen dependency and sets up public include directories for both build and install interfaces. ```cmake MODERNIZE_TARGET_LINK_LIBRARIES( ${PROJECT_NAME} SCOPE PUBLIC TARGETS Eigen3::Eigen INCLUDE_DIRS ${EIGEN3_INCLUDE_DIR} ) target_include_directories( ${LIBRARY_NAME} PUBLIC $ $ $ ) ``` -------------------------------- ### Install Python Library Target and Stub File Source: https://github.com/coal-library/coal/blob/devel/python-nb/CMakeLists.txt Installs the compiled Python library and its corresponding stub file to the Python site-packages directory. This makes the library available for import in Python environments. ```cmake install( TARGETS ${PYTHON_LIB_NAME_V2} EXPORT ${TARGETS_EXPORT_NAME} LIBRARY DESTINATION ${Python_SITELIB}/${MODULE_DIR} ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${PYTHON_LIB_STUB_FILE} DESTINATION ${Python_SITELIB}/${MODULE_DIR} ) ``` -------------------------------- ### Install Compatibility Modules Source: https://github.com/coal-library/coal/blob/devel/python/CMakeLists.txt Installs hpp-fcl compatibility scripts if the COAL_BACKWARD_COMPATIBILITY_WITH_HPP_FCL flag is set. ```cmake if(COAL_BACKWARD_COMPATIBILITY_WITH_HPP_FCL) PYTHON_INSTALL_ON_SITE(hppfcl __init__.py COMPONENT hpp-fcl-compatibility) PYTHON_INSTALL_ON_SITE(hppfcl viewer.py COMPONENT hpp-fcl-compatibility) endif() ``` -------------------------------- ### GitHub Release Body Example Source: https://github.com/coal-library/coal/blob/devel/development/release.md Content to be used in the GitHub release body. Replace X.Y.Z with the new version and XX.YY.ZZ with the last release version. ```markdown ## What's Changed CHANGELOG CONTENT **Full Changelog**: https://github.com/coal-library/coal/compare/vXX.YY.ZZ...vX.Y.Z ``` -------------------------------- ### Find Boost and nanoeigenpy Packages Source: https://github.com/coal-library/coal/blob/devel/python-nb/CMakeLists.txt This section finds the Boost and nanoeigenpy libraries, which are required dependencies for the project. Ensure these packages are installed and discoverable by CMake. ```cmake find_package(Boost REQUIRED) find_package(nanoeigenpy CONFIG REQUIRED) ``` -------------------------------- ### Coal Collision Detection Example Source: https://github.com/coal-library/coal/blob/devel/README.md Demonstrates creating shapes, defining their placements, setting up collision requests, performing a collision check, and accessing the results. Remember to clear the collision result before subsequent calls. ```python import pinocchio as pin import coal import numpy as np # Assuming loadConvexMesh is defined as above # shape2 = loadConvexMesh("../path/to/mesh/file.obj") # Create coal shapes shape1 = coal.Ellipsoid(0.7, 1.0, 0.8) # shape2 = loadConvexMesh("../path/to/mesh/file.obj") # Placeholder for actual mesh loading # Define the shapes' placement in 3D space T1 = coal.Transform3s() T1.setTranslation(pin.SE3.Random().translation) T1.setRotation(pin.SE3.Random().rotation) T2 = coal.Transform3s(); # Using np arrays also works T1.setTranslation(np.random.rand(3)) T2.setRotation(pin.SE3.Random().rotation) # Define collision requests and results col_req = coal.CollisionRequest() col_res = coal.CollisionResult() # Collision call # coal.collide(shape1, T1, shape2, T2, col_req, col_res) # Placeholder for actual collision call # Accessing the collision result once it has been populated # print("Is collision? ", {col_res.isCollision()}) # if col_res.isCollision(): # contact: coal.Contact = col_res.getContact(0) # print("Penetration depth: ", contact.penetration_depth) # print("Distance between the shapes including the security margin: ", contact.penetration_depth + col_req.security_margin) # print("Witness point shape1: ", contact.getNearestPoint1()) # print("Witness point shape2: ", contact.getNearestPoint2()) # print("Normal: ", contact.normal) # Before running another collision call, it is important to clear the old one # col_res.clear() ``` -------------------------------- ### Detect and Import nanobind CMake Module Source: https://github.com/coal-library/coal/blob/devel/python-nb/CMakeLists.txt This snippet detects the installed nanobind package and imports its CMake configuration. It ensures nanobind is available for use in the project. ```cmake execute_process( COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE nanobind_ROOT ) cmake_policy(PUSH) cmake_policy(SET CMP0074 NEW) find_package(nanobind CONFIG REQUIRED) cmake_policy(POP) ``` -------------------------------- ### Manual Build with CMake and Ninja Source: https://github.com/coal-library/coal/blob/devel/development/build.md Enter the Pixi shell to manually build the project using CMake and Ninja. This method offers more control over the build process. ```bash pixi shell ``` -------------------------------- ### Project Initialization and Module Inclusion Source: https://github.com/coal-library/coal/blob/devel/CMakeLists.txt Includes core project modules and initializes the project with standard arguments. ```cmake include("${JRL_CMAKE_MODULES}/base.cmake") COMPUTE_PROJECT_ARGS(PROJECT_ARGS LANGUAGES CXX) project(${PROJECT_NAME} ${PROJECT_ARGS}) include("${JRL_CMAKE_MODULES}/boost.cmake") include("${JRL_CMAKE_MODULES}/python.cmake") include("${JRL_CMAKE_MODULES}/apple.cmake") include("${JRL_CMAKE_MODULES}/ide.cmake") include("${JRL_CMAKE_MODULES}/tracy.cmake") include(CMakeDependentOption) ``` -------------------------------- ### Define Library Sources and Build Targets Source: https://github.com/coal-library/coal/blob/devel/python/CMakeLists.txt Defines source files, creates the library, and sets include directories and dependencies. ```cmake set( ${PYTHON_LIB_NAME}_SOURCES version.cc math.cc collision-geometries.cc collision.cc contact_patch.cc distance.cc coal.cc gjk.cc broadphase/broadphase.cc ) if(COAL_HAS_OCTOMAP) list(APPEND ${PYTHON_LIB_NAME}_SOURCES octree.cc) endif(COAL_HAS_OCTOMAP) add_library( ${PYTHON_LIB_NAME} MODULE ${${PYTHON_LIB_NAME}_SOURCES} ${${PYTHON_LIB_NAME}_HEADERS} ) target_include_directories( ${PYTHON_LIB_NAME} SYSTEM PRIVATE ${PYTHON_INCLUDE_DIRS} ) target_include_directories( ${PYTHON_LIB_NAME} PRIVATE "${PROJECT_SOURCE_DIR}/src" "${CMAKE_CURRENT_BINARY_DIR}" ) if(WIN32) target_link_libraries(${PYTHON_LIB_NAME} PUBLIC ${PYTHON_LIBRARY}) endif(WIN32) add_dependencies(${PROJECT_NAME}_python ${PYTHON_LIB_NAME}) ADD_HEADER_GROUP(${PYTHON_LIB_NAME}_HEADERS) ADD_SOURCE_GROUP(${PYTHON_LIB_NAME}_SOURCES) if(ENABLE_DOXYGEN_AUTODOC) add_dependencies(${PYTHON_LIB_NAME} generate_doxygen_cpp_doc) target_compile_definitions( ${PYTHON_LIB_NAME} PRIVATE COAL_HAS_DOXYGEN_AUTODOC ) endif() target_link_libraries( ${PYTHON_LIB_NAME} PUBLIC ${PROJECT_NAME}::${PROJECT_NAME} eigenpy::eigenpy Boost::boost ) ``` -------------------------------- ### Create New Release with Pixi Source: https://github.com/coal-library/coal/blob/devel/development/release.md Run these commands on the 'devel' branch to create a new version. Ensure you follow Semantic Versioning rules. Replace X.Y.Z with your new version. ```bash COAL_VERSION=X.Y.Z pixi run release-new-version git push origin git push origin vX.Y.Z ``` -------------------------------- ### Define Build Options Source: https://github.com/coal-library/coal/blob/devel/CMakeLists.txt Configures optional features such as logging, precision, and profiling support. ```cmake option(INSTALL_DOCUMENTATION "Generate and install the documentation" OFF) option(SUFFIX_SO_VERSION "Suffix library name with its version" OFF) option( COAL_TURN_ASSERT_INTO_EXCEPTION "Turn some critical Coal asserts to exception." FALSE ) option( COAL_ENABLE_LOGGING "Activate logging for warnings or error messages. Turned on by default in Debug." FALSE ) option( COAL_BACKWARD_COMPATIBILITY_WITH_HPP_FCL "Make Coal retro-compatible with HPP-FCL." FALSE ) option( COAL_USE_FLOAT_PRECISION "Use float precision (32-bit) instead of the default double precision (64-bit)" FALSE ) option( COAL_BUILD_WITH_TRACY "Build with tracy profiler for performance analysis" FALSE ) ``` -------------------------------- ### Configure Python Bindings Build Source: https://github.com/coal-library/coal/blob/devel/python/CMakeLists.txt Initializes dependencies and defines the Python library name and header files. ```cmake find_package(Boost REQUIRED) if(GENERATE_PYTHON_STUBS) include(${JRL_CMAKE_MODULES}/stubs.cmake) endif(GENERATE_PYTHON_STUBS) # Name of the Python library set(PYTHON_LIB_NAME ${PROJECT_NAME}_pywrap) set( ${PYTHON_LIB_NAME}_HEADERS fwd.hh coal.hh deprecation.hh broadphase/fwd.hh broadphase/broadphase_collision_manager.hh broadphase/broadphase_callbacks.hh pickle.hh utils/std-pair.hh serializable.hh printable.hh ) ``` -------------------------------- ### Configure Boost Policy Source: https://github.com/coal-library/coal/blob/devel/CMakeLists.txt Sets CMP0167 policy to NEW when not using clang-cl on Windows to avoid FindBoost issues. ```cmake if(NOT WIN32 OR NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") if(POLICY CMP0167) cmake_policy(SET CMP0167 NEW) # Set a default value to this policy to avoid issue with find_dependency # macro redefinition with different policy in some modules. set(CMAKE_POLICY_DEFAULT_CMP0167 NEW) endif() endif() ``` -------------------------------- ### Define Output Directory Function Source: https://github.com/coal-library/coal/blob/devel/CMakeLists.txt Sets standard output directories for runtime, library, and archive targets. ```cmake function(set_standard_output_directory target) set_target_properties( ${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib ) endfunction() ``` -------------------------------- ### Configure Source and Header Groups Source: https://github.com/coal-library/coal/blob/devel/src/CMakeLists.txt Organizes source and header files into groups for IDE project structure. ```cmake ADD_SOURCE_GROUP(${LIBRARY_NAME}_SOURCES) ADD_HEADER_GROUP(PROJECT_HEADERS_FULL_PATH) ``` -------------------------------- ### Define Project Metadata Source: https://github.com/coal-library/coal/blob/devel/CMakeLists.txt Sets the project name, description, and compatibility version for the build system. ```cmake cmake_minimum_required(VERSION 3.22) set(CXX_DISABLE_WERROR TRUE) set(PROJECT_NAME coal) set(PROJECT_ORG "coal-library") set( PROJECT_DESCRIPTION "Coal, The Collision Detection Library. Previously known as HPP-FCL, fork of FCL -- The Flexible Collision Library" ) set(PROJECT_URL "https://github.com/coal-library/coal") if(NOT BUILD_STANDALONE_PYTHON_INTERFACE) set(PROJECT_USE_CMAKE_EXPORT TRUE) endif() set(PROJECT_COMPATIBILITY_VERSION AnyNewerVersion) # To enable jrl-cmakemodules compatibility with workspace we must define the two # following lines set(PROJECT_AUTO_RUN_FINALIZE FALSE) set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}) set(PROJECT_USE_KEYWORD_LINK_LIBRARIES TRUE) set(DOXYGEN_USE_TEMPLATE_CSS TRUE) ``` -------------------------------- ### Configure Doxygen Autodocumentation Source: https://github.com/coal-library/coal/blob/devel/python/CMakeLists.txt Checks for required Python packages and sets up a custom target to generate documentation if enabled. ```cmake set( ENABLE_PYTHON_DOXYGEN_AUTODOC TRUE CACHE BOOL "Enable automatic documentation of Python bindings from Doxygen documentation" ) if(NOT ENABLE_PYTHON_DOXYGEN_AUTODOC OR NOT DOXYGEN_FOUND) set(ENABLE_DOXYGEN_AUTODOC FALSE) else() set(ENABLE_DOXYGEN_AUTODOC TRUE) execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "import lxml" RESULT_VARIABLE _pypkg_found OUTPUT_QUIET ERROR_QUIET ) if(_pypkg_found EQUAL 0) message(STATUS "Found Python package lxml.") else() set(ENABLE_DOXYGEN_AUTODOC FALSE) message( STATUS "Python package lxml not found. Python bindings will not be documented." ) message(STATUS " You can install it with: pip install lxml") endif() execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "import pylatexenc" RESULT_VARIABLE _pypkg_found OUTPUT_QUIET ERROR_QUIET ) if(NOT _pypkg_found EQUAL 0) message(STATUS "Python package pylatexenc not found.") message( STATUS " Formulas in the Python bindings documentation may look ugly." ) message(STATUS " You can install it with: pip install pylatexenc") endif() unset(_pypkg_found) endif() if(ENABLE_DOXYGEN_AUTODOC) add_custom_target( generate_doxygen_cpp_doc COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/doc/python/doxygen_xml_parser.py ${PROJECT_BINARY_DIR}/doc/doxygen-xml/index.xml ${CMAKE_CURRENT_BINARY_DIR}/doxygen_autodoc > ${CMAKE_CURRENT_BINARY_DIR}/doxygen_autodoc.log BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/doxygen_autodoc/doxygen_xml_parser_for_cmake.hh ${CMAKE_CURRENT_BINARY_DIR}/doxygen_autodoc.log COMMENT "Generating Doxygen C++ documentation" ) add_dependencies(generate_doxygen_cpp_doc doc) list( APPEND ${PYTHON_LIB_NAME}_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/doxygen_autodoc/doxygen_xml_parser_for_cmake.hh ) endif() ``` -------------------------------- ### Build Benchmark Executable Source: https://github.com/coal-library/coal/blob/devel/test/CMakeLists.txt Configures and links an executable for benchmarking Coal library performance. It includes the utility target and Boost filesystem. ```cmake ## Benchmark set(test_benchmark_target ${PROJECT_NAME}-test-benchmark) add_executable(${test_benchmark_target} benchmark.cpp) set_standard_output_directory(${test_benchmark_target}) target_link_libraries( ${test_benchmark_target} PUBLIC ${utility_target} Boost::filesystem ${PROJECT_NAME} ) ``` -------------------------------- ### Generate Python Stub File with nanobind Source: https://github.com/coal-library/coal/blob/devel/python-nb/CMakeLists.txt Generates a Python stub file (.pyi) for the nanobind module. This is useful for static analysis and IDE autocompletion. It depends on the main library target. ```cmake set(PYTHON_LIB_STUB_FILE ${MODULE_DIR}/${PYTHON_LIB_NAME_V2}.pyi) nanobind_add_stub( ${PYTHON_LIB_NAME_V2}_stub VERBOSE MODULE ${PROJECT_NAME}.${PYTHON_LIB_NAME_V2} OUTPUT ${PYTHON_LIB_STUB_FILE} DEPENDS ${PYTHON_LIB_NAME_V2} PYTHON_PATH ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_DIR} ) add_dependencies(${PROJECT_NAME}_python ${PYTHON_LIB_NAME_V2}) ``` -------------------------------- ### Add Utility Library Source: https://github.com/coal-library/coal/blob/devel/test/CMakeLists.txt Creates a static library for utility functions used by Coal. It links against the main Coal library. ```cmake set(utility_target ${PROJECT_NAME}-utility) add_library(${utility_target} STATIC utility.cpp) set_standard_output_directory(${utility_target}) target_link_libraries(${utility_target} PUBLIC ${PROJECT_NAME}) ``` -------------------------------- ### Find Boost.UnitTestFramework Source: https://github.com/coal-library/coal/blob/devel/test/CMakeLists.txt Finds the Boost library with required components for unit testing and filesystem operations. This is a prerequisite for building tests. ```cmake if(NOT BUILD_STANDALONE_PYTHON_INTERFACE) find_package(Boost REQUIRED COMPONENTS unit_test_framework filesystem) ``` -------------------------------- ### Run Coal Docker Image Source: https://github.com/coal-library/coal/blob/devel/README.md Run the Coal development Docker image. This provides a pre-configured environment for using Coal. ```bash docker run --rm -it ghcr.io/coal-library/coal:devel ``` -------------------------------- ### Configure Boost Include Directories Source: https://github.com/coal-library/coal/blob/devel/src/CMakeLists.txt Adds a third-party include directory if the detected Boost version is older than 1.78.0. ```cmake if(Boost_VERSION VERSION_LESS 1.78) target_include_directories( ${LIBRARY_NAME} PUBLIC $ $ ) endif() ``` -------------------------------- ### Load Convex Mesh in C++ Source: https://github.com/coal-library/coal/blob/devel/README.md Loads a convex mesh from a file (obj, stl, dae) and builds its convex hull for efficient collision detection. Requires the file_name as input. ```cpp #include "coal/math/transform.h" #include "coal/mesh_loader/loader.h" #include "coal/BVH/BVH_model.h" #include "coal/collision.h" #include "coal/collision_data.h" #include #include // Function to load a convex mesh from a ".obj", ".stl" or ".dae" file. // // This function imports the object inside the file as a BVHModel, i.e. a point cloud // which is hierarchically transformed into a tree of bounding volumes. // The leaves of this tree are the individual points of the point cloud // stored in the ".obj" file. // This BVH can then be used for collision detection. // // For better computational efficiency, we sometimes prefer to work with // the convex hull of the point cloud. This insures that the underlying object // is convex and thus very fast collision detection algorithms such as // GJK or EPA can be called with this object. // Consequently, after creating the BVH structure from the point cloud, this function // also computes its convex hull. std::shared_ptr loadConvexMesh(const std::string& file_name) { coal::NODE_TYPE bv_type = coal::BV_AABB; coal::MeshLoader loader(bv_type); coal::BVHModelPtr_t bvh = loader.load(file_name); bvh->buildConvexHull(true, "Qt"); return bvh->convex; } ``` -------------------------------- ### Configure HPP-FCL backward compatibility headers Source: https://github.com/coal-library/coal/blob/devel/CMakeLists.txt Sets a list of legacy HPP-FCL headers to be included when backward compatibility is enabled and the standalone Python interface is disabled. ```cmake if( COAL_BACKWARD_COMPATIBILITY_WITH_HPP_FCL AND NOT BUILD_STANDALONE_PYTHON_INTERFACE ) set( HPP_FCL_BACKWARD_COMPATIBILITY_HEADERS include/hpp/fcl/broadphase/broadphase_bruteforce.h include/hpp/fcl/broadphase/broadphase_callbacks.h include/hpp/fcl/broadphase/broadphase_collision_manager.h include/hpp/fcl/broadphase/broadphase_continuous_collision_manager.h include/hpp/fcl/broadphase/broadphase_continuous_collision_manager-inl.h include/hpp/fcl/broadphase/broadphase_dynamic_AABB_tree_array.h include/hpp/fcl/broadphase/broadphase_dynamic_AABB_tree_array-inl.h include/hpp/fcl/broadphase/broadphase_dynamic_AABB_tree.h include/hpp/fcl/broadphase/broadphase_dynamic_AABB_tree-inl.h include/hpp/fcl/broadphase/broadphase.h include/hpp/fcl/broadphase/broadphase_interval_tree.h include/hpp/fcl/broadphase/broadphase_SaP.h include/hpp/fcl/broadphase/broadphase_spatialhash.h include/hpp/fcl/broadphase/broadphase_spatialhash-inl.h include/hpp/fcl/broadphase/broadphase_SSaP.h include/hpp/fcl/broadphase/default_broadphase_callbacks.h include/hpp/fcl/broadphase/detail/hierarchy_tree_array.h include/hpp/fcl/broadphase/detail/hierarchy_tree_array-inl.h include/hpp/fcl/broadphase/detail/hierarchy_tree.h include/hpp/fcl/broadphase/detail/hierarchy_tree-inl.h include/hpp/fcl/broadphase/detail/interval_tree.h include/hpp/fcl/broadphase/detail/interval_tree_node.h include/hpp/fcl/broadphase/detail/morton.h include/hpp/fcl/broadphase/detail/morton-inl.h include/hpp/fcl/broadphase/detail/node_base_array.h include/hpp/fcl/broadphase/detail/node_base_array-inl.h include/hpp/fcl/broadphase/detail/node_base.h include/hpp/fcl/broadphase/detail/node_base-inl.h include/hpp/fcl/broadphase/detail/simple_hash_table.h include/hpp/fcl/broadphase/detail/simple_hash_table-inl.h include/hpp/fcl/broadphase/detail/simple_interval.h include/hpp/fcl/broadphase/detail/simple_interval-inl.h include/hpp/fcl/broadphase/detail/sparse_hash_table.h include/hpp/fcl/broadphase/detail/sparse_hash_table-inl.h include/hpp/fcl/broadphase/detail/spatial_hash.h include/hpp/fcl/broadphase/detail/spatial_hash-inl.h include/hpp/fcl/BV/AABB.h include/hpp/fcl/BV/BV.h include/hpp/fcl/BV/BV_node.h include/hpp/fcl/BVH/BVH_front.h include/hpp/fcl/BVH/BVH_internal.h include/hpp/fcl/BVH/BVH_model.h include/hpp/fcl/BVH/BVH_utility.h include/hpp/fcl/BV/kDOP.h include/hpp/fcl/BV/kIOS.h include/hpp/fcl/BV/OBB.h include/hpp/fcl/BV/OBBRSS.h include/hpp/fcl/BV/RSS.h include/hpp/fcl/coal.hpp include/hpp/fcl/collision_data.h include/hpp/fcl/collision_func_matrix.h include/hpp/fcl/collision.h include/hpp/fcl/collision_object.h include/hpp/fcl/collision_utility.h include/hpp/fcl/config.hh include/hpp/fcl/contact_patch/contact_patch_solver.h include/hpp/fcl/contact_patch/contact_patch_solver.hxx include/hpp/fcl/contact_patch_func_matrix.h include/hpp/fcl/contact_patch.h include/hpp/fcl/data_types.h include/hpp/fcl/deprecated.hh include/hpp/fcl/distance_func_matrix.h include/hpp/fcl/distance.h include/hpp/fcl/fwd.hh include/hpp/fcl/hfield.h include/hpp/fcl/internal/BV_fitter.h include/hpp/fcl/internal/BV_splitter.h include/hpp/fcl/internal/intersect.h include/hpp/fcl/internal/shape_shape_contact_patch_func.h include/hpp/fcl/internal/shape_shape_func.h include/hpp/fcl/internal/tools.h include/hpp/fcl/internal/traversal.h include/hpp/fcl/internal/traversal_node_base.h include/hpp/fcl/internal/traversal_node_bvhs.h include/hpp/fcl/internal/traversal_node_bvh_shape.h include/hpp/fcl/internal/traversal_node_hfield_shape.h include/hpp/fcl/internal/traversal_node_setup.h include/hpp/fcl/internal/traversal_node_shapes.h include/hpp/fcl/internal/traversal_recurse.h include/hpp/fcl/internal/traversal_node_octree.h include/hpp/fcl/logging.h include/hpp/fcl/math/matrix_3f.h include/hpp/fcl/math/transform.h include/hpp/fcl/math/types.h include/hpp/fcl/math/vec_3f.h include/hpp/fcl/mesh_loader/assimp.h include/hpp/fcl/mesh_loader/loader.h include/hpp/fcl/narrowphase/gjk.h include/hpp/fcl/narrowphase/minkowski_difference.h include/hpp/fcl/narrowphase/narrowphase_defaults.h include/hpp/fcl/narrowphase/narrowphase.h ``` -------------------------------- ### Initialize JRL CMake Modules Source: https://github.com/coal-library/coal/blob/devel/CMakeLists.txt Locates JRL CMake modules via local submodule, system package, or by fetching them from a remote repository. ```cmake set(JRL_CMAKE_MODULES "${CMAKE_CURRENT_LIST_DIR}/cmake") if(EXISTS "${JRL_CMAKE_MODULES}/base.cmake") message(STATUS "JRL cmakemodules found in 'cmake/' git submodule") else() find_package(jrl-cmakemodules QUIET CONFIG) if(jrl-cmakemodules_FOUND) get_property( JRL_CMAKE_MODULES TARGET jrl-cmakemodules::jrl-cmakemodules PROPERTY INTERFACE_INCLUDE_DIRECTORIES ) message(STATUS "JRL cmakemodules found on system at ${JRL_CMAKE_MODULES}") else() message(STATUS "JRL cmakemodules not found. Let's fetch it.") include(FetchContent) FetchContent_Declare( "jrl-cmakemodules" GIT_REPOSITORY "https://github.com/jrl-umi3218/jrl-cmakemodules.git" ) FetchContent_MakeAvailable("jrl-cmakemodules") FetchContent_GetProperties("jrl-cmakemodules" SOURCE_DIR JRL_CMAKE_MODULES) endif() endif() ``` -------------------------------- ### Set Module Path Source: https://github.com/coal-library/coal/blob/devel/CMakeLists.txt Prepends the Assimp external module directory to the CMAKE_MODULE_PATH. ```cmake set( CMAKE_MODULE_PATH ${JRL_CMAKE_MODULES}/find-external/assimp/ ${CMAKE_MODULE_PATH} ) ``` -------------------------------- ### Link External Dependencies Source: https://github.com/coal-library/coal/blob/devel/src/CMakeLists.txt Links the library against external dependencies using custom modernization macros and standard CMake commands. ```cmake MODERNIZE_TARGET_LINK_LIBRARIES( ${LIBRARY_NAME} SCOPE PRIVATE TARGETS assimp::assimp LIBRARIES ${assimp_LIBRARIES} INCLUDE_DIRS ${assimp_INCLUDE_DIR} ) target_link_libraries( ${LIBRARY_NAME} PUBLIC Boost::serialization Boost::filesystem ) ``` -------------------------------- ### Perform Collision Detection in C++ Source: https://github.com/coal-library/coal/blob/devel/README.md Demonstrates collision detection between two shapes (ellipsoid and convex mesh) using the Coal library. Sets up collision request parameters like security margin and retrieves collision results including penetration depth and witness points. ```cpp #include "coal/math/transform.h" #include "coal/mesh_loader/loader.h" #include "coal/BVH/BVH_model.h" #include "coal/collision.h" #include "coal/collision_data.h" #include #include // Function to load a convex mesh from a ".obj", ".stl" or ".dae" file. // // This function imports the object inside the file as a BVHModel, i.e. a point cloud // which is hierarchically transformed into a tree of bounding volumes. // The leaves of this tree are the individual points of the point cloud // stored in the ".obj" file. // This BVH can then be used for collision detection. // // For better computational efficiency, we sometimes prefer to work with // the convex hull of the point cloud. This insures that the underlying object // is convex and thus very fast collision detection algorithms such as // GJK or EPA can be called with this object. // Consequently, after creating the BVH structure from the point cloud, this function // also computes its convex hull. std::shared_ptr loadConvexMesh(const std::string& file_name) { coal::NODE_TYPE bv_type = coal::BV_AABB; coal::MeshLoader loader(bv_type); coal::BVHModelPtr_t bvh = loader.load(file_name); bvh->buildConvexHull(true, "Qt"); return bvh->convex; } int main() { // Create the coal shapes. // Coal supports many primitive shapes: boxes, spheres, capsules, cylinders, ellipsoids, cones, planes, // halfspace and convex meshes (i.e. convex hulls of clouds of points). // It also supports BVHs (bounding volumes hierarchies), height-fields and octrees. std::shared_ptr shape1 = std::make_shared(0.7, 1.0, 0.8); std::shared_ptr shape2 = loadConvexMesh("../path/to/mesh/file.obj"); // Define the shapes' placement in 3D space coal::Transform3s T1; T1.setQuatRotation(coal::Quaternion3f::UnitRandom()); T1.setTranslation(coal::Vec3s::Random()); coal::Transform3s T2 = coal::Transform3s::Identity(); T2.setQuatRotation(coal::Quaternion3f::UnitRandom()); T2.setTranslation(coal::Vec3s::Random()); // Define collision requests and results. // // The collision request allows to set parameters for the collision pair. // For example, we can set a positive or negative security margin. // If the distance between the shapes is less than the security margin, the shapes // will be considered in collision. // Setting a positive security margin can be usefull in motion planning, // i.e to prevent shapes from getting too close to one another. // In physics simulation, allowing a negative security margin may be usefull to stabilize the simulation. coal::CollisionRequest col_req; col_req.security_margin = 1e-1; // A collision result stores the result of the collision test (signed distance between the shapes, // witness points location, normal etc.) coal::CollisionResult col_res; // Collision call coal::collide(shape1.get(), T1, shape2.get(), T2, col_req, col_res); // We can access the collision result once it has been populated std::cout << "Collision? " << col_res.isCollision() << "\n"; if (col_res.isCollision()) { coal::Contact contact = col_res.getContact(0); // The penetration depth does **not** take into account the security margin. // Consequently, the penetration depth is the true signed distance which separates the shapes. // To have the distance which takes into account the security margin, we can simply add the two together. std::cout << "Penetration depth: " << contact.penetration_depth << "\n"; std::cout << "Distance between the shapes including the security margin: " << contact.penetration_depth + col_req.security_margin << "\n"; std::cout << "Witness point on shape1: " << contact.nearest_points[0].transpose() << "\n"; std::cout << "Witness point on shape2: " << contact.nearest_points[1].transpose() << "\n"; std::cout << "Normal: " << contact.normal.transpose() << "\n"; } // Before calling another collision test, it is important to clear the previous results stored in the collision result. col_res.clear(); return 0; } ``` -------------------------------- ### Configure Conditional Build Features Source: https://github.com/coal-library/coal/blob/devel/src/CMakeLists.txt Applies compile definitions and links libraries based on enabled project features like logging, precision, or profiling. ```cmake if(COAL_ENABLE_LOGGING) target_link_libraries(${LIBRARY_NAME} PUBLIC Boost::log) # The compile flag `BOOST_LOG_DYN_LINK` is required here. target_compile_definitions( ${LIBRARY_NAME} PUBLIC COAL_ENABLE_LOGGING BOOST_LOG_DYN_LINK ) endif() if(COAL_USE_FLOAT_PRECISION) target_compile_definitions(${LIBRARY_NAME} PUBLIC COAL_USE_FLOAT_PRECISION) endif() if(COAL_BUILD_WITH_TRACY) target_compile_definitions(${LIBRARY_NAME} PUBLIC COAL_TRACY_ENABLE) target_link_libraries(${LIBRARY_NAME} PUBLIC Tracy::TracyClient) endif() if(WIN32) # There is an issue with MSVC 2017 and Eigen (due to std::aligned_storage). # See https://github.com/ceres-solver/ceres-solver/issues/481 target_compile_definitions( ${LIBRARY_NAME} PRIVATE _ENABLE_EXTENDED_ALIGNED_STORAGE ) endif(WIN32) if(COAL_TURN_ASSERT_INTO_EXCEPTION) target_compile_definitions( ${LIBRARY_NAME} PUBLIC COAL_TURN_ASSERT_INTO_EXCEPTION ) endif() if(COAL_BACKWARD_COMPATIBILITY_WITH_HPP_FCL) target_compile_definitions( ${LIBRARY_NAME} PUBLIC COAL_BACKWARD_COMPATIBILITY_WITH_HPP_FCL ) endif() if(COAL_HAS_QHULL) target_compile_definitions(${LIBRARY_NAME} PRIVATE COAL_HAS_QHULL) target_link_libraries(${LIBRARY_NAME} PRIVATE Qhull::qhull_r Qhull::qhullcpp) endif() ``` -------------------------------- ### Load Convex Mesh with Coal Source: https://github.com/coal-library/coal/blob/devel/README.md Loads a mesh file and builds its convex hull. Ensure the file path is correct. ```python import pinocchio as pin import coal def loadConvexMesh(file_name: str): loader = coal.MeshLoader() bvh: coal.BVHModelBase = loader.load(file_name) bvh.buildConvexHull(True, "Qt") return bvh.convex ``` -------------------------------- ### Informative Build Message Source: https://github.com/coal-library/coal/blob/devel/test/python_unit/CMakeLists.txt Displays a message during the build process indicating the Python executable that will be used for running tests. This helps in debugging test execution environments. ```cmake message( STATUS " Python tests will be run with Python executable at ${Python_EXECUTABLE}" ) ``` -------------------------------- ### Build Python Interface Subdirectory Source: https://github.com/coal-library/coal/blob/devel/test/CMakeLists.txt Conditionally includes the 'python_unit' subdirectory for building the Python interface if the BUILD_PYTHON_INTERFACE option is enabled. ```cmake ## Python tests if(BUILD_PYTHON_INTERFACE) add_subdirectory(python_unit) endif(BUILD_PYTHON_INTERFACE) ``` -------------------------------- ### Set Default Build Type Source: https://github.com/coal-library/coal/blob/devel/CMakeLists.txt Sets the default CMake build type to RelWithDebInfo. ```cmake SET_DEFAULT_CMAKE_BUILD_TYPE("RelWithDebInfo") ``` -------------------------------- ### Python Bindings for Coal Source: https://github.com/coal-library/coal/blob/devel/README.md This snippet shows the import statements for using the Coal library in Python. It includes the numpy library and the coal library itself. Optional import for Pinocchio is also shown. ```python import numpy as np import coal # Optional: # The Pinocchio library is a rigid body algorithms library and has a handy SE3 module. # It can be installed as simply as `conda -c conda-forge install pinocchio`. ``` -------------------------------- ### Configure OctoMap Preprocessor Macros Source: https://github.com/coal-library/coal/blob/devel/CMakeLists.txt Appends OctoMap version and feature flags to the compiler flags via PKG_CONFIG_APPEND_CFLAGS. ```cmake PKG_CONFIG_APPEND_CFLAGS( "-DCOAL_HAS_OCTOMAP -DCOAL_HAVE_OCTOMAP -DFCL_HAVE_OCTOMAP -DOCTOMAP_MAJOR_VERSION=${OCTOMAP_MAJOR_VERSION} -DOCTOMAP_MINOR_VERSION=${OCTOMAP_MINOR_VERSION} -DOCTOMAP_PATCH_VERSION=${OCTOMAP_PATCH_VERSION}" ) ``` -------------------------------- ### Define Python Library Module with nanobind Source: https://github.com/coal-library/coal/blob/devel/python-nb/CMakeLists.txt This snippet defines a nanobind Python module, specifying static linking, LTO, and suppression of warnings. It includes source files and links against the main project library and Boost. ```cmake set(PYTHON_LIB_NAME_V2 ${PROJECT_NAME}_pywrap_nb) set( PYTHON_LIB_HEADERS broadphase/broadphase_callbacks_collision_manager.hh fwd.h pickle.hh serializable.hh ) set( PYTHON_LIB_SOURCES broadphase/broadphase.cc aabb.cc bvh.cc collision-geometries.cc collision.cc contact_patch.cc distance.cc math.cc gjk.cc height_field.cc memory-footprint.cc shapes.cc module.cc ) if(COAL_HAS_OCTOMAP) list(APPEND PYTHON_LIB_SOURCES octree.cc) endif(COAL_HAS_OCTOMAP) nanobind_add_module(${PYTHON_LIB_NAME_V2} NB_STATIC LTO NB_SUPPRESS_WARNINGS ${PYTHON_LIB_SOURCES}) target_link_libraries( ${PYTHON_LIB_NAME_V2} PRIVATE ${PROJECT_NAME}::${PROJECT_NAME} Boost::boost ) target_compile_definitions( ${PYTHON_LIB_NAME_V2} PRIVATE COAL_PYTHON_LIBNAME=${PYTHON_LIB_NAME_V2} ) ``` -------------------------------- ### Add Python Unit Tests Source: https://github.com/coal-library/coal/blob/devel/test/python_unit/CMakeLists.txt Adds individual Python unit tests to the build system. Each test is defined by a target name, the path to its Python script, and the directory where Python bindings are located. ```cmake foreach(TEST ${${PROJECT_NAME}_PYTHON_TESTS}) ADD_PYTHON_UNIT_TEST( "${PROJECT_NAME}-py-${TEST}" "test/python_unit/${TEST}.py" ${PYTHON_BINDINGS_BINARY_DIR} ) endforeach() ``` -------------------------------- ### Set Target Properties for Python Library Source: https://github.com/coal-library/coal/blob/devel/python-nb/CMakeLists.txt Configures the output directory for the Python library target. This ensures the compiled library is placed in the expected location within the build directory. ```cmake set(MODULE_DIR ${PROJECT_NAME}) set_target_properties( ${PYTHON_LIB_NAME_V2} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${MODULE_DIR}" ) ``` -------------------------------- ### Set Python Test Targets Source: https://github.com/coal-library/coal/blob/devel/test/python_unit/CMakeLists.txt Configures the list of Python test targets for the project. These are used later to add individual tests. ```cmake set( ${PROJECT_NAME}_PYTHON_TESTS geometric_shapes api collision collision_manager pickling ) ``` -------------------------------- ### Set Python Bindings Directory Source: https://github.com/coal-library/coal/blob/devel/test/python_unit/CMakeLists.txt Conditionally sets the directory for Python bindings based on the COAL_PYTHON_NANOBIND flag. Use this to specify the output location for generated Python modules. ```cmake if(COAL_PYTHON_NANOBIND) set(PYTHON_BINDINGS_BINARY_DIR "python-nb") else() set(PYTHON_BINDINGS_BINARY_DIR "python") endif() ``` -------------------------------- ### Add Multiple Coal Tests Source: https://github.com/coal-library/coal/blob/devel/test/CMakeLists.txt Adds various unit tests for different functionalities of the Coal library, such as math, collision, and shape operations. ```cmake add_coal_test(math math.cpp) ``` ```cmake add_coal_test(collision collision.cpp) ``` ```cmake add_coal_test(contact_patch contact_patch.cpp) ``` ```cmake add_coal_test(distance distance.cpp) ``` ```cmake add_coal_test(swept_sphere_radius swept_sphere_radius.cpp) ``` ```cmake add_coal_test(normal_and_nearest_points normal_and_nearest_points.cpp) ``` ```cmake add_coal_test(distance_lower_bound distance_lower_bound.cpp) ``` ```cmake add_coal_test(security_margin security_margin.cpp) ``` ```cmake add_coal_test(geometric_shapes geometric_shapes.cpp) ``` ```cmake add_coal_test(shape_inflation shape_inflation.cpp) ``` ```cmake add_coal_test(polygon_convex_hull polygon_convex_hull.cpp) ``` ```cmake add_coal_test(patch_simplifier patch_simplifier.cpp) ``` ```cmake add_coal_test(gjk_asserts gjk_asserts.cpp) ``` ```cmake add_coal_test(frontlist frontlist.cpp) set_tests_properties(${PROJECT_NAME}-frontlist PROPERTIES TIMEOUT 7200) ``` ```cmake add_coal_test(capsule_capsule capsule_capsule.cpp) ``` ```cmake add_coal_test(box_box_distance box_box_distance.cpp) ``` ```cmake add_coal_test(box_box_collision box_box_collision.cpp) ``` ```cmake add_coal_test(simple simple.cpp) ``` ```cmake add_coal_test(capsule_box_1 capsule_box_1.cpp) ``` ```cmake add_coal_test(capsule_box_2 capsule_box_2.cpp) ``` ```cmake add_coal_test(obb obb.cpp) ``` ```cmake add_coal_test(convex convex.cpp) ``` ```cmake add_coal_test(bvh_models bvh_models.cpp) ``` ```cmake add_coal_test(collision_node_asserts collision_node_asserts.cpp) ``` ```cmake add_coal_test(hfields hfields.cpp) ``` ```cmake add_coal_test(profiling profiling.cpp) ``` ```cmake add_coal_test(gjk gjk.cpp) ``` ```cmake add_coal_test(accelerated_gjk accelerated_gjk.cpp) ``` ```cmake add_coal_test(gjk_convergence_criterion gjk_convergence_criterion.cpp) ``` ```cmake if(COAL_HAS_OCTOMAP) add_coal_test(octree octree.cpp) endif(COAL_HAS_OCTOMAP) ``` ```cmake add_coal_test(serialization serialization.cpp) ``` ```cmake add_coal_test(alloca alloca.cpp) ``` ```cmake # Broadphase add_coal_test(broadphase broadphase.cpp) set_tests_properties(${PROJECT_NAME}-broadphase PROPERTIES WILL_FAIL TRUE) add_coal_test(broadphase_dynamic_AABB_tree broadphase_dynamic_AABB_tree.cpp) add_coal_test(broadphase_collision_1 broadphase_collision_1.cpp) add_coal_test(broadphase_collision_2 broadphase_collision_2.cpp) ``` -------------------------------- ### Generate Python Stubs Source: https://github.com/coal-library/coal/blob/devel/python/CMakeLists.txt Conditionally generates Python stubs using the stubgen tool if the GENERATE_PYTHON_STUBS flag is enabled. ```cmake if(GENERATE_PYTHON_STUBS) LOAD_STUBGEN() GENERATE_STUBS( ${CMAKE_CURRENT_BINARY_DIR} ${PROJECT_NAME} ${ABSOLUTE_PYTHON_SITELIB} ${PYTHON_LIB_NAME} ${PROJECT_NAME}::${PROJECT_NAME} ) endif(GENERATE_PYTHON_STUBS) ```