### Python Installation via Anaconda Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/CompilationNotes.txt Instructions for compiling and installing Python bindings for the Hamilton Fast Marching library using Anaconda. This involves modifying library paths, activating an environment, building, and installing the Python package. ```bash source activate testhfm cd JMM_CPPLibs/build make install cd HamiltonFastMarching/Interfaces/Python python setup.py install ``` -------------------------------- ### CMake Project Setup and Library Inclusion Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/MathematicaHFM/CMakeLists.txt Initializes the CMake project, sets the C++ standard to 17, and includes external libraries from specified directories. It also sets up include paths for the project. ```cmake cmake_minimum_required(VERSION 3.1) set (CMAKE_CXX_STANDARD 17) project(MathematicaHFM) # Include headers (../../JMM_CPPLibs and ../../Headers) set(DummyBinDir "${CMAKE_CURRENT_BINARY_DIR}/Dummy") add_subdirectory("../../JMM_CPPLibs" "${DummyBinDir}/JMM_CPPLibs") add_subdirectory("../../Headers" "${DummyBinDir}/HFMHeaders") include(${CMAKE_CURRENT_SOURCE_DIR}/../common.cmake) include_directories(${PROJECT_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) ``` -------------------------------- ### CMake Project Setup and C++ Standard Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/FileHFM/CMakeLists.txt Initializes the CMake project and sets the C++ standard to C++17. This is a foundational step for any CMake project to define the build environment and language features. ```cmake cmake_minimum_required(VERSION 3.1) set (CMAKE_CXX_STANDARD 17) project(FileHFM) ``` -------------------------------- ### Install HamiltonFastMarching using Conda (Python) Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Readme.md Installs pre-compiled binaries of the HFM library linked with Python using the Anaconda package manager. This is the recommended method if you do not plan to modify the C++ source code. It requires Anaconda or Miniconda to be installed. ```console conda install -c agd-lbr hfm ``` -------------------------------- ### Mathematica Integration and Configuration Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/MathematicaHFM/CMakeLists.txt Configures the build to find and link against a Mathematica installation. It sets the module path, enables specific library usage, and prints information about the found Mathematica installation, including version and system IDs. ```cmake ######################## Additional lines for Wolfram Library link set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake/Mathematica") set (Mathematica_USE_LIBCXX_LIBRARIES ON) # finds newest Mathematica installation and its default components find_package(Mathematica) if (${Mathematica_FOUND}) message(STATUS "Mathematica Version ${Mathematica_VERSION}") # Mathematica_SYSTEM_IDS contains the list of Mathematica platform system IDs that the # project is being compiled for. This usually contains just one entry (e.g., "Windows"). # It may contain multiple entries if we are building a universal binary under Mac OS X # (e.g., "MacOSX-x86-64;MacOSX-x86"). message(STATUS "Mathematica Target System IDs ${Mathematica_SYSTEM_IDS}") # Mathematica_HOST_SYSTEM_IDS is the list of Mathematica platform system IDs that can run on the build host. If we are executing the CMake build under a 64-bit version of Windows this would be "Windows-x86-64;Windows". Under a 32-bit version of Windows this would be just "Windows". message(STATUS "Mathematica Host System IDs ${Mathematica_HOST_SYSTEM_IDS}") # Mathematica_BASE_DIR is the directory for systemwide files to be loaded by Mathematica message(STATUS "Mathematica Base Directory ${Mathematica_BASE_DIR}") # Mathematica_USERBASE_DIR is the directory for user-specific files to be loaded by Mathematica message(STATUS "Mathematica User Base Directory ${Mathematica_USERBASE_DIR}") endif() if (${Mathematica_WolframLibrary_FOUND}) # library found, so let's compile code include_directories(${Mathematica_INCLUDE_DIRS}) endif() ``` -------------------------------- ### Install HamiltonFastMarching via Conda Source: https://context7.com/mirebeau/hamiltonfastmarching/llms.txt Installs the HamiltonFastMarching (HFM) library and its Python binaries using the conda package manager. It is recommended to create a dedicated environment for the installation. This method is suitable for Python users who want to quickly set up the library. ```bash # Create a dedicated environment (recommended) conda create -n hfm_env python=3.9 conda activate hfm_env # Install HFM library from agd-lbr channel conda install -c agd-lbr hfm ``` -------------------------------- ### Implement Custom Fast Marching Solvers in C++ Source: https://context7.com/mirebeau/hamiltonfastmarching/llms.txt This C++ code demonstrates the core API for custom fast-marching solvers using the HamiltonFastMarching class. It includes setup for isotropic 2D problems, configuring domain parameters, speed fields, seed points, and endpoints. The output provides computed distance values and geodesic paths. ```cpp #include "Headers/Base/HamiltonFastMarching.h" #include "Headers/Specializations/Isotropic.h" // Define traits and stencil for isotropic 2D problem using StencilType = StencilIsotropic<2>; using HFM = HamiltonFastMarching>; using IndexType = HFM::IndexType; using ScalarType = HFM::ScalarType; using PointType = HFM::PointType; // Setup IO interface (file-based or library-based) IO io; // Implementation depends on interface choice // Configure domain io.Set("dims", PointType{100, 100}); io.Set("gridScale", 1.0/100.0); // Set constant speed field io.Set("speed", 1.0); // Define seed points std::vector seeds = {{0.5, 0.5}}; io.SetVector("seeds", seeds); // Define geodesic endpoints std::vector tips = {{0.1, 0.1}, {0.9, 0.9}}; io.SetVector("tips", tips); // Create stencil and run HFM StencilType stencil; HFMInterface> hfmi(io, stencil); hfmi.Run(); // Access computed distance values auto values = io.GetArray("values"); // Access geodesic paths auto geodesicPoints = io.GetArray("geodesicPoints"); auto geodesicLengths = io.GetArray("geodesicLengths"); ``` -------------------------------- ### Compile HamiltonFastMarching for Matlab Interface Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Readme.md Builds the executables for the Matlab interface of HamiltonFastMarching. Unlike other interfaces, this involves navigating to the specific MatlabHFM example files directory and using the provided CompileMexHFM script. Consult the script and examples for detailed instructions. ```matlab cd Interfaces/MatlabHFM/ExampleFiles CompileMexHFM ``` -------------------------------- ### Select Fast Marching Models in Python Source: https://context7.com/mirebeau/hamiltonfastmarching/llms.txt This Python code snippet demonstrates how to configure different metric models for fast-marching computations. It includes examples for isotropic, Riemannian, Reeds-Shepp, Dubins, and Elastica models, specifying their respective key parameters. ```python # Example: Model selection in Python model_configs = { 'isotropic': {'model': 'Isotropic2', 'speed': 1.0}, 'riemannian': {'model': 'Riemann2', 'metric': metric_tensor}, 'reeds_shepp': {'model': 'ReedsShepp2', 'xi': 0.1, 'eps': 0.1, 'projective': 1}, 'dubins': {'model': 'Dubins2', 'xi': 0.2, 'eps': 0.1}, 'elastica': {'model': 'Elastica2', 'xi': 0.1, 'eps': 0.1}, } ``` -------------------------------- ### CMake Project Setup and pybind11 Module Definition Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/PythonHFM/CMakeLists.txt Initializes the CMake project, sets the C++ standard, and finds the pybind11 package. It then defines pybind11 modules for different HFM models, setting specific compile definitions for each model. This is crucial for creating Python extensions for the C++ HFM library. ```cmake cmake_minimum_required(VERSION 3.3) set(CMAKE_CXX_STANDARD 17) set(CMAKE_OSX_DEPLOYMENT_TARGET 10.14 CACHE STRING "Minimum OS X deployment version" FORCE) # Needed for pybind11 2.4.3 under osx. #https://stackoverflow.com/questions/34208360/cmake-seems-to-ignore-cmake-osx-deployment-target project(pybind11_hfm) FIND_PACKAGE(pybind11) message("pybind11 version : " ${pybind11_VERSION} ", CMAKE_CXX_COMPILER_ID " ${CMAKE_CXX_COMPILER_ID}) message("CMAKE_OSX_DEPLOYMENT_TARGET " ${CMAKE_OSX_DEPLOYMENT_TARGET}) include(${CMAKE_CURRENT_SOURCE_DIR}/../common.cmake) INCLUDE_DIRECTORIES(../../Headers ../../JMM_CPPLibs) # ------- Declare the different builds ------- foreach(model ${ModelNames}) pybind11_add_module(HFM_${model} src/main.cpp) target_compile_definitions(HFM_${model} PRIVATE ModelName=${model} PythonModuleName=HFM_${model}) # Fixes an issue with pybind11 on clang, see https://github.com/pybind/pybind11/issues/1604 #if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") # message("Applying fix for pybind11 under AppleClang") # target_compile_options(HFM_${model} INTERFACE -fsized-deallocation) #endif() endforeach(model) ``` -------------------------------- ### CMake Project Setup and Configuration Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/FileVDQ/CMakeLists.txt Configures the CMake build system for the FileVDQ project. It sets the C++ standard to 17, defines the project name, and sets up directories for dummy binaries and external libraries. It also includes subdirectories for 'JMM_CPPLibs' and 'Headers'. ```cmake cmake_minimum_required(VERSION 3.1) set (CMAKE_CXX_STANDARD 17) project(FileVDQ) #set(JMM_CPPLibs_dir "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../Github/JMM_CPPLibs" CACHE FILEPATH "JMM_CPPLibs directory") set(DummyBinDir "${CMAKE_CURRENT_BINARY_DIR}/Dummy") add_subdirectory("../../JMM_CPPLibs" "${DummyBinDir}/JMM_CPPLibs") add_subdirectory("Headers") ``` -------------------------------- ### Installing Jupyter Conda Package Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/CompilationNotes.txt Command to install the nb_conda package for use within Jupyter notebooks, typically used in conjunction with Anaconda environments. ```bash conda install nb_conda ``` -------------------------------- ### CMake Project Setup and Library Inclusion Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/MatlabHFM/CMakeLists.txt Configures the CMake build system for the project, setting the C++ standard to 17 and including external libraries from 'JMM_CPPLibs' and 'HFMHeaders'. It also defines a cache variable for the MATLAB directory, which is used for include paths. ```cmake cmake_minimum_required(VERSION 3.1) set (CMAKE_CXX_STANDARD 17) project(NotMatlabHFM) set(DummyBinDir "${CMAKE_CURRENT_BINARY_DIR}/Dummy") add_subdirectory("../../JMM_CPPLibs" "${DummyBinDir}/JMM_CPPLibs") add_subdirectory("../../Headers" "${DummyBinDir}/HFMHeaders") #set a machine dependent path set(Matlab_dir "/Applications/MATLAB_R2020a.app/extern/include" CACHE FILEPATH "Matlab directory") include(${CMAKE_CURRENT_SOURCE_DIR}/../common.cmake) include_directories(${PROJECT_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${Matlab_dir}) ``` -------------------------------- ### Include Implementation Subdirectory in CMake Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Headers/Base/CMakeLists.txt This CMake command adds the 'Implementation' subdirectory to the build. It allows for modular project structure, where the implementation details of the Hamilton-Fast-Marching algorithm are managed separately. It also makes implementation headers available in the parent scope. ```cmake add_subdirectory(Implementation) set(Base_Implementation_Headers ${Base_Implementation_Headers} PARENT_SCOPE) ``` -------------------------------- ### Include Implementation Subdirectory in CMake Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Headers/ExtraAlgorithms/CMakeLists.txt This CMake command adds the 'Implementation' subdirectory to the build process. It allows for modular development by including build rules and configurations defined within that subdirectory. The `set` command then collects headers from this implementation subdirectory into a parent scope variable. ```cmake add_subdirectory(Implementation) set(ExtraAlgorithms_Implementation_Headers ${ExtraAlgorithms_Implementation_Headers} PARENT_SCOPE) ``` -------------------------------- ### Compile HamiltonFastMarching from Source Source: https://context7.com/mirebeau/hamiltonfastmarching/llms.txt Builds the HamiltonFastMarching library from source using CMake, primarily for file-based interfaces. This process involves cloning the repository and its dependencies, creating a build directory, and then compiling the FileHFM interface. The compilation produces executables for different model names. ```bash # Clone repository and dependencies git clone https://github.com/Mirebeau/HamiltonFastMarching.git git clone https://github.com/Mirebeau/JMM_CPPLibs.git # Create build directory and compile FileHFM interface mkdir bin && cd bin cmake ../HamiltonFastMarching/Interfaces/FileHFM make # Verify compilation - produces FileHFM_ executables ls FileHFM_* ``` -------------------------------- ### Include Project Subdirectories and Headers Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/FileHFM/CMakeLists.txt Adds subdirectories for JMM_CPPLibs and Headers, placing them in a dummy binary directory to manage build outputs. It also includes common CMake modules and project-specific headers. ```cmake # Include headers (../../JMM_CPPLibs and ../../Headers) set(DummyBinDir "${CMAKE_CURRENT_BINARY_DIR}/Dummy") add_subdirectory("../../JMM_CPPLibs" "${DummyBinDir}/JMM_CPPLibs") add_subdirectory("../../Headers" "${DummyBinDir}/HFMHeaders") include(${CMAKE_CURRENT_SOURCE_DIR}/../common.cmake) include(ide_headers_layout.cmake) include_directories(${PROJECT_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) ``` -------------------------------- ### CMake Build Configuration: Setting Base Implementation Headers Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Headers/Base/Implementation/CMakeLists.txt This CMake code snippet defines a list of header files to be included as base implementations for the project. It utilizes CMAKE variables to specify the source directory and includes several .hxx files related to Eulerian stencils, periodic grids, and the Hamilton Fast Marching algorithm. ```cmake set(Base_Implementation_Headers ${CMAKE_CURRENT_SOURCE_DIR}/EulerianStencil.hxx ${CMAKE_CURRENT_SOURCE_DIR}/PeriodicGrid.hxx ${CMAKE_CURRENT_SOURCE_DIR}/EulerianStencil.hxx ${CMAKE_CURRENT_SOURCE_DIR}/HamiltonFastMarching.hxx ${CMAKE_CURRENT_SOURCE_DIR}/HFM_ParamDefault.hxx ${CMAKE_CURRENT_SOURCE_DIR}/HFMInterface.hxx ${CMAKE_CURRENT_SOURCE_DIR}/GeodesicODESolver.hxx ${CMAKE_CURRENT_SOURCE_DIR}/GeodesicDiscreteSolver.hxx ${CMAKE_CURRENT_SOURCE_DIR}/HFM_StencilLag2.hxx ${CMAKE_CURRENT_SOURCE_DIR}/HFM_StencilLag3.hxx ${CMAKE_CURRENT_SOURCE_DIR}/HFM_StencilRecompute.hxx ${CMAKE_CURRENT_SOURCE_DIR}/HFM_StencilShare.hxx PARENT_SCOPE ) ``` -------------------------------- ### Include Output Subdirectory and Manage Variables (CMake) Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/JMM_CPPLibs/FileIO/CMakeLists.txt This snippet configures the CMake build system. It includes the 'Output' subdirectory, making its build targets available. It also sets and propagates the 'Output_Headers' and 'PROJECT_DIR' variables to the parent scope, ensuring they are accessible in the main project configuration. ```cmake add_subdirectory(Output) set(Output_Headers ${Output_Headers} PARENT_SCOPE) set(PROJECT_DIR ${PROJECT_DIR} "${CMAKE_CURRENT_SOURCE_DIR}" PARENT_SCOPE) ``` -------------------------------- ### Python Input Parameter Configuration Source: https://context7.com/mirebeau/hamiltonfastmarching/llms.txt Defines the input parameters for the HamiltonFastMarching library in Python using a dictionary. This includes grid dimensions, metric properties, seed and tip points, obstacles, output options, and stopping criteria. ```python input_params = { # === Domain Configuration === 'dims': np.array([nx, ny]), # Grid dimensions 'gridScale': 1.0/n, # Physical size per pixel 'origin': np.array([0.0, 0.0]), # Physical origin coordinates 'arrayOrdering': 'YXZ_RowMajor', # 'YXZ_RowMajor' (NumPy) or 'XYZ_ColumnMajor' (Fortran) # === Metric Definition === 'speed': 1.0, # Isotropic: scalar or array 'metric': metric_array, # Riemannian: symmetric tensor field 'dualMetric': dual_metric_array, # Riemannian: dual (inverse) metric 'xi': 0.1, # Curvature models: typical radius 'eps': 0.1, # Curvature models: relaxation # === Source/Target Points === 'seeds': np.array([[x, y]]), # Starting points for propagation 'seeds_Unoriented': np.array([[x, y]]),# Seeds without orientation (curvature models) 'tips': np.array([[x, y]]), # Geodesic endpoints 'tips_Unoriented': np.array([[x, y]]), # Tips without orientation # === Obstacles === 'walls': wall_array, # Binary obstacle mask (1=blocked) # === Output Options === 'exportValues': 1, # Export distance map 'exportGeodesicFlow': 1, # Export flow directions 'verbosity': 1, # 0=silent, 1=normal, 2=verbose # === Stopping Criteria === 'stopWhenTipsReached': 1, # Stop when all tips reached 'geodesicVolumeBound': 10.0, # Max geodesic computation volume } ``` -------------------------------- ### Include Implementation Subdirectory in CMake Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Headers/Specializations/CMakeLists.txt This CMake command adds the 'Implementation' subdirectory to the build. It also sets the `Specializations_Implementation_Headers` variable, making implementation-specific headers available in parent scopes. This is crucial for organizing and managing project components. ```cmake add_subdirectory(Implementation) set(Specializations_Implementation_Headers ${Specializations_Implementation_Headers} PARENT_SCOPE) ``` -------------------------------- ### CMake: Include Subdirectories and Aggregate Headers Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Headers/CMakeLists.txt This CMake configuration snippet demonstrates how to include subdirectories and aggregate header files from them. It uses add_subdirectory to process child directories and then sets variables in the parent scope to collect headers from these subdirectories. ```cmake add_subdirectory(Base) set(Base_Headers ${Base_Headers} PARENT_SCOPE) set(Base_Implementation_Headers ${Base_Implementation_Headers} PARENT_SCOPE) add_subdirectory(Specializations) set(Specializations_Headers ${Specializations_Headers} PARENT_SCOPE) set(Specializations_Implementation_Headers ${Specializations_Implementation_Headers} PARENT_SCOPE) add_subdirectory(ExtraAlgorithms) set(ExtraAlgorithms_Headers ${ExtraAlgorithms_Headers} PARENT_SCOPE) set(ExtraAlgorithms_Implementation_Headers ${ExtraAlgorithms_Implementation_Headers} PARENT_SCOPE) add_subdirectory(Experimental) set(Experimental_Headers ${Experimental_Headers} PARENT_SCOPE) set(Experimental_Implementation_Headers ${Experimental_Implementation_Headers} PARENT_SCOPE) ``` -------------------------------- ### Compile HamiltonFastMarching for Python Interface Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Readme.md Compiles the HamiltonFastMarching library for use with Python. This process involves creating a 'bin' directory, navigating into it, and then using CMake to configure the build and Make to compile the project. This is necessary if you intend to modify the C++ code or build from source. ```console mkdir bin cd bin cmake ../HamiltonFastMarching/Interfaces/FileHFM make ``` -------------------------------- ### Include Implementation Subdirectory in CMake Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Headers/Experimental/CMakeLists.txt This CMake code snippet includes the 'Implementation' subdirectory into the build process. It then appends any headers defined within that subdirectory to the `Experimental_Implementation_Headers` variable, making them accessible in the parent scope. ```cmake add_subdirectory(Implementation) set(Experimental_Implementation_Headers ${Experimental_Implementation_Headers} PARENT_SCOPE) ``` -------------------------------- ### Set Project and Library Directories (CMake) Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/JMM_CPPLibs/CMakeLists.txt This CMake code snippet defines the project's root directory and establishes paths to various C++ library subdirectories. It uses `CMAKE_CURRENT_SOURCE_DIR` to set relative paths, ensuring the configuration is portable within the project structure. ```cmake set(PROJECT_DIR ${PROJECT_DIR} "${CMAKE_CURRENT_SOURCE_DIR}" PARENT_SCOPE) set(JMM_CPPLibs_Dir "${CMAKE_CURRENT_SOURCE_DIR}/JMM_CPPLibs") set(LinearAlgebra_Dir "${JMM_CPPLibs_Dir}/LinearAlgebra") set(Output_Dir "${JMM_CPPLibs_Dir}/Output") set(DataStructures_Dir "${JMM_CPPLibs_Dir}/DataStructures") set(Macros_Dir "${JMM_CPPLibs_Dir}/Macros") ``` -------------------------------- ### Configure CMake Headers for ExtraAlgorithms Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Headers/ExtraAlgorithms/CMakeLists.txt This CMake code snippet defines the header files to be included in the ExtraAlgorithms library. It lists various header files related to common stopping criteria, path length calculations, variations, time-dependent fields, Voronoi diagrams, and obstruction tests. The `PARENT_SCOPE` directive ensures these settings are available in the parent CMake scope. ```cmake set(ExtraAlgorithms_Headers ${CMAKE_CURRENT_SOURCE_DIR}/CommonStoppingCriteria.h ${CMAKE_CURRENT_SOURCE_DIR}/EuclideanPathLength.h ${CMAKE_CURRENT_SOURCE_DIR}/FirstVariation.h ${CMAKE_CURRENT_SOURCE_DIR}/TimeDependentFields.h ${CMAKE_CURRENT_SOURCE_DIR}/VoronoiDiagram.h ${CMAKE_CURRENT_SOURCE_DIR}/WallObstructionTest.h # ${CMAKE_CURRENT_SOURCE_DIR}/DynamicFactoring.h ${CMAKE_CURRENT_SOURCE_DIR}/StaticFactoring.h PARENT_SCOPE ) ``` -------------------------------- ### Define Optional Custom Executable Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/FileHFM/CMakeLists.txt Creates a custom executable named 'FileHFM_Custom' if the 'CustomExecutable' flag is set. It compiles 'FileHFM.cpp' and includes project headers, defining 'Custom' as a preprocessor macro. ```cmake # Optional custom executable if(CustomExecutable) add_executable(FileHFM_Custom "FileHFM.cpp" ${Project_Headers}) target_compile_definitions(FileHFM_Custom PRIVATE Custom) endif() ``` -------------------------------- ### Set Specializations Implementation Headers with CMake Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Headers/Specializations/Implementation/CMakeLists.txt This CMake command sets the specializations implementation headers for the current source directory. It ensures that header files like QuadLinLag2.hxx are available for compilation. The PARENT_SCOPE option makes the variable accessible in the parent scope. ```cmake set(Specializations_Implementation_Headers ${CMAKE_CURRENT_SOURCE_DIR}/QuadLinLag2.hxx PARENT_SCOPE ) ``` -------------------------------- ### Define Base Headers in CMake Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Headers/Base/CMakeLists.txt This CMake command defines a list of header files for the Base module. These headers are essential for the Hamilton-Fast-Marching algorithm and related grid functionalities. They are declared with PARENT_SCOPE to be accessible in parent directories. ```cmake set(Base_Headers ${CMAKE_CURRENT_SOURCE_DIR}/BaseGrid.h ${CMAKE_CURRENT_SOURCE_DIR}/PeriodicGrid.h ${CMAKE_CURRENT_SOURCE_DIR}/CommonStencil.h ${CMAKE_CURRENT_SOURCE_DIR}/EulerianStencil.h ${CMAKE_CURRENT_SOURCE_DIR}/Lagrangian2Stencil.h ${CMAKE_CURRENT_SOURCE_DIR}/Lagrangian3Stencil.h ${CMAKE_CURRENT_SOURCE_DIR}/HamiltonFastMarching.h ${CMAKE_CURRENT_SOURCE_DIR}/HFMInterface.h ${CMAKE_CURRENT_SOURCE_DIR}/GeodesicODESolver.h ${CMAKE_CURRENT_SOURCE_DIR}/GeodesicDiscreteSolver.h PARENT_SCOPE ) ``` -------------------------------- ### Define Output Headers (CMake) Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/JMM_CPPLibs/CMakeLists.txt This CMake code defines a list of header files for the Output library, which likely handles data serialization and I/O operations. It constructs the full paths to each header file using the `Output_Dir` variable. ```cmake set(Output_Headers ${Output_Dir}/BaseIO.h ${Output_Dir}/EnumToString.h ${Output_Dir}/FileIO.h ${Output_Dir}/IO.h ${Output_Dir}/MathematicaIO.h ${Output_Dir}/MathematicaIOExternC.h ${Output_Dir}/MexIO.h ${Output_Dir}/PythonIO.h PARENT_SCOPE ) ``` -------------------------------- ### Define Experimental Headers in CMake Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Headers/Experimental/CMakeLists.txt This CMake code snippet defines a list of experimental header files for the project. It uses the `set` command to assign header file paths to the `Experimental_Headers` variable, making them available within the current scope and parent scope. ```cmake set(Experimental_Headers ${CMAKE_CURRENT_SOURCE_DIR}/AsymmetricQuadratic.h ${CMAKE_CURRENT_SOURCE_DIR}/PrescribedCurvature2.h ${CMAKE_CURRENT_SOURCE_DIR}/RiemannLifted.h ${CMAKE_CURRENT_SOURCE_DIR}/Quaternionic.h ${CMAKE_CURRENT_SOURCE_DIR}/ReedsSheppAdaptive2.h ${CMAKE_CURRENT_SOURCE_DIR}/IsotropicBox.h ${CMAKE_CURRENT_SOURCE_DIR}/Differentiable.h ${CMAKE_CURRENT_SOURCE_DIR}/RollingBall.h ${CMAKE_CURRENT_SOURCE_DIR}/Seismic2.h ${CMAKE_CURRENT_SOURCE_DIR}/Seismic3.h ${CMAKE_CURRENT_SOURCE_DIR}/AlignedBillard.h ${CMAKE_CURRENT_SOURCE_DIR}/TTI.h ${CMAKE_CURRENT_SOURCE_DIR}/AsymRander.h PARENT_SCOPE ) ``` -------------------------------- ### Rebuilding Python Package Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/CompilationNotes.txt Instructions for forcing a full rebuild of the Python package by removing the build directory. This is necessary to ensure that changes in common.cmake are taken into account. ```bash rm -rf build ``` -------------------------------- ### Define Root Headers in CMake Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/FileVDQ/Headers/CMakeLists.txt This CMake code snippet defines a list of header files for the project, specifically including 'DispatchAndRun.h'. The 'PARENT_SCOPE' ensures these variables are available in the parent scope. ```cmake set(Root_Headers ${CMAKE_CURRENT_SOURCE_DIR}/DispatchAndRun.h PARENT_SCOPE ) ``` -------------------------------- ### Configure Elastica Model Parameters in Python Source: https://context7.com/mirebeau/hamiltonfastmarching/llms.txt This Python function configures parameters for Elastica, Reeds-Shepp, or Dubins models. It sets up grid dimensions, speed, curvature, seed points, and optional wall constraints. The output is a dictionary suitable for file-based input. ```python import numpy as np import math from subprocess import call def create_elastica_input(n, model, with_wall=False): """Configure Elastica/Reeds-Shepp/Dubins model parameters.""" input_data = { 'arrayOrdering': 'YXZ_RowMajor', # NumPy-compatible ordering 'eps': 0.1, # Relaxation parameter 'dims': np.array([n+1, n, 60]), # [space_x, space_y, angles] 'gridScale': 1.0/n, # Physical pixel size 'speed': 1, # Speed multiplier 'xi': 0.1, # Curvature radius # Seed: [x, y, theta] 'seeds': np.array([[0.5, 0.5, 1.0]]), # Endpoint tips with orientation 'tips': np.array([ [0.08, 0.08, 0.0], [0.25, 0.25, 0.0], [0.75, 0.75, 0.0], [0.92, 0.92, 0.0] ]), # Unoriented tips (optimal angle selected) 'tips_Unoriented': np.array([ [0.08, 0.92], [0.92, 0.08] ]), 'verbosity': 1, } if with_wall: # Vertical wall blocking part of domain input_data['walls'] = np.array([ [x == n//3 and y < 2*n/3 for x in range(n+1)] for y in range(n) ]) return input_data # Model options: 'ReedsShepp2', 'ReedsSheppForward2', 'Elastica2', 'Dubins2' model = 'Elastica2' n = 61 # Create input configuration input_config = create_elastica_input(n, model, with_wall=True) # Write input, execute, read output using FileIO helper # result = FileIO.WriteCallRead(input_config, f'FileHFM_{model}', binary_dir='./bin') # Process geodesic results # geodesics = np.vsplit(result['geodesicPoints'], # result['geodesicLengths'].astype(int).cumsum()[:-1]) ``` -------------------------------- ### Define Linear Algebra Headers (CMake) Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/JMM_CPPLibs/CMakeLists.txt This CMake code defines a list of header files for the Linear Algebra library. It constructs the full paths to each header file by prepending the `LinearAlgebra_Dir` variable, making it easy to include these headers in build targets. ```cmake set(LinearAlgebra_Headers ${LinearAlgebra_Dir}/HopfLaxMinimize.h ${LinearAlgebra_Dir}/AffineTransformType.h ${LinearAlgebra_Dir}/ArrayType.h ${LinearAlgebra_Dir}/AsymmetricQuadraticNorm.h ${LinearAlgebra_Dir}/BasisReduction.h ${LinearAlgebra_Dir}/DifferentiationType.h ${LinearAlgebra_Dir}/FriendOperators.h ${LinearAlgebra_Dir}/MatrixType.h ${LinearAlgebra_Dir}/PointBaseType.h ${LinearAlgebra_Dir}/PointType.h ${LinearAlgebra_Dir}/RanderNorm.h ${LinearAlgebra_Dir}/SquareCube.h ${LinearAlgebra_Dir}/SymmetricMatrixPair.h ${LinearAlgebra_Dir}/SymmetricMatrixType.h ${LinearAlgebra_Dir}/VectorPairType.h ${LinearAlgebra_Dir}/VectorType.h ${LinearAlgebra_Dir}/VoronoiReduction.h ${LinearAlgebra_Dir}/SeismicNorm.h ${LinearAlgebra_Dir}/AD2.h ${LinearAlgebra_Dir}/Pol1.h ${LinearAlgebra_Dir}/AnisotropicGeometry.h ${LinearAlgebra_Dir}/ComposedNorm.h ${LinearAlgebra_Dir}/TTINorm.h ${LinearAlgebra_Dir}/AsymRanderNorm.h ${LinearAlgebra_Dir}/DiagonalNorm.h PARENT_SCOPE ) ``` -------------------------------- ### Building Optional Custom Executable Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/MathematicaHFM/CMakeLists.txt Conditionally builds a shared library for a custom executable if the CustomExecutable variable is set. It links against standard C++ and Mathematica libraries and sets a compile definition for 'Custom'. ```cmake # Optional custom executable if(CustomExecutable) add_library(MathematicaHFM_Custom SHARED "MathematicaHFM.cpp" ${Project_Headers}) target_link_libraries(MathematicaHFM_Custom -Wl, -lstdc++ -lpthread -Wl, ${Mathematica_Libraries}) target_compile_definitions(MathematicaHFM_Custom PRIVATE Custom) endif() ``` -------------------------------- ### CMake Executable Definition Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/FileVDQ/CMakeLists.txt Defines the main executable for the FileVDQ project. It specifies the executable name as 'FileVDQ' and lists its source file ('FileVDQ.cpp') along with all the project headers. It also includes the project directory and current source directory in the include paths. ```cmake include_directories(${PROJECT_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) add_executable(FileVDQ "FileVDQ.cpp" ${Project_Headers}) ``` -------------------------------- ### Configure Specializations Headers in CMake Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Headers/Specializations/CMakeLists.txt This CMake code snippet configures the header files for specializations within the project. It uses the `set` command to define a list of header files, including common traits and curvature-related headers. The `PARENT_SCOPE` ensures these variables are available in parent CMake directories. ```cmake set( Specializations_Headers ${CMAKE_CURRENT_SOURCE_DIR}/CommonTraits.h ${CMAKE_CURRENT_SOURCE_DIR}/Isotropic.h ${CMAKE_CURRENT_SOURCE_DIR}/Curvature2.h ${CMAKE_CURRENT_SOURCE_DIR}/Curvature3.h ${CMAKE_CURRENT_SOURCE_DIR}/Riemannian.h ${CMAKE_CURRENT_SOURCE_DIR}/QuadLinLag2.h ${CMAKE_CURRENT_SOURCE_DIR}/QuadLinLag2.h PARENT_SCOPE ) ``` -------------------------------- ### Define Model-Specific Executables Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/FileHFM/CMakeLists.txt Generates executables for each model specified in ModelNames. It creates a target named 'FileHFM_' and defines the model name as a preprocessor macro. ```cmake # Single model executables foreach(model ${ModelNames}) add_executable(FileHFM_${model} "FileHFM.cpp") target_compile_definitions(FileHFM_${model} PRIVATE ModelName=${model}) endforeach(model) ``` -------------------------------- ### Building Shared Libraries for Models Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/MathematicaHFM/CMakeLists.txt Defines shared libraries for different models specified in the ModelNames variable. It links against standard C++ libraries and Mathematica libraries, and sets a compile definition for the specific model name. ```cmake # Single model executables foreach(model ${ModelNames}) add_library(MathematicaHFM_${model} SHARED "MathematicaHFM.cpp") target_link_libraries(MathematicaHFM_${model} -Wl, -lstdc++ -lpthread -Wl, ${Mathematica_Libraries}) target_compile_definitions(MathematicaHFM_${model} PRIVATE ModelName=${model}) endforeach(model) ``` -------------------------------- ### CMake: Define Root Headers Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Headers/CMakeLists.txt This CMake snippet defines the root header files for the project. It uses the set command to add header files from the current source directory to a variable named Root_Headers, making them available in the parent scope. ```cmake set(Root_Headers ${CMAKE_CURRENT_SOURCE_DIR}/DispatchAndRun.h PARENT_SCOPE ) ``` -------------------------------- ### Compute Anisotropic Shortest Paths in MATLAB Source: https://context7.com/mirebeau/hamiltonfastmarching/llms.txt This MATLAB code computes anisotropic shortest paths using the Riemannian Fast Marching method. It involves defining a dual metric tensor field, grid parameters, seed points, and geodesic endpoints. The output is visualized as a distance map with overlaid geodesics. ```matlab clear input; nx = 81; ny = 83; nGeo = 8; % Create coordinate grid (MATLAB uses y,x,z ordering) [x, y] = meshgrid(1:nx, 1:ny); % Define dual metric tensor field % Format: [xx; xy; yy] symmetric matrix components input.dualMetric = zeros([3, ny, nx]); input.dualMetric(1,:,:) = 1; % xx input.dualMetric(2,:,:) = 0.5*((x>nx/2)-(x0.75*ny); % yy % Grid parameters input.origin = [0; 0]; input.gridScale = 1/nx; input.dims = [nx; ny]; % Seed point for distance computation input.seeds = [0.5; 0.5]; % Define geodesic endpoints on regular grid epsGeo = 1/nGeo; arrGeo = (epsGeo/2):epsGeo:(1-epsGeo/2); [xTips, yTips] = meshgrid(arrGeo, arrGeo); input.tips = [reshape(xTips, 1, []); reshape(yTips, 1, [])]; input.exportValues = 1; % Run fast marching output = MatlabHFM_Riemann2(input); % Visualize results imagesc(output.values); colorbar; title('Riemannian Distance Map'); % Extract and plot geodesics geodesics = mat2cell(output.geodesicPoints, 2, output.geodesicLengths); hold on; for i = 1:length(geodesics) geo = geodesics{i}; rescaled = RescaledCoords(geo, input.origin, [input.gridScale; input.gridScale]); plot(rescaled(1,:), rescaled(2,:), 'r-', 'LineWidth', 1.5); end hold off; ``` -------------------------------- ### CMake Executable Definition for Models Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/MatlabHFM/CMakeLists.txt Defines executables for each model specified in the 'ModelNames' variable. Each executable is built from 'MatlabHFM.cpp' and has a preprocessor definition 'ModelName' set to the corresponding model name. ```cmake foreach(model ${ModelNames}) add_executable(NotMatlabHFM_${model} "MatlabHFM.cpp") target_compile_definitions(NotMatlabHFM_${model} PRIVATE ModelName=${model}) endforeach(model) ``` -------------------------------- ### Set Project Directory in CMake Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/FileVDQ/Headers/CMakeLists.txt This CMake code snippet sets the project directory variable. It appends the current source directory to the existing PROJECT_DIR, making it accessible in the parent scope. ```cmake set(PROJECT_DIR ${PROJECT_DIR} "${CMAKE_CURRENT_SOURCE_DIR}" PARENT_SCOPE) ``` -------------------------------- ### Compute Collision-Free Paths with Obstacles in MATLAB Source: https://context7.com/mirebeau/hamiltonfastmarching/llms.txt This MATLAB code computes collision-free paths in curvature-penalized models, incorporating wall obstacles. It loads an obstacle map from an image, configures the grid, and uses unoriented seeds and tips for navigation. The output visualizes the distance map and plotted geodesics, avoiding obstacles. ```matlab clear input; modelName = 'ReedsShepp2'; % Model parameters input.xi = 0.7; % Curvature radius input.eps = 0.1; % Relaxation input.speed = 1; % For ReedsShepp2: enable projective mode (identifies opposite directions) nTheta = 60; if strcmp(modelName, 'ReedsShepp2') input.projective = 1; nTheta = nTheta / 2; end % Load obstacle map from image im = imread('centre_pompidou_800x546.png'); obstacles = ((im(:,:,1)==255) | (im(:,:,3)==255)) & (im(:,:,2)==0); input.walls = 1.0 - double(obstacles); % Grid configuration gridScale = 1.0/90; input.origin = [0; 0]; input.gridScale = gridScale; input.dims = [fliplr(size(im(:,:,1)))'; nTheta]; % Unoriented seeds (optimal orientation selected automatically) input.seeds_Unoriented = [80, 80; 170, 290] * gridScale; % Unoriented tips input.tips_Unoriented = [ 369.4, 252.2, 285.0, 418.6, 479.8, 687.2, 745.8; 482.5, 354.5, 478.0, 488.0, 487.5, 478.0, 502.5 ] * gridScale; % Limit geodesic computation volume input.geodesicVolumeBound = 12; input.exportValues = 1; % Run solver output = eval(['MatlabHFM_' modelName '(input)']); % Visualize results dist = min(output.values, [], 3); dist(isinf(dist)) = 0; imagesc(dist); colorbar; % Plot geodesics geodesics = mat2cell(output.geodesicPoints_Unoriented, 3, output.geodesicLengths_Unoriented); hold on; for i = 1:length(geodesics) geo = geodesics{i}; rescaled = RescaledCoords(geo(1:2,:), input.origin, [input.gridScale; input.gridScale]); plot(rescaled(1,:), rescaled(2,:), 'g-', 'LineWidth', 2); end hold off; ``` -------------------------------- ### CMake Custom Executable Build with pybind11 Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/PythonHFM/CMakeLists.txt Conditionally defines a pybind11 module for a custom executable if the `CustomExecutable` variable is set. It specifies the source file and project headers, and sets compile definitions to identify it as a custom build. This allows for a separate Python interface for custom HFM functionalities. ```cmake if(CustomExecutable) pybind11_add_module(PythonHFM_Custom src/main.cpp ${Project_Headers}) target_compile_definitions(HFM_Custom PRIVATE Custom PythonModuleName=PythonHFM_Custom) # Fixes an issue with pybind11 on clang, see https://github.com/pybind/pybind11/issues/1604 #if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang") # target_compile_options(HFM_Custom INTERFACE -fsized-deallocation) #endif() endif() ``` -------------------------------- ### Define Macros Headers (CMake) Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/JMM_CPPLibs/CMakeLists.txt This CMake code defines a list of header files for the Macros library, which likely contains utility macros for C++ development. It constructs the full paths to each header file using the `Macros_Dir` variable. ```cmake set(Macros_Headers ${Macros_Dir}/Expand.h ${Macros_Dir}/PPCat.h ${Macros_Dir}/String.h ${Macros_Dir}/Exception.h ${Macros_Dir}/ExportArrow.h ${Macros_Dir}/RedeclareTypes.h PARENT_SCOPE ) ``` -------------------------------- ### Define Data Structures Headers (CMake) Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/JMM_CPPLibs/CMakeLists.txt This CMake code defines a list of header files for the Data Structures library. It specifies headers for various container types and accessors, constructing their full paths using the `DataStructures_Dir` variable. ```cmake set(DataStructures_Headers ${DataStructures_Dir}/CappedVector.h ${DataStructures_Dir}/RangeAccessor.h ${DataStructures_Dir}/ShallowMap.h ${DataStructures_Dir}/VirtualConstIterator.h PARENT_SCOPE ) ``` -------------------------------- ### CMake: Set Project Directory Variable Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Headers/CMakeLists.txt This CMake snippet sets a project directory variable. It appends the current source directory to an existing PROJECT_DIR variable, ensuring the project's root directory is correctly defined and available in the parent scope. ```cmake set(PROJECT_DIR ${PROJECT_DIR} "${CMAKE_CURRENT_SOURCE_DIR}" PARENT_SCOPE) ``` -------------------------------- ### CMake Header and Source Grouping Source: https://github.com/mirebeau/hamiltonfastmarching/blob/master/Interfaces/FileVDQ/CMakeLists.txt Defines and groups header files for the FileVDQ project. It aggregates headers from various sources like DataStructures, LinearAlgebra, Output, and Macros, and then organizes them into logical groups within the CMake build system for better source management. ```cmake set(Project_Headers ${Root_Headers} ${DataStructures_Headers} ${LinearAlgebra_Headers} ${Output_Headers} ${Macros_Headers} ) #source_group("Headers" FILES ${Project_Headers}) source_group("DataStructures" FILES ${DataStructures_Headers}) source_group("Macros" FILES ${Macros_Headers}) source_group("LinearAlgebra" FILES ${LinearAlgebra_Headers}) source_group("Output" FILES ${Output_Headers}) ``` -------------------------------- ### Python Interface: Compute Isotropic 2D Distance Map Source: https://context7.com/mirebeau/hamiltonfastmarching/llms.txt Computes distance maps using the isotropic metric in 2D via direct Python bindings. This snippet initializes the HFM interface, configures grid dimensions and a spatially-varying speed field, sets seed points, and runs the fast marching algorithm. It then retrieves and prints the computed distance values. ```python import numpy as np from HFMpy import HFM_Isotropic2 # Initialize the HFM interface hfm = HFM_Isotropic2.HFMIO() # Configure grid dimensions (width x height) n = 100 hfm.set_array("dims", np.array([2*n, n]).astype(float)) hfm.set_scalar("gridScale", 1.0/n) # Define spatially-varying speed field x, y = np.meshgrid(np.linspace(0, 2, 2*n), np.linspace(0, 1, n)) speed = np.exp(-(x**2 + y**2)) # Gaussian speed falloff hfm.set_array("speed", speed) # Set seed point(s) for front propagation hfm.set_array("seeds", np.array([[0.5, 0.5]])) # Configure output options hfm.set_scalar("exportValues", 1) hfm.set_scalar("verbosity", 2) # Run the fast marching algorithm hfm.run() # Retrieve computed distance values values = hfm.get_array("values") print(f"Distance map shape: {values.shape}") print(f"Max distance: {values.max():.4f}") ```