diff --git a/CMakeLists.txt b/CMakeLists.txt index f763c5e..104eabe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,8 @@ add_custom_command( set(SPDLOG_ACTIVE_LEVEL "SPDLOG_LEVEL_OFF" CACHE STRING "Set the logging level (e.g. SPDLOG_LEVEL_DEBUG, or SPDLOG_LEVEL_OFF)") -add_compile_options(-DSPDLOG_ACTIVE_LEVEL=${SPDLOG_ACTIVE_LEVEL}) +add_compile_options(-DSPDLOG_ACTIVE_LEVEL=${SPDLOG_ACTIVE_LEVEL} -DMODULE_API_EXPORTS) + # Library diff --git a/CMakeLists.txt.in b/CMakeLists.txt.in index 46d3e61..5c472b3 100644 --- a/CMakeLists.txt.in +++ b/CMakeLists.txt.in @@ -28,7 +28,7 @@ ExternalProject_Add(Catch2 ) ExternalProject_Add(eigen - DOWNLOAD_COMMAND URL http://bitbucket.org/eigen/eigen/get/3.3.7.tar.bz2 + DOWNLOAD_COMMAND URL https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.bz2 DOWNLOAD_DIR "${EXTERNAL_PROJECTS_DIR}" DOWNLOAD_NAME "eigen-3.3.7.tar.bz2" SOURCE_DIR "${EXTERNAL_PROJECTS_DIR}/eigen" diff --git a/Readme.md b/Readme.md index eeb5ecb..9071984 100644 --- a/Readme.md +++ b/Readme.md @@ -15,6 +15,7 @@ The corresponding code is in `src/matlab/example.m`. ## Build instructions Build requirements are a C++14 compiler, _cmake_ and _Python3_ for code generation. +_Python3_ needs to have `sympy >= 1.10.1` installed. ``` git clone git@github.com:RobMa/circle_fit.git cd circle_fit diff --git a/src/c_interface.cpp b/src/c_interface.cpp index 3e8fa2f..2cae115 100644 --- a/src/c_interface.cpp +++ b/src/c_interface.cpp @@ -6,9 +6,19 @@ using namespace circle_fit; +#ifdef _WIN32 +# ifdef MODULE_API_EXPORTS +# define MODULE_API __declspec(dllexport) +# else +# define MODULE_API __declspec(dllimport) +# endif +#else +# define MODULE_API +#endif + extern "C" { -int estimate_circle_taubin(double x[], double y[], int length, double *out_x, double *out_y, double *out_r) +MODULE_API int estimate_circle_taubin(double x[], double y[], int length, double *out_x, double *out_y, double *out_r) { if(length < 3 || x==nullptr || y == nullptr || out_x == nullptr || out_y == nullptr || out_r == nullptr) { SPDLOG_ERROR("Invalid arguments"); @@ -26,7 +36,7 @@ int estimate_circle_taubin(double x[], double y[], int length, double *out_x, do return true; } -int estimate_circle_lm(double x[], double y[], int length, double rxy_init[3], double rxy_out[3]) +MODULE_API int estimate_circle_lm(double x[], double y[], int length, double rxy_init[3], double rxy_out[3]) { if(length < 3 || x==nullptr || y == nullptr || rxy_init == nullptr || rxy_out == nullptr) { SPDLOG_ERROR("Invalid arguments"); @@ -46,7 +56,7 @@ int estimate_circle_lm(double x[], double y[], int length, double rxy_init[3], d return true; } -int estimate_circle(double x[], double y[], int length, double *out_x, double *out_y, double *out_r) +MODULE_API int estimate_circle(double x[], double y[], int length, double *out_x, double *out_y, double *out_r) { if(length < 3 || x==nullptr || y == nullptr || out_x == nullptr || out_y == nullptr || out_r == nullptr) { SPDLOG_ERROR("Invalid arguments"); @@ -61,7 +71,7 @@ int estimate_circle(double x[], double y[], int length, double *out_x, double *o return true; } -int estimate_circle_lm_trace(double x[], double y[], int length, double rxy_init[3], int *out_numiters, double **out_x, double **out_y, double **out_r, double **out_grad_norm, double **out_mse) +MODULE_API int estimate_circle_lm_trace(double x[], double y[], int length, double rxy_init[3], int *out_numiters, double **out_x, double **out_y, double **out_r, double **out_grad_norm, double **out_mse) { if(length < 3 || x==nullptr || y == nullptr || rxy_init == nullptr || out_numiters == nullptr || out_x == nullptr || out_y == nullptr || out_r == nullptr || out_grad_norm == nullptr || out_mse == nullptr) { SPDLOG_ERROR("Invalid arguments"); diff --git a/src/python/codegenerator.py b/src/python/codegenerator.py index b0a798a..d7415fd 100644 --- a/src/python/codegenerator.py +++ b/src/python/codegenerator.py @@ -1,11 +1,11 @@ #!/usr/bin/python3 import sympy as sp -from sympy.printing.codeprinter import Assignment -from sympy.printing.cxxcode import CXX17CodePrinter +from sympy.codegen.ast import Assignment +from sympy.printing.cxx import CXX17CodePrinter class CxxMatrixPrinter(CXX17CodePrinter): - def _print_list(self, list_of_exprs): + def _print_List(self, list_of_exprs): if all(isinstance(x, sp.Eq) for x in list_of_exprs): list_of_lhs = [x.lhs for x in list_of_exprs] list_of_rhs = [x.rhs for x in list_of_exprs] @@ -19,8 +19,8 @@ def _print_list(self, list_of_exprs): lines.append(self._print(ass)) return '\n'.join(lines) -from sympy.printing.ccode import _as_macro_if_defined -from sympy.printing.ccode import precedence +from sympy.printing.c import _as_macro_if_defined +from sympy.printing.c import precedence class EigenMatrixPrinter(CxxMatrixPrinter): def _print_MatrixElement(self, expr): return "{0}({1},{2})".format( @@ -52,6 +52,7 @@ def _traverse_matrix_indices(self, mat): def codegen(expressions, template_path, output_path): p = EigenMatrixPrinter() p._print_Pow + with open(template_path, 'r') as f: template = f.read()