Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions src/c_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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");
Expand Down
11 changes: 6 additions & 5 deletions src/python/codegenerator.py
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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(
Expand Down Expand Up @@ -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()

Expand Down